Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: ensure that sshd2 is completely stopped and removed #286

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion tests/tests_second_service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
__sshd_test_backup_files:
- /etc/ssh/sshd_config
- /etc/ssh/sshd_config.d/00-ansible_system_role.conf
- /etc/ssh2/sshd_config
- /etc/systemd/system/sshd.service
- /etc/systemd/system/[email protected]
- /etc/systemd/system/sshd.socket
- /etc/systemd/system/ssh.service
- /etc/systemd/system/[email protected]
- /etc/systemd/system/ssh.socket
__sshd_test_remove_files:
- /etc/ssh2
- /etc/systemd/system/sshd2.service
- /etc/systemd/system/[email protected]
- /etc/systemd/system/sshd2.socket
Expand Down Expand Up @@ -105,5 +106,25 @@
- "' -f/etc/ssh/sshd_config' not 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"
ansible.builtin.include_tasks: tasks/restore.yml
30 changes: 25 additions & 5 deletions tests/tests_second_service_drop_in.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
__sshd_test_backup_files:
- /etc/ssh/sshd_config
- /etc/ssh/sshd_config.d/00-ansible_system_role.conf
- /etc/ssh2/sshd_config
- /etc/sshd/sshd_config.d/04-ansible.conf
__sshd_test_remove_files:
- /etc/ssh2
- /etc/systemd/system/sshd2.service
- /etc/systemd/system/[email protected]
- /etc/systemd/system/sshd2.socket
Expand Down Expand Up @@ -117,6 +117,26 @@
that:
- "' -f/etc/ssh/sshd_config' not in service_inst.content | b64decode"
- "' -f/etc/ssh2/sshd_config' in service_inst.content | b64decode"

- name: "Restore configuration files"
ansible.builtin.include_tasks: tasks/restore.yml
always:
- 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"
ansible.builtin.include_tasks: tasks/restore.yml