AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,100 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example" published by Apress, and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Ansible 'Connection failed' Error: Fix SSH & WinRM Issues (Guide) — Video Tutorial

Fix Ansible connection failed errors. Troubleshoot SSH timeouts, authentication failures, WinRM issues, and unreachable hosts with step-by-step solutions.

Watch Video

Watch "Ansible 'Connection failed' Error: Fix SSH & WinRM Issues (Guide)" on YouTube

What You'll Learn

Full Tutorial Content

Today we're going to talk about Ansible troubleshooting and specifically about connection failed errors. I'm Luca Berton and welcome to today's episode of the Ansible Pilot. The root cause of these types of problems rely directly on the networking. So jump on the ssh command line and troubleshoot like an ssh connection error. In the following example the `Operation timed out` was caused by the virtual machine that doesn’t have network card enabled. Links - [Network Debug and Troubleshooting Guide](https://docs.ansible.com/ansible/latest/network/user_guide/network_debug_troubleshooting.html) Demo The best way of talking about Ansible troubleshooting is to jump in a live Playbook to show you practically the connection failed error and how to solve it! Error Ansible relies on an SSH connection to the target machine. Let's try manually: ```bash $ ssh username@hostname Failed to connect to the host via ssh: ssh: connecto to host hostname port 22: Operation timed out ``` You need to verify the network connection between the source and the target machine. Fix Once the network connection is fixed you could successfully connect to the target machine. ```bash $ ssh username@hostname username@hostname:~$ ``` [code with ❤️ in GitHub](https://github.com/lucab85/ansible-pilot/tree/master/troubleshooting) Conclusion Now you know better how to troubleshoot the most common Ansible error about connection failure. Common Connection Errors and Fixes Error 1: Operation timed out ``` fatal: [server]: UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: ssh: connect to host 192.168.1.100 port 22: Operation timed out"} ``` **Causes:** - Target machine is powered off or unreachable - Firewall blocking port 22 - Wrong IP address in inventory - Network routing issue **Fix checklist:** ```bash 1. Can you reach the host at all? ping 192.168.1.100 2. Is SSH port open? nc -zv 192.168.1.100 22 3. Can you SSH manually? ssh user@192.168.1.100 4. Check firewall on target (if you have console access) sudo firewall-cmd --list-ports # RHEL/CentOS sudo ufw status # Ubuntu/Debian ``` Error 2: Permission denied (publickey,password) ``` fatal: [server]: UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: user@192.168.1.100: Permission denied (publickey,password)."} ``` **Causes:** - Wrong username - SSH key not copied to target - SSH key passphrase not provided - `PasswordAuthentication no` in sshd_config **Fix:** ```bash Copy your SSH key to the target ssh-copy-id user@192.168.1.100 Or specify the key in inventory inventory.yml all: hosts: server: ansible_host: 192.168.1.100 ansible_user: devops ansible_ssh_private_key_file: ~/.ssh/id_rsa ``` Error 3: Host key verification failed ``` fatal: [server]: UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: Host key verification failed."} ``` **Fix (choose one):** ```bash Option 1: Accept the host key manually ssh user@192.168.1.100 #

About This Tutorial

Read the full written article: Ansible 'Connection failed' Error: Fix SSH & WinRM Issues (Guide)

Topics Covered

Related Video Tutorials