Host File as a command line variable

14 views
Skip to first unread message

John Andrew

unread,
May 6, 2019, 7:15:56 AM5/6/19
to Ansible Project

Can i do this in my hosts/inventory file? Also, can i pass a host group in command line -e?

[env1]
vm1 ansible_host=vm001
vm2 ansible_host=vm002

[env2]
vm1 ansible_host=vm888
vm2 ansible_host=vm999

I want to use the same synonym host name in my playbook (vm1 or vm2 ) but point to different virtual machine depending on what group i specify in the yml file. (hosts: env1)
This way i can make the code generic across groups with the same vm1 or vm2. I have duplicate VMs for testing and development.

thanks

Kai Stian Olstad

unread,
May 9, 2019, 1:56:45 PM5/9/19
to ansible...@googlegroups.com
You can't, groups is not for separating variable it's for grouping host
together so you don't need to list them all.
A host will get all variables defined in all groups it's a member of.

So your ansible_host for vm1 in group env1 will be overwritten by
ansible_host for vm1 in group env2.

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages