commit c2f84a57cc507596074ad104161b84ede17fb52c
parent d1d03ad41043f5565db0ec2bcc39605c91b59623
Author: Leah (ctucx) <leah@ctu.cx>
Date: Sun, 21 Feb 2021 18:22:43 +0100
parent d1d03ad41043f5565db0ec2bcc39605c91b59623
Author: Leah (ctucx) <leah@ctu.cx>
Date: Sun, 21 Feb 2021 18:22:43 +0100
roles/bind: restart using handlers
7 files changed, 37 insertions(+), 38 deletions(-)
diff --git a/roles/bind/handlers/main.yml b/roles/bind/handlers/main.yml @@ -0,0 +1,17 @@ +--- + +- name: "[OpenRC] Restart service: bind (to deploy config changes)" + service: + name: bind + state: restarted + when: + - ansible_service_mgr == "openrc" + listen: "Restart bind" + +- name: "[systemd] Restart service: bind (to deploy config changes)" + systemd: + name: bind + state: restarted + when: + - ansible_service_mgr == "systemd" + listen: "Restart bind"
diff --git a/roles/bind/meta/main.yml b/roles/bind/meta/main.yml @@ -0,0 +1,4 @@ +--- + +dependencies: + - nftables-handler+ \ No newline at end of file
diff --git a/roles/bind/tasks/configure.yml b/roles/bind/tasks/configure.yml @@ -4,7 +4,7 @@ git: repo: '{{ services.bind.zonesRepo }}' dest: /var/lib/named/zones - register: zonesClone + notify: "Restart bind" when: - services.bind.zonesRepo is defined @@ -15,7 +15,6 @@ group: named state: directory recurse: yes - register: setPermissions - name: "[Alpine] Generate named.conf" template: @@ -23,7 +22,7 @@ dest: /etc/bind/named.conf owner: named group: named - register: namedConfig + notify: "Restart bind" when: - ansible_distribution == "Alpine" @@ -33,6 +32,6 @@ dest: /etc/named.conf owner: named group: named - register: namedConfig + notify: "Restart bind" when: - ansible_distribution == "Archlinux"
diff --git a/roles/bind/tasks/firewall.yml b/roles/bind/tasks/firewall.yml @@ -4,17 +4,4 @@ copy: src: nftables-rule.nft dest: /etc/nftables.d/bind.nft - -- name: "[OpenRC] Restart service: nftables" - service: - name: nftables - state: restarted - when: - - ansible_service_mgr == "openrc" - -- name: "[systemd] Restart service: nftables" - systemd: - name: nftables - state: restarted - when: - - ansible_service_mgr == "systemd" + notify: Restart nftables+ \ No newline at end of file
diff --git a/roles/bind/tasks/install.yml b/roles/bind/tasks/install.yml @@ -5,6 +5,7 @@ name: bind state: present update_cache: yes + notify: "Restart bind" when: - ansible_distribution == "Alpine" @@ -13,5 +14,6 @@ name: bind state: present update_cache: yes + notify: "Restart bind" when: - ansible_distribution == "Archlinux"
diff --git a/roles/bind/tasks/main.yml b/roles/bind/tasks/main.yml @@ -10,16 +10,19 @@ - services.bind.enable is defined - services.bind.enable is true -- include: start.yml +- include: firewall.yml when: - services.bind.enable is defined - services.bind.enable is true + - network.nftables.enable is true -- include: firewall.yml +- include: start.yml when: - services.bind.enable is defined - services.bind.enable is true - - network.nftables.enable is true + +- name: Run handlers + meta: flush_handlers - include: remove.yml when:
diff --git a/roles/bind/tasks/start.yml b/roles/bind/tasks/start.yml @@ -14,20 +14,4 @@ enabled: yes state: started when: - - ansible_service_mgr == "systemd" - -- name: "[OpenRC] Restart service: named (to deploy config changed)" - service: - name: named - state: restarted - when: - - ansible_service_mgr == "openrc" - - zonesClone.changed or setPermissions.changed or namedConfig.changed - -- name: "[systemd] Restart service: named (to deploy config changed)" - systemd: - name: named - state: restarted - when: - - ansible_service_mgr == "systemd" - - zonesClone.changed or setPermissions.changed or namedConfig.changed + - ansible_service_mgr == "systemd"+ \ No newline at end of file