Hi,
Is it possible to use a group_vars/ directory alongside inventory directories (as opposed to files)?
Take this simplified example, which has an inventory file (staging) and an inventory directory (production):
$ tree
.
└── inventories
├── group_vars
│ └── all.yml
├── production
│ └── hosts
└── staging
staging and production/hosts both contain a single host:
group_vars/all.yml defines a variable example_var:
Running the staging inventory
file picks up group_vars:
$ ansible -i inventories/staging all -m debug -a 'msg="{{hostvars}}"'
127.0.0.1 | success >> {
"msg": "{'inventory_hostname': '127.0.0.1', 'example_var': 'present', 'inventory_hostname_short': '127', 'group_names': ['localhost']}"
}
But running the production inventory
directory doesn't pick them up (no example_var in the output):
$ ansible -i inventories/production/ all -m debug -a 'msg="{{hostvars}}"'
127.0.0.1 | success >> {
"msg": "{'inventory_hostname': '127.0.0.1', 'inventory_hostname_short': '127', 'group_names': ['localhost']}"
}
How can I have the group_vars be picked up without having to duplicate them under inventories/production/group_vars?
I want to use an inventory directory to mix static and dynamic inventory, with one inventory directory per environment (dev/stage/prod), and some shared vars. Maybe there's a better way to do this though?
Thanks!
Niko
PS: I asked a similar (and quite long-winded) question yesterday. Since I didn't get an answer, I thought I'd come up with a more specific formulation, I hope that's fine! I'm new to this list -- if there's anything I can do to make answering my questions easier, please let me know!