2021-08-16 02:23:06 +02:00
|
|
|
---
|
2023-04-10 22:19:29 +02:00
|
|
|
- name: Test indentation
|
|
|
|
hosts: all
|
2021-08-16 02:23:06 +02:00
|
|
|
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
|
2021-08-16 02:23:06 +02:00
|
|
|
|
|
|
|
- name: Configure sshd with simple config options
|
2022-06-05 09:54:56 +02:00
|
|
|
ansible.builtin.include_role:
|
2021-08-16 02:23:06 +02:00
|
|
|
name: ansible-sshd
|
|
|
|
vars:
|
|
|
|
sshd:
|
2023-04-10 22:19:29 +02:00
|
|
|
PasswordAuthentication: true
|
|
|
|
PermitRootLogin: true
|
2023-04-14 17:49:02 +02:00
|
|
|
AcceptEnv:
|
|
|
|
- TEST
|
|
|
|
- LC_ALL
|
2021-08-16 02:23:06 +02:00
|
|
|
Match:
|
|
|
|
Condition: user root
|
2023-04-10 22:19:29 +02:00
|
|
|
AllowAgentForwarding: false
|
2023-04-14 17:49:02 +02:00
|
|
|
AcceptEnv:
|
|
|
|
- TESTENV
|
|
|
|
- LANG
|
|
|
|
when:
|
|
|
|
- not (ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] == '6')
|
2021-08-16 02:23:06 +02:00
|
|
|
|
|
|
|
- name: Verify the options are correctly set
|
2023-04-10 22:19:29 +02:00
|
|
|
tags: tests::verify
|
2023-04-14 17:49:02 +02:00
|
|
|
when:
|
|
|
|
- not (ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] == '6')
|
2021-08-16 02:23:06 +02:00
|
|
|
block:
|
2022-06-05 09:54:56 +02:00
|
|
|
- name: Flush handlers
|
|
|
|
ansible.builtin.meta: flush_handlers
|
2021-08-16 02:23:06 +02:00
|
|
|
|
|
|
|
- name: Print current configuration file
|
2022-06-05 09:54:56 +02:00
|
|
|
ansible.builtin.slurp:
|
2021-08-16 02:23:06 +02:00
|
|
|
src: "{{ main_sshd_config }}"
|
|
|
|
register: config
|
|
|
|
|
|
|
|
- name: Check the options are correctly indented in configuration file
|
2022-06-05 09:54:56 +02:00
|
|
|
ansible.builtin.assert:
|
2021-08-16 02:23:06 +02:00
|
|
|
that:
|
2023-04-14 17:49:02 +02:00
|
|
|
- content is search ('^PasswordAuthentication yes$', multiline=True)
|
|
|
|
- content is search ('^PermitRootLogin yes$', multiline=True)
|
|
|
|
- content is search ("^AcceptEnv TEST$", multiline=True)
|
|
|
|
- content is search ("^AcceptEnv LC_ALL$", multiline=True)
|
|
|
|
- content is search ('^Match user root$', multiline=True)
|
|
|
|
- content is search ("^ AcceptEnv TESTENV$", multiline=True)
|
|
|
|
- content is search ("^ AcceptEnv LANG$", multiline=True)
|
|
|
|
- content is search ('^ AllowAgentForwarding no$', multiline=True)
|
|
|
|
vars:
|
|
|
|
content: "{{ config.content | b64decode }}"
|
2021-08-16 02:23:06 +02:00
|
|
|
|
|
|
|
- name: "Restore configuration files"
|
2022-06-05 09:54:56 +02:00
|
|
|
ansible.builtin.include_tasks: tasks/restore.yml
|