Use --extra-vars with .json file as input but per host

176 views
Skip to first unread message

Marc Roelofs

unread,
Nov 24, 2014, 6:19:20 AM11/24/14
to ansible...@googlegroups.com
HI All, 

Not sure how to put this in writing ... hopefully I can make my point clear. 

We use ansible for many different hosts to setup basic stuff like ntp/ssh access keys etc ..
What I would like to do ( and what works for 1 host ) : 
Create json variable files per host with contents for local facts and motd filling of that specific host 

Commandline : ansible-playbook -i 'my-targeted-host,' all.yml --extra-vars "@hosts/my-targeted-host.json"

This fills up several variables define throughout the playbook with multiple roles
Question 1 : When I omit the json file , I want no changes to be made to the taget system in the variables.

Question 2: I would like to run the playbook against multiple hosts and have the playbook lookup the specific variables per host from these json files (hostname matches .json name)

So in this way I can use these .json files as a "inventory system"  and these files can contain info per server like application owner which is placed in /etc/motd, when an owners leaves the company I want to do a subsitute of the name and rerun the playbook and refill the /etc/motd with the new aplication owners name ont the machines with that owner 

Hopefully this is clear .. 
Pleas let me know what is possible ? 

Brian Coca

unread,
Nov 24, 2014, 9:52:09 AM11/24/14
to ansible...@googlegroups.com
why not just use host_vars?

they will always be 'included', so q1 and q2 become mute.

--
Brian Coca

Marc Roelofs

unread,
Nov 25, 2014, 9:21:09 AM11/25/14
to ansible...@googlegroups.com
Thanx !!
Reply all
Reply to author
Forward
0 new messages