| # All the data below will be stored as a string object | |
#cloud-config, see http://cloudinit.readthedocs.io/en/latest/topics/examples.html | |
ssh_pwauth: True | |
users: | |
- name: root | |
sudo: ALL=(ALL) NOPASSWD:ALL | |
shell: /bin/bash | |
ssh_authorized_keys: | |
{% for key in config.underlay.ssh_keys %} | |
- ssh-rsa {{ key['public'] }} | |
{% endfor %} | |
disable_root: false | |
chpasswd: | |
list: | | |
root:r00tme | |
expire: False | |
bootcmd: | |
# Block access to SSH while node is preparing | |
- cloud-init-per once sudo touch /is_cloud_init_started | |
# Enable root access | |
- sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin yes/' /etc/ssh/sshd_config | |
- service sshd restart | |
output: | |
all: '| tee -a /var/log/cloud-init-output.log /dev/tty0' | |
runcmd: | |
- echo "******** MOUNT CONFIG DRIVE" | |
# Mount config drive | |
- mkdir /root/config-drive | |
- mount /dev/sr0 /root/config-drive | |
# Configure dhclient | |
- sudo echo "nameserver {gateway}" >> /etc/resolvconf/resolv.conf.d/base | |
- sudo resolvconf -u | |
# Enable grub menu using updated config below | |
- update-grub | |
# Prepare network connection | |
#- sudo ifdown ens3 | |
#- sudo ip r d default || true # remove existing default route to get it from dhcp | |
#- sudo ifup ens3 | |
#- sudo route add default gw {gateway} {interface_name} | |
# Create swap | |
- fallocate -l 16G /swapfile | |
- chmod 600 /swapfile | |
- mkswap /swapfile | |
- swapon /swapfile | |
- echo "/swapfile none swap defaults 0 0" >> /etc/fstab | |
# Run user data script from config drive | |
- ifdown --force ens3; ifconfig ens3 down; ip a flush dev ens3; rm -f /var/run/network/ifstate.ens3; ip l set down ens3 | |
- ifdown --force ens4; ifconfig ens4 down; ip a flush dev ens4; rm -f /var/run/network/ifstate.ens4; ip l set down ens4 | |
- rm -f /etc/network/interfaces | |
#- ifdown --force ens5; ifconfig ens5 down; ip a flush dev ens5; rm -f /var/run/network/ifstate.ens5 | |
#- cp /root/config-drive/user-data /root/user-data | |
#- sed -i '/^reboot$/d' /root/user-data | |
#- set -x; cd /root && /bin/bash -xe ./user-data | |
- | | |
set -x | |
cd /root/config-drive | |
if /bin/bash -xe ./user-data; then | |
touch /is_cloud_init_finished | |
else | |
set +x | |
echo "bootstrap script /root/config-drive/user-data failed\n" > /is_cloud_init_failed | |
fi | |
# Enable root access (after reboot) | |
- sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin yes/' /etc/ssh/sshd_config | |
write_files: | |
- path: /etc/default/grub.d/97-enable-grub-menu.cfg | |
content: | | |
GRUB_RECORDFAIL_TIMEOUT=30 | |
GRUB_TIMEOUT=3 | |
GRUB_TIMEOUT_STYLE=menu | |
#- path: /etc/network/interfaces | |
- path: /root/interfaces | |
content: | | |
auto lo | |
iface lo inet loopback | |
auto ens3 | |
iface ens3 inet dhcp | |
- path: /root/.ssh/config | |
owner: root:root | |
permissions: '0600' | |
content: | | |
Host * | |
ServerAliveInterval 60 | |
ServerAliveCountMax 0 | |
StrictHostKeyChecking no | |
UserKnownHostsFile /dev/null |