1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Reduce stormssh searches based on host (#2568) (#2724)

* Reduce stormssh searches based on host

Due to the stormssh searches in the whole config values, we need to reduce the search results based on the full matching of the hosts

* Removed whitespaces in the blank line

* Added changelog fragment and tests for the fix.

* Added newline at the end of the changelog fragment

* Added newline at the end of the tests

* Fixed bug with name in tests

* Changed assertion for the existing host

* Update changelogs/fragments/2568-ssh_config-reduce-stormssh-searches-based-on-host.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* Adjusted tests

* New line at the end of the tests

Co-authored-by: Anton Nikolaev <anikolaev@apple.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 1a4af9bfc3)

Co-authored-by: Anton Nikolaev <drenout@gmail.com>
This commit is contained in:
patchback[bot] 2021-06-05 18:03:14 +02:00 committed by GitHub
parent eb4d7a4199
commit 321fb6c974
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 0 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- ssh_config - reduce stormssh searches based on host (https://github.com/ansible-collections/community.general/pull/2568/).

View file

@ -209,6 +209,8 @@ class SSHConfig():
hosts_removed = [] hosts_removed = []
hosts_added = [] hosts_added = []
hosts_result = [host for host in hosts_result if host['host'] == self.host]
if hosts_result: if hosts_result:
for host in hosts_result: for host in hosts_result:
if state == 'absent': if state == 'absent':

View file

@ -183,3 +183,39 @@
that: that:
- not mut_ex.changed - not mut_ex.changed
- "'parameters are mutually exclusive' in mut_ex.msg" - "'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 == []