It depends on context of your actual task. Adding top-level hash will do if 
you can put definitions for all *_var data in a single unit.
For multiple units (f.e. per-role definitions) you may try to set 
"hash_behaviour=merge" in ansible.cfg, though this is generally not 
recommended.

- hosts: localhost
  connection: local
  vars:
  - cmd_envs:
      djbdns: { FOO: "DJ DNS" }
      vnstat: { FOO: "VN, stat!" }
  tasks:
  - name: Test flexible vars
    command: echo "$FOO"
    environment: cmd_envs[item]
    with_items:
    - djbdns
    - vnstat



On Saturday, May 10, 2014 4:10:24 PM UTC-7, Dmitry Makovey wrote:
>
> 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?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/482b0af4-d338-4cf2-a87d-0e52889d9743%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to