mirror of
https://github.com/willshersystems/ansible-sshd
synced 2024-11-10 05:33:29 +01:00
tests: Verify backup files are created and can be disabled
This commit is contained in:
parent
497db39466
commit
45bf0180fe
2 changed files with 73 additions and 0 deletions
|
@ -93,3 +93,9 @@ script:
|
|||
ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/tests_precedence.yml --connection=local --become -v
|
||||
&& (echo 'Variable precedence test: pass' && exit 0)
|
||||
|| (echo 'Variable precedence test: fail' && exit 1)
|
||||
|
||||
# Test 12: Verify backups are created
|
||||
- >
|
||||
ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/tests_backup.yml --connection=local --become -v
|
||||
&& (echo 'Backup test: pass' && exit 0)
|
||||
|| (echo 'Backup test: fail' && exit 1)
|
||||
|
|
67
tests/tests_backup.yml
Normal file
67
tests/tests_backup.yml
Normal file
|
@ -0,0 +1,67 @@
|
|||
---
|
||||
- hosts: all
|
||||
vars:
|
||||
__sshd_test_backup_files:
|
||||
- /etc/ssh/sshd_config
|
||||
- /etc/ssh/sshd_config.d/00-ansible_system_role.conf
|
||||
main_sshd_config: >-
|
||||
{{
|
||||
"00-ansible_system_role.conf"
|
||||
if ansible_facts['distribution'] == 'Fedora'
|
||||
else "sshd_config"
|
||||
}}
|
||||
main_sshd_config_path: >-
|
||||
{{
|
||||
"/etc/ssh/sshd_config.d/"
|
||||
if ansible_facts['distribution'] == 'Fedora'
|
||||
else "/etc/ssh/"
|
||||
}}
|
||||
tasks:
|
||||
- name: Backup configuration files
|
||||
include_tasks: tasks/backup.yml
|
||||
|
||||
- name: Find old backups files
|
||||
find:
|
||||
paths: "{{ main_sshd_config_path }}"
|
||||
patterns: "{{ main_sshd_config }}.*@*~"
|
||||
register: backup_files
|
||||
|
||||
- name: Remove old backup files
|
||||
file:
|
||||
path: "{{ item.path }}"
|
||||
state: absent
|
||||
with_items: "{{ backup_files.files }}"
|
||||
|
||||
- name: Configure sshd without creating backup
|
||||
include_role:
|
||||
name: ansible-sshd
|
||||
vars:
|
||||
sshd_backup: false
|
||||
|
||||
- name: Find new backups files
|
||||
find:
|
||||
paths: "{{ main_sshd_config_path }}"
|
||||
patterns: "{{ main_sshd_config }}.*@*~"
|
||||
register: no_backup
|
||||
|
||||
- name: Configure sshd again with different configuration and with backup
|
||||
include_role:
|
||||
name: ansible-sshd
|
||||
vars:
|
||||
sshd_Banner: /tmp/banner
|
||||
register: second_run
|
||||
|
||||
- name: Find new backups files
|
||||
find:
|
||||
paths: "{{ main_sshd_config_path }}"
|
||||
patterns: "{{ main_sshd_config }}.*@*~"
|
||||
register: new_backup
|
||||
|
||||
- name: Verify the backup was not done in the first attempt, but in the second one
|
||||
assert:
|
||||
that:
|
||||
- no_backup.files == []
|
||||
- new_backup.files != []
|
||||
|
||||
- name: Restore configuration files
|
||||
include_tasks: tasks/restore.yml
|
Loading…
Reference in a new issue