Variable in defaults/main.yml not resolved

Hi,

I have a setup where I want to dynamically determine the name of a handler (we have multiple tomcat instances running on a machine). A simplified setup can be found here: https://github.com/lvonk/AnsibleTest

The example creates a vagrant box and installs httpd, copies a templates to the root home and restarts httpd.

As you can see in https://github.com/lvonk/AnsibleTest/blob/master/roles/role2/tasks/main.yml the name of the handler to restart is defined by {{ service_name }}.
This property is declared in defaults/main.yml: https://github.com/lvonk/AnsibleTest/blob/master/roles/role2/defaults/main.yml

When running the playbook:

ansible-playbook -i inventory/test --private-key ~/.vagrant.d/insecure_private_key -u vagrant test.yml the output is as follows:

TASK: [role2 | copy templates] ************************************************
changed: [192.168.66.11] => (item=foo.txt)
ERROR: change handler (restart {{ service_name }}) is not defined
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

So it copies the foo.txt and resolves the {{ var_3 }} variable also defined in defaults/main.yml but it can’t determine the {{ service_name }}.

When I move all defaults/main.yml to vars/main.yml it all works. Is this intented behavior?

Also I noticed the description (http://docs.ansible.com/playbooks_roles.html#role-default-variables) of defaults/main.yml in the docs is:

Role default variables allow you to set default variables for included or dependent roles (see below). To create defaults, simply add a defaults/main.yml file in your role directory. These variables will have the lowest priority of any variables available, and can be easily overridden by any other variable, including inventory variables.

From this I understand that defaults is not for default values for “this” role (the role that has the defaults folder), but for the role this role depends on or includes. Is that correct?

I am running ansible 1.8.2

Thanks in advance,

Lars