Question regarding host group variables for intersections of groups

If a host is in multiple groups, which have different values for the same variable key, what value takes precedence for that host? Is it based on the order in the inventory? I couldn’t find anything in the documentation.

Also, do variables from the inventory take precedence over variables in plays or vice versa?

And one other thing: regarding playbook includes, the documentation states:
“(In addition to the explicitly passed in parameters, all variables from the vars section are also available for use here as well.)”

Does this mean that all variables defined in a play A are visible within plays included by A? And if yes, do local variables of the includes plays take precedence over the variables in A?

I probably could test all this, but I would feel more comfortable if it was clearly defined somewhere.

I’m asking these questions because I like to think about host groups as a class hierarchy, which makes me think that variables defined in child groups (aka subclass), e.g., would take precedence over those in their parent (aka superclass). And with overlapping groups, you get something like multiple inheritance, where you want to be cautious with variables common to multiple superclasses…

If a host is in multiple groups, which have different values for the same
variable key, what value takes precedence for that host? Is it based on the
order in the inventory? I couldn't find anything in the documentation.

Most specific groups (groups of the deepest depth) win if there are subgroups.

Behavior for peer level groups is undefined but presumably
alphabetical. You shouldn't rely on it.

Also, do variables from the inventory take precedence over variables in
plays or vice versa?

Should be covered here:
http://ansible.cc/docs/playbooks2.html#understanding-variable-precedence

And one other thing: regarding playbook includes, the documentation states:
"(In addition to the explicitly passed in parameters, all variables from the
vars section are also available for use here as well.)"

Does this mean that all variables defined in a play A are visible within
plays included by A? And if yes, do local variables of the includes plays
take precedence over the variables in A?

plays don't actually include plays

playbooks include plays

playbooks are just lists of plays and don't have variables at all.

I'm asking these questions because I like to think about host groups as a
class hierarchy, which makes me think that variables defined in child groups
(aka subclass), e.g., would take precedence over those in their parent (aka
superclass). And with overlapping groups, you get something like multiple
inheritance, where you want to be cautious with variables common to multiple
superclasses...

this happens.

Most specific groups (groups of the deepest depth) win if there are subgroups.

Ah great, so this is just like you would expect thinking about it as a class hierarchy…

Also, do variables from the inventory take precedence over variables in
plays or vice versa?

Should be covered here:
http://ansible.cc/docs/playbooks2.html#understanding-variable-precedence

Ok, I assume, “6. Group variables from inventory, in order of least specific group to most specific” actually means “in order of most specific to least specific”, as in that list, priority is in descending order, right?

plays don’t actually include plays

playbooks include plays

playbooks are just lists of plays and don’t have variables at all.

Ah thanks, didn’t get the difference between plays and playbooks and also not between include tasks and included playbooks…

Most specific groups (groups of the deepest depth) win if there are
subgroups.

Ah great, so this is just like you would expect thinking about it as a class
hierarchy...

>
> Also, do variables from the inventory take precedence over variables in
> plays or vice versa?
>

Should be covered here:
http://ansible.cc/docs/playbooks2.html#understanding-variable-precedence

Ok, I assume, "6. Group variables from inventory, in order of least specific
group to most specific" actually means "in order of most specific to least
specific", as in that list, priority is in descending order, right?

It means the child-most groups have greater priority in overriding
than parent groups (like US vs NC vs Raleigh, vars set in Raleigh have
more priority than NC). This has confused others so I need to
rephrase this part to be more explicit for sure.