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.

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