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

How to use `files`?

Open mihalt opened this issue 1 year ago • 5 comments

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'>

mihalt avatar May 08 '24 20:05 mihalt

  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 avatar May 09 '24 07:05 felixfontein

  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 avatar May 09 '24 07:05 mihalt

@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 avatar May 09 '24 09:05 mihalt

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

mihalt avatar May 09 '24 12:05 mihalt

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 avatar May 09 '24 14:05 felixfontein

Closing since the above comment likely resolves this.

felixfontein avatar Aug 07 '24 14:08 felixfontein