ansible-sshd/tests/tests_indent.yml

43 lines
1.4 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
2021-08-16 02:23:06 +02:00
Match:
Condition: user root
AllowAgentForwarding: false
2021-08-16 02:23:06 +02:00
- name: Verify the options are correctly set
tags: tests::verify
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:
- "config.content | b64decode | regex_search('^PasswordAuthentication yes$', multiline=True)"
- "config.content | b64decode | regex_search('^PermitRootLogin yes$', multiline=True)"
- "config.content | b64decode | regex_search('^Match user root\\n\\s+AllowAgentForwarding no$', multiline=True)"
- name: "Restore configuration files"
2022-06-05 09:54:56 +02:00
ansible.builtin.include_tasks: tasks/restore.yml