ansible-sshd/tests/tests_indent.yml

60 lines
2.1 KiB
YAML
Raw Normal View History

2021-08-16 02:23:06 +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:
PasswordAuthentication: true
PermitRootLogin: true
AcceptEnv:
- TEST
- LC_ALL
2021-08-16 02:23:06 +02:00
Match:
Condition: user root
AllowAgentForwarding: false
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
tags: tests::verify
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:
- 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