From a1b08d5935de21449861924a509622a33325fcbf Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Tue, 30 Jul 2019 20:18:07 +0300 Subject: [PATCH] Fix(named): Fix conditions Check 3 conditions: the file is absent (`grep` reports error but stdout is empty), the file exists but doesn't contain the line (`grep` returns error code 1 and stdout is '0'), the file contains the line (stdout contains the count >= 1). --- playbooks/debian/roles/named/tasks/main.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/playbooks/debian/roles/named/tasks/main.yml b/playbooks/debian/roles/named/tasks/main.yml index 7e433ec..b39eda3 100644 --- a/playbooks/debian/roles/named/tasks/main.yml +++ b/playbooks/debian/roles/named/tasks/main.yml @@ -1,12 +1,12 @@ - name: Check named.conf.options become: true - shell: "grep -c '^\\s*allow-query' /etc/bind/named.conf.options || echo 0" + shell: "grep -c '^\\s*allow-query' /etc/bind/named.conf.options || :" register: named_conf - changed_when: named_conf.stdout == "0" + changed_when: named_conf.stdout in ('', "0") - debug: msg: "BIND has already been configured" - when: named_conf.stdout != "0" + when: named_conf.stdout not in ('', "0") - name: Install BIND become: true @@ -18,7 +18,7 @@ purge: yes state: latest update_cache: yes - when: named_conf.stdout == "0" + when: named_conf.stdout in ('', "0") - name: Configure BIND become: true @@ -28,11 +28,11 @@ owner: bind group: bind mode: '0600' - when: named_conf.stdout == "0" + when: named_conf.stdout in ('', "0") - name: Reload BIND become: true service: name: bind9 state: reloaded - when: named_conf.stdout == "0" + when: named_conf.stdout in ('', "0") -- 2.39.5