I have a list of servers that only part of them are running port 9090. I need to create two tasks, each should loop the server's hostnames. the first task should define inside a register the first server hostname that was found running port 9090 , the second task should define in a register all server's hostnames that are running port 9090. If no server is running port 9090 the tasks should fail
I have nc installed on the server and I thought about using a shell with the following task:
server_details: - server1 - server2 - server3 - server4 - server5 - name: locate servers running port 9090 shell: nc -zv {{ item.hostname }} 9090 register: results_port_9090 with_items: - "{{ server_details }}" ignore_errors: yes
But I don't know how to filter the answer and add the hostname to a new register - I assume an additional task is required that runs on the existing register and creates a new register with the relevant outputs
For example:
server1
server2
server3 #running 9090
server4
server5 #running 9090
- The first task should create a register that holds server 3 or server 5 hostname
- The second task should create a register that holds server 3 and server 5 hostname