Dennis Dmitriev | 75776c5 | 2017-12-26 18:22:53 +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 |
| 26 | output: |
| 27 | all: '| tee -a /var/log/cloud-init-output.log /dev/tty0' |
| 28 | |
| 29 | runcmd: |
| 30 | - rm /etc/resolv.conf |
| 31 | - touch /etc/resolv.conf |
| 32 | - export LOCAL_DNS_IP=$(ifconfig ens3 | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1) |
| 33 | - echo "nameserver $LOCAL_DNS_IP" >> /etc/resolv.conf; |
| 34 | - echo "nameserver 172.18.208.44" >> /etc/resolv.conf; |
| 35 | - echo "nameserver 8.8.8.8" >> /etc/resolv.conf; |
| 36 | - echo "supersede domain-name-servers $LOCAL_DNS_IP, 8.8.8.8, 172.18.208.44" >> /etc/dhcp/dhclient.conf |
| 37 | - export TERM=linux |
| 38 | - export LANG=C |
| 39 | |
| 40 | # Prepare network connection |
| 41 | - sudo ifup ens3 |
| 42 | #- sudo route add default gw {gateway} {interface_name} |
| 43 | - sudo ifup ens4 |
| 44 | - sudo ifup ens5 |
| 45 | - sudo ifup ens6 |
| 46 | |
| 47 | # Create swap |
| 48 | - fallocate -l 4G /swapfile |
| 49 | - chmod 600 /swapfile |
| 50 | - mkswap /swapfile |
| 51 | - swapon /swapfile |
| 52 | - echo "/swapfile none swap defaults 0 0" >> /etc/fstab |
| 53 | |
| 54 | |
| 55 | ############## Cloud repo01 node ################## |
| 56 | - which wget >/dev/null || (apt-get update; apt-get install -y wget); |
| 57 | - echo "deb [arch=amd64] http://apt.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt extra" > /etc/apt/sources.list.d/mcp_salt.list; |
| 58 | - wget -O - http://apt.mirantis.com/public.gpg | apt-key add -; |
| 59 | - echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main" > /etc/apt/sources.list.d/saltstack.list; |
| 60 | - wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub | apt-key add -; |
| 61 | |
| 62 | - eatmydata apt-get clean && apt-get update |
| 63 | |
| 64 | # Install common packages |
| 65 | - eatmydata apt-get install -y salt-minion python-pip git curl tmux byobu iputils-ping traceroute htop tree ntp; |
| 66 | - openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=gerrit.mcp.mirantis.local.test" -keyout /root/ssl-nginx.key -out /root/ssl-nginx.crt; |
| 67 | - cd /tmp; |
| 68 | - git clone https://github.com/TatyankaLeontovich/salt-formula-nginx; |
| 69 | - git clone https://github.com/TatyankaLeontovich/salt-dnsmasq; |
| 70 | - git clone https://github.com/TatyankaLeontovich/underpillar; |
| 71 | - mkdir -p /srv/pillar/; |
| 72 | - mkdir -p /srv/salt; |
| 73 | - cd /srv/salt; |
| 74 | - ln -s /tmp/salt-formula-nginx/nginx; |
| 75 | - ln -s /tmp/salt-dnsmasq/dnsmasq; |
| 76 | - cp /tmp/underpillar/pillar/*.sls /srv/pillar/; |
| 77 | - cp /tmp/underpillar/states/*.sls /srv/salt/; |
| 78 | - cp /srv/pillar/top_localdns.sls /srv/pillar/top.sls; |
| 79 | - cp /srv/salt/top_localdns.sls /srv/salt/top.sls; |
| 80 | - find /srv/pillar/ -type f -exec sed -i "s/==LOCAL_DNS_IP==/${LOCAL_DNS_IP}/g" {} + |
| 81 | - find /srv/pillar/ -type f -exec sed -i "s/==HOST_APT==/{{ os_env('HOST_APT', 'apt.mirantis.com') }}/g" {} + |
| 82 | - find /srv/pillar/ -type f -exec sed -i "s/==HOST_SALTSTACK==/{{ os_env('HOST_SALTSTACK', 'repo.saltstack.com') }}/g" {} + |
| 83 | - find /srv/pillar/ -type f -exec sed -i "s/==HOST_ARCHIVE_UBUNTU==/{{ os_env('HOST_ARCHIVE_UBUNTU', 'archive.ubuntu.com') }}/g" {} + |
| 84 | - find /srv/pillar/ -type f -exec sed -i "s/==HOST_MIRROR_MCP_MIRANTIS==/{{ os_env('HOST_MIRROR_MCP_MIRANTIS', 'mirror.mcp.mirantis.net') }}/g" {} + |
| 85 | - find /srv/pillar/ -type f -exec sed -i "s/==HOST_MIRROR_FUEL_INFRA==/{{ os_env('HOST_MIRROR_FUEL_INFRA', 'mirror.fuel-infra.org') }}/g" {} + |
| 86 | - find /srv/pillar/ -type f -exec sed -i "s/==HOST_PPA_LAUNCHPAD==/{{ os_env('HOST_PPA_LAUNCHPAD', 'ppa.launchpad.net') }}/g" {} + |
| 87 | - find /srv/pillar/ -type f -exec sed -i "s/==HOST_GERRIT_MCP_MIRANTIS==/{{ os_env('HOST_GERRIT_MCP_MIRANTIS', 'gerrit.mcp.mirantis.net') }}/g" {} + |
| 88 | - salt-call --local --state-output=mixed state.sls dnsmasq; |
| 89 | - salt-call --local --state-output=mixed state.sls nginx; |
| 90 | ######################################################## |
| 91 | # Node is ready, allow SSH access |
| 92 | - echo "Allow SSH access ..." |
| 93 | - sudo iptables -D INPUT -p tcp --dport 22 -j DROP |
| 94 | ######################################################## |
| 95 | |
| 96 | write_files: |
| 97 | - path: /etc/network/interfaces |
| 98 | content: | |
| 99 | auto ens3 |
| 100 | iface ens3 inet dhcp |
| 101 | auto ens4 |
| 102 | iface ens4 inet dhcp |
| 103 | auto ens5 |
| 104 | iface ens5 inet dhcp |
| 105 | auto ens6 |
| 106 | iface ens6 inet dhcp |
| 107 | |
| 108 | - path: /root/.ssh/config |
| 109 | owner: root:root |
| 110 | permissions: '0600' |
| 111 | content: | |
| 112 | Host * |
| 113 | ServerAliveInterval 300 |
| 114 | ServerAliveCountMax 10 |
| 115 | StrictHostKeyChecking no |
| 116 | UserKnownHostsFile /dev/null |