A `delegate_to: localhost` task fails with `/usr/bin/python3.9: No such file or directory`
AdvancedTroubleshootingVariables, Facts and Precedence Problems
Answer
Likely causes → localhost is defined explicitly in the inventory, so it belongs to all and inherits ansible_python_interpreter: /usr/bin/python3.9 from group_vars/all.yml. That path exists on the targets, but not on the controller or in the execution environment.
Diagnose → ansible-inventory --host localhost --vars | grep python
Fix →
# host_vars/localhost.yml
ansible_connection: local
ansible_python_interpreter: "{{ ansible_playbook_python }}"
Or remove localhost from the inventory and rely on implicit localhost, which already uses ansible_playbook_python.
Prevent → Set the interpreter per OS group (rhel8, ubuntu), not in all.
More on Variables, Facts and Precedence Problems
Variables in `group_vars/webservers.yml` are silently ignoredBeginnerYou set `nginx_port: 8443` in inventory `group_vars`, but the role still uses `80`Intermediate`set_fact: release_tag=v2` runs, but later tasks still see `v1`Intermediate`'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_default_ipv4'` when templating `hostvars['db01']`Intermediate`'ansible_eth0' is undefined` on new cloud instancesBeginnerFacts like `ansible_hostname` became undefined after someone changed `ansible.cfg`Intermediate