2020-11-24 09:48:43 +01:00
|
|
|
---
|
|
|
|
- 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:
|
2021-04-07 20:12:03 +02:00
|
|
|
- name: Backup configuration files
|
|
|
|
include_tasks: tasks/backup.yml
|
2020-11-24 09:48:43 +01:00
|
|
|
|
2021-04-07 20:12:03 +02:00
|
|
|
- name: Find old backups files
|
|
|
|
find:
|
|
|
|
paths: "{{ main_sshd_config_path }}"
|
|
|
|
patterns: "{{ main_sshd_config }}.*@*~"
|
|
|
|
register: backup_files
|
2020-11-24 09:48:43 +01:00
|
|
|
|
2021-04-07 20:12:03 +02:00
|
|
|
- name: Remove old backup files
|
|
|
|
file:
|
|
|
|
path: "{{ item.path }}"
|
|
|
|
state: absent
|
|
|
|
with_items: "{{ backup_files.files }}"
|
2020-11-24 09:48:43 +01:00
|
|
|
|
2021-04-07 20:12:03 +02:00
|
|
|
- name: Configure sshd without creating backup
|
|
|
|
include_role:
|
|
|
|
name: ansible-sshd
|
|
|
|
vars:
|
|
|
|
sshd_backup: false
|
2020-11-24 09:48:43 +01:00
|
|
|
|
2021-04-07 20:12:03 +02:00
|
|
|
- name: Find new backups files
|
|
|
|
find:
|
|
|
|
paths: "{{ main_sshd_config_path }}"
|
|
|
|
patterns: "{{ main_sshd_config }}.*@*~"
|
|
|
|
register: no_backup
|
2020-11-24 09:48:43 +01:00
|
|
|
|
2021-04-07 20:12:03 +02:00
|
|
|
- name: Configure sshd again with different configuration and with backup
|
|
|
|
include_role:
|
|
|
|
name: ansible-sshd
|
|
|
|
vars:
|
|
|
|
sshd_Banner: /tmp/banner
|
|
|
|
register: second_run
|
2020-11-24 09:48:43 +01:00
|
|
|
|
2021-04-07 20:12:03 +02:00
|
|
|
- name: Find new backups files
|
|
|
|
find:
|
|
|
|
paths: "{{ main_sshd_config_path }}"
|
|
|
|
patterns: "{{ main_sshd_config }}.*@*~"
|
|
|
|
register: new_backup
|
2020-11-24 09:48:43 +01:00
|
|
|
|
2021-04-07 20:12:03 +02:00
|
|
|
- name: Verify the backup was not done in the first attempt, but in the second one
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- no_backup.files == []
|
|
|
|
- new_backup.files != []
|
2020-11-24 09:48:43 +01:00
|
|
|
|
2021-04-07 20:12:03 +02:00
|
|
|
- name: Restore configuration files
|
|
|
|
include_tasks: tasks/restore.yml
|