Ansible docker_service module is not actually stopping containers/services

  ansible, docker, docker-compose

I’m trying to use ansible to do a "docker-compose down" using docker-compose.yml, using the following task:

  - name: Stop Harbor
      docker_service:
        project_src: "/installdir/harbor"
        files: docker-compose.yml
        stopped: yes
        state: absent
        timeout: 30

When I ran the playbook, I saw these messages :

ok: [myhost.com] => {
    "changed": false, 
    "invocation": {
        "module_args": {
            "api_version": "auto", 
            "build": false, 
            "ca_cert": null, 
            "client_cert": null, 
            "client_key": null, 
            "debug": false, 
            "definition": null, 
            "dependencies": true, 
            "docker_host": "unix://var/run/docker.sock", 
            "files": [
                "docker-compose.yml"
            ], 
            "hostname_check": false, 
            "nocache": false, 
            "project_name": null, 
            "project_src": "/installdir/harbor", 
            "pull": false, 
            "recreate": "smart", 
            "remove_images": null, 
            "remove_orphans": false, 
            "remove_volumes": false, 
            "restarted": false, 
            "scale": null, 
            "services": null, 
            "ssl_version": null, 
            "state": "absent", 
            "stopped": true, 
            "timeout": 30, 
            "tls": false, 
            "tls_hostname": "localhost", 
            "validate_certs": false
        }
    }
}

However when I ran a docker ps on myhost.com I see all containers still up:

CONTAINER ID        IMAGE                                  COMMAND                  CREATED             STATUS                 PORTS                                                                            NAMES
cccec3b05364        goharbor/nginx-photon:v2.0.1           "nginx -g 'daemon ..."   2 hours ago         Up 2 hours (healthy)   0.0.0.0:8082->8082/tcp, 0.0.0.0:2443->2443/tcp                                   nginx
1f5c0866c517        goharbor/clair-adapter-photon:v2.0.1   "/home/clair-adapt..."   2 hours ago         Up 2 hours (healthy)   8082/tcp                                                                         clair-adapter
6c7b3eff84fe        goharbor/harbor-jobservice:v2.0.1      "/harbor/entrypoin..."   2 hours ago         Up 2 hours (healthy)                                                                                    harbor-jobservice
046aca489871        goharbor/trivy-adapter-photon:v2.0.1   "/home/scanner/ent..."   2 hours ago         Up 2 hours (healthy)   8082/tcp                                                                         trivy-adapter
4c02624e4202        goharbor/harbor-core:v2.0.1            "/harbor/entrypoin..."   2 hours ago         Up 2 hours (healthy)                                                                                    harbor-core
3d6cc6973ecf        goharbor/clair-photon:v2.0.1           "./docker-entrypoi..."   2 hours ago         Up 2 hours (healthy)   6000-6451/tcp                                                                    clair
ba3317af4ce2        goharbor/registry-photon:v2.0.1        "/home/harbor/entr..."   2 hours ago         Up 2 hours (healthy)   5050/tcp                                                                         registry
aeaeeb4f3fb7        goharbor/chartmuseum-photon:v2.0.1     "./docker-entrypoi..."   2 hours ago         Up 2 hours (healthy)   9899/tcp                                                                         chartmuseum
aa21db256583        goharbor/harbor-db:v2.0.1              "/docker-entrypoin..."   2 hours ago         Up 2 hours (healthy)   5452/tcp                                                                         harbor-db
6836a58c9192        goharbor/harbor-registryctl:v2.0.1     "/home/harbor/star..."   2 hours ago         Up 2 hours (healthy)                                                                                    registryctl
07ec339cd657        goharbor/harbor-portal:v2.0.1          "nginx -g 'daemon ..."   2 hours ago         Up 2 hours (healthy)   8280/tcp                                                                         harbor-portal
a3820b05baf9        goharbor/redis-photon:v2.0.1           "redis-server /etc..."   2 hours ago         Up 2 hours (healthy)   6399/tcp                                                                         redis
18e41e6a5695        goharbor/harbor-log:v2.0.1             "/bin/sh -c /usr/l..."   2 hours ago         Up 2 hours (healthy)   127.0.0.1:1514->10514/tcp                                                        harbor-log

These got stopped just fine if I stop them via docker-compose down.
Why is ansible not stopping the containers even though no errors were registered?

THanks
J

Source: Docker Questions

LEAVE A COMMENT