From what I understand, the docker_image Ansible module pushes an image to a registry only if the image is not already present inside the registry with the same tag. In my context, I'm trying to do a very simple workflow that pushes/pulls an image and I don't care about overwriting the image (for now).
However, I'm not sure it is possible to force the push action with this module. If it is not possible, I'm opened to suggestions.
Context
I'm trying to replace a workflow that does the following actions on every run:
Archive the image into a tar file
Transfer the tar file to a distant machine
Load the image from the tar file
I'd like to replace it with a workflow that does the following actions
Push the image to a private ghcr.io registry
Pull the image from the private ghcr.io registry on the distant machine
I have started to implement the below Ansible steps:
- name: Log into GitHub Container Registry (ghcr.io)
tags: [docker-registry]
community.docker.docker_login:
registry_url: ghcr.io
username: "{{ ghcr_username }}"
password: "{{ ghcr_password }}"
- name: Push images to registry
tags: [docker-registry]
community.docker.docker_image:
name: "my-image"
repository: "ghcr.io/my-/my-repo/my-image:latest"
push: True
source: local
From what I understand, the docker_image Ansible module pushes an image to a registry only if the image is not already present inside the registry with the same tag. In my context, I'm trying to do a very simple workflow that pushes/pulls an image and I don't care about overwriting the image (for now).
However, I'm not sure it is possible to force the push action with this module. If it is not possible, I'm opened to suggestions.
Context
I'm trying to replace a workflow that does the following actions on every run:
Archive the image into a tar file
Transfer the tar file to a distant machine
Load the image from the tar file
I'd like to replace it with a workflow that does the following actions
Push the image to a private ghcr.io registry
Pull the image from the private ghcr.io registry on the distant machine
I have started to implement the below Ansible steps:
- name: Log into GitHub Container Registry (ghcr.io)
tags: [docker-registry]
community.docker.docker_login:
registry_url: ghcr.io
username: "{{ ghcr_username }}"
password: "{{ ghcr_password }}"
- name: Push images to registry
tags: [docker-registry]
community.docker.docker_image:
name: "my-image"
repository: "ghcr.io/my-/my-repo/my-image:latest"
push: True
source: local
Share
Improve this question
edited Feb 2 at 7:37
Zeitounator
44.8k7 gold badges63 silver badges76 bronze badges
asked Jan 30 at 10:21
oursours
371 silver badge9 bronze badges
4
|
1 Answer
Reset to default 1In the docs page you linked they give an example of how to do this using the tag latest as an example https://docs.ansible/ansible/latest/collections/community/docker/docker_image_module.html#ansible-collections-community-docker-docker-image-module
force_tag - Use with state=present to force tagging an image.
- name: Add tag latest to image
community.docker.docker_image:
name: myimage:7.1.2
repository: myimage:latest
# As 'latest' usually already is present, we need to enable overwriting of existing tags:
force_tag: true
source: local
docker push
's usual behavior is to unconditionally push the image, with no option to check first. Are you suredocker_image
(ordocker_image_push
) does a similar check? I don't see it mentioned in its documentation page. – David Maze Commented Jan 30 at 10:59force_tag
? – Zeitounator Commented Jan 30 at 18:47