2019-01-03 22:34:37 +08:00
|
|
|
---
|
|
|
|
|
|
|
|
- name: Create image directory
|
|
|
|
file:
|
|
|
|
state: directory
|
2019-04-25 04:34:46 +08:00
|
|
|
path: "{{ images_dir }}"
|
2024-07-26 09:42:20 +08:00
|
|
|
mode: "0755"
|
2019-01-03 22:34:37 +08:00
|
|
|
|
|
|
|
- name: Download images files
|
|
|
|
get_url:
|
|
|
|
url: "{{ item.value.url }}"
|
|
|
|
dest: "{{ images_dir }}/{{ item.value.filename }}"
|
|
|
|
checksum: "{{ item.value.checksum }}"
|
2024-07-26 09:42:20 +08:00
|
|
|
mode: "0644"
|
2023-07-05 11:36:54 +08:00
|
|
|
loop: "{{ images | dict2items }}"
|
2019-01-03 22:34:37 +08:00
|
|
|
|
2020-07-10 16:07:48 +08:00
|
|
|
- name: Unxz compressed images
|
|
|
|
command: unxz --force {{ images_dir }}/{{ item.value.filename }}
|
2023-07-05 11:36:54 +08:00
|
|
|
loop: "{{ images | dict2items }}"
|
2020-07-10 16:07:48 +08:00
|
|
|
when:
|
|
|
|
- item.value.filename.endswith('.xz')
|
|
|
|
|
2019-01-03 22:34:37 +08:00
|
|
|
- name: Convert images which is not in qcow2 format
|
2020-07-10 16:07:48 +08:00
|
|
|
command: qemu-img convert -O qcow2 {{ images_dir }}/{{ item.value.filename.rstrip('.xz') }} {{ images_dir }}/{{ item.key }}.qcow2
|
2023-07-05 11:36:54 +08:00
|
|
|
loop: "{{ images | dict2items }}"
|
2019-01-03 22:34:37 +08:00
|
|
|
when:
|
2023-07-05 11:36:54 +08:00
|
|
|
- not (item.value.converted | bool)
|
2019-01-03 22:34:37 +08:00
|
|
|
|
|
|
|
- name: Make sure all images are ending with qcow2
|
2020-07-10 16:07:48 +08:00
|
|
|
command: cp {{ images_dir }}/{{ item.value.filename.rstrip('.xz') }} {{ images_dir }}/{{ item.key }}.qcow2
|
2023-07-05 11:36:54 +08:00
|
|
|
loop: "{{ images | dict2items }}"
|
2019-01-03 22:34:37 +08:00
|
|
|
when:
|
2023-07-05 11:36:54 +08:00
|
|
|
- item.value.converted | bool
|
2019-01-03 22:34:37 +08:00
|
|
|
|
2023-06-30 17:51:57 +08:00
|
|
|
- name: Resize images
|
2019-01-03 22:34:37 +08:00
|
|
|
command: qemu-img resize {{ images_dir }}/{{ item.key }}.qcow2 +8G
|
2023-07-05 11:36:54 +08:00
|
|
|
loop: "{{ images | dict2items }}"
|
2019-01-03 22:34:37 +08:00
|
|
|
|
|
|
|
# STEP 2: Include the images inside a container
|
|
|
|
- name: Template default Dockerfile
|
|
|
|
template:
|
|
|
|
src: Dockerfile
|
|
|
|
dest: "{{ images_dir }}/Dockerfile"
|
2024-07-26 09:42:20 +08:00
|
|
|
mode: "0644"
|
2019-01-03 22:34:37 +08:00
|
|
|
|
2023-06-30 17:51:57 +08:00
|
|
|
- name: Create docker images for each OS
|
2020-10-21 19:08:20 +08:00
|
|
|
command: docker build -t {{ registry }}/vm-{{ item.key }}:{{ item.value.tag }} --build-arg cloud_image="{{ item.key }}.qcow2" {{ images_dir }}
|
2023-07-05 11:36:54 +08:00
|
|
|
loop: "{{ images | dict2items }}"
|
2019-01-03 22:34:37 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Docker login
|
2019-01-03 22:34:37 +08:00
|
|
|
command: docker login -u="{{ docker_user }}" -p="{{ docker_password }}" "{{ docker_host }}"
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Docker push image
|
2020-10-21 19:08:20 +08:00
|
|
|
command: docker push {{ registry }}/vm-{{ item.key }}:{{ item.value.tag }}
|
2023-07-05 11:36:54 +08:00
|
|
|
loop: "{{ images | dict2items }}"
|
2020-10-21 19:08:20 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Docker logout
|
2020-10-21 19:08:20 +08:00
|
|
|
command: docker logout -u="{{ docker_user }}" "{{ docker_host }}"
|