inventory script
An executable program that prints the inventory as JSON when Ansible runs it with --list, and one host's variables with --host.
In more detail
It is the original dynamic inventory mechanism and still works, but Ansible cannot cache, validate or configure it. It must be executable, because Ansible decides whether to run or parse a file by asking the operating system. Write one only when no plugin exists for your source.
Examples
chmod +x dynamic.pyansible-inventory -i dynamic.py --graphRelated terms
- dynamic inventory — An inventory produced at run time by a program or plugin, usually by asking a cloud provider, instead of a file maintained by hand.
- inventory plugin — A plugin that builds inventory from a source such as a cloud account, configured with a small YAML file rather than written as a program.
- JSON — A simple text format for structured data made of keys, values, lists and nested objects.
- hostvars — The variables Ansible holds for each host; in a dynamic inventory's JSON they are supplied under _meta.hostvars.
- shebang — The first line of a script, starting with #!, that names the program the operating system should use to run it.
Taught in
- Dynamic Inventory — Ansible Configuration Management at Scale
- ansible.cfg: Which File Wins, And The Settings That Matter — RHCE in Ansible (EX294): Automate Red Hat Systems
- Mock Exam, Part 1: Seven Tasks Across Three Sections — RHCE in Ansible (EX294): Automate Red Hat Systems