lvps / 389ds-server

Ansible role to configure 389DS
Apache License 2.0
23 stars 14 forks source link

Fixed a bug in calling handlers when multiple instances run in a loop. #14

Closed falon closed 3 years ago

falon commented 3 years ago

Hello, I noticed that if I run the role in order to add many instances of 389ds server, the handlers doesn't keep the right dirsrv_serverid value, it keeps only the last one in the loop.

For instance, if my task is:

   - name: Install 389ds on each instance
      include_role:
        name: lvps.389ds_server
      loop: "{{ test.instances }}"
      loop_control:
        label: "{{ instance.dirsrv_serverid }}"
        loop_var: instance
      vars:
        dirsrv_serverid: "{{ instance.dirsrv_serverid }}"
        dirsrv_suffix: "{{ instance.dirsrv_suffix }}"
        dirsrv_port: "{{ (instance.dirsrv_port  | default(389, true)) }}"

where the inventory is:

all:
  children:
    test:
      children:
        ldapservers:
          vars:
            test:
              instances:
                - dirsrv_serverid: 'tst-A'
                  dirsrv_suffix: c=enA
                - dirsrv_serverid: 'tst-B'
                  dirsrv_suffix: c=enB
                  dirsrv_port: 489

Then, at the end of "tst-A" installation the handler of dirsrv restart runs on 'tst-B' value of dirsrv_serverid. To work correctly I must add the dirsrv_serverid value on the name of the handler.

I don't know why, I suppose is something related how Ansible manages the variables in loop. Maybe this is not the better way to fix this, but it works well for me.

lvps commented 3 years ago

Looks good to me, too. Probably handlers were running at the very end of the playbook, so giving them different names was the only solution.