

Fixing 'UNREACHABLE' SSH error when running Ansible playbooks ag...
source link: https://www.tuicool.com/articles/hit/vERn6vF
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Ubuntu 16.04 and 18.04 (and likely future versions) often don't have Python 2 installed by default. Sometimes Python 3 is installed, available at /usr/bin/python3
, but for many minimal images I've used, there's no
preinstalled Python at all.
Therefore, when you run Ansible playbooks against new VMs running Ubuntu, you might be greeted with the following error:
TASK [Gathering Facts] ************************************************************************************************* fatal: [example.com]: UNREACHABLE! => {"changed": false, "msg": "SSH Error: data could not be sent to remote host "example.com". Make sure this host can be reached over ssh", "unreachable": true}
It's easy enough to work around this problem, though! If you have the ability to build your own base images (e.g. AMIs on AWS), you can just make sure /usr/bin/python
is already installed on the image. And if only python3
is present, you can set ansible_python_interpreter=/usr/bin/python3
in your inventory for the affected hosts. If you can't do either of these things, the best way is to:
gather_facts raw setup
Here's a scaffold playbook I usually use on any Ubuntu 16 or 18 hosts:
--- - hosts: all gather_facts: no pre_tasks: - name: Install Python if not already present. raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal) changed_when: False - name: Gather facts after Python is definitely present. setup: roles: ...
This way, you'll still have access to host facts, and you won't get cryptic errors about Ansible not being able to connect to the host via SSH.
Recommend
-
84
README.md Ansible Jupyter Kernel
-
38
Ansible allows us to automate the configuration management of systems and add any number of clients as we wish. Have you ever wondered how complex this can get? Have you ever wondered how long and confusing the playbooks...
-
56
README.rst ceph-ansible Ansible playbooks for Ceph, the distributed filesystem. Please refer to our hosted documentation here:
-
16
Introduction Sovereign is a set of Ansible playbooks that you can use to build and maintain your own
-
14
Ansible Error Fixing ControlPath Too Long Error Dec 29, 2016 If you get the ansible error ControlPath Too Long Error then all you need to do is create an ansible.cfg file in the directory where you ru...
-
12
Tutorial How To Create and Use Templates in Ansible Playbooks Ubuntu
-
6
Tutorial How To Define and Use Handlers in Ansible Playbooks Ubuntu
-
10
Tutorial How To Install and Manage System Packages in Ansible Playbooks Ubuntu
-
5
Tutorial How To Use Loops in Ansible Playbooks Configuration Management
-
5
Tutorial Understanding Privilege Escalation in Ansible Playbooks Configuration Management
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK