How do you skip unchanged work to make repeat runs fast?
IntermediateProductionPerformance and Scale
Answer
Use idempotent modules (they check state quickly), creates/removes on commands, and when guards based on a version marker so expensive steps happen only on change.
- ansible.builtin.command: cat /opt/app/.version
register: ver
changed_when: false
failed_when: false
- ansible.builtin.include_tasks: upgrade.yml
when: ver.rc != 0 or ver.stdout | trim != app_version
Better: use tags to run targeted subsets, --limit to affected hosts, and fact caching. Avoid always-changed tasks, because they also trigger handlers and cost restarts.
More on Performance and Scale
Why can Ansible be slower than a shell script for 100 servers, and what dominates the time?BeginnerHow do you choose the `forks` value?BeginnerWhat is SSH pipelining and why does it help?BeginnerWhich SSH settings matter for performance and stability?IntermediateHow do you find out which tasks are slow?BeginnerHow do you reduce the cost of fact gathering?Intermediate