Getting variables defined in group_vars

41 views
Skip to first unread message

Ivan Kurnosov

unread,
May 5, 2015, 8:41:08 AM5/5/15
to ansible...@googlegroups.com
Hi,

is it possible to retrieve variables defined per host with all group_vars and host_vars definitions applied?

The case:

let's say we have a task to configure an haproxy instance.

In its config file template we iterate over servers in the `webserver` group and need to retrieve the `httpd_port` variable that might be defined in either some of `group_vars` or `host_vars`.

So for a particular server it might be a specific setting in `host_vars/hostname` or a generic one from `group_vars/webserver`

How would you resolve it?

Brian Coca

unread,
May 5, 2015, 8:49:02 AM5/5/15
to ansible...@googlegroups.com
These will all be merged in, so you'll have httpd_port available as
the result of that merge. host vars will overrite group vars so this
should work as you want it.


--
Brian Coca

jack.ma...@gmail.com

unread,
May 5, 2015, 12:01:53 PM5/5/15
to ansible...@googlegroups.com

Use the debug module and print out the value of httpd_port when running over some or all of your servers. You can do this with an ad-hoc command like:

ansible all -m debug -a 'msg="Port is {{ httpd_port }}"'
Reply all
Reply to author
Forward
0 new messages