Setting defaults in group_vars/all is usually a very good place to set
global defaults.

Note that role defaults are a lower priority than inventory though.

You could also consider symlinks.




On Wed, Aug 27, 2014 at 12:59 PM, Daniele Varrazzo <
[email protected]> wrote:

> Hello, first of all thank you very much for Ansible.
>
> I'm setting up the deployment of a complex system and splitting it across
> roles. I haven't found yet a satisfactory way of sharing variables across
> the roles. A simple example: set the database port in the db role and use
> it in the web role. I'm expecting to be able do do something along this
> line:
>
>     roles/
>         db/
>             defaults/main.yml
>                 db_port: 5432
>         web/
>             templates/
>                  web.conf.j2
>                     [database]
>                     port: {{ db_port }}
>
> The above wants to represent the fact that the default port for the
> database is 5432; this may be overridden by a group_vars file for specific
> installation having the db on a non-standard port. Currently it doesn't
> work because the db_port variable is not known by the web role. How to work
> around that?
>
> 1. put all the shared variables in group_vars/all. It works but it breaks
> the encapsulation of the roles: without a certain unknown set of variables
> defined at least in "all" the db cannot be configured.
> 2. add the db role as a dependency of web: this makes it execute the
> entire db tasks list, which is not what hoped.
> 3. add "include_vars: ../../db/defaults/main.yml" to the web's tasks. This
> gives a higher preference to the default variable and overriding it in
> group_vars (or in the inventory) doesn't work anymore.
>
> As it is now I'm stuck with 1, which is also what I've generally found in
> the examples. Is there anything better? It seems a relatively
> straightforward use case to me:
>
> 1. a provider role defines a variable and provides a default for it;
> 2. a consumer role uses the variable provided;
> 3. a group or inventory variable can override the default.
>
> Thank you very much,
>
> -- Daniele
>
> --
> 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/7762fbc1-5491-4f77-8db3-0581af9bbf1e%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/7762fbc1-5491-4f77-8db3-0581af9bbf1e%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CA%2BnsWgznfBnQb_Hawj30R%2BxMe5yWrvrxNLM_ER_%3DWxetg_0s6Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to