add_host and variable mass-population

24 views
Skip to first unread message

Dmitry Makovey

unread,
May 25, 2015, 6:00:37 PM5/25/15
to ansible...@googlegroups.com
I have a dilemma: I've got a module that can produce list of sites that given app is configured to serve, "app_info"  which produces JSON output like this:

        "site_info": {                                                                                                                                                                                                                      
           
"some.site.com": {                                                                                                                                                                                              
               
"dataroot": "/var/lib/app-instances/some_site",                                                                                                                                                                        
               
"dbname": "some_site",                                                                                                                                                                                                    
               
"ip": "1.2.3.4",                                                                                                                                                                                                      
               
"status": "No"                                                                                                                                                                                                              
           
},                                                                                                                                                                                                                              



so I'm collecting this data from the "[web]" servers using "data_collect" role:

- name: collect sites info
  app_info
: list
 
register: site_info


- debug: var=site_info


- name: register sites
  add_host
: name={{ item.key }} group=sites {{ item.value }}
  with_dict
: site_info



as you can see I'm trying to initialize new group "sites" which is working fine, except population of variables per site. How can I grab vars from site_info for specific site and populate that site's "facts" with them in the most efficient way? set_fact seems to be cumbersome a bit, can I somehow convince add_host to take already arranged vars and assign them to my site?
Reply all
Reply to author
Forward
0 new messages