Skip to content

Commit

Permalink
add ssh_backup tests
Browse files Browse the repository at this point in the history
analog to sshd_backup tests (willshersystems/ansible-sshd)
  • Loading branch information
skwde committed Jun 14, 2023
1 parent 7b7b3cd commit 77b17ce
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/tasks/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,18 @@
package:
name: "{{ __ssh_test_packages }}"
state: present

- name: Define common variables
ansible.builtin.set_fact:
main_ssh_config: /etc/ssh/ssh_config
main_ssh_config_name: ssh_config
main_ssh_config_path: /etc/ssh/

- name: Define specific variables
ansible.builtin.set_fact:
main_ssh_config: /etc/ssh/ssh_config.d/00-ansible.conf
main_ssh_config_name: 00-ansible.conf
main_ssh_config_path: /etc/ssh/ssh_config.d/
when:
- (ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version']|int > 8) or

Check failure on line 30 in tests/tasks/setup.yml

View workflow job for this annotation

GitHub Actions / ansible_lint

yaml[line-length]

Line too long (105 > 80 characters)
(ansible_facts['distribution'] == 'Ubuntu' and ansible_facts['distribution_major_version']|int >= 22)

Check failure on line 31 in tests/tasks/setup.yml

View workflow job for this annotation

GitHub Actions / ansible_lint

yaml[line-length]

Line too long (107 > 80 characters)
56 changes: 56 additions & 0 deletions tests/tests_backup.yml
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

Check failure on line 49 in tests/tests_backup.yml

View workflow job for this annotation

GitHub Actions / ansible_lint

yaml[line-length]

Line too long (86 > 80 characters)
ansible.builtin.assert:
that:
- no_backup.files == []
- new_backup.files != []

- name: Restore configuration files
ansible.builtin.include_tasks: tasks/restore.yml

0 comments on commit 77b17ce

Please sign in to comment.