Inventories instruct Ansible on how to interact with your infrastructure, describing things like the path to a Python interpreter on the remote host, the SSH user Ansible should connect as and which SSH key to use, variables for your playbooks and roles, as well as custom/arbitrary variable declaration for things like software versions (if a play/role installs a specific version of a piece of software), secrets/tokens, & more.
Variables are declared in a directory alongside the inventory file, group_vars/all.yml. You can add other .yml files for variables, and Ansible will "join" them all when running plays.
I have used both, but more recently prefer yaml for describing my inventory. This guide assumes you will also use yaml inventories, but if you choose to use ini instead, you can translate the configurations by referencing the Ansible documentation.
---## A group for all machines in this inventory.# You can call these hosts in groups within this inventory after declaring hereall:## Describe your hostshost1:## Set the host IP/FQDN Ansible will use to connectansible_host:"192.168.1.xxx"host2:ansible_host:"192.168.1.xxx"## Override the remote machine's user Ansible will run asansible_user:"username"host3:ansible_host:"192.168.1.xxx"## Override the example_var_int value for just this hostexample_var_int:42## Vars that apply to all hosts.# Can be overridden at the host definition or group levelvars:## Set variables Ansible will pass to plays/roles when this inventory is used# Call in a playbook/role with {{ example_var }} or {{ example_var_int }}example_var:"I'manexamplestring"example_var_int:100## Group hosts declared in 'all' for controlling execution# with ansible-playbook -i inventory.yml --limit <group-name>debian:## You can just use the hostname from 'all'. Any vars declared at this level# will override values set in 'all' definitionhost1:host3:example_var:"Myvalueisnowthisstring,andexample_var_intwillbe42becauseitwasoverriddeninthe'all'group"## If you use a service like DigitalOcean, you can create a group for those hostsdigitalOcean:host2:## You can add variables you haven't declared yetexample_bool:true