I want to share defaults between different roles in Ansible. Is it possible to achieve this directly? Is there a workaround, maybe another approach to this problem? I just want to keep default values DRY.
You can re-use tightly focused playbooks, but you can only re-use them statically, not dynamically. A role contains a set of related tasks, variables, defaults, handlers, and even modules or other plugins in a defined file-tree.
in a directory called roles/ , relative to the playbook file. in the configured roles_path. The default search path is ~/. ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles.
In Ansible, the role is the primary mechanism for breaking a playbook into multiple files. This simplifies writing complex playbooks, and it makes them easier to reuse. The breaking of playbook allows you to logically break the playbook into reusable components.
Have you tried to put thoses variables in /etc/ansible/group_vars/all
?
from documentation:
Site wide defaults should be defined as a ‘group_vars/all’ setting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With