community.docker
community.docker copied to clipboard
docker_compose: `recreate: never` wrongly reports changed
SUMMARY
ISSUE TYPE
- Bug Report
COMPONENT NAME
docker_compose
ANSIBLE VERSION
ansible [core 2.12.5]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.10/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.10.4 (main, Apr 14 2022, 04:16:58) [GCC 10.2.1 20210110]
jinja version = 3.1.1
libyaml = True
COLLECTION VERSION
# /root/.ansible/collections/ansible_collections
Collection Version
---------------- -------
community.docker 2.4.0
# /usr/local/lib/python3.10/site-packages/ansible_collections
Collection Version
---------------- -------
community.docker 2.4.0
CONFIGURATION
ANSIBLE_PIPELINING(/etc/ansible/ansible.cfg) = True
CALLBACKS_ENABLED(/etc/ansible/ansible.cfg) = ['timer']
DEFAULT_FORKS(/etc/ansible/ansible.cfg) = 50
DEFAULT_LOG_PATH(/etc/ansible/ansible.cfg) = /ansible.log
DEFAULT_STDOUT_CALLBACK(/etc/ansible/ansible.cfg) = yaml
DEFAULT_STRATEGY(/etc/ansible/ansible.cfg) = free
DIFF_ALWAYS(/etc/ansible/ansible.cfg) = True
DISPLAY_SKIPPED_HOSTS(/etc/ansible/ansible.cfg) = False
INTERPRETER_PYTHON(/etc/ansible/ansible.cfg) = auto_silent
MAX_FILE_SIZE_FOR_DIFF(/etc/ansible/ansible.cfg) = 512000
OS / ENVIRONMENT
Target host (not controller):
# docker-compose -v
docker-compose version 1.25.0, build unknown
# docker -v
Docker version 20.10.14, build a224086
# python3 --version
Python 3.9.2
STEPS TO REPRODUCE
- Create a
/srv/dc/traefik/docker-compose.yml
with a single service. - Run
/srv/dc/traefik$ docker-compose up -d
- Run the playbook below (optionally in check mode).
- name: ensure traefik is up
community.docker.docker_compose:
project_src: /srv/dc/traefik
recreate: never
EXPECTED RESULTS
Task reports as unchanged / up-to date. No changes to container.
ACTUAL RESULTS
Task reports as changed but the container doesn't get recreated (both with and without check mode).
Notes:
- The
recreate: never
functionality itself seems to work: Even if the container needs an update, it will not get recreated. - Removing
recreate
fixes the problem (provided the container is up to date of course).
Full logs (with -vvvv
): https://gist.github.com/gzm0/eb704c1886509188d19f6247c71ec06a
Module output:
Check mode
TASK [ensure traefik is up] [CHECK MODE] ****************************************************************************************************************************************************
task path: /etc/ansible/debug.yml:4
changed: [support02.datawan.ch] => changed=true
actions:
- service: reverse-proxy
start:
- id: 202d4fd5707538a8b8904a821fcfd7f4a0ac93fd13a777bf393ae4a0e9643223
name: traefik_reverse-proxy_1
short_id: 202d4fd57075
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
env_file: null
files: null
hostname_check: false
nocache: false
profiles: null
project_name: null
project_src: /srv/dc/traefik
pull: false
recreate: never
remove_images: null
remove_orphans: false
remove_volumes: false
restarted: false
scale: null
services: null
ssl_version: null
state: present
stopped: false
timeout: null
tls: false
tls_hostname: null
use_ssh_client: false
validate_certs: false
services:
reverse-proxy:
traefik_reverse-proxy_1:
cmd:
- traefik
image: traefik:v2.5.3
labels:
com.docker.compose.config-hash: 24a81c10a827bc3cfe8d6db644c91fa56c2148aba0d4d1b78ca1e3bbf2c546b0
com.docker.compose.container-number: '1'
com.docker.compose.oneoff: 'False'
com.docker.compose.project: traefik
com.docker.compose.project.config_files: docker-compose.yml
com.docker.compose.project.working_dir: /srv/dc/traefik
com.docker.compose.service: reverse-proxy
com.docker.compose.version: 1.25.0
org.opencontainers.image.description: A modern reverse-proxy
org.opencontainers.image.documentation: https://docs.traefik.io
org.opencontainers.image.title: Traefik
org.opencontainers.image.url: https://traefik.io
org.opencontainers.image.vendor: Traefik Labs
org.opencontainers.image.version: v2.5.3
networks:
proxy:
IPAddress: 172.18.0.2
IPPrefixLen: 16
aliases:
- reverse-proxy
- 202d4fd57075
globalIPv6: ''
globalIPv6PrefixLen: 0
links: null
macAddress: 02:42:ac:12:00:02
state:
running: true
status: running
Non-check mode:
TASK [ensure traefik is up] ******************************************************************************************************************************************************************
task path: /etc/ansible/debug.yml:4
changed: [support02.datawan.ch] => changed=true
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
env_file: null
files: null
hostname_check: false
nocache: false
profiles: null
project_name: null
project_src: /srv/dc/traefik
pull: false
recreate: never
remove_images: null
remove_orphans: false
remove_volumes: false
restarted: false
scale: null
services: null
ssl_version: null
state: present
stopped: false
timeout: null
tls: false
tls_hostname: null
use_ssh_client: false
validate_certs: false
services:
reverse-proxy:
traefik_reverse-proxy_1:
cmd:
- traefik
image: traefik:v2.5.3
labels:
com.docker.compose.config-hash: 24a81c10a827bc3cfe8d6db644c91fa56c2148aba0d4d1b78ca1e3bbf2c546b0
com.docker.compose.container-number: '1'
com.docker.compose.oneoff: 'False'
com.docker.compose.project: traefik
com.docker.compose.project.config_files: docker-compose.yml
com.docker.compose.project.working_dir: /srv/dc/traefik
com.docker.compose.service: reverse-proxy
com.docker.compose.version: 1.25.0
org.opencontainers.image.description: A modern reverse-proxy
org.opencontainers.image.documentation: https://docs.traefik.io
org.opencontainers.image.title: Traefik
org.opencontainers.image.url: https://traefik.io
org.opencontainers.image.vendor: Traefik Labs
org.opencontainers.image.version: v2.5.3
networks:
proxy:
IPAddress: 172.18.0.2
IPPrefixLen: 16
aliases:
- reverse-proxy
- 202d4fd57075
globalIPv6: ''
globalIPv6PrefixLen: 0
links: null
macAddress: 02:42:ac:12:00:02
state:
running: true
status: running
I suspect the reason we do not see actions
in non-check mode is that they are removed here:
https://github.com/ansible-collections/community.docker/blob/51d4c557e883d17041c964f2ce869013bad26fcc/plugins/modules/docker_compose.py#L718-L719
Adding debug: true
confirms this: The actions now also appear without check mode.
actions:
- service: reverse-proxy
start:
- id: 202d4fd5707538a8b8904a821fcfd7f4a0ac93fd13a777bf393ae4a0e9643223
name: traefik_reverse-proxy_1
short_id: 202d4fd57075
Hrm... Is this a docker-compose bug? From the little I understand here is that the convergence plan contains the start
action but it shouldn't...
That actions
is only shown in check mode or when debug=true
is mentioned in the documentation: https://docs.ansible.com/ansible/latest/collections/community/docker/docker_compose_module.html#return-actions