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

How to use files? #849

Open
mihalt opened this issue May 8, 2024 · 5 comments
Open

How to use files? #849

mihalt opened this issue May 8, 2024 · 5 comments
Labels
docker-compose-v1 Docker Compose v1 docker-compose-v2 Docker Compose v2 question Further information is requested

Comments

@mihalt
Copy link

mihalt commented May 8, 2024

I haven't found in docs how to use files. I try something like

User
  tasks:
    community.docker.docker_compose:
      files:
        - "./mycustom-compose.yml"

And get an error like:
ERROR! A malformed block was encountered while loading tasks: {'community.docker.docker_compose': {'files': ['./mycustom-compose.yml']}} should be a list or None but is <class 'ansible.parsing.yaml.objects.AnsibleMapping'>

@felixfontein
Copy link
Collaborator

  1. I would suggest to not use the docker_compose module, since it is now deprecated, and use docker_compose_v2 instead.

  2. The problem has nothing to do with files, but that your file above is not anything that ansible itself can parse. Tasks should be a list of tasks, not a dictionary of tasks. If you need more help with this, better ask on the Ansible community forum (https://forum.ansible.com/).

@felixfontein felixfontein added question Further information is requested docker-compose-v1 Docker Compose v1 labels May 9, 2024
@mihalt
Copy link
Author

mihalt commented May 9, 2024

  1. I would suggest to not use the docker_compose module, since it is now deprecated, and use docker_compose_v2 instead.

    1. The problem has nothing to do with files, but that your file above is not anything that ansible itself can parse. Tasks should be a list of tasks, not a dictionary of tasks. If you need more help with this, better ask on the Ansible community forum (https://forum.ansible.com/).

wow, ahaha, you are righ!

so, I use like this now

  tasks:
    - community.docker.docker_compose_v2:
        project_src: "."
        files:
          - "./mycustom-compose.yml"

But it says now
{"changed": false, "msg": "Cannot find Compose file \"mycustom-compose.yml\" relative to project directory \".\""}

@mihalt
Copy link
Author

mihalt commented May 9, 2024

@felixfontein by the way, if I put mycustom-compose.yml (with renaming to compose.yml) to folder in the root of project, where ansible playbook located too and use:

  tasks:
    - community.docker.docker_compose_v2:
        project_src: "./folder" #the same as just "folder"

I have error {"changed": false, "msg": "\"./folder\" is not a directory"}

@mihalt
Copy link
Author

mihalt commented May 9, 2024

Should compose file be on ansible machine or on the target machine that I configure via ansible? My files just on ansible machine now.

@felixfontein
Copy link
Collaborator

The compose file must be on the same machine as where the module is run. If you don't use hosts: localhost or delegate_to: localhost, it must be on the target.

In any case, using relative paths is usually not a good idea since they depend a lot on where exactly - in particular from which directory - the module is executed. It's generally better to use absolute paths.

@felixfontein felixfontein added the docker-compose-v2 Docker Compose v2 label May 9, 2024
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 docker-compose-v2 Docker Compose v2 question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants