Hi there,
I have a play with a role that creates a load balancer template. I've successfully tested it in my dev environment, using
{% for host in groups['dev-web'] %}
server {{ host }} {{ host }}:80
{% endfor %}
the 'dev-web' group is defined in my inventory, as well as 'stage-web', 'prod-web', etc. What I'd like to do is change this template so that it can be used in any environment. I am already passing a parameter upon calling the play, --extra-vars "deploy_env=dev". In the play itself I can use this variable to determine on which balancer the template gets applied, by using something like this:
- hosts: [ '{{ deploy_env }}-bal' ]
serial: 1
vars_files:
- /var/lib/ansible/vars/{{ deploy_env }}.yml
roles:
- role: "haproxy-webbal"
However, if I try something similar in the template, e.g.