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 |
Dmitry Tyzhnenko | b610afd | 2018-02-19 15:43:45 +0200 | [diff] [blame] | 22 | - cloud-init-per once sudo echo 'sshd:ALL' >> /etc/hosts.deny |
Dmitry Tyzhnenko | 5a5d8da | 2017-12-14 14:14:42 +0200 | [diff] [blame] | 23 | # Enable root access |
| 24 | - sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin yes/' /etc/ssh/sshd_config |
Dmitry Tyzhnenko | 5a5d8da | 2017-12-14 14:14:42 +0200 | [diff] [blame] | 25 | 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 Tyzhnenko | 80ce020 | 2019-02-07 13:27:19 +0200 | [diff] [blame^] | 41 | - iptables -I OUTPUT -p tcp --dport 53 -j DROP |
| 42 | - iptables -I OUTPUT -p udp --dport 53 -j DROP |
Dmitry Tyzhnenko | b610afd | 2018-02-19 15:43:45 +0200 | [diff] [blame] | 43 | - ifdown --force ens3; ifconfig ens3 down; ip a flush dev ens3; rm -f /var/run/network/ifstate.ens3 |
| 44 | - ifdown --force ens4; ifconfig ens4 down; ip a flush dev ens4; rm -f /var/run/network/ifstate.ens4 |
| 45 | - ifdown --force ens5; ifconfig ens5 down; ip a flush dev ens5; rm -f /var/run/network/ifstate.ens5 |
Dmitry Tyzhnenko | 80ce020 | 2019-02-07 13:27:19 +0200 | [diff] [blame^] | 46 | - ifdown --force ens6; ifconfig ens6 down; ip a flush dev ens6; rm -f /var/run/network/ifstate.ens6 |
| 47 | - cd /root/config-drive && cloud-init --file /root/config-drive/vendor-data --debug modules |
| 48 | # - [bash, -cex, *master_config] |
| 49 | # - cp /root/config-drive/user-data /root/config.sh && chmod 664 /root/config.sh |
| 50 | # - sed -i '/^reboot$/d' /root/config.sh |
| 51 | # - cd /root && /bin/bash -xe ./config.sh |
| 52 | |
Dmitry Tyzhnenko | 5a5d8da | 2017-12-14 14:14:42 +0200 | [diff] [blame] | 53 | |
| 54 | # Enable root access |
| 55 | - sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin yes/' /etc/ssh/sshd_config |
Dmitry Tyzhnenko | 468564a | 2018-08-23 16:39:06 +0300 | [diff] [blame] | 56 | - systemctl reload sshd |
Dmitry Tyzhnenko | 5a5d8da | 2017-12-14 14:14:42 +0200 | [diff] [blame] | 57 | |
| 58 | ######################################################## |
Dmitry Tyzhnenko | 468564a | 2018-08-23 16:39:06 +0300 | [diff] [blame] | 59 | # Node is ready, allow SSH access and reboot |
Dmitry Tyzhnenko | 5a5d8da | 2017-12-14 14:14:42 +0200 | [diff] [blame] | 60 | - echo "Allow SSH access ..." |
Dmitry Tyzhnenko | b610afd | 2018-02-19 15:43:45 +0200 | [diff] [blame] | 61 | - "sed -i -e '/sshd:ALL/d' /etc/hosts.deny" |
| 62 | - touch /is_cloud_init_finish |
Dmitry Tyzhnenko | 468564a | 2018-08-23 16:39:06 +0300 | [diff] [blame] | 63 | - reboot |
Dmitry Tyzhnenko | 5a5d8da | 2017-12-14 14:14:42 +0200 | [diff] [blame] | 64 | ######################################################## |
| 65 | |
| 66 | write_files: |
| 67 | - path: /root/.ssh/config |
| 68 | owner: root:root |
| 69 | permissions: '0600' |
| 70 | content: | |
| 71 | Host * |
| 72 | ServerAliveInterval 300 |
| 73 | ServerAliveCountMax 10 |
| 74 | StrictHostKeyChecking no |
| 75 | UserKnownHostsFile /dev/null |
Dmitry Tyzhnenko | b610afd | 2018-02-19 15:43:45 +0200 | [diff] [blame] | 76 | |
| 77 | ssh_pwauth: True |
Dmitry Tyzhnenko | 80ce020 | 2019-02-07 13:27:19 +0200 | [diff] [blame^] | 78 | disable_root: false |
Dmitry Tyzhnenko | b610afd | 2018-02-19 15:43:45 +0200 | [diff] [blame] | 79 | users: |
| 80 | - name: root |
| 81 | sudo: ALL=(ALL) NOPASSWD:ALL |
| 82 | shell: /bin/bash |
| 83 | ssh_authorized_keys: |
| 84 | {% for key in config.underlay.ssh_keys %} |
| 85 | - ssh-rsa {{ key['public'] }} |
| 86 | {% endfor %} |
Dmitry Tyzhnenko | 80ce020 | 2019-02-07 13:27:19 +0200 | [diff] [blame^] | 87 | |
| 88 | chpasswd: |
| 89 | list: | |
| 90 | root:r00tme |
| 91 | expire: False |