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) %} {% macro render_option(key,value,indent=false) %}
{% if value is defined %} {% if value is defined %}
{% if indent %} {% endif %}
{% if value is sameas true %} {% if value is sameas true %}
{% if indent %} {% endif %}
{{ key }} yes {{ key }} yes
{% elif value is sameas false %} {% elif value is sameas false %}
{% if indent %} {% endif %}
{{ key }} no {{ key }} no
{% elif value is string or value is number %} {% elif value is string or value is number %}
{% if indent %} {% endif %}
{{ key }} {{ value | string }} {{ key }} {{ value | string }}
{% else %} {% else %}
{% for i in value %} {% for i in value %}
{% if indent %} {% endif %}
{{ key }} {{ i | string }} {{ key }} {{ i | string }}
{% endfor %} {% endfor %}
{% endif %} {% endif %}

View file

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

View file

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

View file

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