From c3cd4a20671b5a1313b5eb8e534fd8d1cf67db9f Mon Sep 17 00:00:00 2001 From: zsdc Date: Thu, 18 Mar 2021 17:51:00 +0200 Subject: Multiple build improvements - Removed `empty_config` option. The config should be now always empty because Cloud-init adds required parts dynamically at the first boot. - Added ability to include any additional packages to the image, from list or deb files. - Moved common resources for multiple tasks from tasks folder to `files` and `templates` on the root folder. - Make `trim` actually works. Before this, it actually was a no-op, because RAW image mounted without the `discard` option cannot be trimmed. This significantly reduced the size of images with any additional packages inside, for example with Cloud-init. - Fixed APT repository paths, according to the new structure of `dev.packages.vyos.net`. - Added proper build repository for VyOS 1.3. It used the wrong `current` repo when should be `equuleus` now. - Removed unused `boot/grub/device.map.j2` template. - Deleted a secondary console option from the `grub.cfg.j2` template. According to testing an active console is only the latest listed, so it seems that there is no sense to keep there two items. --- roles/fstrim/tasks/main.yml | 4 -- roles/install-cloud-init/files/debian.list.buster | 7 --- roles/install-cloud-init/files/debian.list.jessie | 8 --- roles/install-cloud-init/files/resolv.conf | 1 - roles/install-cloud-init/tasks/main.yml | 12 ++--- roles/install-config/templates/config.boot.j2 | 14 +---- .../install-custom-packages-wrapper/tasks/main.yml | 4 ++ .../tests/inventory | 2 + .../install-custom-packages-wrapper/tests/test.yml | 4 ++ roles/install-custom-packages/tasks/main.yml | 60 ++++++++++++++++++++++ roles/install-custom-packages/tests/inventory | 2 + roles/install-custom-packages/tests/test.yml | 4 ++ .../install-grub/templates/boot/grub/device.map.j2 | 1 - roles/install-grub/templates/boot/grub/grub.cfg.j2 | 8 +-- roles/install-guest-agent/files/debian.list.buster | 4 -- roles/install-guest-agent/files/debian.list.jessie | 5 -- roles/install-guest-agent/files/resolv.conf | 1 - roles/install-guest-agent/tasks/main.yml | 8 ++- roles/setup-root-partition/tasks/main.yml | 1 + 19 files changed, 95 insertions(+), 55 deletions(-) delete mode 100644 roles/install-cloud-init/files/debian.list.buster delete mode 100644 roles/install-cloud-init/files/debian.list.jessie delete mode 100644 roles/install-cloud-init/files/resolv.conf create mode 100644 roles/install-custom-packages-wrapper/tasks/main.yml create mode 100644 roles/install-custom-packages-wrapper/tests/inventory create mode 100644 roles/install-custom-packages-wrapper/tests/test.yml create mode 100644 roles/install-custom-packages/tasks/main.yml create mode 100644 roles/install-custom-packages/tests/inventory create mode 100644 roles/install-custom-packages/tests/test.yml delete mode 100644 roles/install-grub/templates/boot/grub/device.map.j2 delete mode 100644 roles/install-guest-agent/files/debian.list.buster delete mode 100644 roles/install-guest-agent/files/debian.list.jessie delete mode 100644 roles/install-guest-agent/files/resolv.conf (limited to 'roles') diff --git a/roles/fstrim/tasks/main.yml b/roles/fstrim/tasks/main.yml index e7230a7..c0b9b19 100644 --- a/roles/fstrim/tasks/main.yml +++ b/roles/fstrim/tasks/main.yml @@ -1,8 +1,4 @@ # Trim filesystems to minimize resulted image -- name: Trim {{ vyos_install_root }}/boot - become: true - command: fstrim {{ vyos_install_root }}/boot - - name: Trim {{ vyos_write_root }} become: true command: fstrim {{ vyos_write_root }} diff --git a/roles/install-cloud-init/files/debian.list.buster b/roles/install-cloud-init/files/debian.list.buster deleted file mode 100644 index fd5a770..0000000 --- a/roles/install-cloud-init/files/debian.list.buster +++ /dev/null @@ -1,7 +0,0 @@ -deb http://deb.debian.org/debian buster main contrib non-free -deb-src http://deb.debian.org/debian buster main contrib non-free -deb http://security.debian.org/debian-security/ buster/updates main contrib non-free -deb-src http://security.debian.org/debian-security/ buster/updates main contrib non-free -deb http://deb.debian.org/debian buster-updates main contrib non-free -deb-src http://deb.debian.org/debian buster-updates main contrib non-free -deb http://dev.packages.vyos.net/repositories/current current main diff --git a/roles/install-cloud-init/files/debian.list.jessie b/roles/install-cloud-init/files/debian.list.jessie deleted file mode 100644 index 0750699..0000000 --- a/roles/install-cloud-init/files/debian.list.jessie +++ /dev/null @@ -1,8 +0,0 @@ -deb http://deb.debian.org/debian jessie main contrib non-free -deb-src http://deb.debian.org/debian jessie main contrib non-free -deb http://security.debian.org/debian-security/ jessie/updates main contrib non-free -deb-src http://security.debian.org/debian-security/ jessie/updates main contrib non-free -deb http://deb.debian.org/debian jessie-updates main contrib non-free -deb-src http://deb.debian.org/debian jessie-updates main contrib non-free -deb http://dev.packages.vyos.net/repositories/crux/vyos crux main -deb http://dev.packages.vyos.net/repositories/crux/debian crux main diff --git a/roles/install-cloud-init/files/resolv.conf b/roles/install-cloud-init/files/resolv.conf deleted file mode 100644 index 81027f8..0000000 --- a/roles/install-cloud-init/files/resolv.conf +++ /dev/null @@ -1 +0,0 @@ -nameserver 1.1.1.1 \ No newline at end of file diff --git a/roles/install-cloud-init/tasks/main.yml b/roles/install-cloud-init/tasks/main.yml index 2ae314b..ae6f67b 100644 --- a/roles/install-cloud-init/tasks/main.yml +++ b/roles/install-cloud-init/tasks/main.yml @@ -6,10 +6,14 @@ set_fact: vyos_branch: "crux" when: vyos_version is regex("^1\.2.*$") +- name: Set VyOS branch name equuleus + set_fact: + vyos_branch: "equuleus" + when: vyos_version is regex("^1\.3.*$") - name: Put debian.list become: true - copy: - src: "files/debian.list.{{ debian_version.stdout }}" + template: + src: "templates/debian.list.j2" dest: "{{ vyos_install_root }}/etc/apt/sources.list.d/debian.list" - name: backup resolv.conf become: true @@ -61,7 +65,3 @@ - name: restore original resolv.conf become: true command: mv /tmp/resolv.conf {{ vyos_install_root }}/etc/resolv.conf -- name: change /etc/network/interfaces to include config from Cloud-Init - become: true - command: chroot {{ vyos_install_root }} sed -i 's/source-directory \/etc\/network\/interfaces.d/source \/etc\/network\/interfaces.d\/*/g' /etc/network/interfaces - when: vyos_version is regex("^1\.2.*$") diff --git a/roles/install-config/templates/config.boot.j2 b/roles/install-config/templates/config.boot.j2 index 30506f8..852905e 100644 --- a/roles/install-config/templates/config.boot.j2 +++ b/roles/install-config/templates/config.boot.j2 @@ -10,7 +10,9 @@ system { {% endif %} plaintext-password "" } +{% if vyos_version | regex_search('(^1\.2)') %} level admin +{% endif %} } } syslog { @@ -33,18 +35,6 @@ system { } } interfaces { -{% if cloud_init == "true" and not ( empty_config is defined and empty_config == "true" ) %} - ethernet eth0 { - address dhcp - } -{% endif %} loopback lo { } } -{% if cloud_init == "true" and not ( empty_config is defined and empty_config == "true" ) %} -service { - ssh { - port 22 - } -} -{% endif %} diff --git a/roles/install-custom-packages-wrapper/tasks/main.yml b/roles/install-custom-packages-wrapper/tasks/main.yml new file mode 100644 index 0000000..b67f73c --- /dev/null +++ b/roles/install-custom-packages-wrapper/tasks/main.yml @@ -0,0 +1,4 @@ +- name: Check if we need to install custom packages + include_role: + name: install-custom-packages + when: custom_packages is defined diff --git a/roles/install-custom-packages-wrapper/tests/inventory b/roles/install-custom-packages-wrapper/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/install-custom-packages-wrapper/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/install-custom-packages-wrapper/tests/test.yml b/roles/install-custom-packages-wrapper/tests/test.yml new file mode 100644 index 0000000..085b15c --- /dev/null +++ b/roles/install-custom-packages-wrapper/tests/test.yml @@ -0,0 +1,4 @@ +--- +- hosts: localhost + roles: + - install-custom-packages-wrapper diff --git a/roles/install-custom-packages/tasks/main.yml b/roles/install-custom-packages/tasks/main.yml new file mode 100644 index 0000000..1d8cd47 --- /dev/null +++ b/roles/install-custom-packages/tasks/main.yml @@ -0,0 +1,60 @@ +- name: Get Debian version + become: true + command: chroot {{ vyos_install_root }} awk 'match($0, /VERSION=.*\((\w+)\)/, version) { print version[1] }' /etc/os-release + register: debian_version +- name: Set VyOS branch name crux + set_fact: + vyos_branch: "crux" + when: vyos_version is regex("^1\.2.*$") +- name: Set VyOS branch name equuleus + set_fact: + vyos_branch: "equuleus" + when: vyos_version is regex("^1\.3.*$") +- name: Put debian.list + become: true + template: + src: "templates/debian.list.j2" + dest: "{{ vyos_install_root }}/etc/apt/sources.list.d/debian.list" +- name: backup resolv.conf + become: true + command: mv {{ vyos_install_root }}/etc/resolv.conf /tmp/resolv.conf +- name: add nameserver settings to chroot + become: true + copy: + src: "files/resolv.conf" + dest: "{{ vyos_install_root }}/etc/resolv.conf" +- name: apt-get update + become: true + command: chroot {{ vyos_install_root }} apt-get update +- name: Copy packages to a temporary directory + become: true + copy: + src: "files/custom_debs/" + dest: "{{ vyos_install_root }}/tmp/custom_debs/" +- name: Install custom packages from a list + command: chroot {{ vyos_install_root }} apt-get -t {{ vyos_branch | default('current') }} install -y --no-install-recommends {{ lookup('file', 'files/custom_packages_list.txt') }} +- name: Check if custom debs directory exists + stat: + path: "{{ vyos_install_root }}/tmp/custom_debs/" + register: custom_debs_dir +- name: Install custom packages from deb files + command: chroot {{ vyos_install_root }} dpkg -i --force-depends -R /tmp/custom_debs/ + when: custom_debs_dir.stat.exists +- name: Install missed dependencies + command: chroot {{ vyos_install_root }} apt-get -f -y install +- name: Delete DEB packages + command: chroot {{ vyos_install_root }} rm -rf /tmp/custom_debs/ +- name: apt-get clean + become: true + command: chroot {{ vyos_install_root }} apt-get clean +- name: delete apt lists from cache + become: true + command: chroot {{ vyos_install_root }} rm -rf /var/lib/apt/lists/ +- name: Delete debian.list + become: true + file: + path: "{{ vyos_install_root }}/etc/apt/sources.list.d/debian.list" + state: absent +- name: restore original resolv.conf + become: true + command: mv /tmp/resolv.conf {{ vyos_install_root }}/etc/resolv.conf diff --git a/roles/install-custom-packages/tests/inventory b/roles/install-custom-packages/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/install-custom-packages/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/install-custom-packages/tests/test.yml b/roles/install-custom-packages/tests/test.yml new file mode 100644 index 0000000..9522565 --- /dev/null +++ b/roles/install-custom-packages/tests/test.yml @@ -0,0 +1,4 @@ +--- +- hosts: localhost + roles: + - install-custom-packages diff --git a/roles/install-grub/templates/boot/grub/device.map.j2 b/roles/install-grub/templates/boot/grub/device.map.j2 deleted file mode 100644 index e14205e..0000000 --- a/roles/install-grub/templates/boot/grub/device.map.j2 +++ /dev/null @@ -1 +0,0 @@ -(hd0) /dev/sda diff --git a/roles/install-grub/templates/boot/grub/grub.cfg.j2 b/roles/install-grub/templates/boot/grub/grub.cfg.j2 index 45aec3b..e16194d 100644 --- a/roles/install-grub/templates/boot/grub/grub.cfg.j2 +++ b/roles/install-grub/templates/boot/grub/grub.cfg.j2 @@ -11,21 +11,21 @@ insmod efi_gop insmod efi_uga menuentry "VyOS {{ vyos_version }} for {{ vyos_platform }} (KVM console)" { - linux /boot/{{ vyos_version }}/vmlinuz boot=live rootdelay=5 noautologin net.ifnames=0 biosdevname=0 vyos-union=/boot/{{ vyos_version }} console=ttyS0 console=tty0 + linux /boot/{{ vyos_version }}/vmlinuz boot=live rootdelay=5 noautologin net.ifnames=0 biosdevname=0 vyos-union=/boot/{{ vyos_version }} console=tty0 initrd /boot/{{ vyos_version }}/initrd.img } menuentry "VyOS {{ vyos_version }} for {{ vyos_platform }} (Serial console)" { - linux /boot/{{ vyos_version }}/vmlinuz boot=live rootdelay=5 noautologin net.ifnames=0 biosdevname=0 vyos-union=/boot/{{ vyos_version }} console=tty0 console=ttyS0 + linux /boot/{{ vyos_version }}/vmlinuz boot=live rootdelay=5 noautologin net.ifnames=0 biosdevname=0 vyos-union=/boot/{{ vyos_version }} console=ttyS0 initrd /boot/{{ vyos_version }}/initrd.img } menuentry "VyOS {{ vyos_version }} for {{ vyos_platform }} - password reset (KVM console)" { - linux /boot/{{ vyos_version }}/vmlinuz boot=live rootdelay=5 noautologin net.ifnames=0 biosdevname=0 vyos-union=/boot/{{ vyos_version }} console=ttyS0 console=tty0 init=/opt/vyatta/sbin/standalone_root_pw_reset + linux /boot/{{ vyos_version }}/vmlinuz boot=live rootdelay=5 noautologin net.ifnames=0 biosdevname=0 vyos-union=/boot/{{ vyos_version }} console=tty0 init=/opt/vyatta/sbin/standalone_root_pw_reset initrd /boot/{{ vyos_version }}/initrd.img } menuentry "VyOS {{ vyos_version }} for {{ vyos_platform }} - password reset (Serial console)" { - linux /boot/{{ vyos_version }}/vmlinuz boot=live rootdelay=5 noautologin net.ifnames=0 biosdevname=0 vyos-union=/boot/{{ vyos_version }} console=tty0 console=ttyS0 init=/opt/vyatta/sbin/standalone_root_pw_reset + linux /boot/{{ vyos_version }}/vmlinuz boot=live rootdelay=5 noautologin net.ifnames=0 biosdevname=0 vyos-union=/boot/{{ vyos_version }} console=ttyS0 init=/opt/vyatta/sbin/standalone_root_pw_reset initrd /boot/{{ vyos_version }}/initrd.img } diff --git a/roles/install-guest-agent/files/debian.list.buster b/roles/install-guest-agent/files/debian.list.buster deleted file mode 100644 index 4950c4e..0000000 --- a/roles/install-guest-agent/files/debian.list.buster +++ /dev/null @@ -1,4 +0,0 @@ -deb http://deb.debian.org/debian buster main contrib non-free -deb http://security.debian.org/debian-security/ buster/updates main contrib non-free -deb http://deb.debian.org/debian buster-updates main contrib non-free -deb http://dev.packages.vyos.net/repositories/current current main diff --git a/roles/install-guest-agent/files/debian.list.jessie b/roles/install-guest-agent/files/debian.list.jessie deleted file mode 100644 index 885e26b..0000000 --- a/roles/install-guest-agent/files/debian.list.jessie +++ /dev/null @@ -1,5 +0,0 @@ -deb http://deb.debian.org/debian jessie main contrib non-free -deb http://security.debian.org/debian-security/ jessie/updates main contrib non-free -deb http://deb.debian.org/debian jessie-updates main contrib non-free -deb http://dev.packages.vyos.net/repositories/crux/vyos crux main -deb http://dev.packages.vyos.net/repositories/crux/debian crux main diff --git a/roles/install-guest-agent/files/resolv.conf b/roles/install-guest-agent/files/resolv.conf deleted file mode 100644 index 81027f8..0000000 --- a/roles/install-guest-agent/files/resolv.conf +++ /dev/null @@ -1 +0,0 @@ -nameserver 1.1.1.1 \ No newline at end of file diff --git a/roles/install-guest-agent/tasks/main.yml b/roles/install-guest-agent/tasks/main.yml index f636f53..3c0985c 100644 --- a/roles/install-guest-agent/tasks/main.yml +++ b/roles/install-guest-agent/tasks/main.yml @@ -6,10 +6,14 @@ set_fact: vyos_branch: "crux" when: vyos_version is regex("^1\.2.*$") +- name: Set VyOS branch name equuleus + set_fact: + vyos_branch: "equuleus" + when: vyos_version is regex("^1\.3.*$") - name: Put debian.list become: true - copy: - src: "files/debian.list.{{ debian_version.stdout }}" + template: + src: "templates/debian.list.j2" dest: "{{ vyos_install_root }}/etc/apt/sources.list.d/debian.list" - name: backup resolv.conf become: true diff --git a/roles/setup-root-partition/tasks/main.yml b/roles/setup-root-partition/tasks/main.yml index bf183f3..ff1a81b 100644 --- a/roles/setup-root-partition/tasks/main.yml +++ b/roles/setup-root-partition/tasks/main.yml @@ -70,3 +70,4 @@ src: "{{ vyos_target_drive }}p{{ partition_num_root }}" fstype: "{{ vyos_root_fstype }}" state: mounted + opts: discard -- cgit v1.2.3