Skip to content

Instantly share code, notes, and snippets.

@jmehnle
Last active November 29, 2017 22:45
Show Gist options
  • Save jmehnle/6027e04fd7495fcc9e6b3ff104953dce to your computer and use it in GitHub Desktop.
Save jmehnle/6027e04fd7495fcc9e6b3ff104953dce to your computer and use it in GitHub Desktop.
Ansible handler not role-scoped
$ ansible-playbook -i localhost, -v playbook.yml
No config file found; using defaults
PLAY [all] *********************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [a : set_fact] ************************************************************
ok: [localhost] => {"ansible_facts": {"x": "foo"}, "changed": false}
TASK [a : debug] ***************************************************************
ok: [localhost] => {
"msg": "a task here!"
}
TASK [b : set_fact] ************************************************************
ok: [localhost] => {"ansible_facts": {"x": "bar"}, "changed": false}
TASK [b : debug] ***************************************************************
ok: [localhost] => {
"msg": "b task here!"
}
RUNNING HANDLER [a : dummy] ****************************************************
ok: [localhost] => {
"msg": "a handler here! x=bar"
}
RUNNING HANDLER [b : dummy] ****************************************************
ok: [localhost] => {
"msg": "b handler here! x=bar"
}
PLAY RECAP *********************************************************************
localhost : ok=7 changed=2 unreachable=0 failed=0
$ tree
.
├── playbook.yml
└── roles
├── a
│   ├── handlers
│   │   └── main.yml
│   └── tasks
│   └── main.yml
└── b
├── handlers
│   └── main.yml
└── tasks
└── main.yml
- hosts: all
roles:
- a
- name: dummy
listen: handler
debug: msg="a handler here! x={{x}}"
- set_fact: x=foo
- debug: msg="a task here!"
changed_when: true
notify: handler
- include_role: name=b
- name: dummy
listen: handler
debug: msg="b handler here! x={{x}}"
- set_fact: x=bar
- debug: msg="b task here!"
changed_when: true
notify: handler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment