96 lines
2.5 KiB
YAML
96 lines
2.5 KiB
YAML
---
|
|
- name: Ensure QEMU, KVM and dependencies are installed
|
|
ansible.builtin.apt:
|
|
name:
|
|
- qemu-system-x86
|
|
- qemu-utils
|
|
- libvirt-daemon-system
|
|
- libvirt-clients
|
|
- bridge-utils
|
|
- virtinst
|
|
- virt-manager
|
|
- cpu-checker
|
|
- unzip
|
|
- curl
|
|
state: present
|
|
become: true
|
|
|
|
- name: Download Packer
|
|
ansible.builtin.get_url:
|
|
url: "https://releases.hashicorp.com/packer/{{ packer_version }}/packer_{{ packer_version }}_linux_amd64.zip"
|
|
dest: "/tmp/packer.zip"
|
|
mode: '0644'
|
|
|
|
- name: Unarchive Packer
|
|
ansible.builtin.unarchive:
|
|
src: /tmp/packer.zip
|
|
dest: /usr/local/bin/
|
|
remote_src: yes
|
|
become: true
|
|
|
|
- name: Ensure packer is executable
|
|
ansible.builtin.file:
|
|
path: /usr/local/bin/packer
|
|
mode: '0755'
|
|
owner: root
|
|
group: root
|
|
become: true
|
|
|
|
- name: Create output directory for Packer images
|
|
ansible.builtin.file:
|
|
path: "{{ image_output_dir }}"
|
|
state: directory
|
|
mode: '0755'
|
|
become: true
|
|
|
|
- name: Create HTTP directory inside output dir for preseed.cfg
|
|
ansible.builtin.file:
|
|
path: "{{ image_output_dir }}/http"
|
|
state: directory
|
|
mode: '0755'
|
|
become: true
|
|
|
|
- name: Copy preseed.cfg template to HTTP directory
|
|
ansible.builtin.template:
|
|
src: preseed.cfg.j2
|
|
dest: "{{ image_output_dir }}/http/preseed.cfg"
|
|
mode: '0644'
|
|
|
|
- name: Download Debian ISO checksums
|
|
ansible.builtin.get_url:
|
|
url: "{{ debian_iso_checksum_url }}"
|
|
dest: /tmp/debian_sha256sums.txt
|
|
mode: '0644'
|
|
|
|
- name: Extract checksum for ISO
|
|
ansible.builtin.shell: |
|
|
grep "{{ debian_iso_filename }}" /tmp/debian_sha256sums.txt | awk '{ print $1 }'
|
|
register: debian_iso_checksum_result
|
|
changed_when: false
|
|
|
|
- name: Set fact with full checksum string
|
|
ansible.builtin.set_fact:
|
|
debian_iso_checksum: "sha256:{{ debian_iso_checksum_result.stdout }}"
|
|
|
|
- name: Template Packer HCL config
|
|
ansible.builtin.template:
|
|
src: debian_minimal.pkr.hcl.j2
|
|
dest: "{{ image_output_dir }}/debian_minimal.pkr.hcl"
|
|
|
|
- name: Run `packer init`
|
|
ansible.builtin.command: packer init debian_minimal.pkr.hcl
|
|
args:
|
|
chdir: "{{ image_output_dir }}"
|
|
|
|
- name: Run `packer build`
|
|
ansible.builtin.command: >
|
|
sh -c 'PACKER_LOG=1 PACKER_LOG_PATH=/tmp/packer.log packer build debian_minimal.pkr.hcl'
|
|
args:
|
|
chdir: "{{ image_output_dir }}"
|
|
|
|
- name: Copy built image to role files directory
|
|
ansible.builtin.copy:
|
|
src: "{{ image_output_dir }}/debian-minimal/debian-minimal.qcow2"
|
|
dest: "{{ role_path }}/files/debian-minimal.qcow2"
|
|
remote_src: yes
|
|
become: true
|