You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
1.1 KiB

  1. ---
  2. - set_fact:
  3. pull_by_digest: >-
  4. {%- if download.sha256 is defined and download.sha256 != '' -%}true{%- else -%}false{%- endif -%}
  5. - set_fact:
  6. pull_args: >-
  7. {%- if pull_by_digest|bool %}{{download.repo}}@sha256:{{download.sha256}}{%- else -%}{{download.repo}}:{{download.tag}}{%- endif -%}
  8. - name: Register docker images info
  9. raw: >-
  10. {{ docker_bin_dir }}/docker images -q | xargs {{ docker_bin_dir }}/docker inspect -f "{{ '{{' }} .RepoTags {{ '}}' }},{{ '{{' }} .RepoDigests {{ '}}' }}"
  11. register: docker_images_raw
  12. failed_when: false
  13. when: not download_always_pull|bool
  14. - set_fact: docker_images="{{docker_images_raw.stdout|regex_replace('\[|\]|\\n]','')|regex_replace('\s',',')}}"
  15. when: not download_always_pull|bool
  16. - set_fact:
  17. pull_required: >-
  18. {%- if pull_args in docker_images.split(',') %}false{%- else -%}true{%- endif -%}
  19. when: not download_always_pull|bool
  20. - name: Check the local digest sha256 corresponds to the given image tag
  21. assert:
  22. that: "{{download.repo}}:{{download.tag}} in docker_images.split(',')"
  23. when: not download_always_pull|bool and not pull_required|bool and pull_by_digest|bool