Ansible Ping

Ansible Ping
Techiio-author
Written by Nilima PaulJanuary 21, 2022
10 min read
Ansible
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE
Techiio-author
Nilima Paul

Technology Security Analyst

Today let's discuss what are the Ansible Ping.

Introduction to Ansible Ping

In Ansible, to do an assignment on remote hosts, we want to have a few fundamental necessities on track remote has with the goal that Ansible climate can be arranged and work true to form. These prerequisites are generally connected with the network, client the board, honors, and accessibility of Python on track remote machine. We can either check these prerequisites physically individually or we can utilize modules like ping to test the greater part of those necessities. When utilizing ping, the return worth will be either an accomplishment as a string or mistake messages if there should arise an occurrence of disappointment. Ansible ping module is an exceptionally valuable yet basic test module to take a look at the availability and usefulness of track remote machines. This attempts to check not many things on remote machines which are the essential requirements for Ansible to work in a non-inconsistent way.

So ping module is used to check the below requirements on remote target machines.

  • Network Connectivity
  • Current User Login
  • Usable Python Availability

After taking a look at these things on track remote machines. It returns a worth given accomplishment or disappointment. This module ought to be utilized as a first keep an eye on your Ansible climate to character non-open machines. With the goal that your playbooks won't fall flat. As Ansible playbook's work conduct is to such an extent that it will fall flat on first disappointment happened and won't proceed even the while later undertakings are possible. For target Windows climate, Ansible gives win_ping module, and to target network gadgets, Ansible gives net_ping module.

How does Ansible Ping work?

Ansible ping module works in an exceptionally basic way and returns the achievement or disappointment as a characterized/default string or blunder, individually. This module doesn't have any extraordinary boundaries or choices.

Given underneath are the couple of focuses that one should know before utilizing them.

  • After fruitful checking the capacity to login and accessibility of usable python on remote hosts. It of course returns pong string, which fundamentally implies the availability and accessible Python on remote machines are sufficient to work.
  • This doesn't chip away at ICMP, yet works naturally on SSH or some other characterized association technique.
  • One satisfactory boundary is information that acknowledges values as one or the other pong, crash, or another string.
  • Default is pong. This addresses the return esteem on progress.
  • If information is given worth an accident, this module will return a special case.
  • However we can involve this module in playbooks, yet this module is for the most part utilized with the order/user/canister/ansible, which is straightforwardly utilized on the terminal.
  • This module is ensured for in reverse similarity by the Ansible Core group.

Examples of Ansible Ping

Given below are the examples mentioned:

Here we have an Ansible control server named ansible-controller and two remotes hosts named host-one and host-two. We will create playbooks run Ansible commands on ansithe ble-controller node and see the results on remote hosts.

Example #1

In this example, we use an ansible command like below, using which we try to check the status for Ansible to work on remote target nodes.

Code:

ansible all -m ping -v

Here we saw that when using the Ansible ping module. It checked for network connection, login ability over SSH and python interpreter on remote target machines.

Example #2

In the below example, we will try to run this module in a playbook. This is not most useful but can be used when we have a condition to test the connection first, then start doing the rest of tthe asks.

Code:

hosts:
all
tasks:
name: here we are checking the ping-pong ping:

Now running this playbook like below:

ansible-playbook --syntax-check ansible_ping.YAML

Now registering the output in a variable named “var_ping” and then using debug module in this playbook like below to print the returned values, we can see that in the output, we have pong as return value.

Code:

hosts:
all
tasks:
name: here we are checking the ping-pong ping:
register: var_ping
debug:
var: var_ping

Run this like below:

ansible-playbook ansible_ping.YAML

Example #3

In this example, we will try to change the return value from default pong to crash. We can write a playbook like below. Here we are expecting that it will return an exception.

Code:

hosts:
all
tasks:
name: Here we are trying to return "crash" on successful ping:
data: crash

Running the playbook like below:

ansible-playbook ansible_ping_crash.YAML -v

We get output like below, where we can see that an exception was returned from both target remote machines.

Example #4

In this example, we will try to return a value named “test” on successful test validation. We will register the return value in a variable named “var_ping”. Then using debug module, we will print the returned strings.

For this we create a playbook like the below:

Code:

hosts: all
gather_facts:
no tasks:
ping:
data: test
register: var_ping
debug:
var: var_ping

Now running this playbook like below:

ansible-playbook ansible_ping_string.YAML

We get the output like below, where we can see that we get “test” in return strings.

Example #5

In this model, we will eliminate the ssh key from the record .ssh/authorized_keys of host-one, with the goal that passwordless association won't be imaginable from Ansible regulator hub to have one. We won't do any progressions to have two. Presently checking with ping module like underneath.

Code:

ansible all -m ping

We get the result as beneath, here we can see that however the organization association was running after have one and Python was accessible too. Be that as it may, as secret phraseless SSH validation was not working, the ping test fizzled on to have one. On other hand it dealt with have two.

Conclusion

As we saw in the above models, the Ansible ping module is a valuable and simple to utilize module which educates you concerning the availability status of target remote hosts. However this insignificant test module isn't furnished with numerous choices like other Ansible modules, yet we want this sort of module to look at fundamental level functionality.

Ansible Ping
Ansible
Python
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE
Was this blog helpful?
techiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plan
You must be Logged in to comment
Code Block
Techiio-author
Nilima Paul
Technology Security Analyst
Techiio-followerTechiio-followerTechiio-follower
201 Blog Posts
0 Discussion Threads
Trending Technologies
15
Software91
DevOps48
Frontend Development24
Backend Development20
Server Administration17
Linux Administration28
Data Center24
Sentry24
Terraform23
Ansible83
Docker70
Penetration Testing16
Kubernetes21
NGINX20
JenkinsX17
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance