Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share defaults between multiple roles in Ansible?

Tags:

ansible

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.

like image 729
Slava Fomin II Avatar asked Dec 11 '13 12:12

Slava Fomin II


People also ask

Can Ansible roles be reused by playbooks in a different directory?

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.

What is the default path of Ansible roles?

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.

What is difference between Ansible roles and playbooks?

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.


1 Answers

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.

like image 129
magnetik Avatar answered Sep 22 '22 14:09

magnetik