Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

container doesn't get recreated when 'command' gets omitted #168

Closed
ChristianCiach opened this issue Jun 27, 2021 · 3 comments · Fixed by #186
Closed

container doesn't get recreated when 'command' gets omitted #168

ChristianCiach opened this issue Jun 27, 2021 · 3 comments · Fixed by #186
Labels
docker-plain plain Docker (no swarm, no compose, no stack)

Comments

@ChristianCiach
Copy link

SUMMARY

I need to deploy the same container twice. The first time I use a custom command parameter, but the second time want to deploy the container with the default command, so I try to omit the command parameter on the second task. Unfortunately, the container doesn't get changed, because this module never detects the change.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.docker.docker_container

ANSIBLE VERSION
ansible 2.9.16
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/christianc/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/christianc/.local/lib/python3.8/site-packages/ansible
  executable location = /data/ssd/christianc/emsconda/envs/core-platform-ng/bin/ansible
  python version = 3.8.10 | emsys distribution | (default, Jun 24 2021, 14:24:42) [GCC 9.3.1 20200408 (Red Hat 9.3.1-2)]

COLLECTION VERSION
ansible-galaxy collection list community.docker
usage: ansible-galaxy collection [-h] COLLECTION_ACTION ...
ansible-galaxy collection: error: argument COLLECTION_ACTION: invalid choice: 'list' (choose from 'init', 'build', 'publish', 'install')

Ansible 2.9 doesn't know the command ansible-galaxy collection list. But I am using community.docker in version 1.7.0.

CONFIGURATION
DEFAULT_VAULT_IDENTITY_LIST(env: ANSIBLE_VAULT_IDENTITY_LIST) = ['sorry, confidential']
STEPS TO REPRODUCE
- hosts: galera
  tasks:
    - name: Create mariadb bootstrap container
      community.docker.docker_container:
        name: 'mariadb'
        image: 'mariadb:10.5.11'
        restart_policy: always
        network_mode: host
        env:
          MARIADB_ROOT_PASSWORD: '{{ galera_root_password }}'
        log_driver: journald
        command: "{{ '--wsrep-new-cluster' if galera_bootstrap else omit }}"
        container_default_behavior: compatibility
        comparisons:
          'command': strict
      vars:
        galera_bootstrap: true

    - name: Change to non-bootstrap
      community.docker.docker_container:
        name: 'mariadb'
        image: 'mariadb:10.5.11'
        restart_policy: always
        network_mode: host
        env:
          MARIADB_ROOT_PASSWORD: '{{ galera_root_password }}'
        log_driver: journald
        command: "{{ '--wsrep-new-cluster' if galera_bootstrap else omit }}"
        container_default_behavior: compatibility
        comparisons:
          'command': strict
      vars:
        galera_bootstrap: false

The example is a bit more complicated than it needs to be. You can just as well use command: "--wsrep-new-cluster" on the first task and omit this parameter on the second task completely.

Not matter what I try, this module never changes the container when executing the second task.

EXPECTED RESULTS

Recreated container with custom command removed.

ACTUAL RESULTS

Second tasks return with "changed": false.

@felixfontein
Copy link
Collaborator

That's per design. Parameters which are not specified are not used for idempotency checks.

If you want to force re-creation, pass recreate: true. You can also try to pass an empty list (command: []) and see whether that works.

@felixfontein felixfontein added the docker-plain plain Docker (no swarm, no compose, no stack) label Jun 28, 2021
@ChristianCiach
Copy link
Author

ChristianCiach commented Jun 28, 2021

recreate: true is what I am using, but I only thought of it as a workaround.

Well, that's at least unexpected, but if you say that's by design, then so be it.

command: "" or command: [] don't seem to make a difference.

@felixfontein
Copy link
Collaborator

resolved_by_pr #186

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docker-plain plain Docker (no swarm, no compose, no stack)
Projects
None yet
2 participants