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.

57 lines
1.9 KiB

  1. ---
  2. - name: Create image directory
  3. file:
  4. state: directory
  5. path: "{{ images_dir }}"
  6. mode: 0755
  7. - name: Download images files
  8. get_url:
  9. url: "{{ item.value.url }}"
  10. dest: "{{ images_dir }}/{{ item.value.filename }}"
  11. checksum: "{{ item.value.checksum }}"
  12. loop: "{{ images|dict2items }}"
  13. - name: Unxz compressed images
  14. command: unxz --force {{ images_dir }}/{{ item.value.filename }}
  15. loop: "{{ images|dict2items }}"
  16. when:
  17. - item.value.filename.endswith('.xz')
  18. - name: Convert images which is not in qcow2 format
  19. command: qemu-img convert -O qcow2 {{ images_dir }}/{{ item.value.filename.rstrip('.xz') }} {{ images_dir }}/{{ item.key }}.qcow2
  20. loop: "{{ images|dict2items }}"
  21. when:
  22. - not (item.value.converted|bool)
  23. - name: Make sure all images are ending with qcow2
  24. command: cp {{ images_dir }}/{{ item.value.filename.rstrip('.xz') }} {{ images_dir }}/{{ item.key }}.qcow2
  25. loop: "{{ images|dict2items }}"
  26. when:
  27. - item.value.converted|bool
  28. - name: Resize images # noqa 301
  29. command: qemu-img resize {{ images_dir }}/{{ item.key }}.qcow2 +8G
  30. loop: "{{ images|dict2items }}"
  31. # STEP 2: Include the images inside a container
  32. - name: Template default Dockerfile
  33. template:
  34. src: Dockerfile
  35. dest: "{{ images_dir }}/Dockerfile"
  36. mode: 0644
  37. - name: Create docker images for each OS # noqa 301
  38. command: docker build -t {{ registry }}/vm-{{ item.key }}:{{ item.value.tag }} --build-arg cloud_image="{{ item.key }}.qcow2" {{ images_dir }}
  39. loop: "{{ images|dict2items }}"
  40. - name: docker login # noqa 301
  41. command: docker login -u="{{ docker_user }}" -p="{{ docker_password }}" "{{ docker_host }}"
  42. - name: docker push image # noqa 301
  43. command: docker push {{ registry }}/vm-{{ item.key }}:{{ item.value.tag }}
  44. loop: "{{ images|dict2items }}"
  45. - name: docker logout # noqa 301
  46. command: docker logout -u="{{ docker_user }}" "{{ docker_host }}"