In this article, we explore how to configure an inventory in Ansible. By managing one or multiple systems simultaneously, Ansible establishes connections to target servers using protocols built into modern infrastructures. For Linux hosts, it relies on SSH, and for Windows systems, it uses PowerShell remoting. This agentless design eliminates the need for installing additional software on target machines—SSH connectivity alone is enough. Unlike many other orchestration tools that require agents, Ansible leverages native protocols to interact with your infrastructure. Information about these target systems is stored in an inventory file. By default, Ansible uses the inventory file located atDocumentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
/etc/ansible/hosts unless you specify a custom file.
An inventory file is written in an INI-like format. It can list servers sequentially or group them by placing the group name in square brackets, followed by the list of servers. For example:
The example below demonstrates a basic inventory file structure that lists and groups servers without relying on any additional diagrams or images.
[inventory], [mail], [db], and [web]:
ansible_host parameter, which defines the FQDN or IP address of the server. Other useful inventory parameters include:
- ansible_connection: Defines the connection method Ansible uses (e.g.,
sshfor Linux orwinrmfor Windows). Setting it tolocalhostmeans no remote connection is required. - ansible_port: Specifies the port for the connection (default is 22 for SSH).
- ansible_user: Specifies the username for remote connections (for instance,
rootfor Linux by default). - ansible_ssh_pass: Specifies the SSH password. Note: Storing passwords in plain text is strongly discouraged. It is best practice to configure key-based authentication, especially in production environments.