I am having file consists of Ip address I using below method to to make this inventory for my tasks
ips.text
192.168.0.1
192.168.0.2
192.168.0.3
192.168.0.4
main.yml
- name: Add Instance IP Addresses to temporary inventory groups
shell: cat ~/ips.text
register: serverlist
- debug: msg={{ serverlist.stdout_lines }}
- name: Add Instance IP Addresses to temporary inventory groups
add_host
groups: working_hosts
hostname: "{{item}}"
with_items: "{{ serverlist.stdout_lines }}"
- hosts: working_hosts
become: yes
Now I want to make it like if 192.168.0.1 is reachable then it should skip rest of the ips from that file and if 192.168.0.1 is unreachable then only goes to next 192.168.0.2.
How can we achieve this?