Suppose i want to start a docker container and its parameters would differ based on a condition. Something like this:
docker_container:
name: typeA
image: typeA
volumes:
- a1:a1
- a2:a2
when: type == A
docker_container:
name: typeB
image: typeB
volumes:
- b1:b1
- b2:b2
privileged: yes
when: type == B
I want to avoid writing and maintaining two similar tasks when i know always only one of them will execute. So is there a more elegant way to do this ? Like i define the differences in a dict var and only specify one docker_container.
I tried this but this didn’t work. I was hoping that there is something similar possible
Avars:
name: typeA
image: typeA
volumes:
- a1:a1
Bvars:
name: typeB
image: typeB
volumes:
- b1:b1
- b2:b2
privileged: yes
docker_container: “{{ (type == A) | ternary ( Avars, Bvars) }}”