HI!
I'd like to override a default for
var_b defined in roles/role_b/defaults/main.yml
with a value of
var_a defined in roles/role_a/defaults/main.yml
Is this possible?
Can I reference role vars?
Or is this rather a use-case of include_role?
Ciao, Michael.
racke
(Stefan Hornburg)
2
Can you please explain your actual use case instead of describing your problem with bogus variable and role names?
Regards
Racke
vbotka
(Vladimir Botka)
3
I'd like to override a default for
var_b defined in roles/role_b/defaults/main.yml
with a value of
var_a defined in roles/role_a/defaults/main.yml
Is this possible?
If you import the roles try (not tested)
> cat roles/role_b/defaults/main.yml
var_b: "{{ ('role_a' in ansible_role_names)|
ternary(var_a, 'var_b_default_in_role_b') }}"
Can I reference role vars?
Yes. Simply reference the variable. For example
- debug:
var: var_b
Or is this rather a use-case of include_role?
Include role is more complex because the variables of the included role might
be available in the playbook after the include. See attribute "public"
https://docs.ansible.com/ansible/latest/modules/include_role_module.html#parameter-public
HTH,
-vlado