Inventory file or folder
inventory = ~/.ansible/hosts
Inventory path can be a folder or a file.
As a file you have everything withing a single file.
localhost ansible_connection=local
[jenkinsgroup]
jenkins
[webgroup]
web01 php_version='7.1'
[demogroup:children]
jenkinsgroup
webgroup
As a folder you can make many inventory files for grouping
~/.ansible/hosts/mpp_hosts
~/.ansible/hosts/demo_hosts
[jenkinsgroup]
jenkins
[webgroup]
web01 php_version='7.1'
[demogroup:children]
jenkinsgroup
webgroup
Local ansible.cfg
In your the local folder for your playbook you can create a local config file.
path_to_playbook/ansible.cfg
[defaults]
inventory = inventory
# additional paths to search for roles in, colon separated
roles_path = ~/.ansible/roles
# uncomment this to disable SSH key host checking
#host_key_checking = False
display_skipped_hosts = no
display_ok_hosts = yes
# change the default callback, you can only have one 'stdout' type enabled at a time.
stdout_callback = default
vault_password_file = ~/.ansible/vault-password
[ssh_connection]
# Enabling pipelining reduces the number of SSH operations required to
# execute a module on the remote server. This can result in a significant
# performance improvement when enabled, however when using "sudo:" you must
# first disable 'requiretty' in /etc/sudoers
#
# By default, this option is disabled to preserve compatibility with
# sudoers configurations that have requiretty (the default on many distros).
#
pipelining = true
Then make an inventory
file for the localized hosts.
Dynamic inventory with DigitalOcean
Copy these two files to your inventory path i.e. inventory = ~/.ansible/hosts
digital_ocean.py and digital_ocean.ini
Update digital_ocean.ini
with your API Key from your account. Using tags on your droplets you can make groups and custom variables in your inventory file.
ls ~/.ansible/hosts
digital_ocean_hosts
digital_ocean.ini
digital_ocean.py
digital_ocean_hosts
content using tags: web, client, php71 and php72. php_version
is used in Ansible Role: PHP Versions by geerlingguy
[web:vars]
ansible_port="7822"
ansible_user="sudouser"
[php71:vars]
php_version="7.1"
[php72:vars]
php_version="7.2"
[client:vars]
ansible_port="22"
ansible_user="sudouser"