Hi,
Thank you very much for the answer.
Unfortunetly, I don’t think that it will answer my question.
I probably was not clear enough, and I’m sorry…
I thinks that what I’m asking is not possible due to handler scope, but I hope I’m wrong…
An example :
cat << EOF > playbook1.yml
- hosts: localhost
gather_facts: no
handlers:
- import_tasks: handler.yml
tasks:
- debug:
msg: “Child playbook 1 - task 1”
notify: “one handler”
changed_when: True
- debug:
msg: “Child playbook 1 - task 2”
notify: “one handler”
changed_when: True
EOF
cat << EOF > playbook2.yml
- hosts: localhost
gather_facts: no
handlers:
- import_tasks: handler.yml
tasks:
- debug:
msg: “Child playbook 2 - task 1”
notify: “one handler”
changed_when: True
- debug:
msg: “Child playbook 2 - task 2”
notify: “one handler”
changed_when: True
EOF
cat << EOF > playbook_parent.yml
- name: child playbook1
import_playbook: playbook1.yml
- name: child playbook2
import_playbook: playbook2.yml
EOF
cat << EOF > handler.yml
- name: “Handler”
debug:
msg: “Handler”
listen: “one handler”
EOF
Exécution of playbook_parent.yml :
user-docker@6f808e321c8c:~$ ansible-playbook playbook_parent.yml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match ‘all’
PLAY [localhost] *************************************************************************************************************************************
TASK [debug] *****************************************************************************************************************************************
changed: [localhost] => {
“msg”: “Child playbook 1 - task 1”
}
TASK [debug] *****************************************************************************************************************************************
changed: [localhost] => {
“msg”: “Child playbook 1 - task 2”
}
RUNNING HANDLER [Handler] ****************************************************************************************************************************
ok: [localhost] => {
“msg”: “Handler”
}
PLAY [localhost] *************************************************************************************************************************************
TASK [debug] *****************************************************************************************************************************************
changed: [localhost] => {
“msg”: “Child playbook 2 - task 1”
}
TASK [debug] *****************************************************************************************************************************************
changed: [localhost] => {
“msg”: “Child playbook 2 - task 2”
}
RUNNING HANDLER [Handler] ****************************************************************************************************************************
ok: [localhost] => {
“msg”: “Handler”
}
PLAY RECAP *******************************************************************************************************************************************
localhost : ok=6 changed=4 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
The handler is run two times (one time after last notify in playbook1 and one after last notify in playbook2). I would like to run it only once at the last notify of all playbooks (here just after last notify in playbook2).