Dennis Dmitriev | 0f624a8 | 2018-06-11 12:57:13 +0300 | [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 touch /is_cloud_init_started |
| 23 | # Enable root access |
| 24 | - sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin yes/' /etc/ssh/sshd_config |
| 25 | - service sshd restart |
| 26 | |
| 27 | output: |
| 28 | all: '| tee -a /var/log/cloud-init-output.log /dev/tty0' |
| 29 | |
| 30 | runcmd: |
| 31 | - echo "******** MOUNT CONFIG DRIVE" |
| 32 | # Mount config drive |
| 33 | - mkdir /root/config-drive |
| 34 | - mount /dev/sr0 /root/config-drive |
| 35 | |
| 36 | # Configure dhclient |
| 37 | - sudo echo "nameserver {gateway}" >> /etc/resolvconf/resolv.conf.d/base |
| 38 | - sudo resolvconf -u |
| 39 | |
| 40 | # Enable grub menu using updated config below |
| 41 | - update-grub |
| 42 | |
| 43 | # Prepare network connection |
| 44 | #- sudo ifdown ens3 |
| 45 | #- sudo ip r d default || true # remove existing default route to get it from dhcp |
| 46 | #- sudo ifup ens3 |
| 47 | #- sudo route add default gw {gateway} {interface_name} |
| 48 | |
| 49 | # Create swap |
| 50 | - fallocate -l 16G /swapfile |
| 51 | - chmod 600 /swapfile |
| 52 | - mkswap /swapfile |
| 53 | - swapon /swapfile |
| 54 | - echo "/swapfile none swap defaults 0 0" >> /etc/fstab |
| 55 | |
| 56 | # Run user data script from config drive |
| 57 | - ifdown --force ens3; ifconfig ens3 down; ip a flush dev ens3; rm -f /var/run/network/ifstate.ens3; ip l set down ens3 |
| 58 | - ifdown --force ens4; ifconfig ens4 down; ip a flush dev ens4; rm -f /var/run/network/ifstate.ens4; ip l set down ens4 |
| 59 | - rm -f /etc/network/interfaces |
| 60 | #- ifdown --force ens5; ifconfig ens5 down; ip a flush dev ens5; rm -f /var/run/network/ifstate.ens5 |
| 61 | #- cp /root/config-drive/user-data /root/user-data |
| 62 | #- sed -i '/^reboot$/d' /root/user-data |
| 63 | #- set -x; cd /root && /bin/bash -xe ./user-data |
Dennis Dmitriev | 86085b4 | 2018-07-02 14:14:25 +0300 | [diff] [blame] | 64 | - | |
| 65 | set -x |
| 66 | cd /root/config-drive |
Dennis Dmitriev | 3d28aa3 | 2018-07-04 16:14:59 +0300 | [diff] [blame] | 67 | if /bin/bash -xe ./user-data; then |
Dennis Dmitriev | 86085b4 | 2018-07-02 14:14:25 +0300 | [diff] [blame] | 68 | touch /is_cloud_init_finished |
| 69 | else |
| 70 | set +x |
Dennis Dmitriev | 3d28aa3 | 2018-07-04 16:14:59 +0300 | [diff] [blame] | 71 | echo "bootstrap script /root/config-drive/user-data failed\n" > /is_cloud_init_failed |
Dennis Dmitriev | 86085b4 | 2018-07-02 14:14:25 +0300 | [diff] [blame] | 72 | fi |
Dennis Dmitriev | 0f624a8 | 2018-06-11 12:57:13 +0300 | [diff] [blame] | 73 | |
| 74 | # Enable root access (after reboot) |
| 75 | - sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin yes/' /etc/ssh/sshd_config |
Dennis Dmitriev | 0f624a8 | 2018-06-11 12:57:13 +0300 | [diff] [blame] | 76 | |
| 77 | write_files: |
| 78 | - path: /etc/default/grub.d/97-enable-grub-menu.cfg |
| 79 | content: | |
| 80 | GRUB_RECORDFAIL_TIMEOUT=30 |
| 81 | GRUB_TIMEOUT=3 |
| 82 | GRUB_TIMEOUT_STYLE=menu |
| 83 | |
| 84 | #- path: /etc/network/interfaces |
| 85 | - path: /root/interfaces |
| 86 | content: | |
| 87 | auto lo |
| 88 | iface lo inet loopback |
| 89 | |
| 90 | auto ens3 |
| 91 | iface ens3 inet dhcp |
| 92 | |
| 93 | - path: /root/.ssh/config |
| 94 | owner: root:root |
| 95 | permissions: '0600' |
| 96 | content: | |
| 97 | Host * |
| 98 | ServerAliveInterval 60 |
| 99 | ServerAliveCountMax 0 |
| 100 | StrictHostKeyChecking no |
| 101 | UserKnownHostsFile /dev/null |