You are a champion! Thank you so much!
On Sunday, February 3, 2019 at 2:03:42 PM UTC-6, James Cassell wrote:
>
>
>
> On Sun, Feb 3, 2019, at 11:45 AM, cortado wrote:
> > I need to add an item to a list. This works:
> >
> > - name: "Build Pool IP List"
> > set_fact:
> > pool_server_ips_list: "{{pool_server_ips_list}} + [{'ip': {'addr':
> > item, 'type': 'V4'}}]"
> > with_items: "{{pool_server_ips}}"
> >
> > with this list:
> >
> > pool_server_ips:
> > - 10.8.10.4
> > - 10.8.10.5
> > - 10.8.10.6
> > - 10.8.10.7
> >
> > I need to add another element to the list so I changed it to:
> >
> > pool_server_ips:
> > - hostip: 10.8.10.4
> > pool_member_enabled: true
> > - hostip: 10.8.10.5
> > pool_member_enabled: false
> > - hostip: 10.8.10.6
> > pool_member_enabled: false
> > - hostip: 10.8.10.7
> > pool_member_enabled: false
> >
> > then changed fact to:
> >
> > set_fact:
> > pool_server_ips_list: "{{pool_server_ips_list}} + [{'ip': {'addr':
> > item.hostip, 'type': 'V4'}}]"
>
>
> Try:
>
> pool_server_ips_list: "{{pool_server_ips_list | default([]) + [{'ip':
> {'addr': item.hostip, 'type': 'V4'}}] }}"
>
>
> > with_items: "{{pool_server_ips}}"
> >
> > If I debug the list i get:
> >
> > "servers": [
> > "[] + [{'ip': {'addr': [item.hostip]",
> > " 'type': 'V4'}}] + [{'ip': {'addr': [item.hostip]",
> > " 'type': 'V4'}}] + [{'ip': {'addr': [item.hostip]",
> > " 'type': 'V4'}}] + [{'ip': {'addr': [item.hostip]",
> > " 'type': 'V4'}}]"
> > ]
> >
>
> V/r,
> James Cassell
>
--
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/aeb075f2-8765-4f5b-b257-45aff96ccb23%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.