blob: 77c18d162c3de2f56c7036dd85740ac9765ea5cd [file] [log] [blame]
Dennis Dmitriev0f624a82018-06-11 12:57:13 +03001| # 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
64 - set -x; cd /root/config-drive && /bin/bash -xe ./user-data
65
66 #- echo "nameserver 172.18.208.44" >> /etc/resolv.conf;
67
68 # Enable root access (after reboot)
69 - sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin yes/' /etc/ssh/sshd_config
70 #- service sshd stop
71
72 ########################################################
73 # Node is ready, allow SSH access
74 - touch /is_cloud_init_finished
75 #- reboot
76 ########################################################
77
78 write_files:
79 - path: /etc/default/grub.d/97-enable-grub-menu.cfg
80 content: |
81 GRUB_RECORDFAIL_TIMEOUT=30
82 GRUB_TIMEOUT=3
83 GRUB_TIMEOUT_STYLE=menu
84
85 #- path: /etc/network/interfaces
86 - path: /root/interfaces
87 content: |
88 auto lo
89 iface lo inet loopback
90
91 auto ens3
92 iface ens3 inet dhcp
93
94 - path: /root/.ssh/config
95 owner: root:root
96 permissions: '0600'
97 content: |
98 Host *
99 ServerAliveInterval 60
100 ServerAliveCountMax 0
101 StrictHostKeyChecking no
102 UserKnownHostsFile /dev/null