Dmitry Tyzhnenko | 5a5d8da | 2017-12-14 14:14:42 +0200 | [diff] [blame] | 1 | | # 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 |
| 22 | - cloud-init-per once sudo iptables -A INPUT -p tcp --dport 22 -j DROP |
| 23 | # Enable root access |
| 24 | - sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin yes/' /etc/ssh/sshd_config |
| 25 | - service sshd restart |
| 26 | output: |
| 27 | all: '| tee -a /var/log/cloud-init-output.log /dev/tty0' |
| 28 | |
| 29 | runcmd: |
| 30 | # Mount config drive |
| 31 | - mkdir /root/config-drive |
| 32 | - mount /dev/sr0 /root/config-drive |
| 33 | |
| 34 | # Create swap |
| 35 | - fallocate -l 4G /swapfile |
| 36 | - chmod 600 /swapfile |
| 37 | - mkswap /swapfile |
| 38 | - swapon /swapfile |
| 39 | - echo "/swapfile none swap defaults 0 0" >> /etc/fstab |
| 40 | |
| 41 | # Run user data script from config drive |
| 42 | - cd /root/config-drive && /bin/bash -xe ./user-data |
| 43 | |
| 44 | # Enable root access |
| 45 | - sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin yes/' /etc/ssh/sshd_config |
| 46 | |
| 47 | ######################################################## |
| 48 | # Node is ready, allow SSH access |
| 49 | - echo "Allow SSH access ..." |
| 50 | - sudo iptables -D INPUT -p tcp --dport 22 -j DROP |
Dmitry Tyzhnenko | b610afd | 2018-02-19 15:43:45 +0200 | [diff] [blame] | 51 | - touch /is_cloud_init_finish |
Dmitry Tyzhnenko | 5a5d8da | 2017-12-14 14:14:42 +0200 | [diff] [blame] | 52 | ######################################################## |
| 53 | |
| 54 | write_files: |
| 55 | - path: /root/.ssh/config |
| 56 | owner: root:root |
| 57 | permissions: '0600' |
| 58 | content: | |
| 59 | Host * |
| 60 | ServerAliveInterval 300 |
| 61 | ServerAliveCountMax 10 |
| 62 | StrictHostKeyChecking no |
| 63 | UserKnownHostsFile /dev/null |