Getting variables defined in group_vars

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?

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.

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 }}”’