diff --git a/changelogs/fragments/2568-ssh_config-reduce-stormssh-searches-based-on-host.yml b/changelogs/fragments/2568-ssh_config-reduce-stormssh-searches-based-on-host.yml new file mode 100644 index 0000000000..2f3e400e7e --- /dev/null +++ b/changelogs/fragments/2568-ssh_config-reduce-stormssh-searches-based-on-host.yml @@ -0,0 +1,2 @@ +bugfixes: + - ssh_config - reduce stormssh searches based on host (https://github.com/ansible-collections/community.general/pull/2568/). diff --git a/plugins/modules/system/ssh_config.py b/plugins/modules/system/ssh_config.py index 943f6b44fc..be177baaaf 100644 --- a/plugins/modules/system/ssh_config.py +++ b/plugins/modules/system/ssh_config.py @@ -209,6 +209,8 @@ class SSHConfig(): hosts_removed = [] hosts_added = [] + hosts_result = [host for host in hosts_result if host['host'] == self.host] + if hosts_result: for host in hosts_result: if state == 'absent': diff --git a/tests/integration/targets/ssh_config/tasks/main.yml b/tests/integration/targets/ssh_config/tasks/main.yml index 12f277b455..bd5acc9e04 100644 --- a/tests/integration/targets/ssh_config/tasks/main.yml +++ b/tests/integration/targets/ssh_config/tasks/main.yml @@ -183,3 +183,39 @@ that: - not mut_ex.changed - "'parameters are mutually exclusive' in mut_ex.msg" + +- name: Add a full name host + community.general.ssh_config: + ssh_config_file: "{{ ssh_config_test }}" + host: "full_name" + hostname: full_name.com + identity_file: '{{ ssh_private_key }}' + port: '2223' + state: present + register: full_name + +- name: Check if changes are made + assert: + that: + - full_name is changed + - full_name.hosts_added == ["full_name"] + - full_name.hosts_changed == [] + - full_name.hosts_removed == [] + +- name: Add a host with name which is contained in full name host + community.general.ssh_config: + ssh_config_file: "{{ ssh_config_test }}" + host: "full" + hostname: full.com + identity_file: '{{ ssh_private_key }}' + port: '2223' + state: present + register: short_name + +- name: Check that short name host is added and full name host is not updated + assert: + that: + - short_name is changed + - short_name.hosts_added == ["full"] + - short_name.hosts_changed == [] + - short_name.hosts_removed == []