Technotes

Technotes for future me

Ansible check if port is listening

Ansible check if port is listening

- name: Check if port 80 is listening
  wait_for:
    port: 80
    delay: 5
    timeout: 10
    msg: "Timeout waiting for 80 to respond"
  register: port_check
  ignore_errors: yes

- name: Try to restart httpd if not started
  service: name=httpd state=started enabled=yes
  when: port_check.failed == true
Last updated on 31 Jan 2021
Published on 11 Dec 2019
Edit on GitHub