Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compose profiles not respected when defined via .env variable #683

Open
hnicke opened this issue Sep 10, 2023 · 3 comments
Open

Compose profiles not respected when defined via .env variable #683

hnicke opened this issue Sep 10, 2023 · 3 comments
Labels
docker-compose-v1 Docker Compose v1 question Further information is requested

Comments

@hnicke
Copy link

hnicke commented Sep 10, 2023

SUMMARY

The docker_compose module does not respect compose profiles which are specified via env variable COMPOSE_PROFILES using the .env file.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

docker_compose

ANSIBLE VERSION
ansible [core 2.15.3]
  config file = None
  configured module search path = ['/home/heiko/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.11/site-packages/ansible
  ansible collection location = /home/heiko/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.11.3 (main, Jun  5 2023, 09:32:32) [GCC 13.1.1 20230429] (/usr/bin/python)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
community.docker 3.4.8

OS / ENVIRONMENT

arch linux

STEPS TO REPRODUCE

Use the following .env file:

# .env file
COMPOSE_PROFILES=foo
EXPECTED RESULTS

The profile foo is activated.
I.e., the very same behavior as when running docker-compose up directly.

ACTUAL RESULTS

The profile foo is not activated. Thus, it runs with profiles=[].

@felixfontein felixfontein added the docker-compose-v1 Docker Compose v1 label Sep 10, 2023
@felixfontein
Copy link
Collaborator

Is this supposed to work with docker-compose v1?

@felixfontein felixfontein added the question Further information is requested label Sep 10, 2023
@hnicke
Copy link
Author

hnicke commented Sep 10, 2023

This works with docker compose v1. See docs. And it looks like it's still supported in v2.

@felixfontein
Copy link
Collaborator

That documentation is about docker-compose v2, and does not necessarily apply to docker-compose v1.

In any case, the module uses docker-compose internals to achieve it goals. The module uses project_from_options from docker-compose, which in turn calls get_profiles_from_options to extract COMPOSE_PROFILES from the env file - if --profile hasn't been specified on the CLI command line, which happens if the module's profiles option is used. So I guess it should work, but I guess someone needs to do more debugging to figure out what exactly happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docker-compose-v1 Docker Compose v1 question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants