Interview Prep/Ansible/Rolling Updates, Delegation and Safe Deployments

What go wrong when delegating to localhost?

AdvancedProductionRolling Updates, Delegation and Safe Deployments
Answer
  • become: true at the play level makes the localhost task try sudo on the controller, which fails or prompts for a password. Set become: false on the task.
  • Group variables meant for remote hosts leak onto the delegated task. ansible_python_interpreter: /usr/bin/python3 in group_vars/all can point at a Python without boto3, and ansible_user or ansible_ssh_private_key_file can 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: local applies only if delegating to the implicit localhost; if localhost is defined in the inventory, check its connection variables.

A dedicated play with hosts: localhost is cleaner when no per-host data is needed.

All Ansible questions Roadmap: Ansible

More on Rolling Updates, Delegation and Safe Deployments