ansible Inventory Hosts file


Example

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
[hosts:children]
web-servers
offsite
onsite
backup-servers

[web-servers]
server1 ansible_host=192.168.0.1 ansible_port=1600
server2 ansible_host=192.168.0.2 ansible_port=1800

[offsite]
server3 ansible_host=10.160.40.1 ansible_port=22 ansible_user=root
server4 ansible_host=10.160.40.2 ansible_port=4300 ansible_user=root

# You can make groups of groups
[offsite:children]
backup-servers

[onsite]
server5 ansible_host=10.150.70.1 ansible_ssh_pass=password

[backup-servers]
server6 ansible_host=10.160.40.3 ansible_port=77