volant inventory
Print an inventory as JSON, YAML or TOML, the way ansible-inventory does.
volant inventory prints an inventory as JSON, YAML or TOML, the way ansible-inventory does. Started under the name ansible-inventory (see the shims command), it behaves the same.
volant inventory (--list | --host HOST | --graph [GROUP]) [-i SOURCE]... [-l SUBSET] [-e VARS]... [--vars] [-y | --toml] [--export] [--output FILE] [-v]Exactly one of --list, --host and --graph is required.
Print every host with its variables, the group_vars and host_vars files and its groups’ variables folded in, then the groups with their hosts and children. Keys are sorted, the indent is four spaces, and non-ASCII text is written as is. A string that is data is printed as {"__ansible_unsafe": "..."} and a !vault value as {"__ansible_vault": "..."}; nothing is decrypted.
Print the variables of one host. HOST is a host pattern that must match exactly one host, otherwise the command prints You must pass a single valid host to --host parameter and exits 5. --limit does not apply.
Print the groups as a tree: @name: for a group, bare names for hosts, a group’s children before its hosts, each level indented by |. With a group name, print only that subtree. A name that is not a group prints Pattern must be valid group name when using --graph and exits 5. --limit does not apply.
With --graph, add {name = value} lines under every host (its folded variables) and every group (its own, group_vars files included), sorted by name and written with Python’s str(). !vault values are decrypted, so this needs the vault password, and !unsafe text is printed as it is. The other actions ignore --vars.
Print --list and --host as YAML, in the bytes ansible-inventory prints. --list becomes an inventory you can read back: each group under its parent’s children, its hosts and their variables, keys sorted. A host is written with its variables the first time the walk reaches it and as {} after, a group already written is {}, and an empty group is left out. A !vault value is written as !vault | and its ciphertext, without decrypting it. !unsafe text is written as plain text. --graph ignores --yaml.
When several hosts get a variable from the same group, the same group_vars file or -e, the reference holds one value for all of them, and PyYAML writes it once with an anchor (&id001) and then as an alias (*id001). Volant writes the same anchors with the same numbers. PyYAML numbers a value when it meets it the second time, so id001 is not always the first anchor in the file. Only lists and mappings get anchors.
all: children: prod: children: web: hosts: w1: list: &id001 - 1 - 2 w2: list: *id001Print --list and --host as TOML, in the layout ansible-inventory prints with the tomli-w package; Volant needs no package for it. --list has one table per group that has something to show: [group] with children as names, and [group.hosts.host] with the host’s variables. There is no all table, and a group that only has hosts has no [group] line. Variables are not sorted: they come in the order the reference merges them, the groups’ first and the host’s own last. A host’s variables are written where the walk first reaches it, so a host that is in several groups has an empty table in the others. Arrays are written one element per line with a trailing comma and a four-space indent. --host prints the variables as a flat document. --yaml wins when both are given, and --graph ignores --toml.
A document with nothing in it prints nothing and exits 1, as the reference does. A null cannot be written in TOML: the command prints [ERROR]: Object of type 'NoneType' is not TOML serializable and exits 250. The reference exits 250 too, with a Python traceback, which Volant does not copy.
Keep each variable where it is set instead of folding group variables into every host. --list gives each group a vars entry with its own variables and its group_vars files. Each host keeps only what its inventory line and its host_vars files set; extra variables are left out. With --yaml, no value is shared, so no anchors appear. With --host, only that host’s own variables are printed. export = true in the [inventory] section of ansible.cfg, or ANSIBLE_INVENTORY_EXPORT, turns it on by default. With --graph --vars, a host’s lines show only its own variables.
With --list, keep only the hosts matching the pattern. Groups stay, with their children. A pattern that matches nothing warns and prints an inventory with no host.
Where a playbook would have sat: the inventory and cache plugins in the plugin directories beside it load. ANSIBLE_PLAYBOOK_DIR sets it too.
Extra variables, added to every host and winning over every other layer.
Write the document to FILE and print nothing. The file holds what standard output would. A JSON document has no newline at the end; a YAML or TOML document keeps its final newline.
-i, -v and the vault options work as they do for volant playbook. Without a selected action the command prints No action selected, at least one of --host, --graph or --list needs to be specified., and with two it prints Conflicting options used, only one of --host, --graph or --list can be used at the same time.; both exit 5.