Dennis Dmitriev | 8555996 | 2018-01-30 15:35:51 +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 |
Dennis Dmitriev | f4e6efc | 2018-03-26 06:15:10 -0500 | [diff] [blame] | 26 | |
Dennis Dmitriev | 8555996 | 2018-01-30 15:35:51 +0200 | [diff] [blame] | 27 | output: |
| 28 | all: '| tee -a /var/log/cloud-init-output.log /dev/tty0' |
| 29 | |
| 30 | runcmd: |
| 31 | # Prepare network connection |
| 32 | - sudo ifdown ens3 |
Dennis Dmitriev | f4e6efc | 2018-03-26 06:15:10 -0500 | [diff] [blame] | 33 | #- sudo ifup ens3 |
Dennis Dmitriev | 8555996 | 2018-01-30 15:35:51 +0200 | [diff] [blame] | 34 | #- sudo route add default gw {gateway} {interface_name} |
| 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 | # Create swap |
| 44 | #- fallocate -l 16G /swapfile |
| 45 | #- chmod 600 /swapfile |
| 46 | #- mkswap /swapfile |
| 47 | #- swapon /swapfile |
| 48 | #- echo "/swapfile none swap defaults 0 0" >> /etc/fstab |
| 49 | |
| 50 | ############## TCP Cloud cfg01 node ################## |
| 51 | - echo "Preparing base OS" |
| 52 | |
| 53 | - echo "nameserver 172.18.208.44" >> /etc/resolv.conf; |
Dennis Dmitriev | 8555996 | 2018-01-30 15:35:51 +0200 | [diff] [blame] | 54 | |
| 55 | - apt-get clean |
| 56 | - apt-get update |
| 57 | |
| 58 | # Ensure that the salt-master service is ready to receive requests |
| 59 | - salt-key -y -D |
| 60 | - service salt-master restart |
| 61 | - service salt-minion restart |
Dennis Dmitriev | 1d3472e | 2018-02-16 22:04:19 +0200 | [diff] [blame] | 62 | - apt-get install -y salt-formula-* |
Dennis Dmitriev | adef095 | 2018-02-17 17:17:02 +0200 | [diff] [blame] | 63 | - for f in $(ls -1 /usr/share/salt-formulas/reclass/service); do ln -s /usr/share/salt-formulas/reclass/service/$f /srv/salt/reclass/classes/service/ || true; done |
Dennis Dmitriev | 8555996 | 2018-01-30 15:35:51 +0200 | [diff] [blame] | 64 | - salt-call --timeout=180 test.ping |
| 65 | |
| 66 | ######################################################## |
| 67 | # Node is ready, allow SSH access |
| 68 | - echo "Allow SSH access ..." |
| 69 | - sudo iptables -D INPUT -p tcp --dport 22 -j DROP |
| 70 | ######################################################## |
| 71 | |
Dennis Dmitriev | f4e6efc | 2018-03-26 06:15:10 -0500 | [diff] [blame] | 72 | # Purge the unattended-upgrades package (Workaround for PROD-17904, PROD-18736)" |
| 73 | - echo "APT::Periodic::Update-Package-Lists 0;" > /etc/apt/apt.conf.d/99dont_update_package_list-salt |
| 74 | - echo "APT::Periodic::Download-Upgradeable-Packages 0;" > /etc/apt/apt.conf.d/99dont_update_download_upg_packages-salt |
| 75 | - echo "APT::Periodic::Unattended-Upgrade 0;" > /etc/apt/apt.conf.d/99disable_unattended_upgrade-salt |
| 76 | - apt-get -y purge unattended-upgrades |
| 77 | - reboot |
| 78 | |
Dennis Dmitriev | 8555996 | 2018-01-30 15:35:51 +0200 | [diff] [blame] | 79 | write_files: |
| 80 | - path: /etc/default/grub.d/97-enable-grub-menu.cfg |
| 81 | content: | |
| 82 | GRUB_RECORDFAIL_TIMEOUT=30 |
| 83 | GRUB_TIMEOUT=3 |
| 84 | GRUB_TIMEOUT_STYLE=menu |
| 85 | |
| 86 | - path: /etc/network/interfaces |
| 87 | content: | |
| 88 | auto ens3 |
| 89 | iface ens3 inet dhcp |
| 90 | |
| 91 | - path: /root/.ssh/config |
| 92 | owner: root:root |
| 93 | permissions: '0600' |
| 94 | content: | |
| 95 | Host * |
| 96 | ServerAliveInterval 300 |
| 97 | ServerAliveCountMax 10 |
| 98 | StrictHostKeyChecking no |
| 99 | UserKnownHostsFile /dev/null |
| 100 | |
| 101 | # Fix hardcoded IP address in the minion.conf |
| 102 | - path: /etc/salt/minion.d/minion.conf |
| 103 | content: | |
| 104 | master: 127.0.0.1 |
| 105 | id: cfg01.{{ DOMAIN_NAME }} |