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:
Variables are lazily evaluated and computed per host. The issues with
set_fact are that the evaluation is happening before setting the
variable as ansible evaluates the expression to pass it to the task:
so
vars:
varname: "{{expression}}" # this is lazy
- set_facts: varname={{expression}} #var is set to result of
'expression' as it is evaluated for the task.