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
- 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?