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
|
|
|
|
tasks:
|
2021-04-07 20:12:03 +02:00
|
|
|
- name: Backup configuration files
|
2022-06-03 12:22:17 +02:00
|
|
|
ansible.builtin.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
|
2022-06-03 12:22:17 +02:00
|
|
|
ansible.builtin.find:
|
2021-04-07 20:12:03 +02:00
|
|
|
paths: "{{ main_sshd_config_path }}"
|
2021-08-03 10:09:13 +02:00
|
|
|
patterns: "{{ main_sshd_config_name }}.*@*~"
|
2021-04-07 20:12:03 +02:00
|
|
|
register: backup_files
|
2020-11-24 09:48:43 +01:00
|
|
|
|
2021-04-07 20:12:03 +02:00
|
|
|
- name: Remove old backup files
|
2022-06-03 12:22:17 +02:00
|
|
|
ansible.builtin.file:
|
2021-04-07 20:12:03 +02:00
|
|
|
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
|
2022-06-03 12:22:17 +02:00
|
|
|
ansible.builtin.include_role:
|
2021-04-07 20:12:03 +02:00
|
|
|
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
|
2022-06-03 12:22:17 +02:00
|
|
|
ansible.builtin.find:
|
2021-04-07 20:12:03 +02:00
|
|
|
paths: "{{ main_sshd_config_path }}"
|
2021-08-03 10:09:13 +02:00
|
|
|
patterns: "{{ main_sshd_config_name }}.*@*~"
|
2021-04-07 20:12:03 +02:00
|
|
|
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
|
2022-06-03 12:22:17 +02:00
|
|
|
ansible.builtin.include_role:
|
2021-04-07 20:12:03 +02:00
|
|
|
name: ansible-sshd
|
|
|
|
vars:
|
2022-06-03 12:22:17 +02:00
|
|
|
sshd_Banner: /tmp/banner # noqa var-naming
|
2021-04-07 20:12:03 +02:00
|
|
|
register: second_run
|
2020-11-24 09:48:43 +01:00
|
|
|
|
2021-04-07 20:12:03 +02:00
|
|
|
- name: Find new backups files
|
2022-06-03 12:22:17 +02:00
|
|
|
ansible.builtin.find:
|
2021-04-07 20:12:03 +02:00
|
|
|
paths: "{{ main_sshd_config_path }}"
|
2021-08-03 10:09:13 +02:00
|
|
|
patterns: "{{ main_sshd_config_name }}.*@*~"
|
2021-04-07 20:12:03 +02:00
|
|
|
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
|
2022-06-03 12:22:17 +02:00
|
|
|
ansible.builtin.assert:
|
2021-04-07 20:12:03 +02:00
|
|
|
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
|
2022-06-03 12:22:17 +02:00
|
|
|
ansible.builtin.include_tasks: tasks/restore.yml
|