ceph-ansible/roles/ceph-docker-common/tasks/fetch_image.yml

73 lines
3.0 KiB
YAML

---
# NOTE(leseb): using failed_when to handle the case when the image is not present yet
- name: "inspecting {{ ceph_docker_registry}}/{{ ceph_docker_image }}:{{ ceph_docker_image_tag }} image before pulling"
command: "docker inspect {{ ceph_docker_registry}}/{{ ceph_docker_image }}:{{ ceph_docker_image_tag }}"
changed_when: false
failed_when: false
register: container_inspect_before_pull
- name: set_fact repodigest_before_pulling
set_fact:
repodigest_before_pulling: "{{ (container_inspect_before_pull.stdout | from_json)[0].RepoDigests[0] }}"
when:
- container_inspect_before_pull.rc == 0
- name: "pulling {{ ceph_docker_registry}}/{{ ceph_docker_image }}:{{ ceph_docker_image_tag }} image"
command: "timeout {{ docker_pull_timeout }} docker pull {{ ceph_docker_registry}}/{{ ceph_docker_image }}:{{ ceph_docker_image_tag }}"
changed_when: false
register: docker_image
until: docker_image.rc == 0
retries: "{{ docker_pull_retry }}"
delay: 10
when:
- (ceph_docker_dev_image is undefined or not ceph_docker_dev_image)
- name: "inspecting {{ ceph_docker_registry}}/{{ ceph_docker_image }}:{{ ceph_docker_image_tag }} image after pulling"
command: "docker inspect {{ ceph_docker_registry}}/{{ ceph_docker_image }}:{{ ceph_docker_image_tag }}"
failed_when: false
register: container_inspect_after_pull
- name: set_fact repodigest_after_pulling
set_fact:
repodigest_after_pulling: "{{ (container_inspect_after_pull.stdout | from_json)[0].RepoDigests[0] }}"
when:
- container_inspect_after_pull.rc == 0
- name: set_fact is_image_updated
set_fact:
is_image_updated: "{{ repodigest_before_pulling == repodigest_after_pulling }}"
changed_when: true
notify:
- restart ceph mons
- restart ceph osds
- restart ceph mdss
- restart ceph rgws
- restart ceph mgrs
- restart ceph rbdmirrors
when:
- container_inspect_before_pull.rc == 0
- repodigest_before_pulling == repodigest_after_pulling
- name: export local ceph dev image
local_action: command docker save -o "/tmp/{{ ceph_docker_username }}-{{ ceph_docker_imagename }}-{{ ceph_docker_image_tag }}.tar" "{{ ceph_docker_username }}/{{ ceph_docker_imagename }}:{{ ceph_docker_image_tag }}"
when:
- (ceph_docker_dev_image is defined and ceph_docker_dev_image)
run_once: true
- name: copy ceph dev image file
copy:
src: "/tmp/{{ ceph_docker_username }}-{{ ceph_docker_imagename }}-{{ ceph_docker_image_tag }}.tar"
dest: "/tmp/{{ ceph_docker_username }}-{{ ceph_docker_imagename }}-{{ ceph_docker_image_tag }}.tar"
when:
- (ceph_docker_dev_image is defined and ceph_docker_dev_image)
- name: load ceph dev image
command: "docker load -i /tmp/{{ ceph_docker_username }}-{{ ceph_docker_imagename }}-{{ ceph_docker_image_tag }}.tar"
when:
- (ceph_docker_dev_image is defined and ceph_docker_dev_image)
- name: remove tmp ceph dev image file
command: "rm /tmp/{{ ceph_docker_username }}-{{ ceph_docker_imagename }}-{{ ceph_docker_image_tag }}.tar"
when:
- (ceph_docker_dev_image is defined and ceph_docker_dev_image)