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 /scripts/vyos | |
parent | 634fa2ba708173da81c7d709063e9fd94b43e94f (diff) | |
download | packer-vyos-b2c4d5920e8e34b286d035bf1a0b2070fca75f38.tar.gz packer-vyos-b2c4d5920e8e34b286d035bf1a0b2070fca75f38.zip |
improved vyos configure cleanup and cloud-init
Diffstat (limited to 'scripts/vyos')
-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 |
9 files changed, 62 insertions, 34 deletions
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 + |