Advanced - nsg/ansible-inventory GitHub Wiki

I told you under Tags and Groups that you need to be careful with tag groups. Let me illustrate a few corner cases that can cause problems.


root:
  hosts:
    - www1.prod.example.com
    - www1.stage.example.com
  vars:
    site: "lon"

tagvars:
  stage:
    site: "stage"

In the above example, we have defined the variable site both on a tag group (tagvar) and on the normal groups. In this example, www1.prod.example.com will of course have site=lon, but what about stage? Let me define the above example in plain old ini:

[root]
www1.prod.example.com
www1.stage.example.com

[root:vars]
site=lon

[stage]
www1.stage.example.com

[stage:vars]
site=stage

/.../

Like you can see, the host is defined twice and it is undefined what will happen. In current version of the ini parser site will be stage because it is defined last. But we can't trust that these things stay the same so please avoid!

If you like to use the tag groups use that think and use that properly, something like this:


root:
  hosts:
    - www1.prod.example.com
    - www1.stage.example.com

tagvars:
  stage:
    site: "stage"
  prod:
    site: "lon"

... or even better, use group_vars.