blob: fc3d2844133bd1b4542b828659619623d8617d94 [file] [log] [blame]
Tatyana Leontovich4885f792017-09-25 15:16:27 +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 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:
Dennis Dmitrieved3f4be2018-01-29 17:42:16 +020030 # Prepare network connection
31 - sudo ifup ens3
32 #- sudo route add default gw {gateway} {interface_name}
33 - sudo ifup ens4
34 - sudo ifup ens5
35 - sudo ifup ens6
36
Tatyana Leontovichecd491d2017-09-13 13:51:12 +030037 - rm /etc/resolv.conf
38 - touch /etc/resolv.conf
39 - export LOCAL_DNS_IP=$(ifconfig ens3 | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1)
40 - echo "nameserver $LOCAL_DNS_IP" >> /etc/resolv.conf;
41 - echo "nameserver 172.18.208.44" >> /etc/resolv.conf;
42 - echo "nameserver 8.8.8.8" >> /etc/resolv.conf;
43 - echo "supersede domain-name-servers $LOCAL_DNS_IP, 8.8.8.8, 172.18.208.44" >> /etc/dhcp/dhclient.conf
Tatyana Leontovich4885f792017-09-25 15:16:27 +030044 - export TERM=linux
45 - export LANG=C
Tatyana Leontovich4885f792017-09-25 15:16:27 +030046
Tatyana Leontovich4885f792017-09-25 15:16:27 +030047
48 # Create swap
49 - fallocate -l 4G /swapfile
50 - chmod 600 /swapfile
51 - mkswap /swapfile
52 - swapon /swapfile
53 - echo "/swapfile none swap defaults 0 0" >> /etc/fstab
54
55
56 ############## Cloud repo01 node ##################
Tatyana Leontovich4885f792017-09-25 15:16:27 +030057 - which wget >/dev/null || (apt-get update; apt-get install -y wget);
Tatyana Leontovich4885f792017-09-25 15:16:27 +030058 - echo "deb [arch=amd64] http://apt.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt extra" > /etc/apt/sources.list.d/mcp_salt.list;
59 - wget -O - http://apt.mirantis.com/public.gpg | apt-key add -;
60 - echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main" > /etc/apt/sources.list.d/saltstack.list;
61 - wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub | apt-key add -;
62
63 - eatmydata apt-get clean && apt-get update
64
65 # Install common packages
66 - eatmydata apt-get install -y salt-minion python-pip git curl tmux byobu iputils-ping traceroute htop tree;
Tatyana Leontovichecd491d2017-09-13 13:51:12 +030067 - 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;
Tatyana Leontovich4885f792017-09-25 15:16:27 +030068 - cd /tmp;
69 - git clone https://github.com/TatyankaLeontovich/salt-formula-nginx;
70 - git clone https://github.com/TatyankaLeontovich/salt-dnsmasq;
71 - git clone https://github.com/TatyankaLeontovich/underpillar;
72 - mkdir -p /srv/pillar/;
73 - mkdir -p /srv/salt;
74 - cd /srv/salt;
75 - ln -s /tmp/salt-formula-nginx/nginx;
76 - ln -s /tmp/salt-dnsmasq/dnsmasq;
77 - cp /tmp/underpillar/pillar/*.sls /srv/pillar/;
78 - cp /tmp/underpillar/states/*.sls /srv/salt/;
79 - cp /srv/pillar/top_localdns.sls /srv/pillar/top.sls;
80 - cp /srv/salt/top_localdns.sls /srv/salt/top.sls;
Tatyana Leontovichd2996e52017-10-03 14:19:40 +030081 - find /srv/pillar/ -type f -exec sed -i "s/==LOCAL_DNS_IP==/${LOCAL_DNS_IP}/g" {} +
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020082 - find /srv/pillar/ -type f -exec sed -i "s/==HOST_APT==/{{ os_env('HOST_APT', 'apt.mirantis.com') }}/g" {} +
83 - find /srv/pillar/ -type f -exec sed -i "s/==HOST_SALTSTACK==/{{ os_env('HOST_SALTSTACK', 'repo.saltstack.com') }}/g" {} +
84 - find /srv/pillar/ -type f -exec sed -i "s/==HOST_ARCHIVE_UBUNTU==/{{ os_env('HOST_ARCHIVE_UBUNTU', 'archive.ubuntu.com') }}/g" {} +
85 - find /srv/pillar/ -type f -exec sed -i "s/==HOST_MIRROR_MCP_MIRANTIS==/{{ os_env('HOST_MIRROR_MCP_MIRANTIS', 'mirror.mcp.mirantis.net') }}/g" {} +
86 - find /srv/pillar/ -type f -exec sed -i "s/==HOST_MIRROR_FUEL_INFRA==/{{ os_env('HOST_MIRROR_FUEL_INFRA', 'mirror.fuel-infra.org') }}/g" {} +
87 - find /srv/pillar/ -type f -exec sed -i "s/==HOST_PPA_LAUNCHPAD==/{{ os_env('HOST_PPA_LAUNCHPAD', 'ppa.launchpad.net') }}/g" {} +
88 - find /srv/pillar/ -type f -exec sed -i "s/==HOST_GERRIT_MCP_MIRANTIS==/{{ os_env('HOST_GERRIT_MCP_MIRANTIS', 'gerrit.mcp.mirantis.net') }}/g" {} +
Tatyana Leontovich4885f792017-09-25 15:16:27 +030089 - salt-call --local --state-output=mixed state.sls dnsmasq;
90 - salt-call --local --state-output=mixed state.sls nginx;
91 ########################################################
92 # Node is ready, allow SSH access
93 - echo "Allow SSH access ..."
94 - sudo iptables -D INPUT -p tcp --dport 22 -j DROP
95 ########################################################
96
97 write_files:
98 - path: /etc/network/interfaces
99 content: |
100 auto ens3
101 iface ens3 inet dhcp
102 auto ens4
103 iface ens4 inet dhcp
Tatyana Leontovichecd491d2017-09-13 13:51:12 +0300104 auto ens5
105 iface ens5 inet dhcp
106 auto ens6
107 iface ens6 inet dhcp
Tatyana Leontovich4885f792017-09-25 15:16:27 +0300108
109 - path: /root/.ssh/config
110 owner: root:root
111 permissions: '0600'
112 content: |
113 Host *
114 ServerAliveInterval 300
115 ServerAliveCountMax 10
116 StrictHostKeyChecking no
117 UserKnownHostsFile /dev/null