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..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 - sudo: yes + become: yes -- include: configuration.yml +- import_tasks: configuration.yml tags: configuration - sudo: yes + become: yes -- include: apparmor.yml +- import_tasks: apparmor.yml tags: apparmor - sudo: yes + become: yes 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 diff --git a/templates/etc/bind/named.conf.local.j2 b/templates/etc/bind/named.conf.local.j2 index 637507f..76d483e 100644 --- a/templates/etc/bind/named.conf.local.j2 +++ b/templates/etc/bind/named.conf.local.j2 @@ -9,10 +9,10 @@ {% if bind_local_includes is defined %} {% for content in bind_local_includes %} - include "{{ content }}"; +include "{{ content }}"; {% endfor %} -{% endif %} +{% endif %} {% if bind_zones is defined %} {% for zone, content in bind_zones.iteritems() | sort %} zone "{{ zone }}" { diff --git a/templates/etc/bind/named.conf.logging.j2 b/templates/etc/bind/named.conf.logging.j2 index a4a2fe9..99ed662 100644 --- a/templates/etc/bind/named.conf.logging.j2 +++ b/templates/etc/bind/named.conf.logging.j2 @@ -2,22 +2,22 @@ {% 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", "") | sort %} {{ line }} -{% endfor %} +{% endfor %} }; -{% endfor %} +{% 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 %} -{% endfor %} +{% for category, channel in bind_named_conf_logging.categories.iteritems() | sort %} +{# Old Style #} +{% if channel is string %} + category {{ category }} { {{ channel }}; }; +{# New Style #} +{% elif channel is sequence %} + category {{ category }} { {{ channel | join('; ')}}; }; +{% endif %} +{% endfor %} }; {% endif %} 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/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 diff --git a/tests/files/tmp/named.conf.logging.expected b/tests/files/tmp/named.conf.logging.expected index 3c117ac..5f236bf 100644 --- a/tests/files/tmp/named.conf.logging.expected +++ b/tests/files/tmp/named.conf.logging.expected @@ -3,25 +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; }; 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; 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__() 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' diff --git a/tests/tasks/main.yml b/tests/tasks/main.yml index 588a677..e2e14fc 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 @@ -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