Error Codes Wiki

Ansible Playbook Errors — Task Failures, SSH Connectivity, and Variable Resolution Issues

Warningcommand

Overview

Fix Ansible playbook execution errors including SSH connection failures, undefined variable errors, privilege escalation issues, and module execution failures.

Key Details

  • Ansible connects to remote hosts via SSH and executes modules to achieve desired state
  • Common errors: 'unreachable', 'FAILED!', 'undefined variable', 'permission denied'
  • SSH key authentication is preferred over password authentication for Ansible
  • become: yes (sudo) requires the remote user to have passwordless sudo or the become password
  • Ansible uses Python on remote hosts — missing Python causes module execution failures

Common Causes

  • SSH connection to remote host failing — wrong IP, port, key, or network connectivity
  • Remote host missing Python interpreter required by Ansible modules
  • Variable not defined or not accessible in the current scope (role, play, task)
  • Sudo password not provided when become: yes requires password authentication

Steps

  1. 1Test SSH connectivity: 'ansible all -m ping -i inventory.ini' to verify all hosts are reachable
  2. 2Check SSH manually: 'ssh -i /path/to/key user@host' to verify key authentication works
  3. 3Set Python interpreter: add 'ansible_python_interpreter=/usr/bin/python3' in inventory or group_vars
  4. 4Debug variables: add 'debug: var=my_variable' task to see the variable value during execution
  5. 5Run with verbose: 'ansible-playbook playbook.yml -vvv' for detailed execution output

Tags

ansibleplaybooksshautomationconfiguration

More in Command

Frequently Asked Questions

Check: 1) SSH from your machine to the host works manually. 2) Inventory file has the correct IP/hostname. 3) SSH key or password is correctly configured. 4) Port 22 is open on the remote host.