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.

29 lines
1.2 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. check_mode: no
  14. when: not download_always_pull|bool
  15. - set_fact: docker_images="{{docker_images_raw.stdout|regex_replace('\[|\]|\\n]','')|regex_replace('\s',',')}}"
  16. when: not download_always_pull|bool
  17. - set_fact:
  18. pull_required: >-
  19. {%- if pull_args in docker_images.split(',') %}false{%- else -%}true{%- endif -%}
  20. when: not download_always_pull|bool
  21. - name: Check the local digest sha256 corresponds to the given image tag
  22. assert:
  23. that: "{{download.repo}}:{{download.tag}} in docker_images.split(',')"
  24. when: not download_always_pull|bool and not pull_required|bool and pull_by_digest|bool