Don't use nested mustaches. In other words try this:

cvmip: "{{ nics[num].ip }}"



[image: photo]
Timothy Appnel
Senior Solutions Architect

Ansible, Inc. *•* www.ansible.com

On Tue, Aug 11, 2015 at 5:19 PM, <[email protected]> wrote:

> Hi Ansible Users,
>
> I am trying to use a variable passed in via "--extra-vars" to index into
> 'nics' which is defined in nics.yml.
>
> It works fine in the "when" clause, but not in the "set_fact". Any
> suggestions?
>
> Thanks,
> Lilian
>
>
> host# cat nics.yml
> ---
> nics:
> - {type: 'static', ip: '10.3.5.4'}
> - {type: 'dhcp'}
> - {type: 'static', ip: '10.3.5.5'}
>
> host # cat test.yml
> - hosts: 127.0.0.1
>   vars_files:
>     - "nics.yml"
>   tasks:
>     - name: Static IP Case - Find out Static Overlay IP
>       set_fact:
>          cvmip: "{{nics[{{num}}].ip}}"                     <----- HOW DO I
> GET PAST THIS?
>       when: nics[{{num}}].type == "static"           <--- It works fine
> here
>
>     - name: Write Overlay IP to file
>       shell: echo {{cvmip}} >> /tmp/staticip.txt
>       when: nics[{{num}}].type == "static"
>
> host# ansible-playbook test.yml --extra-vars "num=0"
> [SNIP]
> TASK: [Static IP Case - Find out Static Overlay IP]
> ***************************
> fatal: [127.0.0.1] => Failed to template {{nics[{{num}}].ip}}: template
> error while templating string: expected token ':', got '}'
>
> --
> 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/8066dec4-1cae-4ca7-b75d-d4d0e8e09397%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/8066dec4-1cae-4ca7-b75d-d4d0e8e09397%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAOMCme7xD9Wt5k6VVN67ee%2BxVYq3NnPYn5QrkCXx7RJcMGLfQw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to