Question on force_source in community.docker.docker_image

97 views
Skip to first unread message

Rafal Skolasinski

unread,
Jul 5, 2021, 5:17:39 AM7/5/21
to Ansible Project
Hi, 

I have a question on how the `force_source` works in `community.docker.docker_image` in case of pulling docker image. 

Assuming that I already have a `my-awesome-stuff/my-image:my-tag` locally and run ansible playbook with task

```yaml
- name: "Pull docker image"
  community.docker.docker_image:
    name: "my-awesome-stuff/my-image:my-tag"
    state: present
    source: pull
    force_source: yes
```

which of the following will happen:

a) - ansible sees that image is present but calls `docker pull` logic anyway
    - docker pull realises that image is the same so no download happens

b) ansible notices `foruce_source` flag so download happens even if not required 




The context I am interested in is if in the hub there is some tag that is rolling, `-dev` for example, and I want to insure that if the image will be updated in the hub then new version would be pulled but at the same time avoid unnecessary pulls. 

Bonus question: how does the behaviour changes if the tag is `latest`? 

Felix Fontein

unread,
Jul 5, 2021, 6:31:04 AM7/5/21
to ansible...@googlegroups.com
Hi,

> I have a question on how the `force_source` works in
> `community.docker.docker_image` in case of pulling docker image.
>
> Assuming that I already have a `my-awesome-stuff/my-image:my-tag`
> locally and run ansible playbook with task
>
> ```yaml
> - name: "Pull docker image"
> community.docker.docker_image:
> name: "my-awesome-stuff/my-image:my-tag"
> state: present
> source: pull
> force_source: yes
> ```
>
> which of the following will happen:
>
> a) - ansible sees that image is present but calls `docker pull` logic
> anyway
> - docker pull realises that image is the same so no download
> happens
>
> b) ansible notices `foruce_source` flag so download happens even if
> not required

a) will happen. Then Ansible will process the `docker pull` log and
notice that nothing was pulled, and will return changed=False.

> Bonus question: how does the behaviour changes if the tag is
> `latest`?

The behavior does not depend on the tag's name.

Cheers,
Felix


Rafal Skolasinski

unread,
Jul 5, 2021, 6:36:23 AM7/5/21
to Ansible Project
Thank you Felix, exactly what I needed!
Reply all
Reply to author
Forward
0 new messages