Thanks for the reply!
I’m not sure there’s any way to persist state between program executions except by saving that state offline like you are doing.
Yes, I recognize that. That’s why I labeled this an enhancement request, and why I brought the discussion here, rather than just posting a bug report. I’m guessing either other people have run into the same problem and found better solutions, or have the same need of an enhancement.
That being said, I think the goal of ansible is to write your play in a way that sets the state of a system accordingly. For instance, use a handler that only gets invoked when a task is changed. If apache hasn’t been changed in any way, the ‘restart apache’ handler doesn’t run.
Yes, and I’m tossing in a notion that part of the “system state” that ansible stores is persistent variables whose values persist until a playbook has run to successful completion. Since Ansible cannot be “transactional” in its operation, registering variables always has failure modes. The smaller the range of those failure modes, the better off the ecosystem will be.
Some of Ansible’s operations (such as a service restart, or command operations) may leave the target system in exactly the same configured / operational state, but they do have side-effects (like dropping connections, momentarily). Those side effects may be worth avoiding…
If you’re storing state offline, you’ll have to write your play to check that data store for state. You might as well write the play in a way that checks the target state before taking action, if needed.
As I indicated in my examples, that’s exactly what I do. However, that makes my playbooks more complicated, more error prone, and harder to understand. And since I don’t think I’m the only one with this problem, it strikes me that it could work well as an enhancement to Ansible itself.