diff --git a/tasks/main.yml b/tasks/main.yml index f340945..a00c1de 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,15 +1,15 @@ --- -- name: include special distribution-dependent variables +- name: Include special distribution-dependent variables include_vars: "{{ ansible_os_family }}.yml" -- name: install bind and dependencies +- name: Install bind and dependencies package: name: "{{ item }}" state: present with_items: "{{ bind_package_names }}" -- name: create logging directory +- name: Create logging directory file: path: "{{ bind_log_directory }}" owner: "{{ bind_unix_user }}" @@ -18,7 +18,16 @@ state: directory recurse: yes -- name: remove existing journal files +- name: Create config directory + file: + path: "{{ bind_config_directory }}" + owner: "{{ bind_unix_user }}" + group: "{{ bind_unix_group }}" + mode: 0755 + state: directory + recurse: yes + +- name: Remove existing journal files block: - name: find existing journal files find: @@ -40,30 +49,39 @@ # loop_control: # loop_var: view -- name: template zone files +- name: Create DNS-Zone files include_tasks: template_zone_files.yml with_items: - "{{ bind9_views }}" loop_control: loop_var: view -- name: set up global bind config +- name: Create main configuration file + template: + src: "etc/named.conf.j2" + dest: "{{ bind_main_config }}" + owner: "{{ bind_unix_user }}" + group: "{{ bind_unix_group }}" + mode: 0644 + notify: restart named + +- name: Create excluded configuration files template: src: "{{ item }}.j2" - dest: "/etc/{{ item }}" + dest: "{{ item | replace('etc/named', bind_config_directory) }}" owner: "{{ bind_unix_user }}" group: "{{ bind_unix_group }}" mode: 0644 with_items: - - named.conf - - named/named.conf.acl - - named/named.conf.logging - - named/named.conf.options - - named/named.conf.tsigkeys - - named/named.conf.views + - etc/named.conf + - etc/named/named.conf.acl + - etc/named/named.conf.logging + - etc/named/named.conf.options + - etc/named/named.conf.tsigkeys + - etc/named/named.conf.views notify: restart named -- name: start and enabled named +- name: Start and enabled named systemd: name: named state: started diff --git a/templates/etc/named.conf.j2 b/templates/etc/named.conf.j2 new file mode 100644 index 0000000..9aaca49 --- /dev/null +++ b/templates/etc/named.conf.j2 @@ -0,0 +1,14 @@ +# +# {{ ansible_managed }} +# + +# zone "." IN { +# type hint; +# file "named.ca"; +# }; + +include "{{ bind_config_directory }}/named.conf.acl"; +include "{{ bind_config_directory }}/named.conf.logging"; +include "{{ bind_config_directory }}/named.conf.options"; +include "{{ bind_config_directory }}/named.conf.tsigkeys"; +include "{{ bind_config_directory }}/named.conf.views"; diff --git a/templates/named/named.conf.acl.j2 b/templates/etc/named/named.conf.acl.j2 similarity index 100% rename from templates/named/named.conf.acl.j2 rename to templates/etc/named/named.conf.acl.j2 diff --git a/templates/named/named.conf.logging.j2 b/templates/etc/named/named.conf.logging.j2 similarity index 100% rename from templates/named/named.conf.logging.j2 rename to templates/etc/named/named.conf.logging.j2 diff --git a/templates/named/named.conf.options.j2 b/templates/etc/named/named.conf.options.j2 similarity index 99% rename from templates/named/named.conf.options.j2 rename to templates/etc/named/named.conf.options.j2 index 11488af..249382d 100644 --- a/templates/named/named.conf.options.j2 +++ b/templates/etc/named/named.conf.options.j2 @@ -167,7 +167,7 @@ options { # allow-update-forwarding {}; {% endif %} - directory "/etc/named"; + directory "{{ bind_config_directory }}"; dnssec-validation {{ bind9_options.dnssec_validation | default('no') }}; diff --git a/templates/named/named.conf.tsigkeys.j2 b/templates/etc/named/named.conf.tsigkeys.j2 similarity index 100% rename from templates/named/named.conf.tsigkeys.j2 rename to templates/etc/named/named.conf.tsigkeys.j2 diff --git a/templates/named/named.conf.views.j2 b/templates/etc/named/named.conf.views.j2 similarity index 99% rename from templates/named/named.conf.views.j2 rename to templates/etc/named/named.conf.views.j2 index c8edb1f..b0dc33f 100644 --- a/templates/named/named.conf.views.j2 +++ b/templates/etc/named/named.conf.views.j2 @@ -127,7 +127,7 @@ view "{{ view.name }}" { # is complete. If the Master is not available or the Slave fails to # contact the Master, ffor whatever reason, the zone may be left with # no effective Authoritative Name Servers. - file "/etc/named/{{ zone.file }}"; + file "{{ bind_config_directory }}/{{ zone.file }}"; # master servers # https://bind9.readthedocs.io/en/latest/manpages.html?highlight=masters#masters diff --git a/templates/named.conf.j2 b/templates/named.conf.j2 deleted file mode 100644 index f448f0e..0000000 --- a/templates/named.conf.j2 +++ /dev/null @@ -1,12 +0,0 @@ -# zone "." IN { -# type hint; -# file "named.ca"; -# }; - -include "/etc/named/named.conf.acl"; -include "/etc/named/named.conf.logging"; -include "/etc/named/named.conf.options"; -include "/etc/named/named.conf.tsigkeys"; -include "/etc/named/named.conf.views"; -# include "/etc/named.rfc1912.zones"; -# include "/etc/named.root.key"; diff --git a/vars/Debian.yml b/vars/Debian.yml index 1dcb90d..8383451 100644 --- a/vars/Debian.yml +++ b/vars/Debian.yml @@ -1,8 +1,8 @@ --- -bind_main_config: /etc/named.conf -bind_config_directory: /etc/named -bind_log_directory: /var/log/named +bind_main_config: /etc/bind/named.conf +bind_config_directory: /etc/bind +bind_log_directory: /var/log/bind bind_package_names: - bind9