Merge pull request #229 from Jakuje/indent

Make sure the list options are correctly indented
This commit is contained in:
Matt Willsher 2023-04-19 19:52:05 +01:00 committed by GitHub
commit 638e76cf64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 6 deletions

View file

@ -1,14 +1,17 @@
{% macro render_option(key,value,indent=false) %}
{% if value is defined %}
{% if indent %} {% endif %}
{% if value is sameas true %}
{% if indent %} {% endif %}
{{ key }} yes
{% elif value is sameas false %}
{% if indent %} {% endif %}
{{ key }} no
{% elif value is string or value is number %}
{% if indent %} {% endif %}
{{ key }} {{ value | string }}
{% else %}
{% for i in value %}
{% if indent %} {% endif %}
{{ key }} {{ i | string }}
{% endfor %}
{% endif %}

View file

@ -2,15 +2,18 @@
{{ "willshersystems:ansible-sshd" | comment(prefix="", postfix="") }}
{% macro render_option(key,value,indent=false) %}
{% if value is defined %}
{% if indent %} {% endif %}
{% if value is sameas true %}
{% if indent %} {% endif %}
{{ key }} yes
{% elif value is sameas false %}
{% if indent %} {% endif %}
{{ key }} no
{% elif value is string or value is number %}
{% if indent %} {% endif %}
{{ key }} {{ value | string }}
{% else %}
{% for i in value %}
{% if indent %} {% endif %}
{{ key }} {{ i | string }}
{% endfor %}
{% endif %}

View file

@ -1,14 +1,17 @@
{% macro render_option(key,value,indent=true) %}
{% if value is defined %}
{% if indent %} {% endif %}
{% if value is sameas true %}
{% if indent %} {% endif %}
{{ key }} yes
{% elif value is sameas false %}
{% if indent %} {% endif %}
{{ key }} no
{% elif value is string or value is number %}
{% if indent %} {% endif %}
{{ key }} {{ value | string }}
{% else %}
{% for i in value %}
{% if indent %} {% endif %}
{{ key }} {{ i | string }}
{% endfor %}
{% endif %}

View file

@ -16,12 +16,22 @@
sshd:
PasswordAuthentication: true
PermitRootLogin: true
AcceptEnv:
- TEST
- LC_ALL
Match:
Condition: user root
AllowAgentForwarding: false
AcceptEnv:
- TESTENV
- LANG
when:
- not (ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] == '6')
- name: Verify the options are correctly set
tags: tests::verify
when:
- not (ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] == '6')
block:
- name: Flush handlers
ansible.builtin.meta: flush_handlers
@ -34,9 +44,16 @@
- name: Check the options are correctly indented in configuration file
ansible.builtin.assert:
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)"
- 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 }}"
- name: "Restore configuration files"
ansible.builtin.include_tasks: tasks/restore.yml