To troubleshoot unreachable hosts in Ansible, follow these steps:
-
Check Host Connectivity:
- Use
pingto verify basic network connectivity:ping target_host
- Use
-
Verify SSH Access:
- Try to SSH into the host manually:
ssh username@target_host - If you cannot connect, check for issues such as incorrect IP address, hostname, or SSH configuration.
- Try to SSH into the host manually:
-
Check Firewall Settings:
- Ensure that the firewall on the target host allows SSH connections (default port 22):
sudo ufw status - If necessary, allow SSH through the firewall:
sudo ufw allow ssh
- Ensure that the firewall on the target host allows SSH connections (default port 22):
-
Inspect Ansible Inventory:
- Verify that the host is correctly listed in your Ansible inventory file and that the correct connection parameters are specified.
-
Review SSH Configuration:
- Check the SSH configuration file on the target host (
/etc/ssh/sshd_config) for any restrictions, such asAllowUsersorDenyUsers.
- Check the SSH configuration file on the target host (
-
Check Host Key Verification:
- If you see a message about host key verification, you may need to remove the old key from
~/.ssh/known_hosts:ssh-keygen -R target_host
- If you see a message about host key verification, you may need to remove the old key from
-
Use Verbose Mode:
- Run the Ansible command with increased verbosity to get more details about the connection attempt:
ansible all -m ping -vvv
- Run the Ansible command with increased verbosity to get more details about the connection attempt:
-
Inspect Logs:
- Check the SSH logs on the target host for any error messages:
sudo tail -f /var/log/auth.log
- Check the SSH logs on the target host for any error messages:
By following these steps, you should be able to identify and resolve issues that are causing hosts to be unreachable in Ansible.
