In your example, `apps.admin` actually contains a list of dictionaries. So accessing it would be: `apps.admin[0].service`.
On Tue, Nov 4, 2014 at 10:55 AM, James Morgan <[email protected]> wrote: > Hi, > > I need to store information about applications in a variable data > structure and access it via key. > > If I store the information as follows I can access using *with_items* > > > - hosts: localhost > connection: local > vars: > apps: > admin: > - service: admin > handler: /admin > port: 1200 > .... > rpt: > - service: rpt > handler: /rpt > port: 1234 > .... > tasks: > - debug: > msg: "{{ item.service }} = {{ item.port }}" > with_items: apps.admin > > TASK: [debug ] > **************************************************************** > ok: [localhost] => (item={'handler': '/admin', 'port': 1200, 'service': > 'admin'}) => { > "item": { > "handler": "/admin", > "port": 1200, > "service": "admin" > }, > "msg": "admin = 1200" > } > > How can I access one of the nested variables directly keying on > application. The following won't work. > > - debug: > msg: "{{ apps.admin.service }}" > > TASK: [debug ] > **************************************************************** > fatal: [localhost] => One or more undefined variables: 'list' object has > no attribute 'service' > > I can't use *with_items* as I need to call lots of roles. I don't want to > pass the information directly to the roles as variables as I want to have > it defined in one place and it needs to be used in multiple places. > > I.e application configuration and apache virtual host definitions. > > Any help most appreciated. > > I'm happy to change the structure. All I need to do is store an amount of > information keyed by application > > Thanks > > James > > > -- > 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/994092cb-1890-4268-a3e5-1bc7ae7558f2%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/994092cb-1890-4268-a3e5-1bc7ae7558f2%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- Matt Martz @sivel sivel.net -- 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/CAD8N0v96%3DQ%2BZiMEM_%2Bm%2BY%2BOw6-aE-qNoAsqn%2BDAGtoQ3tpLHMw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
