We are using some pipelines to build servers using ansible and one of the task is to check if server is online (means a production server in inventory list by accident). We check the port 443 and break the build pipeline; this is to ensure that no production or active server touched by accident. We have tried below code - out intention is to make playbook "success" when port 443 is down; so that next task in build pipeline can proceed.
- name: check server online or not
hosts: localhost
connection: local
tasks:
- name: check ESXI host connection to port 443
wait_for: host=ams-server-101 port=443 timeout=1
register: command_result
failed_when: "'Timeout' not in command_result"
- debug: var=command_result
But the this is not working as expected. So we have used a work-around (non-ansible way) as below.
shell: echo "QUIT" | nc -w 3 ams-server-101 443 > /dev/null 2>&1 && echo Pass || echo Fail
register: shell_result
failed_when: shell_result.stdout == "Pass"
Any idea ? (maybe some different module to use)