diff options
author | Roberto Berto <463349+robertoberto@users.noreply.github.com> | 2024-05-23 17:49:52 +0000 |
---|---|---|
committer | Roberto Berto <463349+robertoberto@users.noreply.github.com> | 2024-05-23 17:49:52 +0000 |
commit | b2c4d5920e8e34b286d035bf1a0b2070fca75f38 (patch) | |
tree | 481d197cce56dc721d4cb1fa7a369a37db1c5dcb | |
parent | 634fa2ba708173da81c7d709063e9fd94b43e94f (diff) | |
download | packer-vyos-b2c4d5920e8e34b286d035bf1a0b2070fca75f38.tar.gz packer-vyos-b2c4d5920e8e34b286d035bf1a0b2070fca75f38.zip |
improved vyos configure cleanup and cloud-init
-rw-r--r-- | http/cleanup-vyos-configure.py | 25 | ||||
-rw-r--r-- | scripts/vyos/apt-install.sh | 4 | ||||
-rw-r--r-- | scripts/vyos/cleanup-vyos-configure.sh | 31 | ||||
-rw-r--r-- | scripts/vyos/cleanup.sh | 27 | ||||
-rw-r--r-- | scripts/vyos/cloud-init-datasource.sh | 2 | ||||
-rw-r--r-- | scripts/vyos/cloud-init-debian.sh | 8 | ||||
-rw-r--r-- | scripts/vyos/cloud-init-vyos.sh | 7 | ||||
-rw-r--r-- | scripts/vyos/configure.sh | 2 | ||||
-rw-r--r-- | scripts/vyos/init.sh | 1 | ||||
-rw-r--r-- | scripts/vyos/osprep.sh | 14 | ||||
-rw-r--r-- | vyos-1.3.pkrvars.hcl | 2 | ||||
-rw-r--r-- | vyos-1.4.pkrvars.hcl | 2 | ||||
-rw-r--r-- | vyos-1.5.pkrvars.hcl | 2 | ||||
-rw-r--r-- | vyos-image2-1.3.pkr.hcl | 9 | ||||
-rw-r--r-- | vyos-image2-1.4.pkr.hcl | 9 | ||||
-rw-r--r-- | vyos-image2-1.5.pkr.hcl | 9 |
16 files changed, 117 insertions, 37 deletions
diff --git a/http/cleanup-vyos-configure.py b/http/cleanup-vyos-configure.py new file mode 100644 index 0000000..b58b03b --- /dev/null +++ b/http/cleanup-vyos-configure.py @@ -0,0 +1,25 @@ +import json +from vyos.configtree import ConfigTree + +config_path = '/config/config.boot' + +with open(config_path, 'r') as file: + config_string = file.read() + +config = ConfigTree(config_string=config_string) + +interfaces = config.list_nodes(['interfaces', 'ethernet']) + +# remove all hw-id from interfaces ethernet since it cause issue on interface order +# for interface in interfaces: +# hw_id_path = ['interfaces', 'ethernet', interface, 'hw-id'] +# if config.exists(hw_id_path): +# config.delete(hw_id_path) + +# remove all interfaces ethernet +for interface in interfaces: + hw_id_path = ['interfaces', 'ethernet', interface] + config.delete(hw_id_path) + +with open(config_path, 'w') as config_file: + config_file.write(config.to_string()) diff --git a/scripts/vyos/apt-install.sh b/scripts/vyos/apt-install.sh index 0e47bce..22f28dc 100644 --- a/scripts/vyos/apt-install.sh +++ b/scripts/vyos/apt-install.sh @@ -10,7 +10,3 @@ apt install -y \ vim \ net-tools -# install packer-vyos requirements (it will be removed at cleanup.sh) -apt install -y \ - python3-pexpect \ - expect diff --git a/scripts/vyos/cleanup-vyos-configure.sh b/scripts/vyos/cleanup-vyos-configure.sh new file mode 100644 index 0000000..26f3bfd --- /dev/null +++ b/scripts/vyos/cleanup-vyos-configure.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +set -e +set -x + +export DEBIAN_FRONTEND=noninteractive + +# delete interfaces ethernet eth0 address +# delete interfaces ethernet eth0 hw-id +# delete system name-server + +cat <<EOF > /home/vyos/cleanup-vyos.sh +#!/bin/vbash +source /opt/vyatta/etc/functions/script-template +configure +set system host-name 'vyosbuild' +commit +save +exit +EOF +chmod 0700 /home/vyos/cleanup-vyos.sh +chown vyos:users /home/vyos/cleanup-vyos.sh +su - vyos -c "/home/vyos/cleanup-vyos.sh" + +# run cleanup on vyos configure using python vyos.configtree, since can't remove interfaces via configure cli +config_update_url="http://${PACKER_HTTP_IP}:${PACKER_HTTP_PORT}/cleanup-vyos-configure.py" +wget $config_update_url -O /home/vyos/cleanup-vyos-configure.py +chown vyos:users /home/vyos/cleanup-vyos-configure.py +chmod 0664 /home/vyos/cleanup-vyos-configure.py +python3 /home/vyos/cleanup-vyos-configure.py +rm -rf /home/vyos/cleanup-vyos-configure.py diff --git a/scripts/vyos/cleanup.sh b/scripts/vyos/cleanup.sh index f1586f7..15e67b6 100644 --- a/scripts/vyos/cleanup.sh +++ b/scripts/vyos/cleanup.sh @@ -5,32 +5,15 @@ set -x export DEBIAN_FRONTEND=noninteractive -# delete interfaces ethernet eth0 address -# delete interfaces ethernet eth0 hw-id -# delete system name-server - -cat <<EOF > /home/vyos/cleanup-vyos.sh -#!/bin/vbash -source /opt/vyatta/etc/functions/script-template -configure -set system host-name 'vyosbuild' -commit -save -exit -EOF -chmod 0700 /home/vyos/cleanup-vyos.sh -chown vyos:users /home/vyos/cleanup-vyos.sh -su - vyos -c "/home/vyos/cleanup-vyos.sh" +rm -rf /home/vyos/cleanup-vyos.sh + +# fix config permissions since if we edited with root user +# sudo chown -R root:vyattacfg /opt/vyatta/config/active/ # reconfiguring ssh rm -f /etc/ssh/ssh_host_* dpkg-reconfigure openssh-server -# those packages can't be removed since they are needed for next script vyos-install.sh -# apt remove -y \ -# python3-pexpect \ -# expect - # cleanup apt rm -f /etc/apt/sources.list.d/debian.list apt -y autoremove --purge @@ -45,8 +28,6 @@ rm -rf /tmp/* # removing log files rm -rf /var/log/* -rm -rf /home/vyos/cleanup-vyos.sh - # removing history export HISTFILE=0 rm -f /home/vyos/.bash_history diff --git a/scripts/vyos/cloud-init-datasource.sh b/scripts/vyos/cloud-init-datasource.sh index 66e5509..2573a19 100644 --- a/scripts/vyos/cloud-init-datasource.sh +++ b/scripts/vyos/cloud-init-datasource.sh @@ -5,7 +5,7 @@ set -x if [[ "${CLOUD_INIT}" == "debian" || "${CLOUD_INIT}" == "vyos" ]]; then if [[ "${CLOUD_INIT_DATASOURCE}" == "nocloud_configdrive" ]]; then - cat <<EOF > /etc/cloud/cloud.cfg.d/99_nocloud_configdrive.cfg + cat <<EOF > /etc/cloud/cloud.cfg.d/99-datasource.cfg datasource_list: [ NoCloud, ConfigDrive ] EOF else diff --git a/scripts/vyos/cloud-init-debian.sh b/scripts/vyos/cloud-init-debian.sh index 6a66935..0f12066 100644 --- a/scripts/vyos/cloud-init-debian.sh +++ b/scripts/vyos/cloud-init-debian.sh @@ -19,11 +19,11 @@ apt install -y \ cloud-init \ cloud-utils \ ifupdown - + systemctl enable cloud-init -cat <<EOF > /etc/cloud/cloud.cfg.d/99_pve.cfg -datasource_list: [ NoCloud, ConfigDrive ] +cat <<EOF > /etc/cloud/cloud.cfg.d/99-disable_network_config.cfg +network: {config: disabled} EOF - +rm -rf /etc/network/interfaces.d/50-cloud-init || : diff --git a/scripts/vyos/cloud-init-vyos.sh b/scripts/vyos/cloud-init-vyos.sh index 0dd3d93..0d10668 100644 --- a/scripts/vyos/cloud-init-vyos.sh +++ b/scripts/vyos/cloud-init-vyos.sh @@ -19,11 +19,16 @@ apt install -t "$VYOS_RELEASE" --force-yes -y \ cloud-init \ cloud-utils \ ifupdown + systemctl enable cloud-init +cat <<EOF > /etc/cloud/cloud.cfg.d/99-disable_network_config.cfg +network: {config: disabled} +EOF -cat <<EOF > /etc/cloud/cloud.cfg.d/90_disable_config_stage.cfg +cat <<EOF > /etc/cloud/cloud.cfg.d/90-disable_config_stage.cfg # Disable all config-stage modules cloud_config_modules: EOF +rm -rf /etc/network/interfaces.d/50-cloud-init || : diff --git a/scripts/vyos/configure.sh b/scripts/vyos/configure.sh index 8d328ee..f52c336 100644 --- a/scripts/vyos/configure.sh +++ b/scripts/vyos/configure.sh @@ -21,4 +21,4 @@ EOF chmod 0700 /home/vyos/configure-vyos.sh chown vyos:users /home/vyos/configure-vyos.sh su - vyos -c "/home/vyos/configure-vyos.sh" - +rm -rf /home/vyos/configure-vyos.sh diff --git a/scripts/vyos/init.sh b/scripts/vyos/init.sh index 7f0db84..863692c 100644 --- a/scripts/vyos/init.sh +++ b/scripts/vyos/init.sh @@ -9,3 +9,4 @@ ln -fs /etc/machine-id /var/lib/dbus/machine-id # disable logs systemctl stop rsyslog + diff --git a/scripts/vyos/osprep.sh b/scripts/vyos/osprep.sh new file mode 100644 index 0000000..bb2c448 --- /dev/null +++ b/scripts/vyos/osprep.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e +set -x + +# vimrc no mouse +cat <<EOF > /home/vyos/.vimrc +set mouse= +EOF + +cat <<EOF > /root/.vimrc +set mouse= +EOF + diff --git a/vyos-1.3.pkrvars.hcl b/vyos-1.3.pkrvars.hcl index 081139a..c74c136 100644 --- a/vyos-1.3.pkrvars.hcl +++ b/vyos-1.3.pkrvars.hcl @@ -31,7 +31,7 @@ cloud_init_datasource = "nocloud_configdrive" # # for proxmox: # qm set 9000 --serial0 socket --vga serial0 -grub_serial = 1 +grub_serial = 0 # equuleus: debian 11 (branch 1.3.*) # sagitta: debian 12 (branch 1.4.*) diff --git a/vyos-1.4.pkrvars.hcl b/vyos-1.4.pkrvars.hcl index fd23206..5d9eb8a 100644 --- a/vyos-1.4.pkrvars.hcl +++ b/vyos-1.4.pkrvars.hcl @@ -31,7 +31,7 @@ cloud_init_datasource = "nocloud_configdrive" # # for proxmox: # qm set 9000 --serial0 socket --vga serial0 -grub_serial = 1 +grub_serial = 0 # equuleus: debian 11 (branch 1.3.*) # sagitta: debian 12 (branch 1.4.*) diff --git a/vyos-1.5.pkrvars.hcl b/vyos-1.5.pkrvars.hcl index e9b6127..b307b9e 100644 --- a/vyos-1.5.pkrvars.hcl +++ b/vyos-1.5.pkrvars.hcl @@ -31,7 +31,7 @@ cloud_init_datasource = "nocloud_configdrive" # # for proxmox: # qm set 9000 --serial0 socket --vga serial0 -grub_serial = 1 +grub_serial = 0 # equuleus: debian 11 (branch 1.3.*) # sagitta: debian 12 (branch 1.4.*) diff --git a/vyos-image2-1.3.pkr.hcl b/vyos-image2-1.3.pkr.hcl index 55d913c..a25eb2b 100644 --- a/vyos-image2-1.3.pkr.hcl +++ b/vyos-image2-1.3.pkr.hcl @@ -195,6 +195,14 @@ build { ] } + # prepare os - general customizations here + provisioner "shell" { + execute_command = "VYOS_RELEASE='${var.vyos_release}' {{ .Vars }} sudo -E bash '{{ .Path }}'" + scripts = [ + "scripts/vyos/osprep.sh", + ] + } + # configure vyos provisioner "shell" { execute_command = "VYOS_RELEASE='${var.vyos_release}' {{ .Vars }} sudo -E bash '{{ .Path }}'" @@ -243,6 +251,7 @@ build { provisioner "shell" { execute_command = "VYOS_RELEASE='${var.vyos_release}' {{ .Vars }} sudo -E bash '{{ .Path }}'" scripts = [ + "scripts/vyos/cleanup-vyos-configure.sh", "scripts/vyos/cleanup.sh", ] } diff --git a/vyos-image2-1.4.pkr.hcl b/vyos-image2-1.4.pkr.hcl index 58bc9c5..39f9c0c 100644 --- a/vyos-image2-1.4.pkr.hcl +++ b/vyos-image2-1.4.pkr.hcl @@ -195,6 +195,14 @@ build { ] } + # prepare os - general customizations here + provisioner "shell" { + execute_command = "VYOS_RELEASE='${var.vyos_release}' {{ .Vars }} sudo -E bash '{{ .Path }}'" + scripts = [ + "scripts/vyos/osprep.sh", + ] + } + # configure vyos provisioner "shell" { execute_command = "VYOS_RELEASE='${var.vyos_release}' {{ .Vars }} sudo -E bash '{{ .Path }}'" @@ -243,6 +251,7 @@ build { provisioner "shell" { execute_command = "VYOS_RELEASE='${var.vyos_release}' {{ .Vars }} sudo -E bash '{{ .Path }}'" scripts = [ + "scripts/vyos/cleanup-vyos-configure.sh", "scripts/vyos/cleanup.sh", ] } diff --git a/vyos-image2-1.5.pkr.hcl b/vyos-image2-1.5.pkr.hcl index 0c6963b..70c81f8 100644 --- a/vyos-image2-1.5.pkr.hcl +++ b/vyos-image2-1.5.pkr.hcl @@ -195,6 +195,14 @@ build { ] } + # prepare os - general customizations here + provisioner "shell" { + execute_command = "VYOS_RELEASE='${var.vyos_release}' {{ .Vars }} sudo -E bash '{{ .Path }}'" + scripts = [ + "scripts/vyos/osprep.sh", + ] + } + # configure vyos provisioner "shell" { execute_command = "VYOS_RELEASE='${var.vyos_release}' {{ .Vars }} sudo -E bash '{{ .Path }}'" @@ -243,6 +251,7 @@ build { provisioner "shell" { execute_command = "VYOS_RELEASE='${var.vyos_release}' {{ .Vars }} sudo -E bash '{{ .Path }}'" scripts = [ + "scripts/vyos/cleanup-vyos-configure.sh", "scripts/vyos/cleanup.sh", ] } |