What go wrong when delegating to localhost?
AdvancedProductionRolling Updates, Delegation and Safe Deployments
Answer
become: trueat the play level makes the localhost task trysudoon the controller, which fails or prompts for a password. Setbecome: falseon the task.- Group variables meant for remote hosts leak onto the delegated task.
ansible_python_interpreter: /usr/bin/python3ingroup_vars/allcan point at a Python withoutboto3, andansible_useroransible_ssh_private_key_filecan change how localhost is reached. - The controller's Python needs the libraries (
boto3,kubernetes), not the target's. With execution environments, they must be in the image. connection: localapplies only if delegating to the implicit localhost; iflocalhostis defined in the inventory, check its connection variables.
A dedicated play with hosts: localhost is cleaner when no per-host data is needed.
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