community.docker
community.docker copied to clipboard
How to use `files`?
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'>
-
I would suggest to not use the
docker_composemodule, since it is now deprecated, and usedocker_compose_v2instead. -
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/).
I would suggest to not use the
docker_composemodule, since it is now deprecated, and usedocker_compose_v2instead.
- 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 \".\""}
@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"}
Should compose file be on ansible machine or on the target machine that I configure via ansible? My files just on ansible machine now.
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.
Closing since the above comment likely resolves this.