Nice! Thank you. I am a bit annoyed with myself, because I have used exactly that technique to avoid a missing list. I don't know why it never occurred to me to avoid a missing map the same way :-)
Regards, K. On Fri, Dec 21, 2018 at 3:22 PM James Cassell <[email protected]> wrote: > On Thu, Dec 20, 2018, at 1:17 AM, Karl Auer wrote: > > Is there anything like the "default(omit)" filter available for ordinary > > variable declarations? > > > > I am building a list of volume details, which will be passed too the ec2 > > module. With module parameters, one can comvert an undefined parameter > inot > > no parameter at all with the "default(omit)" filter, but I cn't find a > way > > to simply leave out an undefined item from the list I m building. > > > > Say my input is a list of tables like this: > > > > alist: > > - { 'fred': value1, 'mary': value2 } > > - { 'fred: value3 } > > > > I want to process that list into another list using set_fact, so: > > > > - set_fact: > > mylist: "{{ mylist + [ {'this': item.fred, 'that': item.mary } ] }}" > > with_items: "{{ alist }}" > > > > > Try > > - set_fact: > mylist: "{{ mylist + [ {'this': item.fred } | combine(item.mary is > defined | ternary({ 'that': item.mary }, {})] }}" > with_items: "{{ alist }}" > > > > ... and end up with > > > > { 'this': value1, 'that': value2} > > { 'this': value3 } > > > > But I can't figure out how to omit item.mary if it is undefined. > > > > Any clues? > > > > Regards, K. > > > > -- > > Karl Auer > > > > Email : [email protected] > > Website: http://2pisoftware.com > > > > GPG/PGP : 958A 2647 6C44 D376 3D63 86A5 FFB2 20BC 0257 5816 > > Previous: F0AB 6C70 A49D 1927 6E05 81E7 AD95 268F 2AB6 40EA > > > > -- > > 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/CA%2B%2BT08Q7kOqLoVar0J1n8tpgm%2BovauRw17m7ONhwdJgeMKvh9g%40mail.gmail.com > . > > For more options, visit https://groups.google.com/d/optout. > > -- > 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/1545366130.2300653.1615147544.549E96CE%40webmail.messagingengine.com > . > For more options, visit https://groups.google.com/d/optout. > -- Karl Auer Email : [email protected] Website: http://2pisoftware.com GPG/PGP : 958A 2647 6C44 D376 3D63 86A5 FFB2 20BC 0257 5816 Previous: F0AB 6C70 A49D 1927 6E05 81E7 AD95 268F 2AB6 40EA -- 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/CA%2B%2BT08R6csmjCEj84ErF069Zn-8ZFihz5KzpwnkJ9Wo3yojfrg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
