Ansible 3 1 Ansible Inventory 1
Ansible needs to know which servers it should manage. That list lives in a plain text file called the inventory. The default inventory ships at /etc/ansible/hosts, but most real projects ship their own inventory inside the source tree to keep configuration close to the playbooks.
The format is INI-like: one host per line, or grouped under a section header in square brackets. Groups can be combined in playbooks to target several environments with a single play. Ansible reaches each host through SSH on Linux/Unix or WinRM on Windows — there is no agent to install on the target side, which is one of the strongest selling points of the tool.
Useful inventory parameters
ansible_host— actual FQDN or IP behind a friendly alias such asweb1.ansible_connection— typicallysshfor Linux,winrmfor Windows, orlocalwhen targeting the controller itself.ansible_port— overrides the default SSH port 22 if needed.ansible_user— remote user used to log in (defaults torooton Linux).ansible_ssh_pass— password for the remote user.
[web]
web1 ansible_host=192.168.1.10 ansible_user=osboxes ansible_ssh_pass=osboxes.org
[db]
db1 ansible_host=192.168.1.20 ansible_user=osboxes ansible_ssh_pass=osboxes.org
Storing plain text passwords in the inventory is fine for quick experimentation but never acceptable in production. The recommended approach is to set up passwordless SSH between the controller and the targets using SSH keys. For now we keep things simple so we can focus on Ansible itself; the security side will come back later in the course. In the next lesson we will run our first ad-hoc command against this inventory to verify everything is wired correctly.