How do you perform a one-time action during a multi-host play?
IntermediateProductionRolling Updates, Delegation and Safe Deployments
Answer
run_once: true, usually with delegate_to for an action on a specific host.
- name: Clear CDN cache after the whole batch
ansible.builtin.uri:
url: https://cdn.example.com/purge
method: POST
delegate_to: localhost
run_once: true
Remember that with serial, run_once runs once per batch, not once per play. To run only at the very end, put the action in a later play (hosts: localhost) or use when: inventory_hostname == ansible_play_hosts_all[-1].
More on Rolling Updates, Delegation and Safe Deployments
How do you do a rolling update with Ansible?BeginnerWhat forms can `serial` take?IntermediateShow the standard pattern for a zero-downtime rolling deploy behind a load balancer.IntermediateWhy do you add a health check inside the deployment play?BeginnerHow do `any_errors_fatal` and `max_fail_percentage` help a rollout?BeginnerHow do you do a canary deployment?Intermediate