Hello,

I know that you *can*, but it seems ambiguous on whether one *should*.

For example:
There is a role named "role_1", which has templated variables in both 
"defaults/main.yml" and "vars/main.yml". 
I could create a playbook which prints those variables for a set of hosts, 
and the variables would change for each host.
For the sake of discussion, here is what those role variables could be:
---
# defaults file for role_1
my_default_inventory: "{{inventory_hostname}}-sample"

---
# vars file for role_1
some_var: "{{ansible_hostname}}"

However, many examples from documentation and from around the web seem to 
place all non-templated role variables in either the roles vars or 
defaults. 
This seems especially true if the variables are templated from facts.

Instead, these examples will often use the "set_fact" module to set these 
variables. 

The ambiguity seems to rise from the understanding of "variable scope". The 
documentation does not clearly state when role variables are re-templated. 
So, if you have a variable that you know will change from host to host but 
only needs to be set once per role, it seems that people rely on explicitly 
placing variables into the "facts". I'm *guessing* that the use of 
"set_fact" is used under the assumption that authors are unclear on whether 
they can rely on role variables being in the "host" scope. 
 
So, please help me clear up my guesses and speculations! 
Does the example stated above work by design, or by accident? Specifically, 
can I rely on role variables being re-templated within the "host" scope?

Please let me know if you need more clarification.

Thank you.


-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/bdb59d37-aba4-4d66-8a44-51e38ad57049%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to