I know subject sounds kind of crazy, but here’s the code to explain it a bit:
- hosts: all
vars: - djbdns_var:
FOO: “DJ DNS” - vnstat_var:
FOO: “VN, stat!”
tasks: - name: Test flexible vars
command: echo “$FOO”
environment: “{{ item }}_var”
with_items: - djbdns
- vnstat
which should be equivalent to something like:
tasks:
-
name: Test flexible vars (step 1)
command: echo “$FOO”
environment: djbdns_var" -
name: Test flexible vars (step 2)
command: echo “$FOO”
environment: vnstat_var"
so what I’m trying to do is define different set of environment variables for each step of iteration, and the best way I figured was something like above. However it doesn’t work. Ansible (1.5.3) recognizes passed argument as a string and throws an error rather than interpret resulting variable name.
Question is: can something be done to accomplish what I’m trying to do?