handlers and include files with variables in filenames

So I am running ansible 2.3.0.0. What I want to do is to have my
handlers/main.yml file to include another file (where some handlers
are defined) whose name depends on a variable defined somewhere else.
i.e.

- include: stuff"{{ myvariable }}".yml

where myvariable is defined in the file group_vars/all. I also have

[defaults]
handler_includes_static = True

defined in my ansible.cfg file per
https://github.com/ansible/ansible/issues/13485. But when I run it I
get the following message:

ERROR! Error when evaluating variable in include name: stuff"{{
myvariable }}".yml.

When using static includes, ensure that any variables used in their
names are defined in
vars/vars_files or extra-vars passed in from the command line. Static
includes cannot use
variables from inventory sources like group or host vars.

Where does it want me to define myvariable then? Somewhere in, say,
roles/role_in_question/vars/main.yml?

I solved the problem by using vars_files directive in playbook. The directory structure looks like

`

playbook.yml
vars/main.yml
roles/my-roles/…
`

The playbook.yml looks like

`

I solved the problem by using vars_files directive in playbook. The directory structure looks like

playbook.yml
vars/main.yml
roles/my-roles/...

The playbook.yml looks like

---
  hosts: all
  vars_files:
    - vars/main.yml
  tasks:
    ....
  roles:

      I hate to say but I still do not know how are you selecting
which handlers to use.

Hope it is clear.

The directory structure looks like this
`

playbook.yml
vars/main.yml
roles/my-roles/handlers/main.yml
roles/my-roles/handlers/ocata.yml
roles/my-roles/handlers/kilo.yml

`

The roles/my-roles/handlers/main.yml looks like this

That looks very similar to what I am doing (test.yml is my playbook):

raub@desktop:~/dev/ansible$ cat test.yml

Filename variables in static inclusion could only be defined in 3 places , any one is ok.

  1. extra vars from command line
  2. in vars section of the playbook, not the vars or defaults directory of the role
  3. in vars_file section of the playbook

I don’t see non used from your description.

I have published a repo in github to show the usage of all the ways to define the filename variables. Basically, you should pay attention to the 2 commits

1 shows how to define variables in vars sessions of the playbook

2 shows how to define variables in vars_file session of the playbook