I know about the omit filter but I'm not able to get to work when it's in a list of dictionaries.
I want it so that if for example, the published_port variable is not defined then the publish parameter is omitted
- name: test
community.docker.docker_swarm_service:
name: myservice
image: alpine
publish:
- published_port: "{{ published_port | default(omit) }}"
target_port: "{{ target_port | default(omit) }}"
The error I get is: "missing required arguments: published_port, target_port found in publish". I know it's something to do with it being a list but not sure how to get around this issue.