mirror of
https://github.com/willshersystems/ansible-sshd
synced 2024-11-26 21:10:18 +01:00
68 lines
1.7 KiB
YAML
68 lines
1.7 KiB
YAML
|
---
|
||
|
- 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
|