Sometimes, you need to run more commands if one command causes a change on the remote system. Good examples would be:
- You update a systemd service file. If the file was actually changed, then you need to restart the service.
- You update the configuration for a service (like say /etc/dhcp/dhcpd.conf). If that file was changed, you need to restart the service.
Is there a way to do this with files.put? Ideally you could write code like:
changed = files.put(src='files/dhcpd.conf', dest='/etc/dhcp/dhcpd.conf')
if changed:
systemd.service(service='isc-dhcp-server', running=True, restarted=True)
In pyinfra, every operation returns an object that has a
changedproperty that does what you want: