Skip to content

Commit 22e313d

Browse files
committed
fix: do not remove ssh
1 parent 6463e41 commit 22e313d

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

ansible/tasks/clean-build-dependencies.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# Protect packages that SSH and cloud-init depend on from autoremove
2+
# These must be marked as manually installed BEFORE any autoremove runs
3+
- name: Mark SSH and cloud-init dependencies as manually installed
4+
ansible.builtin.shell: |
5+
apt-mark manual openssh-server cloud-init python3-systemd python3-jinja2 python3-yaml python3-oauthlib python3-configobj || true
6+
changed_when: false
7+
18
- name: Remove build dependencies
29
ansible.builtin.apt:
310
autoremove: true
@@ -25,9 +32,10 @@
2532
# - Dev packages provide headers for building exploits
2633
# - salt-minion is a remote management agent (large attack surface)
2734
# - sshpass stores credentials in plaintext
35+
# NOTE: autoremove disabled here to prevent cascading removal of cloud-init deps
2836
- name: Remove high-security-risk packages
2937
ansible.builtin.apt:
30-
autoremove: true
38+
autoremove: false
3139
pkg:
3240
# Compiler toolchain (gcc-14-base kept - libgcc-s1 runtime depends on it)
3341
- binutils
@@ -56,3 +64,10 @@
5664
# Build tool leftovers
5765
- ansible-core
5866
state: 'absent'
67+
68+
# Run a final autoremove to clean up any remaining orphaned packages
69+
# This runs after apt-mark manual, so cloud-init deps are protected
70+
- name: Clean up orphaned packages
71+
ansible.builtin.apt:
72+
autoremove: true
73+
changed_when: false

scripts/90-cleanup-qemu.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,15 @@ elif [ -n "$(command -v apt-get)" ]; then
4444

4545
source /etc/os-release
4646

47+
# Protect critical runtime packages from autoremove
4748
apt-mark manual libevent-2.1-7t64
4849

50+
# Protect SSH and cloud-init dependencies from autoremove
51+
# Without these, the image won't be accessible via SSH after boot
52+
apt-mark manual openssh-server cloud-init python3-systemd python3-jinja2 \
53+
python3-yaml python3-oauthlib python3-configobj python3-requests \
54+
python3-urllib3 python3-certifi python3-chardet python3-idna || true
55+
4956
apt-get remove -y --purge ansible-core apport appstream bash-completion bcache-tools bind9-dnsutils bind9-host bind9-libs bolt btrfs-progs byobu command-not-found console-setup distro-info eject fonts-ubuntu-console friendly-recovery ftp fwupd gawk gdisk keyboard-configuration libvolume-key1 libssl-dev lvm2 lxd-agent-loader man-db mdadm modemmanager mtd-utils nano netcat-openbsd nfs-common ntfs-3g parted pastebinit screen strace thin-provisioning-tools tmux usb-modeswitch vim vim-runtime wget whiptail xfsprogs
5057

5158
apt remove -y --purge libc6-dev linux-libc-dev libevent-dev libpcre3-dev libsystemd-dev packagekit multipath-tools unattended-upgrades plymouth gnupg open-vm-tools xauth lxd-installer publicsuffix libclang-cpp18 python3-twisted python-babel-localedata libicu74 python3-pygments fonts-dejavu* python3-botocore

scripts/90-cleanup.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,16 @@ elif [ -n "$(command -v apt-get)" ]; then
4141
/etc/apt/sources.list.d/ansible-ubuntu-ansible-*.sources 2>/dev/null || true
4242

4343
source /etc/os-release
44-
44+
4545
apt-get -y update
4646
apt-get -y upgrade
47+
48+
# Protect SSH and cloud-init dependencies from autoremove
49+
# Without these, the AMI won't be accessible via SSH after boot
50+
apt-mark manual openssh-server cloud-init python3-systemd python3-jinja2 \
51+
python3-yaml python3-oauthlib python3-configobj python3-requests \
52+
python3-urllib3 python3-certifi python3-chardet python3-idna || true
53+
4754
apt-get -y autoremove
4855
apt-get -y autoclean
4956
fi

0 commit comments

Comments
 (0)