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

Compose profiles not respected when defined via .env variable

Open hnicke opened this issue 2 years ago • 3 comments

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=[].

hnicke avatar Sep 10 '23 16:09 hnicke

Is this supposed to work with docker-compose v1?

felixfontein avatar Sep 10 '23 18:09 felixfontein

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

hnicke avatar Sep 10 '23 18:09 hnicke

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.

felixfontein avatar Sep 10 '23 19:09 felixfontein

The community.docker.docker_compose module has been removed from today's 4.0.0 release. If you are still using it, please upgrade to community.docker.docker_compose_v2, which no longer uses the End of Life versions Docker Compose 1.x.y, but Docker's Compose plugin (version 2.x.y range).

felixfontein avatar Oct 20 '24 09:10 felixfontein