Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Ansible Variable: How to declare Variables in Ansible Inventory or hosts file?

Example


# user & passowd & sudo without password
[web]			
1.2.3.4	mynameinv=Rajesh in inventory	
1.2.3.5		
1.2.3.6		
1.2.3.7

[web:vars]
ansible_user=user1 
ansible_ssh_pass=pass1 
ansible_become=yes

# user & key & sudo with password
[app]			
2.2.3.4	mynameinv=Rajesh in inventory 		
3.2.3.5		
4.2.3.6
5.2.3.7

[app:vars]
ansible_user=user1  
ansible_ssh_private_key_file=node.pem 
ansible_become=yes 
ansible_become_pass=pass123

# user & key & sudo with Diff user and password
[log]			
6.2.3.4 ansible_user=user1 ansible_ssh_private_key_file=node.pem ansible_become=yes ansible_become_user=user2 ansible_become_pass=pas122
7.2.3.5
8.2.3.6
9.2.3.7

# user & pass & sudo with Diff user and password
[db]			
6.2.3.1 ansible_user=user1 ansible_ssh_pass=pass1 ansible_become=yes ansible_become_user=user2 ansible_become_pass=pass2
7.2.3.2
8.2.3.3
9.2.3.4
Rajesh Kumar
Follow me