Last active
November 5, 2021 18:13
-
-
Save halberom/3553a00e24468b02d8f12ed73fa33f85 to your computer and use it in GitHub Desktop.
ansible - example of calling a handler when a fact is set
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: localhost | |
connection: local | |
gather_facts: False | |
tasks: | |
- debug: msg="call handler" | |
changed_when: True | |
notify: do something | |
handlers: | |
- name: do something | |
debug: msg="I'm doing something" | |
when: foo|default(False)|bool | |
- hosts: localhost | |
connection: local | |
gather_facts: False | |
tasks: | |
- set_fact: | |
foo: True | |
- debug: msg="call handler" | |
changed_when: True | |
notify: do something | |
handlers: | |
- name: do something | |
debug: msg="I'm doing something" | |
when: foo|default(False)|bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ansible-playbook ~/tmp.yml -i '127.0.0.1,' | |
PLAY [localhost] *************************************************************** | |
TASK [debug] ******************************************************************* | |
ok: [127.0.0.1] => { | |
"msg": "call handler" | |
} | |
RUNNING HANDLER [do something] ************************************************* | |
skipping: [127.0.0.1] | |
PLAY [localhost] *************************************************************** | |
TASK [set_fact] **************************************************************** | |
ok: [127.0.0.1] | |
TASK [debug] ******************************************************************* | |
ok: [127.0.0.1] => { | |
"msg": "call handler" | |
} | |
RUNNING HANDLER [do something] ************************************************* | |
ok: [127.0.0.1] => { | |
"msg": "I'm doing something" | |
} | |
PLAY RECAP ********************************************************************* | |
127.0.0.1 : ok=4 changed=2 unreachable=0 failed=0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice and helpful