listen_ports_facts – Gather facts on processes listening on TCP and UDP ports¶
New in version 2.9.
Examples¶
- name: Gather facts on listening ports
  listen_ports_facts:
- name: TCP whitelist violation
  debug:
    msg: TCP port {{ item.port }} by pid {{ item.pid }} violates the whitelist
  vars:
    tcp_listen_violations: "{{ ansible_facts.tcp_listen | selectattr('port', 'in', tcp_whitelist) | list }}"
    tcp_whitelist:
      - 22
      - 25
  loop: "{{ tcp_listen_violations }}"
- name: List TCP ports
  debug:
    msg: "{{ ansible_facts.tcp_listen  | map(attribute='port') | sort | list }}"
- name: List UDP ports
  debug:
    msg: "{{ ansible_facts.udp_listen | map(attribute='port') | sort | list }}"
- name: List all ports
  debug:
    msg: "{{ (ansible_facts.tcp_listen + ansible_facts.udp_listen) | map(attribute='port') | unique | sort | list }}"
Returned Facts¶
Facts returned by this module are added/updated in the hostvars host facts and can be referenced by name just like any other host fact. They do not need to be registered in order to use them.
Status¶
- This module is not guaranteed to have a backwards compatible interface. [preview]
- This module is maintained by the Ansible Community. [community]
Authors¶
- Nathan Davison (@ndavison)
Hint
If you notice any issues in this documentation, you can edit this document to improve it.
