Inventory
Configuration files
Ansible chooses its configuration from one of several possible locations:
The ANSIBLE_CONFIG environment variable (if set, its value is the path to the file)
If it is not set, Ansible will look for the configuration file in the following places:
./ansible.cfg
In the Ansible command's current working directory
~/.ansible.cfg
As a "dot file" in the user's home directory, used if there is no ./ansible.cfg file
/etc/ansible/ansible.cfg
The default configuration file if no other configuration file is found
Host-based connection variables can be put into host_vars directory, syntax is different
Group-based connection vairables can be put into group_vars directory, syntax is different
Example
# ansible.cfg file
[defaults]
inventory = ./inventory
remote_user = ansible
remote_port = 22
ask_pass = false
[privilege_escalation]
become = true
become_user = root
become_method = sudo
become_ask_pass = falseDynamic Inventory
Python Script in inventory_plugins in the same folder as playbook
Yaml file to store information about inventory: csvinv.yml
Sample CSV File: devices.csv
List inventory: ansible-inventory -i csvinv.yml –-list -–playbook-dir=.
inventory_plugins is relative to playbook, so commands ansible-config and ansible-inventory will not identify the plugin without additional parameter –playbook-dir=.
Commands
ansible --version or ansible-config --version: identifies which configuration file is currently being used
ansible-inventory -y --list: display current inventory in YAML format
ansible group --list-hosts: verify machine presence in inventory
ansible-inventory [-i $inventoryfile] –list
ansible-inventory [-i $inventoryfile] –graph [$group]
ansible-inventory [-i $inventoryfile] –host [$host]
Last updated