I want to ping several IPs with my linux server, namely:
- ip 10.0.0.1 which is the host connected to the interface swp1
- ip 10.0.0.2 which is the host connected to the interface swp2
with ip source 10.0.0.3 then the results are stored in a file. This command is executed through ansible with the following task:
- hosts: localhost
connection: local
gather_facts: yes
tasks:
- name: VERIFICATION // CONNECTIVITY BY PING
shell: ping {{ item }} -c 2 -s 10.0.0.3 | grep -i received | awk '{print $4}'
register: ping
loop:
- 10.0.0.1
- 10.0.0.2
- copy:
content: "{{ ping.results | map(attribute='stdout') | join('\n') }}"
dest: ping.txt
and the contents of the ping.txt as follows:
2
0
This task was executed successfully, but, how do I add the connected interface of the pinged host, so that the ping.txt become:
swp1 : 2
swp2 : 0
What script can be added to get this result?