2022-04-06 16:43:45 +02:00
|
|
|
---
|
|
|
|
- hosts: all
|
|
|
|
vars:
|
|
|
|
__sshd_test_backup_files:
|
|
|
|
- /etc/ssh/sshd_config
|
|
|
|
- /etc/ssh/sshd_config.d/00-ansible_system_role.conf
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- name: "Backup configuration files"
|
2022-06-05 09:54:56 +02:00
|
|
|
ansible.builtin.include_tasks: tasks/backup.yml
|
2022-04-06 16:43:45 +02:00
|
|
|
|
|
|
|
- name: Remove include directory from the main config file
|
2022-06-05 09:54:56 +02:00
|
|
|
ansible.builtin.lineinfile:
|
2022-04-06 16:43:45 +02:00
|
|
|
path: "/etc/ssh/sshd_config"
|
|
|
|
regexp: "^Include"
|
|
|
|
state: absent
|
|
|
|
when:
|
2022-05-02 18:38:50 +02:00
|
|
|
- (ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version']|int > 8) or
|
|
|
|
(ansible_facts['distribution'] == 'Ubuntu' and ansible_facts['distribution_major_version']|int >= 22)
|
2022-04-06 16:43:45 +02:00
|
|
|
|
|
|
|
- name: Create a new configuration in drop-in directory
|
2022-06-05 09:54:56 +02:00
|
|
|
ansible.builtin.include_role:
|
2022-04-06 16:43:45 +02:00
|
|
|
name: ansible-sshd
|
|
|
|
vars:
|
|
|
|
sshd_config_file: /etc/ssh/sshd_config.d/00-ansible_system_role.conf
|
|
|
|
sshd:
|
|
|
|
Banner: /etc/include-issue
|
|
|
|
Ciphers: aes192-ctr
|
|
|
|
when:
|
2022-05-02 18:38:50 +02:00
|
|
|
- (ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version']|int > 8) or
|
|
|
|
(ansible_facts['distribution'] == 'Ubuntu' and ansible_facts['distribution_major_version']|int >= 22)
|
2022-04-06 16:43:45 +02:00
|
|
|
|
|
|
|
- name: Verify the options are correctly set
|
|
|
|
block:
|
2022-06-05 09:54:56 +02:00
|
|
|
- name: Flush handlers
|
|
|
|
ansible.builtin.meta: flush_handlers
|
2022-04-06 16:43:45 +02:00
|
|
|
|
|
|
|
- name: Print drop-in configuration file
|
2022-06-05 09:54:56 +02:00
|
|
|
ansible.builtin.slurp:
|
2022-04-06 16:43:45 +02:00
|
|
|
src: /etc/ssh/sshd_config.d/00-ansible_system_role.conf
|
|
|
|
register: config
|
|
|
|
|
|
|
|
- name: Print the main configuration file
|
2022-06-05 09:54:56 +02:00
|
|
|
ansible.builtin.slurp:
|
2022-04-06 16:43:45 +02:00
|
|
|
src: /etc/ssh/sshd_config
|
|
|
|
register: config_main
|
|
|
|
|
|
|
|
- name: Check content of drop-in configuration file
|
2022-06-05 09:54:56 +02:00
|
|
|
ansible.builtin.assert:
|
2022-04-06 16:43:45 +02:00
|
|
|
that:
|
|
|
|
- "'Banner /etc/include-issue' in config.content | b64decode"
|
|
|
|
- "'Ciphers aes192-ctr' in config.content | b64decode"
|
|
|
|
- "'Include /etc/ssh/sshd_config.d/*.conf' not in config.content | b64decode"
|
2022-05-02 18:38:50 +02:00
|
|
|
- "'Subsystem sftp /usr/libexec/openssh/sftp-server' not in config.content | b64decode"
|
|
|
|
- "'Subsystem sftp /usr/lib/openssh/sftp-server' not in config.content | b64decode"
|
2022-04-06 16:43:45 +02:00
|
|
|
|
2022-05-02 18:38:50 +02:00
|
|
|
- name: Check common content of the main configuration file
|
2022-06-05 09:54:56 +02:00
|
|
|
ansible.builtin.assert:
|
2022-04-06 16:43:45 +02:00
|
|
|
that:
|
|
|
|
- "'Banner /etc/include-issue' not in config_main.content | b64decode"
|
|
|
|
- "'Ciphers aes192-ctr' not in config_main.content | b64decode"
|
|
|
|
- "'Include /etc/ssh/sshd_config.d/*.conf' in config_main.content | b64decode"
|
2022-05-02 18:38:50 +02:00
|
|
|
|
|
|
|
- name: Check RHEL content of the main configuration file
|
2022-06-05 09:54:56 +02:00
|
|
|
ansible.builtin.assert:
|
2022-05-02 18:38:50 +02:00
|
|
|
that:
|
2022-06-10 09:24:49 +02:00
|
|
|
- "config_main.content | b64decode | regex_search('Subsystem\\ssftp\\s/usr/libexec/openssh/sftp-server')"
|
2022-05-02 18:38:50 +02:00
|
|
|
when: ansible_facts['os_family'] == 'RedHat'
|
|
|
|
|
|
|
|
- name: Check Ubuntu content of the main configuration file
|
2022-06-05 09:54:56 +02:00
|
|
|
ansible.builtin.assert:
|
2022-05-02 18:38:50 +02:00
|
|
|
that:
|
2022-06-10 09:24:49 +02:00
|
|
|
- "config_main.content | b64decode | regex_search('Subsystem\\ssftp\\s/usr/lib/openssh/sftp-server')"
|
2022-05-02 18:38:50 +02:00
|
|
|
when: ansible_facts['os_family'] == 'Ubuntu'
|
|
|
|
|
2022-04-06 16:43:45 +02:00
|
|
|
when:
|
2022-05-02 18:38:50 +02:00
|
|
|
- (ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version']|int > 8) or
|
|
|
|
(ansible_facts['distribution'] == 'Ubuntu' and ansible_facts['distribution_major_version']|int >= 22)
|
2022-04-06 16:43:45 +02:00
|
|
|
|
|
|
|
tags: tests::verify
|
|
|
|
|
|
|
|
- name: "Restore configuration files"
|
2022-06-05 09:54:56 +02:00
|
|
|
ansible.builtin.include_tasks: tasks/restore.yml
|