Last active
September 26, 2023 09:35
-
-
Save x86-39/3addc2564f2867da785f573648f47679 to your computer and use it in GitHub Desktop.
Build VyOS image with modern Ansible.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
### | |
# This play builds a VyOS qcow2 image | |
### | |
- name: Set up vyos-vm-images repo | |
hosts: localhost | |
tags: vyos, prepare-build, build | |
gather_facts: false | |
tasks: | |
- name: Clone vyos-vm-images repo | |
ansible.builtin.git: | |
repo: https://github.com/vyos/vyos-vm-images.git | |
dest: /tmp/vyos-vm-images | |
version: current | |
force: true | |
- name: Copy patch file # noqa: yaml[trailing-spaces] | |
ansible.builtin.copy: # noqa: yaml[trailing-spaces] | |
dest: /tmp/vyos-vm-images/fix-build-qcow2.patch | |
mode: "0644" | |
content: | | |
diff --git a/roles/install-grub/tasks/main.yml b/roles/install-grub/tasks/main.yml | |
index 75de819..575dfbf 100644 | |
--- a/roles/install-grub/tasks/main.yml | |
+++ b/roles/install-grub/tasks/main.yml | |
@@ -15,8 +15,6 @@ | |
mount --bind /proc {{ '{{' }} vyos_install_root }}/proc && | |
mount --bind /sys {{ '{{' }} vyos_install_root }}/sys && | |
mount --bind {{ '{{' }} vyos_write_root }} {{ '{{' }} vyos_install_root }}/boot | |
- args: | |
- warn: no | |
- name: Create efi directory | |
become: true | |
- name: Ensure templates directory exists | |
ansible.builtin.file: | |
path: /tmp/vyos-vm-images/{{ item }}/templates | |
state: directory | |
mode: "0755" | |
loop: | |
- roles/install-cloud-init | |
- roles/install-custom-packages | |
- roles/install-guest-agent | |
- name: Copy debian.list.j2 | |
ansible.builtin.copy: | |
src: /tmp/vyos-vm-images/templates/debian.list.j2 | |
dest: /tmp/vyos-vm-images/{{ item }}/templates/debian.list.j2 | |
mode: "0644" | |
loop: | |
- roles/install-cloud-init | |
- roles/install-custom-packages | |
- roles/install-guest-agent | |
- name: Apply patch # noqa: command-instead-of-module | |
ansible.builtin.shell: | | |
git apply fix-build-qcow2.patch | |
args: | |
chdir: /tmp/vyos-vm-images | |
register: patch_result | |
changed_when: patch_result.stdout == "" | |
# failed_when: false # Don't fail if patch is already applied | |
- name: Build VyOS image | |
hosts: localhost | |
gather_facts: false | |
tags: vyos, create-image, build | |
become: true | |
connection: local | |
# ansible.builtin.import_playbook: /tmp/vyos-vm-images/qemu.yml | |
tasks: | |
- name: Build tasks | |
block: | |
- name: Include role | |
ansible.builtin.include_role: | |
name: "{{ role_var }}" | |
loop: "{{ vyos_build_roles }}" | |
loop_control: | |
loop_var: role_var | |
rescue: | |
- name: Print error | |
ansible.builtin.debug: | |
msg: "Build failed" | |
- name: Safely exit | |
ansible.builtin.include_role: | |
name: '{{ role_var }}' | |
loop: "{{ vyos_rescue_roles }}" | |
loop_control: | |
loop_var: role_var | |
vars: | |
vyos_platform: QEMU | |
vyos_format: qcow2 | |
vyos_qemu_img: /tmp/vyos_qemu_image.qcow2 | |
vyos_output_img: "{{ vyos_qemu_img }}" | |
# vyos_iso_url: https://s3.amazonaws.com/s3-us.vyos.io/rolling/current/vyos-rolling-latest.iso | |
vyos_iso_url: "https://github.com/vyos/vyos-rolling-nightly-builds/releases/download/1.5-rolling-202309250022/vyos-1.5-rolling-202309250022-amd64.iso" | |
vyos_iso_local: "{{ iso_local | default('/tmp/vyos.iso') }}" | |
vyos_key_url: https://downloads.vyos.io/vyos-release.gpg | |
vyos_key_local: /tmp/vyos-release.gpg | |
vyos_version: "1.5.0" | |
vyos_cd_root: /mnt/cdrom | |
vyos_cd_squash_root: /mnt/cdsquash | |
vyos_squashfs_image: "{{ vyos_cd_root }}/live/filesystem.squashfs" | |
vyos_write_root: /mnt/wroot | |
vyos_read_root: /mnt/squashfs | |
vyos_install_root: /mnt/inst_root | |
vyos_disk_size: "{{ disk_size | default(10) }}" | |
vyos_parttable_type: "{{ parttable_type | default('hybrid') }}" | |
vyos_root_fstype: ext4 | |
vyos_target_drive: "" | |
vyos_raw_img: /tmp/vyos_raw_image.img | |
grub_console: "kvm" | |
cloud_init: "true" # Needs to be a string! Fuck these devs | |
cloud_init_ds: NoCloud | |
cloud_init_ds_string: "{{ cloud_init_ds | default('NoCloud,ConfigDrive,None') }}" | |
cloud_init_ds_list: "{{ cloud_init_ds_string.split(',') }}" | |
vyos_build_roles: | |
- /tmp/vyos-vm-images/roles/install-packages | |
- /tmp/vyos-vm-images/roles/download-iso | |
- /tmp/vyos-vm-images/roles/mount-iso | |
- /tmp/vyos-vm-images/roles/get-version | |
- /tmp/vyos-vm-images/roles/create-disk | |
- /tmp/vyos-vm-images/roles/setup-root-partition | |
- /tmp/vyos-vm-images/roles/install-image | |
- /tmp/vyos-vm-images/roles/mount-root-fs | |
- /tmp/vyos-vm-images/roles/install-config | |
- /tmp/vyos-vm-images/roles/install-grub | |
- /tmp/vyos-vm-images/roles/install-persistence-conf | |
- /tmp/vyos-vm-images/roles/install-cloud-init | |
- /tmp/vyos-vm-images/roles/install-guest-agent-wrapper | |
- /tmp/vyos-vm-images/roles/install-custom-packages-wrapper | |
- /tmp/vyos-vm-images/roles/fstrim | |
- /tmp/vyos-vm-images/roles/unmount-pre | |
- /tmp/vyos-vm-images/roles/create-pxe-archive | |
- /tmp/vyos-vm-images/roles/unmount-all | |
- /tmp/vyos-vm-images/roles/qemu-qcow2 | |
- /tmp/vyos-vm-images/roles/cleanup-ending | |
- /tmp/vyos-vm-images/roles/release | |
vyos_rescue_roles: | |
- /tmp/vyos-vm-images/roles/unmount-pre | |
- /tmp/vyos-vm-images/roles/unmount-all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment