Error Codes Wiki

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

Warningcommand

About Ansible Playbook Errors

Fix Ansible playbook execution errors including SSH connection failures, undefined variable errors, privilege escalation issues, and module execution failures. This guide covers everything you need to know about this topic, including common causes, step-by-step solutions, and answers to frequently asked questions.

Here are the key things to understand: 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. Understanding these fundamentals will help you diagnose and resolve this issue more effectively.

The most common reasons this occurs include: 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. Identifying the root cause is the first step toward finding the right solution.

To resolve this, follow these recommended steps: Test SSH connectivity: 'ansible all -m ping -i inventory.ini' to verify all hosts are reachable. Check SSH manually: 'ssh -i /path/to/key user@host' to verify key authentication works. Set Python interpreter: add 'ansible_python_interpreter=/usr/bin/python3' in inventory or group_vars. Debug variables: add 'debug: var=my_variable' task to see the variable value during execution. Run with verbose: 'ansible-playbook playbook.yml -vvv' for detailed execution output. If these steps do not resolve the issue, consider consulting additional resources or a qualified professional.

This article is part of our Linux Error Codes collection on Error Codes Wiki. We provide comprehensive, up-to-date information to help you find solutions quickly.

Quick Answer

Why does Ansible say the host is unreachable?

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.

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.