From 2d3b7c00651bcebf1c6e2dc52341cf93cffb962d Mon Sep 17 00:00:00 2001 From: Max Kochubey Date: Wed, 14 Mar 2018 16:35:26 +0700 Subject: [PATCH 01/12] All "sudo" have been replaced by "become" --- handlers/main.yml | 8 ++++---- tasks/main.yml | 6 +++--- tests/tasks/configuration.yml | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index 163a24d..fd4990c 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -8,22 +8,22 @@ service: name=bind9 state=reloaded - sudo: yes + become: yes - name: restart bind9 service: name=bind9 state=restarted - sudo: yes + become: yes - name: start bind9 service: name=bind9 state=started - sudo: yes + become: yes - name: stop bind9 service: name=bind9 state=stopped - sudo: yes + become: yes diff --git a/tasks/main.yml b/tasks/main.yml index c2dd0d8..d2e7579 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -13,12 +13,12 @@ - include: installation.yml tags: installation - sudo: yes + become: yes - include: configuration.yml tags: configuration - sudo: yes + become: yes - include: apparmor.yml tags: apparmor - sudo: yes + become: yes diff --git a/tests/tasks/configuration.yml b/tests/tasks/configuration.yml index 5784143..e2f24df 100644 --- a/tests/tasks/configuration.yml +++ b/tests/tasks/configuration.yml @@ -32,7 +32,7 @@ copy: src="tmp/named.conf{{ item }}.expected" dest="/tmp/named.conf{{ item }}.expected" - sudo: yes + become: yes changed_when: no with_items: - '' @@ -65,7 +65,7 @@ copy: src="tmp/db.{{ item }}.zone.expected" dest="/tmp/db.{{ item }}.zone.expected" - sudo: yes + become: yes changed_when: no with_items: - 'example.com' From adfe3d3e2588de76559455fcdf808015180deb34 Mon Sep 17 00:00:00 2001 From: Max Kochubey Date: Wed, 14 Mar 2018 16:55:26 +0700 Subject: [PATCH 02/12] There is no need to use jinja2 delimiters in "when" --- tasks/validation.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/validation.yml b/tasks/validation.yml index 9335889..301dc34 100644 --- a/tasks/validation.yml +++ b/tasks/validation.yml @@ -15,7 +15,7 @@ - name: ensure mandatory variables are set fail: msg="{{ item }} is a mandatory variable" - when: "{{ item }} is not defined" + when: "item is not defined" with_items: - bind_default_resolvconf - bind_default_options From eea03f0dc79012f2eeb410729190a0650597ba2f Mon Sep 17 00:00:00 2001 From: Max Kochubey Date: Wed, 14 Mar 2018 17:05:10 +0700 Subject: [PATCH 03/12] Deprecated "include" replaced by "import_tasks" --- tasks/main.yml | 10 +++++----- tests/tasks/main.yml | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index d2e7579..cc7c0c0 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -4,21 +4,21 @@ # tasks file # -- include: debug.yml +- import_tasks: debug.yml when: debug | default(false) tags: debug -- include: validation.yml +- import_tasks: validation.yml tags: validation -- include: installation.yml +- import_tasks: installation.yml tags: installation become: yes -- include: configuration.yml +- import_tasks: configuration.yml tags: configuration become: yes -- include: apparmor.yml +- import_tasks: apparmor.yml tags: apparmor become: yes diff --git a/tests/tasks/main.yml b/tests/tasks/main.yml index 588a677..9c4a2b1 100644 --- a/tests/tasks/main.yml +++ b/tests/tasks/main.yml @@ -4,10 +4,10 @@ # Test tasks to verify role execution. # -- include: installation.yml +- import_tasks: installation.yml tags: installation -- include: configuration.yml +- import_tasks: configuration.yml tags: configuration - name: test syntax of configuration files From 748bdf79aea3c914307759704e558fe97ed28498 Mon Sep 17 00:00:00 2001 From: Max Kochubey Date: Wed, 14 Mar 2018 18:09:52 +0700 Subject: [PATCH 04/12] One more "sudo" replaced --- tests/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tasks/main.yml b/tests/tasks/main.yml index 9c4a2b1..e2e14fc 100644 --- a/tests/tasks/main.yml +++ b/tests/tasks/main.yml @@ -22,7 +22,7 @@ - name: test if bind9 process is running shell: service bind9 status - sudo: yes + become: yes register: test changed_when: no failed_when: test.stdout.find('bind9 is running') == -1 From d8cdb89058f819f8db2c818af9631940072ed9b5 Mon Sep 17 00:00:00 2001 From: Max Kochubey Date: Wed, 14 Mar 2018 18:10:47 +0700 Subject: [PATCH 05/12] Ansible constants chaged to ansible module_utils --- tests/plugins/callback/idempotence.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/plugins/callback/idempotence.py b/tests/plugins/callback/idempotence.py index f583e1b..a35f916 100644 --- a/tests/plugins/callback/idempotence.py +++ b/tests/plugins/callback/idempotence.py @@ -6,7 +6,7 @@ import os from ansible import constants as C -from ansible.constants import mk_boolean +from ansible.module_utils.parsing.convert_bool import boolean try: from ansible.plugins.callback import CallbackBase @@ -27,7 +27,7 @@ class CallbackModule(parent): def __init__(self): self.playbook = None - self.enabled = mk_boolean(os.getenv(VAR_IDEMPOTENCE, 'no')) + self.enabled = boolean(os.getenv(VAR_IDEMPOTENCE, 'no')) super(CallbackModule, self).__init__() From a7b46e438edb857e58a41318036ffb8ef8dfc63e Mon Sep 17 00:00:00 2001 From: Max Kochubey Date: Mon, 19 Mar 2018 16:38:28 +0700 Subject: [PATCH 06/12] Two unnecessary spaces before "include" statement --- templates/etc/bind/named.conf.local.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/etc/bind/named.conf.local.j2 b/templates/etc/bind/named.conf.local.j2 index 637507f..26827a7 100644 --- a/templates/etc/bind/named.conf.local.j2 +++ b/templates/etc/bind/named.conf.local.j2 @@ -9,7 +9,7 @@ {% if bind_local_includes is defined %} {% for content in bind_local_includes %} - include "{{ content }}"; +include "{{ content }}"; {% endfor %} {% endif %} From 8360f809c9e682cf97db9a5318ed516140d1ed28 Mon Sep 17 00:00:00 2001 From: Max Kochubey Date: Mon, 19 Mar 2018 16:40:14 +0700 Subject: [PATCH 07/12] Extra carriage return after "includes" moved to "if" condition --- templates/etc/bind/named.conf.local.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/etc/bind/named.conf.local.j2 b/templates/etc/bind/named.conf.local.j2 index 26827a7..76d483e 100644 --- a/templates/etc/bind/named.conf.local.j2 +++ b/templates/etc/bind/named.conf.local.j2 @@ -11,8 +11,8 @@ {% for content in bind_local_includes %} include "{{ content }}"; {% endfor %} -{% endif %} +{% endif %} {% if bind_zones is defined %} {% for zone, content in bind_zones.iteritems() | sort %} zone "{{ zone }}" { From 60587085570bb027cc5746005b667359a3cfc51f Mon Sep 17 00:00:00 2001 From: Max Kochubey Date: Mon, 19 Mar 2018 17:57:46 +0700 Subject: [PATCH 08/12] Removed unwanted empty list element causing carriage return in named.conf.options --- templates/etc/bind/named.conf.options.j2 | 2 +- tests/files/tmp/named.conf.options.expected | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/templates/etc/bind/named.conf.options.j2 b/templates/etc/bind/named.conf.options.j2 index 2b687c0..5a1e267 100644 --- a/templates/etc/bind/named.conf.options.j2 +++ b/templates/etc/bind/named.conf.options.j2 @@ -1,7 +1,7 @@ // {{ ansible_managed }} options { -{% for line in bind_named_conf_options.split('\n')| sort %} +{% for line in bind_named_conf_options.split('\n') | reject("equalto", "") | sort %} {{ line }} {% endfor %} }; diff --git a/tests/files/tmp/named.conf.options.expected b/tests/files/tmp/named.conf.options.expected index 153c880..97682aa 100644 --- a/tests/files/tmp/named.conf.options.expected +++ b/tests/files/tmp/named.conf.options.expected @@ -1,7 +1,6 @@ // Ansible managed file, do not edit directly options { - auth-nxdomain no; directory "/var/cache/bind"; dnssec-validation auto; From d59f937ffffae6e8ef42cf960fb9c84abc0bc6cb Mon Sep 17 00:00:00 2001 From: Max Kochubey Date: Mon, 19 Mar 2018 18:10:47 +0700 Subject: [PATCH 09/12] Indents in jinja2 conditions breaks tests and named.conf.logging formatting --- templates/etc/bind/named.conf.logging.j2 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/templates/etc/bind/named.conf.logging.j2 b/templates/etc/bind/named.conf.logging.j2 index a4a2fe9..bcecaea 100644 --- a/templates/etc/bind/named.conf.logging.j2 +++ b/templates/etc/bind/named.conf.logging.j2 @@ -11,13 +11,13 @@ logging { {% endfor %} {% for category, channel in bind_named_conf_logging.categories.iteritems() %} - {# Old Style #} - {% if channel is string %} - category {{ category }} { {{ channel }}; }; - {# New Style #} - {% elif channel is sequence %} - category {{ category }} { {{ channel | join('; ')}}; }; - {% endif %} +{# Old Style #} +{% if channel is string %} + category {{ category }} { {{ channel }}; }; +{# New Style #} +{% elif channel is sequence %} + category {{ category }} { {{ channel | join('; ')}}; }; +{% endif %} {% endfor %} }; {% endif %} From 5ce9319a0277b1bc5964384afeb1842cee95ffe1 Mon Sep 17 00:00:00 2001 From: Max Kochubey Date: Mon, 19 Mar 2018 18:37:23 +0700 Subject: [PATCH 10/12] Removed unneeded newlines; formatting improved --- templates/etc/bind/named.conf.logging.j2 | 12 ++++++------ tests/files/tmp/named.conf.logging.expected | 3 --- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/templates/etc/bind/named.conf.logging.j2 b/templates/etc/bind/named.conf.logging.j2 index bcecaea..c09badd 100644 --- a/templates/etc/bind/named.conf.logging.j2 +++ b/templates/etc/bind/named.conf.logging.j2 @@ -2,15 +2,15 @@ {% if bind_named_conf_logging is defined and bind_named_conf_logging.channels is defined %} logging { -{% for channel, content in bind_named_conf_logging.channels.iteritems() | sort %} +{% for channel, content in bind_named_conf_logging.channels.iteritems() | reject("equalto", "") | sort %} channel {{ channel }} { -{% for line in content.split('\n') %} +{% for line in content.split('\n') | reject("equalto", "") %} {{ line }} -{% endfor %} +{% endfor %} }; -{% endfor %} +{% endfor %} -{% for category, channel in bind_named_conf_logging.categories.iteritems() %} +{% for category, channel in bind_named_conf_logging.categories.iteritems() %} {# Old Style #} {% if channel is string %} category {{ category }} { {{ channel }}; }; @@ -18,6 +18,6 @@ logging { {% elif channel is sequence %} category {{ category }} { {{ channel | join('; ')}}; }; {% endif %} -{% endfor %} +{% endfor %} }; {% endif %} diff --git a/tests/files/tmp/named.conf.logging.expected b/tests/files/tmp/named.conf.logging.expected index 3c117ac..74d6eb9 100644 --- a/tests/files/tmp/named.conf.logging.expected +++ b/tests/files/tmp/named.conf.logging.expected @@ -7,21 +7,18 @@ logging { print-category yes; print-severity yes; print-time yes; - }; channel security_info { file "/var/log/named/security_info.log" versions 1 size 100k; severity info; print-severity yes; print-time yes; - }; channel update_debug { file "/var/log/named/update_debug.log" versions 3 size 100k; severity debug; print-severity yes; print-time yes; - }; category default { bind_log; }; From e92d9a2b1c9a1fec6f8a4968e781dba98dcf3417 Mon Sep 17 00:00:00 2001 From: Max Kochubey Date: Mon, 19 Mar 2018 19:14:24 +0700 Subject: [PATCH 11/12] Unsorted lists breaks diffs while file comparisons in travis-ci jobs --- templates/etc/bind/named.conf.logging.j2 | 4 ++-- tests/files/tmp/named.conf.logging.expected | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/etc/bind/named.conf.logging.j2 b/templates/etc/bind/named.conf.logging.j2 index c09badd..99ed662 100644 --- a/templates/etc/bind/named.conf.logging.j2 +++ b/templates/etc/bind/named.conf.logging.j2 @@ -4,13 +4,13 @@ logging { {% for channel, content in bind_named_conf_logging.channels.iteritems() | reject("equalto", "") | sort %} channel {{ channel }} { -{% for line in content.split('\n') | reject("equalto", "") %} +{% for line in content.split('\n') | reject("equalto", "") | sort %} {{ line }} {% endfor %} }; {% endfor %} -{% for category, channel in bind_named_conf_logging.categories.iteritems() %} +{% for category, channel in bind_named_conf_logging.categories.iteritems() | sort %} {# Old Style #} {% if channel is string %} category {{ category }} { {{ channel }}; }; diff --git a/tests/files/tmp/named.conf.logging.expected b/tests/files/tmp/named.conf.logging.expected index 74d6eb9..5f236bf 100644 --- a/tests/files/tmp/named.conf.logging.expected +++ b/tests/files/tmp/named.conf.logging.expected @@ -3,22 +3,22 @@ logging { channel bind_log { file "/var/log/named/bind.log" versions 3 size 1m; - severity info; print-category yes; print-severity yes; print-time yes; + severity info; }; channel security_info { file "/var/log/named/security_info.log" versions 1 size 100k; - severity info; print-severity yes; print-time yes; + severity info; }; channel update_debug { file "/var/log/named/update_debug.log" versions 3 size 100k; - severity debug; print-severity yes; print-time yes; + severity debug; }; category default { bind_log; }; From edef47605e395e698973f4f4446b9338a922c443 Mon Sep 17 00:00:00 2001 From: Max Kochubey Date: Mon, 19 Mar 2018 19:45:41 +0700 Subject: [PATCH 12/12] DNS zone file records should be sorted too --- templates/var/cache/bind/db.name.zone.j2 | 4 ++-- tests/files/tmp/db.example.com.zone.expected | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/var/cache/bind/db.name.zone.j2 b/templates/var/cache/bind/db.name.zone.j2 index 2c10547..b8ce28e 100644 --- a/templates/var/cache/bind/db.name.zone.j2 +++ b/templates/var/cache/bind/db.name.zone.j2 @@ -1,12 +1,12 @@ ; {{ ansible_managed }} {% if 'directives' in item.value %} -{% for directive, value in item.value.directives.iteritems() %} +{% for directive, value in item.value.directives.iteritems() | sort %} ${{ directive }} {{ value }} {% endfor %} {% endif %} {% if 'resource_records' in item.value %} -{% for record in item.value.resource_records %} +{% for record in item.value.resource_records | sort(attribute='type', reverse = True) %} {% if 'name' in record %}{{ (record.name|string).ljust(25) }}{% endif %} {% if 'ttl' in record %}{{ (record.ttl|string).ljust(5) }}{% endif %} {% if 'class' in record %}{{ (record.class|string).ljust(3) }}{% endif %} {% if 'type' in record %}{{ (record.type|string).ljust(10) }}{% endif %} {% if 'data' in record %}{{ record.data }}{% endif %} {% endfor %} diff --git a/tests/files/tmp/db.example.com.zone.expected b/tests/files/tmp/db.example.com.zone.expected index 53eaf42..89e1d8b 100644 --- a/tests/files/tmp/db.example.com.zone.expected +++ b/tests/files/tmp/db.example.com.zone.expected @@ -5,8 +5,8 @@ $TTL 3600 example.com. IN SOA sid.example.com. root.example.com. ( 2007120710 1d 2h 4w 1h ) @ IN NS sid.example.com. @ IN MX 10 sid.example.com. -sid IN A 192.168.0.1 -etch IN A 192.168.0.2 pop IN CNAME sid www IN CNAME sid mail IN CNAME sid +sid IN A 192.168.0.1 +etch IN A 192.168.0.2