ansible Inventory Hosts file


The host file is used to store connections for Anisble playbooks. There are options to define connection parameters:

ansible_host is the hostname or IP address

ansible_port is the port the machine uses for SSH

ansible_user is the remote user to connect as

ansible_ssh_pass if using a password to SSH

ansible_ssh_private_key_file if you need to use multiple keys that are specific to hosts

These are the most commonly used options. More can be found in the Ansible official documentation.

Here is an example hosts file:

# Consolidation of all groups

server1 ansible_host= ansible_port=1600
server2 ansible_host= ansible_port=1800

server3 ansible_host= ansible_port=22 ansible_user=root
server4 ansible_host= ansible_port=4300 ansible_user=root

# You can make groups of groups

server5 ansible_host= ansible_ssh_pass=password

server6 ansible_host= ansible_port=77