mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-28 07:31:23 -07:00
[PR #10458/fe59c6d2 backport][stable-10] listen_ports_facts: Avoid crash when required commands are missing (#10475)
listen_ports_facts: Avoid crash when required commands are missing (#10458)
* Fix listen-port-facts crash
* Update changelog
* Update tests/integration/targets/listen_ports_facts/tasks/main.yml
* Fix sanity tests
* Update changelogs/fragments/10458-listen_port_facts-prevent-type-error.yml
---------
(cherry picked from commit fe59c6d29e
)
Co-authored-by: Giorgos Drosos <56369797+gdrosos@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
374270d242
commit
4412bdba9b
3 changed files with 32 additions and 1 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- "listen_port_facts - avoid crash when required commands are missing (https://github.com/ansible-collections/community.general/issues/10457, https://github.com/ansible-collections/community.general/pull/10458)."
|
|
@ -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']
|
||||||
|
|
|
@ -110,3 +110,32 @@
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
|
- when: ansible_os_family == "Debian"
|
||||||
|
block:
|
||||||
|
- name: Remove netstat and ss dependencies to simulate missing executables
|
||||||
|
ansible.builtin.package:
|
||||||
|
name:
|
||||||
|
- net-tools
|
||||||
|
- iproute2
|
||||||
|
state: absent
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Trigger listen_ports_facts with missing tools
|
||||||
|
community.general.listen_ports_facts:
|
||||||
|
register: listen_ports_failure_result
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Assert graceful failure when dependencies are missing
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- listen_ports_failure_result is failed
|
||||||
|
- "'Unable to find any of the supported commands' in listen_ports_failure_result.msg"
|
||||||
|
|
||||||
|
- name: Reinstall netstat and ss dependencies after test
|
||||||
|
ansible.builtin.package:
|
||||||
|
name:
|
||||||
|
- net-tools
|
||||||
|
- iproute2
|
||||||
|
state: present
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue