generated from linux-system-roles/template
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
analog to sshd_backup tests (willshersystems/ansible-sshd)
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- | ||
- name: Test backups | ||
hosts: all | ||
vars: | ||
__ssh_test_backup_files: | ||
- /etc/ssh/ssh_config | ||
- /etc/ssh/ssh_config.d/00-ansible.conf | ||
tasks: | ||
- name: Backup configuration files | ||
ansible.builtin.include_tasks: tasks/backup.yml | ||
|
||
- name: Find old backups files | ||
ansible.builtin.find: | ||
paths: "{{ main_ssh_config_path }}" | ||
patterns: "{{ main_ssh_config_name }}.*@*~" | ||
register: backup_files | ||
|
||
- name: Remove old backup files | ||
ansible.builtin.file: | ||
path: "{{ item.path }}" | ||
state: absent | ||
with_items: "{{ backup_files.files }}" | ||
|
||
- name: Configure ssh without creating backup | ||
ansible.builtin.include_role: | ||
name: linux-system-roles.ssh | ||
vars: | ||
ssh_backup: false | ||
|
||
- name: Find new backups files | ||
ansible.builtin.find: | ||
paths: "{{ main_ssh_config_path }}" | ||
patterns: "{{ main_ssh_config_name }}.*@*~" | ||
register: no_backup | ||
|
||
- name: Configure ssh again with different configuration and with backup | ||
ansible.builtin.include_role: | ||
name: linux-system-roles.ssh | ||
vars: | ||
ssh_ForwardX11Trusted: 'yes' # noqa var-naming | ||
register: second_run | ||
|
||
- name: Find new backups files | ||
ansible.builtin.find: | ||
paths: "{{ main_ssh_config_path }}" | ||
patterns: "{{ main_ssh_config_name }}.*@*~" | ||
register: new_backup | ||
|
||
- name: Verify the backup was not done in the first attempt, but in the second one | ||
ansible.builtin.assert: | ||
that: | ||
- no_backup.files == [] | ||
- new_backup.files != [] | ||
|
||
- name: Restore configuration files | ||
ansible.builtin.include_tasks: tasks/restore.yml |