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

compose v2: Unknown resource type in dry run with pull_policy: build

Open Crocmagnon opened this issue 1 year ago • 3 comments

SUMMARY

Trying to stop a docker compose service in dry run (--check --diff) with the pull_policy: build results in the following warnings:

[WARNING]: Unknown resource type '' in line b'{"dry-run":true,"id":" ","text":"build service app"}'. Please report this at
https://github.com/ansible-collections/community.docker/issues/new?assignees=&labels=&projects=&template=bug_report.md
[WARNING]: Unknown resource type '==>' in line b'{"dry-run":true,"id":"==\\u003e ==\\u003e","text":"naming to display-
app"}'. Please report this at https://github.com/ansible-
collections/community.docker/issues/new?assignees=&labels=&projects=&template=bug_report.md
[WARNING]: Docker compose: unknown : build service app
[WARNING]: Docker compose: unknown ==>: ==> writing image dryRun-7d1043473d55bfa90e8530d35801d4e381bc69f0
[WARNING]: Docker compose: unknown ==>: naming to display-app
ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.docker.docker_compose_v2

ANSIBLE VERSION
$ ansible --version
ansible [core 2.17.5]
  config file = /Users/gaugendre/Projects/ansible/ansible.cfg
  configured module search path = ['/Users/gaugendre/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/Cellar/ansible/10.5.0/libexec/lib/python3.12/site-packages/ansible
  ansible collection location = /Users/gaugendre/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/bin/ansible
  python version = 3.12.7 (main, Oct  1 2024, 02:05:46) [Clang 16.0.0 (clang-1600.0.26.3)] (/opt/homebrew/Cellar/ansible/10.5.0/libexec/bin/python)
  jinja version = 3.1.4
  libyaml = True
COLLECTION VERSION
$ ansible-galaxy collection list community.docker

# /opt/homebrew/Cellar/ansible/10.5.0/libexec/lib/python3.12/site-packages/ansible_collections
Collection       Version
---------------- -------
community.docker 3.13.0

I don't know how to use the latest release/devel version.

CONFIGURATION
$ ansible-config dump --only-changed
ANSIBLE_NOCOWS(env: ANSIBLE_NOCOWS) = True
ANSIBLE_PIPELINING(/Users/gaugendre/Projects/ansible/ansible.cfg) = True
CALLBACKS_ENABLED(/Users/gaugendre/Projects/ansible/ansible.cfg) = ['timer', 'profile_tasks']
CONFIG_FILE() = /Users/gaugendre/Projects/ansible/ansible.cfg
DEFAULT_HOST_LIST(env: ANSIBLE_INVENTORY) = ['/Users/gaugendre/Projects/ansible/inventories/local.yaml']
DEFAULT_ROLES_PATH(env: ANSIBLE_ROLES_PATH) = ['/Users/gaugendre/Projects/ansible/roles']
DEFAULT_VAULT_PASSWORD_FILE(env: ANSIBLE_VAULT_PASSWORD_FILE) = /Users/gaugendre/Projects/ansible/vault.pass
EDITOR(env: EDITOR) = nvim
OS / ENVIRONMENT
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.5 LTS
Release:	22.04
Codename:	jammy

$ uname -a
Linux ubuntu 5.15.0-118-generic #128-Ubuntu SMP Fri Jul 5 09:28:59 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
STEPS TO REPRODUCE

Write the following docker-compose.yaml in a directory on the target host.

# docker-compose.yaml
services:
  app:
    pull_policy: build
    build:
      context: sources
    restart: always
    ports:
      - "9010:80"

Then run the following task in a playbook in dry run mode (--check --diff)

# task
- name: Stop service
  community.docker.docker_compose_v2:
    project_src: "{{ docker_dir }}"
    state: stopped
EXPECTED RESULTS

I'd expect no warning

ACTUAL RESULTS
Logs
RUNNING HANDLER [docker : Stop service] *************************************************************************************
task path: /Users/gaugendre/Projects/ansible/roles/docker/handlers/main.yaml:2
Saturday 12 October 2024  10:51:36 +0200 (0:00:00.001)       0:00:04.223 ******
Using module file /opt/homebrew/Cellar/ansible/10.5.0/libexec/lib/python3.12/site-packages/ansible_collections/community/docker/plugins/modules/docker_compose_v2.py
Pipelining is enabled.
<192.168.0.6> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.0.6> SSH: EXEC ssh -vvvv -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/Users/gaugendre/.ansible/cp/1f02286d61"' 192.168.0.6 '/bin/sh -c '"'"'/usr/bin/python3.10 && sleep 0'"'"''
<192.168.0.6> (0, b'\n{"changed": true, "actions": [{"what": "container", "id": "display-app-1", "status": "Recreate"}, {"what": "container", "id": "display-app-1", "status": "Stopping"}], "stderr": "{\\"dry-run\\":true,\\"id\\":\\" \\",\\"text\\":\\"build service app\\"}\\n{\\"dry-run\\":true,\\"id\\":\\"==\\\\u003e\\",\\"text\\":\\"==\\\\u003e writing image dryRun-7d1043473d55bfa90e8530d35801d4e381bc69f0\\"}\\n{\\"dry-run\\":true,\\"id\\":\\"==\\\\u003e ==\\\\u003e\\",\\"text\\":\\"naming to display-app\\"}\\n{\\"dry-run\\":true,\\"id\\":\\"Container display-app-1\\",\\"status\\":\\"Recreate\\"}\\n{\\"dry-run\\":true,\\"id\\":\\"Container display-app-1\\",\\"status\\":\\"Recreated\\"}\\n\\n{\\"dry-run\\":true,\\"id\\":\\"Container display-app-1\\",\\"status\\":\\"Stopping\\"}\\n{\\"dry-run\\":true,\\"id\\":\\"Container display-app-1\\",\\"status\\":\\"Stopped\\"}\\n", "containers": [{"Command": "\\"/docker-entrypoint.sh nginx -g \'daemon off;\'\\"", "CreatedAt": "2024-10-12 10:33:41 +0200 CEST", "ExitCode": 0, "Health": "", "ID": "78d650f9bbcd0c7123134f7d1d231f35567494583fe195ae8ff1bca8db411e5d", "Image": "display-app", "Labels": {"com.docker.compose.container-number": "1", "com.docker.compose.image": "sha256:32971072a8beb03a9148b846cf5fade77f5dc833da4c124a19ae3e640f97875b", "com.docker.compose.project.config_files": "/mnt/data/display/docker-compose.yaml", "com.docker.compose.project.working_dir": "/mnt/data/display", "com.docker.compose.service": "app", "maintainer": "NGINX Docker Maintainers <[email protected]>", "com.docker.compose.config-hash": "206b00a65908b52ed9546c0e2e1118da9c861483fdac092c80f85f42bf79abd7", "com.docker.compose.depends_on": "", "com.docker.compose.oneoff": "False", "com.docker.compose.project": "display", "com.docker.compose.replace": "182dcd32b15f0a205f8f7b77fbbfbd6d8e3cfe32d32a81fa0855e28441a59bae", "com.docker.compose.version": "2.29.7"}, "LocalVolumes": "0", "Mounts": "", "Name": "display-app-1", "Names": ["display-app-1"], "Networks": ["display_default"], "Ports": "0.0.0.0:9010->80/tcp, [::]:9010->80/tcp", "Project": "display", "Publishers": [{"URL": "0.0.0.0", "TargetPort": 80, "PublishedPort": 9010, "Protocol": "tcp"}, {"URL": "::", "TargetPort": 80, "PublishedPort": 9010, "Protocol": "tcp"}], "RunningFor": "17 minutes ago", "Service": "app", "Size": "0B", "State": "running", "Status": "Up 9 minutes"}], "images": [{"ID": "sha256:32971072a8beb03a9148b846cf5fade77f5dc833da4c124a19ae3e640f97875b", "ContainerName": "display-app-1", "Repository": "display-app", "Tag": "latest", "Size": 194073208}], "invocation": {"module_args": {"project_src": "/mnt/data/display", "state": "stopped", "api_version": "auto", "tls": false, "validate_certs": false, "dependencies": true, "pull": "policy", "build": "policy", "recreate": "auto", "remove_volumes": false, "remove_orphans": false, "wait": false, "check_files_existing": true, "docker_cli": null, "docker_host": null, "tls_hostname": null, "ca_path": null, "client_cert": null, "client_key": null, "cli_context": null, "remove_images": null, "timeout": null, "services": null, "scale": null, "wait_timeout": null, "project_name": null, "files": null, "definition": null, "env_files": null, "profiles": null}}, "warnings": ["Unknown resource type \'\' in line b\'{\\"dry-run\\":true,\\"id\\":\\" \\",\\"text\\":\\"build service app\\"}\'. Please report this at https://github.com/ansible-collections/community.docker/issues/new?assignees=&labels=&projects=&template=bug_report.md", "Unknown resource type \'==>\' in line b\'{\\"dry-run\\":true,\\"id\\":\\"==\\\\\\\\u003e ==\\\\\\\\u003e\\",\\"text\\":\\"naming to display-app\\"}\'. Please report this at https://github.com/ansible-collections/community.docker/issues/new?assignees=&labels=&projects=&template=bug_report.md", "Docker compose: unknown : build service app", "Docker compose: unknown ==>: ==> writing image dryRun-7d1043473d55bfa90e8530d35801d4e381bc69f0", "Docker compose: unknown ==>: naming to display-app"]}\n', b"OpenSSH_9.8p1, LibreSSL 3.3.6\r\ndebug1: Reading configuration data /Users/gaugendre/.ssh/config\r\ndebug1: /Users/gaugendre/.ssh/config line 1: include ~/.ssh/work.config matched no files\r\ndebug1: /Users/gaugendre/.ssh/config line 53: Applying options for *\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files\r\ndebug1: /etc/ssh/ssh_config line 54: Applying options for *\r\ndebug2: resolve_canonicalize: hostname 192.168.0.6 is address\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/Users/gaugendre/.ssh/known_hosts'\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/Users/gaugendre/.ssh/known_hosts2'\r\ndebug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling\r\ndebug1: auto-mux: Trying existing master at '/Users/gaugendre/.ansible/cp/1f02286d61'\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 70544\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet_timeout: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n")
[WARNING]: Unknown resource type '' in line b'{"dry-run":true,"id":" ","text":"build service app"}'. Please report this at
https://github.com/ansible-collections/community.docker/issues/new?assignees=&labels=&projects=&template=bug_report.md
[WARNING]: Unknown resource type '==>' in line b'{"dry-run":true,"id":"==\\u003e ==\\u003e","text":"naming to display-
app"}'. Please report this at https://github.com/ansible-
collections/community.docker/issues/new?assignees=&labels=&projects=&template=bug_report.md
[WARNING]: Docker compose: unknown : build service app
[WARNING]: Docker compose: unknown ==>: ==> writing image dryRun-7d1043473d55bfa90e8530d35801d4e381bc69f0
[WARNING]: Docker compose: unknown ==>: naming to display-app
changed: [ubuntu] => {
    "actions": [
        {
            "id": "display-app-1",
            "status": "Recreate",
            "what": "container"
        },
        {
            "id": "display-app-1",
            "status": "Stopping",
            "what": "container"
        }
    ],
    "changed": true,
    "containers": [
        {
            "Command": "\"/docker-entrypoint.sh nginx -g 'daemon off;'\"",
            "CreatedAt": "2024-10-12 10:33:41 +0200 CEST",
            "ExitCode": 0,
            "Health": "",
            "ID": "78d650f9bbcd0c7123134f7d1d231f35567494583fe195ae8ff1bca8db411e5d",
            "Image": "display-app",
            "Labels": {
                "com.docker.compose.config-hash": "206b00a65908b52ed9546c0e2e1118da9c861483fdac092c80f85f42bf79abd7",
                "com.docker.compose.container-number": "1",
                "com.docker.compose.depends_on": "",
                "com.docker.compose.image": "sha256:32971072a8beb03a9148b846cf5fade77f5dc833da4c124a19ae3e640f97875b",
                "com.docker.compose.oneoff": "False",
                "com.docker.compose.project": "display",
                "com.docker.compose.project.config_files": "/mnt/data/display/docker-compose.yaml",
                "com.docker.compose.project.working_dir": "/mnt/data/display",
                "com.docker.compose.replace": "182dcd32b15f0a205f8f7b77fbbfbd6d8e3cfe32d32a81fa0855e28441a59bae",
                "com.docker.compose.service": "app",
                "com.docker.compose.version": "2.29.7",
                "maintainer": "NGINX Docker Maintainers <[email protected]>"
            },
            "LocalVolumes": "0",
            "Mounts": "",
            "Name": "display-app-1",
            "Names": [
                "display-app-1"
            ],
            "Networks": [
                "display_default"
            ],
            "Ports": "0.0.0.0:9010->80/tcp, [::]:9010->80/tcp",
            "Project": "display",
            "Publishers": [
                {
                    "Protocol": "tcp",
                    "PublishedPort": 9010,
                    "TargetPort": 80,
                    "URL": "0.0.0.0"
                },
                {
                    "Protocol": "tcp",
                    "PublishedPort": 9010,
                    "TargetPort": 80,
                    "URL": "::"
                }
            ],
            "RunningFor": "17 minutes ago",
            "Service": "app",
            "Size": "0B",
            "State": "running",
            "Status": "Up 9 minutes"
        }
    ],
    "images": [
        {
            "ContainerName": "display-app-1",
            "ID": "sha256:32971072a8beb03a9148b846cf5fade77f5dc833da4c124a19ae3e640f97875b",
            "Repository": "display-app",
            "Size": 194073208,
            "Tag": "latest"
        }
    ],
    "invocation": {
        "module_args": {
            "api_version": "auto",
            "build": "policy",
            "ca_path": null,
            "check_files_existing": true,
            "cli_context": null,
            "client_cert": null,
            "client_key": null,
            "definition": null,
            "dependencies": true,
            "docker_cli": null,
            "docker_host": null,
            "env_files": null,
            "files": null,
            "profiles": null,
            "project_name": null,
            "project_src": "/mnt/data/display",
            "pull": "policy",
            "recreate": "auto",
            "remove_images": null,
            "remove_orphans": false,
            "remove_volumes": false,
            "scale": null,
            "services": null,
            "state": "stopped",
            "timeout": null,
            "tls": false,
            "tls_hostname": null,
            "validate_certs": false,
            "wait": false,
            "wait_timeout": null
        }
    },
    "stderr": "{\"dry-run\":true,\"id\":\" \",\"text\":\"build service app\"}\n{\"dry-run\":true,\"id\":\"==\\u003e\",\"text\":\"==\\u003e writing image dryRun-7d1043473d55bfa90e8530d35801d4e381bc69f0\"}\n{\"dry-run\":true,\"id\":\"==\\u003e ==\\u003e\",\"text\":\"naming to display-app\"}\n{\"dry-run\":true,\"id\":\"Container display-app-1\",\"status\":\"Recreate\"}\n{\"dry-run\":true,\"id\":\"Container display-app-1\",\"status\":\"Recreated\"}\n\n{\"dry-run\":true,\"id\":\"Container display-app-1\",\"status\":\"Stopping\"}\n{\"dry-run\":true,\"id\":\"Container display-app-1\",\"status\":\"Stopped\"}\n",
    "stderr_lines": [
        "{\"dry-run\":true,\"id\":\" \",\"text\":\"build service app\"}",
        "{\"dry-run\":true,\"id\":\"==\\u003e\",\"text\":\"==\\u003e writing image dryRun-7d1043473d55bfa90e8530d35801d4e381bc69f0\"}",
        "{\"dry-run\":true,\"id\":\"==\\u003e ==\\u003e\",\"text\":\"naming to display-app\"}",
        "{\"dry-run\":true,\"id\":\"Container display-app-1\",\"status\":\"Recreate\"}",
        "{\"dry-run\":true,\"id\":\"Container display-app-1\",\"status\":\"Recreated\"}",
        "",
        "{\"dry-run\":true,\"id\":\"Container display-app-1\",\"status\":\"Stopping\"}",
        "{\"dry-run\":true,\"id\":\"Container display-app-1\",\"status\":\"Stopped\"}"
    ]
}

Crocmagnon avatar Oct 12 '24 08:10 Crocmagnon

The warnings also appear on state: present steps with no pull_policy in the compose file but with build: always in the step parameters (still in dry run mode).

Crocmagnon avatar Oct 12 '24 09:10 Crocmagnon

The way docker-compose's code abuses the progress event structure always wants to make me cry...

stderr output:

{"dry-run":true,"id":" ","text":"build service app"}
{"dry-run":true,"id":"==\u003e","text":"==\u003e writing image dryRun-7d1043473d55bfa90e8530d35801d4e381bc69f0"}
{"dry-run":true,"id":"==\u003e ==\u003e","text":"naming to display-app"}

Resulting warnings:

Unknown resource type '' in line b'{"dry-run":true,"id":" ","text":"build service app"}'. Please report this at https://github.com/ansible-collections/community.docker/issues/new?assignees=&labels=&projects=&template=bug_report.md
Unknown resource type '==>' in line b'{"dry-run":true,"id":"==\\u003e ==\\u003e","text":"naming to display-app"}'. Please report this at https://github.com/ansible-collections/community.docker/issues/new?assignees=&labels=&projects=&template=bug_report.md
Docker compose: unknown : build service app
Docker compose: unknown ==>: ==> writing image dryRun-7d1043473d55bfa90e8530d35801d4e381bc69f0
Docker compose: unknown ==>: naming to display-app

felixfontein avatar Oct 13 '24 10:10 felixfontein

#976 should fix this.

felixfontein avatar Oct 13 '24 19:10 felixfontein