Merge pull request #286 from richm/cleanup-sshd2

test: ensure that sshd2 is completely stopped and removed
This commit is contained in:
Richard Megginson 2024-04-09 13:57:08 -06:00 committed by GitHub
commit 72c22bce71
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 5 deletions

View file

@ -5,13 +5,14 @@
__sshd_test_backup_files: __sshd_test_backup_files:
- /etc/ssh/sshd_config - /etc/ssh/sshd_config
- /etc/ssh/sshd_config.d/00-ansible_system_role.conf - /etc/ssh/sshd_config.d/00-ansible_system_role.conf
- /etc/ssh2/sshd_config
- /etc/systemd/system/sshd.service - /etc/systemd/system/sshd.service
- /etc/systemd/system/sshd@.service - /etc/systemd/system/sshd@.service
- /etc/systemd/system/sshd.socket - /etc/systemd/system/sshd.socket
- /etc/systemd/system/ssh.service - /etc/systemd/system/ssh.service
- /etc/systemd/system/ssh@.service - /etc/systemd/system/ssh@.service
- /etc/systemd/system/ssh.socket - /etc/systemd/system/ssh.socket
__sshd_test_remove_files:
- /etc/ssh2
- /etc/systemd/system/sshd2.service - /etc/systemd/system/sshd2.service
- /etc/systemd/system/sshd2@.service - /etc/systemd/system/sshd2@.service
- /etc/systemd/system/sshd2.socket - /etc/systemd/system/sshd2.socket
@ -105,5 +106,25 @@
- "' -f/etc/ssh/sshd_config' not in service_inst.content | b64decode" - "' -f/etc/ssh/sshd_config' not in service_inst.content | b64decode"
- "' -f/etc/ssh2/sshd_config' in service_inst.content | b64decode" - "' -f/etc/ssh2/sshd_config' in service_inst.content | b64decode"
- name: Stop second service
ansible.builtin.service:
name: sshd2
state: stopped
enabled: false
ignore_errors: true # noqa ignore-errors
- name: Remove second service
ansible.builtin.file:
path: "{{ item }}"
state: absent
loop: "{{ __sshd_test_remove_files }}"
- name: Refresh systemd
# noqa command-instead-of-module
ansible.builtin.shell: systemctl reset-failed; systemctl daemon-reload
when: ansible_facts["service_mgr"] == "systemd"
changed_when: true
ignore_errors: true # noqa ignore-errors
- name: "Restore configuration files" - name: "Restore configuration files"
ansible.builtin.include_tasks: tasks/restore.yml ansible.builtin.include_tasks: tasks/restore.yml

View file

@ -5,8 +5,8 @@
__sshd_test_backup_files: __sshd_test_backup_files:
- /etc/ssh/sshd_config - /etc/ssh/sshd_config
- /etc/ssh/sshd_config.d/00-ansible_system_role.conf - /etc/ssh/sshd_config.d/00-ansible_system_role.conf
- /etc/ssh2/sshd_config __sshd_test_remove_files:
- /etc/sshd/sshd_config.d/04-ansible.conf - /etc/ssh2
- /etc/systemd/system/sshd2.service - /etc/systemd/system/sshd2.service
- /etc/systemd/system/sshd2@.service - /etc/systemd/system/sshd2@.service
- /etc/systemd/system/sshd2.socket - /etc/systemd/system/sshd2.socket
@ -117,6 +117,26 @@
that: that:
- "' -f/etc/ssh/sshd_config' not in service_inst.content | b64decode" - "' -f/etc/ssh/sshd_config' not in service_inst.content | b64decode"
- "' -f/etc/ssh2/sshd_config' in service_inst.content | b64decode" - "' -f/etc/ssh2/sshd_config' in service_inst.content | b64decode"
always:
- name: Stop second service
ansible.builtin.service:
name: sshd2
state: stopped
enabled: false
ignore_errors: true # noqa ignore-errors
- name: "Restore configuration files" - name: Remove second service
ansible.builtin.include_tasks: tasks/restore.yml ansible.builtin.file:
path: "{{ item }}"
state: absent
loop: "{{ __sshd_test_remove_files }}"
- name: Refresh systemd
# noqa command-instead-of-module
ansible.builtin.shell: systemctl reset-failed; systemctl daemon-reload
when: ansible_facts["service_mgr"] == "systemd"
changed_when: true
ignore_errors: true # noqa ignore-errors
- name: "Restore configuration files"
ansible.builtin.include_tasks: tasks/restore.yml