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.
Summary
This lesson introduces Ansible's inventory file, the essential configuration that defines which systems Ansible can manage. The inventory file, formatted in INI style, allows you to specify individual hosts or group multiple servers together, with configurable parameters for connection details. Key parameters like ansible_host, ansible_connection, ansible_port, ansible_user, and ansible_password enable Ansible to communicate with both Linux servers (via SSH) and Windows systems (via WinRM) without requiring agent installation on target machines.
Key points
- Ansible is agentless—it requires no agent installation on target systems, only network connectivity via SSH (Linux) or WinRM (Windows)
- The inventory file uses INI format to list hosts and group them logically; if not created manually, Ansible uses a default inventory at /etc/ansible/hosts
- Hosts can be referenced by FQDN, IP address, or custom aliases, with parameters specified inline (e.g., ansible_host, ansible_port, ansible_user)
- The ansible_connection parameter determines the remote protocol: 'ssh' for Linux, 'winrm' for Windows, or 'local' to target the control machine
- Default connection parameters include port 22 for SSH and 'root' user for Linux, but can be customized per host or group
- While plaintext passwords work for learning, the recommended security practice is SSH key-based authentication instead of password storage
FAQ
What is the inventory file and where does Ansible look for it?
The inventory file is a configuration file that lists all systems Ansible can manage. It uses INI format with hosts listed individually or grouped together. If you don't create one, Ansible uses the default inventory located at /etc/ansible/hosts.
Do I need to install an agent on my target servers before using Ansible?
No. Ansible is agentless and requires only network connectivity to target systems. It communicates via SSH for Linux servers and WinRM for Windows servers, eliminating the need to install any additional software on target machines.
What are the key inventory parameters I need to configure?
Essential parameters include ansible_host (FQDN or IP address), ansible_connection (ssh, winrm, or local), ansible_port (default 22 for SSH), ansible_user (default root for Linux), and ansible_password for authentication. These can be set per host or at the group level.