Ansible Behavior Inventory Parameters
- Refer Here for official docs
- Some Inventory Parameters
localhost ansible_port=8922
- ansible_user: Specifies the username that ansible will connect to the inventory host.
- ansible_ssh_pass: Used to provide the ssh password to authenticate with inventory host.
192.168.10.23 ansible_user="admin" ansible_ssh_pass="admin123"
- ansible_ssh_private_key_file: Used to specify the SSH private key file to connect to inventory host
34.25.15.14 ansible_user="ec2_user" ansible_ssh_private_key_file="./ansible.pem"
Inventory Limiting
- Consider the following inventory
[webserver]
172.31.3.192 ansible_python_interpreter="/usr/bin/python3"
172.31.4.122
[local]
localhost
- Now we have written a playbook or adhoc command for
ansible -m ping all
---
- name: just fun
hosts: all
tasks:
- name: ping host
ping:
- name: print host
debug:
var: inventory_host
- Now executing this playbook will result as shown below

- Now we can supply –limit as shown below

Ansible Variables in separate files
- Rather than writing variable data in inventory, it is a best practice to write them separately in a file, for that we need to understand how to create files for group variables and host variables
- Lets assume this inventory and create it in a file called as hosts
[webservers]
172.31.4.122
172.31.3.192
[dbservers]
localhost
- Now the following playbook is created
---
- name: just fun
hosts: all
tasks:
- name: ping host
ping:
- name: print host
debug:
var: inventory_hostname
- name: print variable
debug:
var: from_where
- Lets add the following entries in group_vars/webservers.yaml
---
from_where: group_webservers
- In group_vars/dbservers.yaml
---
from_where: group_dbservers
- In host_vars/172.31.3.192.yaml
---
ansible_python_interpreter: "/usr/bin/python3"
from_where: hosts_172.31.3.192
- Lets look at folder structure

- The convention is in the folder wherever you have inventory in the same folder create folder named "group_vars" and the file name will be
group_vars/<groupname>.yaml. Similarly for host variable the file names will be host_vars/<hostname>.yaml
- lets execute playbook

Next Steps
- Steps while parsing playbooks
- Order of operations
- Play behavior directives
- Execution strategies