Build a correct Ansible inventory, INI or YAML
The inventory tells Ansible which hosts to manage and how to reach them. Getting the group, variable, and children syntax right by hand is fiddly — especially across the INI and YAML formats. This builder lets you model groups, hosts, variables, and hierarchy once and emit either format cleanly.
How it works
In INI format, hosts are listed under a [group] header, group variables go in a [group:vars] section, and nested groups are declared in [group:children]. Per-host variables follow the host name on the same line as key=value pairs. This is the layout Ansible’s ini inventory plugin parses.
In YAML format, everything nests under the implicit all group: all → children → <group> → hosts/vars/children. Each host becomes a mapping whose values are its connection variables. The builder quotes any YAML scalar that could be misread as a number or boolean, so a value like ansible_port: "2222" stays a string when intended.
Tips and notes
- Use
ansible_hostto keep readable inventory aliases while connecting to real IPs. - Define shared settings such as
ansible_useronce as a group var rather than repeating them per host. - Build hierarchy with children groups (e.g. a
productiongroup whose children arewebserversanddatabases) to target broad or narrow sets in playbooks. - Validate the result with
ansible-inventory -i <file> --listto confirm Ansible parses it as you expect.