From the documentation of puppet bolt and their inventory.yaml, here, it seems you can define multiple levels of the yaml file by specifying another group
in the definition of agroup
. Thus creating a multilevel or nested inventory file.
However I can't find any examples of how to call the nested inventory files with the bolt
command from cli.
For instance this yaml from the docmentation:
groups:
- name: ssh_nodes
groups:
- name: webservers
targets:
- 192.168.100.179
- 192.168.100.180
- 192.168.100.181
- name: memcached
targets:
- 192.168.101.50
- 192.168.101.60
config:
ssh:
user: root
config:
transport: ssh
ssh:
user: centos
private-key: ~/.ssh/id_rsa
host-key-check: false
How do I call from the ssh_nodes group the webservers
group?
Normally I use something like this to call a top level group, which in this case the ssh_nodes
group.
bolt plan run "deploy::update_package" \
--targets "ssh_nodes" \
--user "${BOLT_USER}" \
--private-key "${KEY}" \
--modulepath "path/to/module" \
--inventoryfile "${INVENTORY_FILE}" \
package_name="${PACKAGE}" \
package_version="${VERSION}"
Yes, nesting groups is supported. All groups must be uniquely named, irrespective of nesting.
For example, if your inventory looked like this:
groups:
- name: dc1
groups:
- name: webservers
targets:
- 192.168.100.179
- 192.168.100.180
- 192.168.100.181
- name: dc2
groups:
- name: webservers
targets:
- 192.168.101.50
- 192.168.101.60
Then you attempted to view the inventory, you will get the error:
Tried to redefine group physical for group at ["webservers", "dc2", "all"]
To get around this, I suggest prefixing nested groups like so:
groups:
- name: dc1
groups:
- name: dc1/webservers
targets:
- 192.168.100.179
- 192.168.100.180
- 192.168.100.181
- name: dc2
groups:
- name: dc2/webservers
targets:
- 192.168.101.50
- 192.168.101.60
Then you can target the groups:
bolt inventory show -t dc2/webservers