publish_image.yml 1.5 KB

1234567891011121314151617181920212223242526272829303132
  1. ---
  2. - name: Require openshift_gcp_image
  3. fail:
  4. msg: "A source image name or family is required for image publishing. Please ensure `openshift_gcp_image` is defined."
  5. when: openshift_gcp_image is undefined
  6. - name: Require openshift_gcp_target_image
  7. fail:
  8. msg: "A target image name or family is required for image publishing. Please ensure `openshift_gcp_target_image` is defined."
  9. when: openshift_gcp_target_image is undefined
  10. - block:
  11. - name: Retrieve images in the {{ openshift_gcp_target_image }} family
  12. command: >
  13. gcloud --project "{{ openshift_gcp_project }}" compute images list
  14. "--filter=family={{ openshift_gcp_target_image }}"
  15. --format=json --sort-by ~creationTimestamp
  16. register: images
  17. - name: Prune oldest images
  18. command: >
  19. gcloud --project "{{ openshift_gcp_project }}" compute images delete "{{ item['name'] }}"
  20. with_items: "{{ (images.stdout | default('[]') | from_json )[( openshift_gcp_keep_images | int ):] }}"
  21. when: openshift_gcp_keep_images is defined
  22. - name: Copy the latest image in the family {{ openshift_gcp_image }} to {{ openshift_gcp_target_image }}
  23. command: >
  24. gcloud --project "{{ openshift_gcp_target_project | default(openshift_gcp_project) }}"
  25. beta compute images create
  26. "{{ openshift_gcp_target_image_name | default(openshift_gcp_target_image + '-' + lookup('pipe','date +%Y%m%d-%H%M%S')) }}"
  27. --family "{{ openshift_gcp_target_image }}"
  28. --source-image-family "{{ openshift_gcp_image }}"
  29. --source-image-project "{{ openshift_gcp_project }}"