Bobcares

Ansible Error Unreachable | How To Fit It?

by | Mar 4, 2023

While using Ansible Playbook, have you encountered the error “unreachable?” then this article is for you. Bobcares, as a part of our Server Management Services, offers solutions to every query that comes our way.

Ansible Playbook Error “Unreachable”

Ansible identifies a host as “UNREACHABLE” and removes it from the list of active hosts for the run if it is unable to establish a connection. We can ignore a task failure due to the host instance being ‘UNREACHABLE’ with the ignore_unreachable keyword. The ignore_unreachable the keyword is a boolean that enables us to continue the play despite task failures brought on by an unreachable host. This is helpful for groups of volatile/ephemeral hosts but has no effect on other task errors. Ansible disregards the task failures but keeps running subsequent tasks against the unavailable host. As an example, at the task level:

- name: This executes, fails, and the failure is ignored
  ansible.builtin.command: /bin/true
  ignore_unreachable: true

- name: This executes, fails, and ends the play for this host
  ansible.builtin.command: /bin/true

At the Ansible playbook level:

- hosts: all
  ignore_unreachable: true
  tasks:
  - name: This executes, fails, and the failure is ignored
    ansible.builtin.command: /bin/true

  - name: This executes, fails, and ends the play for this host
    ansible.builtin.command: /bin/true
    ignore_unreachable: false

We can use meta: clear_host_errors to reactivate all hosts, so subsequent tasks can try to reach them again. Now we will see some solutions to fix the issue

Troubleshooting Methods

1. User can connect to his Rasberry Pi through ssh through an ethernet cable using SSH running Ansible with this IP address as a host fails. The user configures Rasberry Pi with ansible through wifi (using the wifi IP address). When trying to use ansible via the direct ethernet connection, the following error is received.

The user can successfully connect to this pi using that IP address through ssh from the terminal. He thinks it is a bug in Ansible. The codes tried to run the role are as follows:

ansible-playbook ansible-pi/playbook.yml -i ansible-pi/hosts --ask-pass --sudo -c paramiko -vvvv
ansible-playbook ansible-pi/playbook.yml -i ansible-pi/hosts --ask-pass --sudo -vvvv

The result was the same. Ansible is expected to connect to pi and run the role. However, instead, the unreachable error is displayed.

The solution to fix the issue is by bypassing this by providing ansible_password in the inventory.

2. We can try the code $ ansible-playbook --user=remoteuser -vvv ansible-playbook-test.yml and check the SSH arguments in the output.

3. Another method is by saving the key under the name of id_rsa and then copying the entire key, and paste in the file as follows:

$ cd /root/.ssh
$ ssh-keygen -t rsa

$ cat id_rsa.pub

$ sudo nano authorized_keys

 

To check, run the below code:

$ ansible all -m ping -u root

The result will be like this:

master-node | SUCCESS => {
"changed": false,
"ping": "pong"
}

4. We can try adding the user designation also.

ansible-playbook [...yml] -u deploy

5. A customer has a .ssh/config entry for his user to match the remote hostname. And he can SSH directly to the server with ssh servername.servername

Host servername  
    User username

With Ansible, it is needed to add -u parameter to deploy the code:

ansible-playbook -vvvv -i poc book_deploy.yml --ask-vault-pass --ask-become-pass -u username

The deployment worked with this solution.

[Need help with another issue? We’re just a click away.]

Conclusion

The article provides some of the troubleshooting methods from our Tech team to fix the Ansible error “Unreachable”.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF