blob: 8e4d5061c54bf992ced02ccb23c204037a0233e3 [file] [log] [blame]
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +02001| # All the data below will be stored as a string object
2 #cloud-config, see http://cloudinit.readthedocs.io/en/latest/topics/examples.html
3
4 ssh_pwauth: True
5 users:
6 - name: root
7 sudo: ALL=(ALL) NOPASSWD:ALL
8 shell: /bin/bash
9 ssh_authorized_keys:
10 {% for key in config.underlay.ssh_keys %}
11 - ssh-rsa {{ key['public'] }}
12 {% endfor %}
13
14 disable_root: false
15 chpasswd:
16 list: |
17 root:r00tme
18 expire: False
19
20 bootcmd:
21 # Block access to SSH while node is preparing
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +020022 - cloud-init-per once sudo echo 'sshd:ALL' >> /etc/hosts.deny
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +020023 # Enable root access
24 - sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin yes/' /etc/ssh/sshd_config
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +020025 output:
26 all: '| tee -a /var/log/cloud-init-output.log /dev/tty0'
27
28 runcmd:
29 # Mount config drive
30 - mkdir /root/config-drive
31 - mount /dev/sr0 /root/config-drive
32
33 # Create swap
34 - fallocate -l 4G /swapfile
35 - chmod 600 /swapfile
36 - mkswap /swapfile
37 - swapon /swapfile
38 - echo "/swapfile none swap defaults 0 0" >> /etc/fstab
39
40 # Run user data script from config drive
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +020041 - ifdown --force ens3; ifconfig ens3 down; ip a flush dev ens3; rm -f /var/run/network/ifstate.ens3
42 - ifdown --force ens4; ifconfig ens4 down; ip a flush dev ens4; rm -f /var/run/network/ifstate.ens4
43 - ifdown --force ens5; ifconfig ens5 down; ip a flush dev ens5; rm -f /var/run/network/ifstate.ens5
Dmitry Tyzhnenko468564a2018-08-23 16:39:06 +030044 - cp /root/config-drive/user-data /root/config.sh && chmod 664 /root/config.sh
45 - sed -i '/^reboot$/d' /root/config.sh
46 - cd /root && /bin/bash -xe ./config.sh
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +020047
48 # Enable root access
49 - sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin yes/' /etc/ssh/sshd_config
Dmitry Tyzhnenko468564a2018-08-23 16:39:06 +030050 - systemctl reload sshd
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +020051
52 ########################################################
Dmitry Tyzhnenko468564a2018-08-23 16:39:06 +030053 # Node is ready, allow SSH access and reboot
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +020054 - echo "Allow SSH access ..."
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +020055 - "sed -i -e '/sshd:ALL/d' /etc/hosts.deny"
56 - touch /is_cloud_init_finish
Dmitry Tyzhnenko468564a2018-08-23 16:39:06 +030057 - reboot
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +020058 ########################################################
59
60 write_files:
61 - path: /root/.ssh/config
62 owner: root:root
63 permissions: '0600'
64 content: |
65 Host *
66 ServerAliveInterval 300
67 ServerAliveCountMax 10
68 StrictHostKeyChecking no
69 UserKnownHostsFile /dev/null
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +020070
71 ssh_pwauth: True
72 users:
73 - name: root
74 sudo: ALL=(ALL) NOPASSWD:ALL
75 shell: /bin/bash
76 ssh_authorized_keys:
77 {% for key in config.underlay.ssh_keys %}
78 - ssh-rsa {{ key['public'] }}
79 {% endfor %}