How to use omit with Ansible and avoid any errors?

前端 未结 2 2120
野趣味
野趣味 2021-01-03 04:32

I tried to use omit with an expression like this:

id: \"{{ openstack_networks.id | default(omit) }}\"

But it seems that it keeps failing w

2条回答
  •  醉酒成梦
    2021-01-03 05:19

    Not super elegant, but 100% working solution to handle keys of possibly undefined parent dicts:

    id: "{{ (openstack_networks | default({})).id | default(omit) }}"
    

    This will give you omit if openstack_networks is defined but has no id key or if openstack_networks is undefined.

提交回复
热议问题