Group vars override role vars?

165 views
Skip to first unread message

Matt Hughes

unread,
Dec 3, 2014, 5:49:21 PM12/3/14
to ansible...@googlegroups.com
I have a role defined with:

- hosts: elk
 sudo
: true
 vars
:
   es_heap
: 8G


I run that role against a given inventory that attempts to override that variable:

[elk]
node1 es_heap
=2G

[elk:vars]
es_heap
=2G

Tried overriding with both host and group vars, but I keep getting the role variable.  Aren't the former supposed to override the latter?  I also tried moving the variable from the role in /vars/main.yml, but that had no effect.  I must be missing something, because having host variable override role variable seems pretty basic.

Brian Coca

unread,
Dec 3, 2014, 5:53:20 PM12/3/14
to ansible...@googlegroups.com
no, they override the role's defaults/main.yml, but not vars/main.yml

--
Brian Coca

Michael Peters

unread,
Dec 3, 2014, 5:54:20 PM12/3/14
to ansible...@googlegroups.com
Put it into the role's defaults (roles/foo/defaults/main.yml). Those
are the ones that are really meant to be overridden.
> --
> 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 ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/12a0601b-3d75-40c3-8c1c-3c7476cbcf82%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Matt Hughes

unread,
Dec 3, 2014, 5:55:43 PM12/3/14
to ansible...@googlegroups.com, Michael Peters

Ah thanks, that makes more sense.

I’m not sure why I’d ever want to use vars/ then. Sure I could be convinced of a use-case, but it seems much more natural for inventory/group/host vars to override anything defined in a role, but I see this discussion has taken place before. :)

You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/63PKx3Lxb4U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

Michael DeHaan

unread,
Dec 3, 2014, 6:05:54 PM12/3/14
to ansible...@googlegroups.com, Michael Peters
I use group_vars a lot and it's fine to do so.

It is useful for declaring something like a constant though, to save typing, or make things configured in one specific place.

(It keeps configuration of that thing with the playbook vs the inventory)


Josh Smift

unread,
Dec 3, 2014, 6:09:08 PM12/3/14
to ansible...@googlegroups.com
MH> I’m not sure why I’d ever want to use vars/ then. Sure I could be
MH> convinced of a use-case

A use case I've seen, which doesn't seem all that uncommon, is when you
want to use a given role with multiple inventories, each of which has its
own inventory/group/host vars structure. Putting the default in the role
lets you have it in one place, and be confident that it's consistent
across your various inventories unless you explicitly override it.

-Josh (j...@care.com)



This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

Michael DeHaan

unread,
Dec 3, 2014, 6:36:50 PM12/3/14
to ansible...@googlegroups.com
Role variables are definitely a thing.

Where you can move top level playbook things to vars/ or defaults/ in a role it can be a good idea.

Simple playbooks like "fix shellshock" could use vars or vars_files fine, or even if you find other uses, that's fine too.

We're not particularly dogmatic about it.


--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages