community.docker icon indicating copy to clipboard operation
community.docker copied to clipboard

community.docker.docker_stack does not use .env file for compose yml

Open adnoh opened this issue 1 year ago • 2 comments

SUMMARY

When you community.docker.docker_stack deploy a stack which uses variables in its compose.yml the deployment will fail.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.docker.docker_stack

ANSIBLE VERSION
2.12.2
COLLECTION VERSION
community.docker 2.1.1
STEPS TO REPRODUCE
place a variable from your .env file like ${DOMAIN} into your compose.yml, it will not substitute on stack deploy

as it is a know pattern that stack deploy does not read the .env into compose.yml I'm not sure if it's a bug or a FR or a issue for discussion. But in my Opinion to workaround the problem the module should use something similar to docker-compose -f myCompose.yml config|docker stack deploy -c - STACKNAME

adnoh avatar Oct 07 '22 15:10 adnoh

What's "my .env file" here? Where is it located? How does your role/playbook look, and your file/directory structure?

felixfontein avatar Oct 07 '22 17:10 felixfontein

it does not really play a role where the file is located as the default docker-compose stack deploy also can't handle it. Have a look at the orange warning on https://docs.docker.com/compose/environment-variables/ So it is "by design" somehow, but it would be a great workaround in my opinion if we still can use it like described in my issue. If not I need to deploy the stack by hand with the mentioned pipe from compose to docker. Or do I do something wrong? To be clear - a .env sets the variables as ENV INSIDE of the container - but does not (and thats my problem) substitue it inside the compose.yml file But to answer your question - I've put the compose and the .env file in the same directory, deploy it with ansible to the server (/root/deploy) and use that compose file with

community.docker.docker_stack:
        name: myApp
        compose:
          - /root/deploy/myApp.yml

it does not make a difference if it's named .env or has a specific name and if I reference it inside the compose.yml with env_file: .... It's the stage before which is failing

adnoh avatar Oct 07 '22 18:10 adnoh