How to notify a handler when using set_fact module?

840 views
Skip to first unread message

Ivan Godorogea

unread,
Jun 19, 2017, 11:35:38 AM6/19/17
to Ansible Project
Hi,

I am trying to notify a handler in a set_fact task, but it doesn't work.
Is that not implemented or I'm doing it wrong?

Thank you,
Ivan

Here are the code snippets: 

/tasks/main.yml

---

...

- name: Store fact into role variable
  set_fact:
    important_fact: "{{ read_tmpfile_cmd.stdout }}"
  when:
    - "'stdout' in read_tmpfile_cmd"
    - read_tmpfile_cmd.stdout != ''
  notify: fact stored


 /handlers/main.yml
 
---
- name: fact stored
  debug:
    msg: "Important fact: {{ important_fact}}"


Sergey Baranov

unread,
Jun 19, 2017, 1:56:07 PM6/19/17
to Ansible Project
Hi
 
notify action is triggered when task have made a change on the remote system.
Seems you problem is that set_fact module doesn't make changes on the remote server. Try to use changed_when with set_fact module
 
- name: Store fact into role variable
  set_fact
:

    important_fact
: "fact"
  changed_when
: "important_fact=='fact'"
  notify
: fact stored

hope this helps

Brian Coca

unread,
Jun 19, 2017, 5:30:16 PM6/19/17
to Ansible Project
this shoudl also work:

changed_when: True


----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages