'Ansible: second lineinfile task doesn't do anything

I'm trying to add entries to 2 ACLs in named.conf with ansible's lineinfile module, but it seems that only the first task is being run.

The configuration is:

acl operacao {
        192.168.1.33;
        192.168.2.29;
        10.10.0.0/24;
        };

acl monitoring {
        10.10.0.0/24;
        };

So I created a playbook with 2 tasks:

    - name: add to operacao acl
      lineinfile:
        path: "/etc/named.conf"
        line: "        10.2.2.0/24;"
        insertafter: "acl operacao"
      register: acl_op

    - name: add to monitoring acl
      lineinfile:
        path: "/etc/named.conf"
        line: "        10.2.2.0/24;"
        insertafter: "acl monitoring"
      register: acl_mon

When run with the --check flag, it correctly predicts where the lines will be inserted:

TASK [add to operacao acl] **************************************************************************************************************************************************************************************************************************************************************************************************
--- before: /etc/named.conf (content)
+++ after: /etc/named.conf (content)
@@ -21,6 +21,7 @@
 };

 acl operacao {
+        10.2.2.0/24;
         192.168.1.33;
         192.168.2.29;
         10.10.0.0/24;

changed: [dnshost01]

TASK [add to monitoring acl] ************************************************************************************************************************************************************************************************************************************************************************************************
--- before: /etc/named.conf (content)
+++ after: /etc/named.conf (content)
@@ -27,6 +27,7 @@
         };

 acl monitoring {
+        10.2.2.0/24;
         10.10.0.0/24;
         };

However, when run without the --check flag, it only shows changes on the first task, the second doesn't run:

TASK [add to operacao acl] **************************************************************************************************************************************************************************************************************************************************************************************************
--- before: /etc/named.conf (content)
+++ after: /etc/named.conf (content)
@@ -21,6 +21,7 @@
 };

 acl operacao {
+        10.2.2.0/24;
         192.168.1.33;
         192.168.2.29;
         10.10.0.0/24;

changed: [dnshost01]

TASK [add to monitoring acl] ************************************************************************************************************************************************************************************************************************************************************************************************
ok: [dnshost01]

This is always run with --flush-cache.

What is happening here? Am I misunderstanding something, or is ansible bugged?

I'm running ansible 2.9.27 on RHEL8.5 / python 3.6.8. This behaviour happens for RHEL6 and RHEL7 hosts.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source