When and how do you use `delegate_to: localhost`?
BeginnerProductionRolling Updates, Delegation and Safe Deployments
Answer
For actions that operate through an API from the controller and are not tied to the host's OS: calling a cloud API, a webhook, a monitoring silence, or DNS update.
- ansible.builtin.uri:
url: "https://monitoring.example.com/api/silences"
method: POST
body_format: json
body: { host: "{{ inventory_hostname }}", duration: "30m" }
delegate_to: localhost
become: false
The task runs once per host, so add run_once: true when it is a single, global action. Also set become: false, which otherwise inherits the play's setting.
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