Parametrized notification - question about the concept

9 views
Skip to first unread message

Tomáš Kadlec

unread,
Mar 14, 2016, 10:32:50 AM3/14/16
to Ansible Project
Hi,

I am playing around with parametrized notifications (handler calls) and I have came to the following questions:

1/ Is it documented somewhere? I did not find anything about the subject in official docs only several issues on github (e.g. https://github.com/ansible/ansible/issues/4853#issuecomment-28719258). So please forgive me that I am only guessing.

2/ I have not found any valid reason to parametrize a notification with role variable only. Is there any? I am confused by this kind of behavior.

To be clear I am trying to notify a handler named client-handler-something and that something is stored as a variable. The task that notifies an appropriate handler may look as follows.

---
# roles/client/tasks/main.yml

- name: "notify client-handler"
  debug
:
    msg
: "Handler: {{handler_name}}"
  changed_when
: true
  notify
:
   
- "{{handler_name}}"


- name: "run client-handler immediately"
  meta
: flush_handlers

If I pass the variable with the role, it works.

---
# playbook.yml
- roles:
 
- { role: client, handler_name: something }

If I use set_fact or try to compute the value on the fly it does not.

---
# roles/client/tasks/main.yml

- set_fact:
    handler_name
: "client-handler-{{client.type|default('none')}}"

- name: "notify client-handler"
  debug
:
    msg
: "Handler: {{handler_name}}"
  changed_when
: true
  notify
:
   
- "{{handler_name}}"

I would like to know why. I assume that this is a general concept which can be very useful and it does not have nothing to do with roles in my opinion.

Thanks for clarifying this for me.

Tomas
Reply all
Reply to author
Forward
0 new messages