Tatyana Leontovich | d34f410 | 2018-04-03 17:49:24 +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 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 | # Prepare network connection |
| 31 | - sudo ifdown ens3 |
| 32 | - sudo ip r d default || true # remove existing default route to get it from dhcp |
| 33 | - sudo ifup ens3 |
| 34 | |
| 35 | #- sudo route add default gw {gateway} {interface_name} |
| 36 | - rm /etc/resolv.conf |
| 37 | - touch /etc/resolv.conf |
| 38 | - LOCAL_IP=$(ifconfig ens3 | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1 | cut -d"." -f1-3) |
| 39 | - export DNS_IP=$LOCAL_IP".122" |
| 40 | - echo "nameserver $DNS_IP" >> /etc/resolv.conf; |
| 41 | - echo "nameserver $LOCAL_IP.1" >> /etc/resolv.conf; |
| 42 | - echo "supersede domain-name-servers $DNS_IP" >> /etc/dhcp/dhclient.conf |
| 43 | |
| 44 | # Create swap |
| 45 | - fallocate -l 4G /swapfile |
| 46 | - chmod 600 /swapfile |
| 47 | - mkswap /swapfile |
| 48 | - swapon /swapfile |
| 49 | - echo "/swapfile none swap defaults 0 0" >> /etc/fstab |
| 50 | |
| 51 | ############## TCP Cloud cfg01 node ################## |
| 52 | - echo "Preparing base OS" |
| 53 | - sleep 160; |
| 54 | # find /etc/apt/ -type f -exec sed -i "s/ubuntu.com/ubuntu.local.test/g" {} +; |
| 55 | ######################################################## |
| 56 | # Node is ready, allow SSH access |
| 57 | - echo "Allow SSH access ..." |
| 58 | - sudo iptables -D INPUT -p tcp --dport 22 -j DROP |
| 59 | ######################################################## |
| 60 | |
| 61 | write_files: |
| 62 | - path: /etc/network/interfaces |
| 63 | content: | |
| 64 | auto ens3 |
| 65 | iface ens3 inet dhcp |
| 66 | |
| 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 |