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/1549224212.1851201.1649939408.2EBE8EA6%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.