ansible / ansible.builtin / v2.9.25 / module / listen_ports_facts Gather facts on processes listening on TCP and UDP ports. | "added in version" 2.9 of ansible.builtin" Authors: Nathan Davison (@ndavison) preview | supported by communityansible.builtin.listen_ports_facts (v2.9.25) — module
pip
Install with pip install ansible==2.9.25
Gather facts on processes listening on TCP and UDP ports.
- 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 }}"
ansible_facts: contains: tcp_listen: contains: address: description: The address the server is listening on. returned: always sample: 0.0.0.0 type: str name: description: The name of the listening process. returned: if user permissions allow sample: mysqld type: str pid: description: The pid of the listening process. returned: always sample: 1223 type: int port: description: The port the server is listening on. returned: always sample: 3306 type: int protocol: description: The network protocol of the server. returned: always sample: tcp type: str stime: description: The start time of the listening process. returned: always sample: Thu Feb 2 13:29:45 2017 type: str user: description: The user who is running the listening process. returned: always sample: mysql type: str description: A list of processes that are listening on a TCP port. returned: if TCP servers were found type: list udp_listen: contains: address: description: The address the server is listening on. returned: always sample: 0.0.0.0 type: str name: description: The name of the listening process. returned: if user permissions allow sample: rsyslogd type: str pid: description: The pid of the listening process. returned: always sample: 609 type: int port: description: The port the server is listening on. returned: always sample: 514 type: int protocol: description: The network protocol of the server. returned: always sample: udp type: str stime: description: The start time of the listening process. returned: always sample: Thu Feb 2 13:29:45 2017 type: str user: description: The user who is running the listening process. returned: always sample: root type: str description: A list of processes that are listening on a UDP port. returned: if UDP servers were found type: list description: Dictionary containing details of TCP and UDP ports with listening servers returned: always type: complex