Ok, so after looking into this further I don't think with_items can
look 'inside' the dictionary, and I should instead be using
with_subelements. That doesn't appear to work either though:

- name: Write out SSLs to files
  copy: dest=/etc/ukfast/{{item.tls.domain}}.pem owner=root group=root
mode=0600 content={{item.tls.pem}}
  with_subelements:
    - l7config
    - frontends
  when: item.tls is defined


TASK: [layer7-lb | Write out SSLs to files] ***********************************
fatal: [192.168.122.76] => subelements lookup expects a dictionary,
got 'AirwavesEyedrops'


I'm not sure why it's pulling out the value of stats_password instead
of looking up the list 'frontends' inside the dictionary 'l7config'.

I've loaded my JSON into Python to confirm the types, too:

>>> type(a['l7config'])
<type 'dict'>
>>> type(a['l7config']['frontends'])
<type 'list'>

Regards

Dane

On 21 October 2014 14:17, Dane Elwell <[email protected]> wrote:
> Hello list,
>
> I've got a complex dictionary I'm using to configure haproxy with,
> which looks something like this (non-relevant portions have been
> removed):
>
> {
>     "l7config": {
>         "stats_password": "AirwavesEyedrops",
>         "frontends": [
>             {
>                 "frontend_id": "6dcb7365-1b6c-4f24-a7ff-79590af2d536",
>                 "vip": "192.0.1.200",
>                 "service": "http",
>                 "port": 80,
>                 "backend_id": "49cd3849-455c-4e5c-9e13-70cda7be0397"
>             },
>             {
>                 "frontend_id": "01f99586-c14c-4c99-99e0-cf6effac3ee8",
>                 "vip": "192.0.1.200",
>                 "port": 443,
>                 "service": "http",
>                 "backend_id": "49cd3849-455c-4e5c-9e13-70cda7be0397",
>                 "tls": {
>                     "pem": "-----BEGIN PRIVATE KEY-----\nMII
> ...snip... 7w==\n-----END CERTIFICATE-----\n",
>                     "domain": "foobar.com"
>                 }
>             }
>         ],
>         "backends": [
>             {
>                 ...
>             },
>             ...
>         ]
>     }
> }
>
> As you can see, I've got two frontend configurations, one which has a
> 'tls' field and the other which doesn't. What I need to do is iterate
> over the frontends and discover which ones have the tls field, then
> write out the 'pem' certificates into a file.
>
> I have this code in my playbook which isn't working as I think it
> should, as it always seems to just skip the task:
>
>     - name: Write out SSLs to files
>       copy: dest=/etc/ssl/{{item.tls.domain}}.pem owner=root
> group=root mode=0600 content={{item.tls.pem}}
>       with_items:
>         - l7config.frontends
>       when: item.tls is defined
>
> I suspect I'm on the right track, but I'm missing something blindingly
> obvious and stupid. I just need someone to point out where I'm being
> daft :)
>
> Thanks
>
> Dane

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

Reply via email to