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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to