Hello all,

I am trying to build a play that allows for variable subelement selection, 
and subsequent iteration over array contained therein.  The following test 
playbook hopefully illustrates the situation:

---
- hosts: localhost
  connection: local
  gather_facts: false
  vars:
    foo:
      bar:
        - name: somebar1
          desc: somebar1text
        - name: somebar2
          desc: somebar2text
      baz:
        - name: somebaz1
          desc: somebaz1test

  tasks:
    - debug: var=foo.bar

    - debug: var=foo.{{select}}

    #- debug: var={{item}}
    #  with_items: "foo.{{select}}"

    - command: echo "{{item.name}}"
      with_items: "foo.{{select}}"


When select is passed in with -e "select=bar" or baz, the debug statements 
look fine, but the final with_items results in:

fatal: [localhost]: FAILED! => {"failed": true, "msg": "'unicode object' 
has no attribute 'name'"}

When I uncomment the third debug statement, output seems to indicate that 
with_items is not returning the elements of the array, but the entire array:

ok: [localhost] => (item=foo.bar) => {
    "foo.bar": [
        {
            "desc": "somebar1text", 
            "name": "somebar1"
        }, 
        {
            "desc": "somebar2text", 
            "name": "somebar2"
        }
    ], 
    "item": "foo.bar"
}


I have looked at with_dict and with_subelements and a few others, but they 
do not seem to fit the situation.  I have some workarounds in mind that are 
less than pretty.  Can someone point me in the right direction?  Thank you.

-- 
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/0968593a-f145-4406-be94-cb909827861a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to