1

Found part of answer for my question in How to run docker-compose commands with ansible?

- name: copy Docker Compose files
  copy:
    src: files/{{ item }}
    dest: /somewhere/yourproject/{{ item }}
  loop:
  - docker-compose.yml
  - docker-compose.prod.yml

# use files parameter to use multiple docker-compose.yml files
- name: deploy Docker Compose stack
  docker_compose:
    project_src: /somewhere/yourproject
    files:
    - docker-compose.yml
    - docker-compose.prod.yml

But if using the module, how can I specify the path to .env if it is located in a different directory than docker-compose.yaml. If need to repeat the result of the command: docker-compose -f docker-compose.yml -f docker-compose.prod.yml --env-file=path/to/.env up. Where the path/to/.env can change depending on the need.

  • 1
    You cannot, the module doesn't provide any option for that: https://docs.ansible.com/ansible/latest/collections/community/docker/docker_compose_module.html#ansible-collections-community-docker-docker-compose-module – zigarn Mar 27 '21 at 07:19
  • 1
    You could try to load env file into ansible to use it in `environment:` (not even sure it would work): https://stackoverflow.com/a/60375316/439790 – zigarn Mar 27 '21 at 07:22

0 Answers0