# Ping Role for clients to ping all IP from HOST\_VAR files?

**URL:** <https://forum.ansible.com/t/ping-role-for-clients-to-ping-all-ip-from-host-var-files/33677>\
**Category:** Ansible Project\
**Created:** [August 26, 2020, 12:21am UTC](https://forum.ansible.com/t/ping-role-for-clients-to-ping-all-ip-from-host-var-files/33677 "2020-08-26T00:21:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fatos\_Dervisi](https://avatars.discourse-cdn.com/v4/letter/f/ee7513/32.png) [@Fatos\_Dervisi](https://forum.ansible.com/u/Fatos_Dervisi)\
**Post date:** [August 26, 2020, 12:21am UTC](https://forum.ansible.com/t/ping-role-for-clients-to-ping-all-ip-from-host-var-files/33677/1 "2020-08-26T00:21:54Z")

</div>

Dear Community,

I want to write a simple Ping Role, which takes IP Addresses from all YAML files in HOST\_VARS and connected to Linux devices and ping all the collected IP

Example:

HOST\_VARS:  
-server1.yml (contains an IP = 1.1.1.1  
-server2.yml (contains an IP = 2.2.2.

The role should connect to a Linux Client and ping all IP (in this example 1.1.1.1 and 2.2.2.2)

It should be simple but I’m struggling to solve it:

Here my try:  
[https://github.com/fdervisi/cisco-config-generator/blob/master/list-test.yml](https://github.com/fdervisi/cisco-config-generator/blob/master/list-test.yml)

- name: “Ping all Linux VMs”  
hosts: servers

vars:  
ip\_test:

- 8.8.8.8
- 10.116.207.5

tasks:

- name: Search for all Server IP Address in HOST\_VAR folder and create a list  
debug:  
msg: “{{ lookup(‘template’, ‘templates/test.j2’) }}”  
register: ip

- debug: var=ip

- name: Check all port numbers are accessible from current host  
wait\_for:  
host: “{{ item }}”  
port: 80  
state: started # Port should be open  
delay: 0 # No wait before first check (sec)  
timeout: 3 # Stop checking after timeout (sec)  
ignore\_errors: yes  
#with\_items: “{{ hostvars[‘{{ hostname }}’][‘vm\_interfaces’][1][‘ip’] }}”  
with\_items: “{{ ip\_test }}”

Can somebody help me to solve this “simple” task?

---

<div class="post-metadata">

**Author:** ![Fatos\_Dervisi](https://avatars.discourse-cdn.com/v4/letter/f/ee7513/32.png) [@Fatos\_Dervisi](https://forum.ansible.com/u/Fatos_Dervisi)\
**Post date:** [September 1, 2020, 2:27pm UTC](https://forum.ansible.com/t/ping-role-for-clients-to-ping-all-ip-from-host-var-files/33677/2 "2020-09-01T14:27:26Z")

</div>

This should be the solution but it does not work, because I dont gather facts, I want to scan thru my inventroy:

- name: “Ping all Linux VMs”  
hosts: servers  
gather\_facts: no

tasks:

- debug:  
msg: “{{ hostvars[‘{{ item }}’] **.ansible\_host** }}”  
with\_items: “{{ groups[‘servers’] }}”  
delegate\_to: localhost

What I want to access it this variable within host\_vars/linux1.yml:

hostname: “linux1”  
**ansible\_host** : **192.168.99.101**  
server\_template: CentOS7\_Template  
host\_groups:

- servers

Does anybody have an idea how I can solve it?

Thanks  
Cheers  
Fatos
