Greetings,

I found an unexpected behavior when role variables, with default values 
defined, are overwritten by role parameters in the playbook. I would like 
to confirm whether its a bug or working as designed before opening an issue 
on github.

Here is the test case. I have defined a role to configure multiple 
instances of a given service. Whenever the instance configuration changes, 
I need to reload that specific instance informing the path of its 
configuration file.

roles/some_role/defaults.yml:
instance_name: "default"
instance_conf_file: "/etc/servicename-{{instance_name}}.conf"
instance_param1: "some value"
instance_param2: "some other value"

roles/some_role/tasks.yml:
- template: 
    dest: {{instance_conf_file}}
    src: some_role_conf.j2
  notify:
    - reload conf

roles/some_role/handers.yml:
- name: reload conf
  command: some command to reload  {{instance_name}} {{instance_conf_file}}

In the main playbook, I call the role multiple times with different values 
for instance parameters, like this:

- hosts: all
  roles:
    # first instance "default"
    - role: some_role

    # second instance
    - role: some_role
      instance_name: "i2"
      instance_param1: "abc"

   # third instance
    - role: some_role
      instance_name: "i3"
      instance_param1: "xyz"
     
When configuration of either "i2" or 'i3" is modified, notification to 
"reload conf" actually goes to handler of first instance (variables in 
"reload conf" are filled with default values). 

I would expect that, like for tasks, variables in role/handlers.yml were 
evaluated considering the current role environment. 

Should I open a bug or this is the intended behavior? If this is the 
intended behavior, are there any other means to pass instance parameters to 
handlers?

Any help is appreciated.

Best regards,

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/9f97969c-58c9-4f0e-b4e3-2ad17648aac0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to