Fix listen-port-facts crash

This commit is contained in:
Giorgos Drosos 2025-07-25 21:56:53 +03:00
commit f2c12576d5
2 changed files with 32 additions and 1 deletions

View file

@ -397,7 +397,7 @@ def main():
break break
if bin_path is None: if bin_path is None:
raise EnvironmentError(msg='Unable to find any of the supported commands in PATH: {0}'.format(", ".join(sorted(commands_map)))) raise EnvironmentError('Unable to find any of the supported commands in PATH: {0}'.format(", ".join(sorted(commands_map))))
# which ports are listening for connections? # which ports are listening for connections?
args = commands_map[command]['args'] args = commands_map[command]['args']

View file

@ -110,3 +110,34 @@
loop: "{{ [tcp_listen, udp_listen]|flatten }}" loop: "{{ [tcp_listen, udp_listen]|flatten }}"
when: item.name == 'nc' when: item.name == 'nc'
ignore_errors: true ignore_errors: true
- name: Remove netstat and ss dependencies to simulate missing executables
ansible.builtin.package:
name:
- net-tools
- iproute2
state: absent
ignore_errors: true
when: ansible_os_family == "Debian"
- name: Trigger listen_ports_facts with missing tools
community.general.listen_ports_facts:
register: listen_ports_failure_result
ignore_errors: true
when: ansible_os_family == "Debian"
- name: Assert graceful failure when dependencies are missing
ansible.builtin.assert:
that:
- listen_ports_failure_result.failed
- "'Unable to find any of the supported commands' in listen_ports_failure_result.msg"
when: ansible_os_family == "Debian"
- name: Reinstall netstat and ss dependencies after test
ansible.builtin.package:
name:
- net-tools
- iproute2
state: present
when: ansible_os_family == "Debian"