--
You received this message because you are subscribed to the Google Groups "Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-devel/04701668-e7dc-4ec9-b0de-7d02594edf51n%40googlegroups.com.
Hi John,
Thank you for the response. I just tried it and got the following error:"msg": "template error while templating string: unexpected char u'\\u2018' at 63. String: {{ hc_pim_info.dpListProcessesReply.dpServiceList.dpService[0][‘@Name’] }}"
Must be a copy/paste error - those single quotes around @Name are not ASCII quotes:
>cat <<EOF | od -c
> [‘@Name’]
> EOF
0000000 [ 342 200 230 @ N a m e 342 200 231 ] \n
0000016
Works fine for me if I use plain ASCII single quotes.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-devel/CABiKD-FfcqWCyGrEnAZ_0hOTKcu4YTpNY_F2nMVqukKc2%3DSBvQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-devel/9815e00a-894a-879d-70ff-d76b2d86dd77%40redhat.com.
Ahh got it! ok, that worked. 1 more question, since that is an array at dpService, I want to iterate through that. I tried leaving the brackets blank, but that failed. How would I tell it to give me each element?
I guess it depends on what you want to do with it.
Do you want to use it in a loop? https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#
Do you want to select some elements from the list? https://jinja.palletsprojects.com/en/2.11.x/templates/#select or selectattr
Do you want to perform some modification to each item? https://jinja.palletsprojects.com/en/2.11.x/templates/#map
or
https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#list-filters
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-devel/CABiKD-HFMw91UdSW6mnoHnqGQxz%3DA2PmT9pDx-c-odv8C11Drw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-devel/2d4ad56a-d586-a25d-a442-ebef70b733cc%40redhat.com.
Hi Rich,I'm looking to collect the name field into a list and then use that in further tasks.
Something like this:
set_fact:
keyvallist: "{{ hc_pim_info.dpListProcessesReply.dpServiceList.dpService | map(attribute='@key') | list }}"
see the examples under https://jinja.palletsprojects.com/en/2.11.x/templates/#map