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

docker_image misbehaves in check_mode when using force_source and pull #283

Open
jcgruenhage opened this issue Jan 13, 2022 · 2 comments
Open
Labels
docker-plain plain Docker (no swarm, no compose, no stack) enhancement New feature or request

Comments

@jcgruenhage
Copy link

SUMMARY

In check mode, docker_image always says the image is changed when using force_source and source: pull, even when that's not actually the case.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

docker_image

Further description instead of system, collection and ansible version details

I allowed myself to not post all those details, because I read your module code and it's fairly obvious how this issue comes to be:

It's not quite trivial to solve this I'm afraid, as fetching the hash of the image on the registry is not implemented here afaict. Any opinions on this?

For context how/why we need this: We have a role that deploys a containerized service, and in the playbook for the test infrastructure, we want to drop a database before running the role if the container image has changed. As the role depends on the result of pulling the container image, we have to run the task in the playbook in check mode and have to do the actual pull inside the role.

STEPS TO REPRODUCE
- hosts: localhost
  become: yes
  tasks:
    - name: Check if new image would be pulled
      docker_image:
        name: "docker.io/nginx"
        source: pull
        state: present
        force_source: true
      register: image_pulled
      until: image_pulled is success
      retries: 10
      delay: 5
      check_mode: true
    - name: some tasks to do before pulling and starting a new container image
      debug:
        msg: "Hello"
      when: image_pulled.changed
    - name: Pull new image
      docker_image:
        name: "docker.io/nginx"
        source: pull
        state: present
        force_source: true
      register: image_pulled
      until: image_pulled is success
      retries: 10
      delay: 5
EXPECTED RESULTS
PLAY [localhost] ******************************************************************************************************************************************************************************

TASK [Gathering Facts] ************************************************************************************************************************************************************************
ok: [localhost]

TASK [Check if new image would be pulled] *****************************************************************************************************************************************************
ok: [localhost]

TASK [some tasks to do before pulling and starting a new container image] *********************************************************************************************************************
skipping: [localhost]

TASK [Pull new image] *************************************************************************************************************************************************************************
ok: [localhost]

PLAY RECAP ************************************************************************************************************************************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   
ACTUAL RESULTS
PLAY [localhost] ******************************************************************************************************************************************************************************

TASK [Gathering Facts] ************************************************************************************************************************************************************************
ok: [localhost]

TASK [Check if new image would be pulled] *****************************************************************************************************************************************************
changed: [localhost]

TASK [some tasks to do before pulling and starting a new container image] *********************************************************************************************************************
ok: [localhost] => {
    "msg": "Hello"
}

TASK [Pull new image] *************************************************************************************************************************************************************************
ok: [localhost]

PLAY RECAP ************************************************************************************************************************************************************************************
localhost                  : ok=4    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
@felixfontein
Copy link
Collaborator

This is expected behavior of the module (albeit undocumented), since - as you noticed - it is not possible to implement this without re-implementing parts of the Docker daemon in the module. And even if someone would do that, it won't cover every case since the Docker daemon can run on a random other machine, and the registry might not even be reachable directly from the machine this module runs on.

@felixfontein felixfontein added the enhancement New feature or request label Jan 13, 2022
@jcgruenhage
Copy link
Author

If the docker daemon does not provide a way to gather this information, then that's very unfortunate. Maybe expanding the API in that direction would make sense instead?

I've just looked for alternatives, and it seems like the podman_image behaves similarly. skopeo does support working with remote images, but there's no ansible modules available for working directly with skopeo. We'll see how we'll solve this instead :/

@felixfontein felixfontein added the docker-plain plain Docker (no swarm, no compose, no stack) label Jan 16, 2022
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) enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants