summaryrefslogtreecommitdiff
path: root/roles/cloud-install/templates/hetzner_postinst.sh.j2
blob: 3ee5a390adc7c640c913dabd669d2bea8ce0a1dc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash
set -euf -o pipefail

export DEBIAN_FRONTEND=noninteractive
apt-get update -q
apt-get full-upgrade -y -q
apt-get install -y -q --no-install-recommends openssh-server python

passwd -d root && passwd -l root
{% if install_distro == "debian" %}
sed -e 's/^allow-hotplug/auto/' -i /etc/network/interfaces
{% endif %}
sed -r 's#(\s+/var/log\s+ext4\s+)defaults#\1noatime,nodev,noexec#g' -i /etc/fstab

mkdir -p -m 0700 /target/root/.ssh
cat <<EOK > /root/.ssh/authorized_keys
{{ ssh_keys_root | join('\n') }}
EOK
{% if hostvars[hostname].ansible_port is defined %}
sed -e 's/^\(\s*#*\s*Port.*\)/Port {{ hostvars[hostname].ansible_port }}/' -i /etc/ssh/sshd_config
{% endif %}

{# this is actually only needed on ubuntu bionic and beyond but should not hurt on other installations either #}
swapoff -a; sed -e '/^\/swapfile/d' -i /etc/fstab; rm -f /swapfile

echo "postinst.sh finished successfully"