I have written the below playbook to fetch the failed port status.
- name: Check port status
wait_for:
host: 127.0.0.1
port: "{{ item }}"
timeout: 2
state: started
ignore_errors: yes
with_items:
- 80
- 22
- 8080
register: wait_result
- debug:
msg: "{{ 'Failed with message: ' ~ wait_result.msg if wait_result.failed else 'Success' }}"
While fetching the msg
from debug logs I am unable to get the timeout message.
PLAY [mysrv] ************************************************************************************************************************************
TASK [Gathering Facts] **************************************************************************************************************************
ok: [localhost]
TASK [Check Nagios port status] *****************************************************************************************************************
ok: [localhost] => (item=80)
ok: [localhost] => (item=22)
failed: [localhost] (item=8080) => {"ansible_loop_var": "item", "changed": false, "elapsed": 2, "item": 8080, "msg": "Timeout when waiting for 127.0.0.1:8080"}
...ignoring
TASK [debug] ************************************************************************************************************************************
ok: [localhost] => {
"msg": "Failed with message: One or more items failed"
}
PLAY RECAP **************************************************************************************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=1
Can someone please help to correct my code?