blob: 3f4c1a2bf5c79e3e8187f5adbd4aaeaa1e92dbcf [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;
Dennis Dmitrievd86ffa12018-03-15 22:07:51 +020042 - echo "supersede domain-name-servers $LOCAL_DNS_IP, 172.18.208.44" >> /etc/dhcp/dhclient.conf
Tatyana Leontovich4885f792017-09-25 15:16:27 +030043 - export TERM=linux
44 - export LANG=C
Tatyana Leontovich4885f792017-09-25 15:16:27 +030045
Tatyana Leontovich4885f792017-09-25 15:16:27 +030046
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 ##################
Tatyana Leontovich4885f792017-09-25 15:16:27 +030056 - which wget >/dev/null || (apt-get update; apt-get install -y wget);
Tatyana Leontovich4885f792017-09-25 15:16:27 +030057 - 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 -;
Tatyana Leontovich14e201d2018-07-05 13:28:54 +030059 - echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2017.7 xenial main" > /etc/apt/sources.list.d/saltstack.list;
60 - wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2017.7/SALTSTACK-GPG-KEY.pub | apt-key add -;
Tatyana Leontovich4885f792017-09-25 15:16:27 +030061
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;
Tatyana Leontovichecd491d2017-09-13 13:51:12 +030066 - 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 +030067 - 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;
Tatyana Leontovichd2996e52017-10-03 14:19:40 +030080 - find /srv/pillar/ -type f -exec sed -i "s/==LOCAL_DNS_IP==/${LOCAL_DNS_IP}/g" {} +
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020081 - 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" {} +
Dennis Dmitriev0f272312018-10-01 13:29:40 +030087 - find /srv/pillar/ -type f -exec sed -i "s/==HOST_GERRIT_MCP_MIRANTIS==/{{ os_env('HOST_GERRIT_MCP_MIRANTIS', 'gerrit.mcp.mirantis.com') }}/g" {} +
Tatyana Leontovich4885f792017-09-25 15:16:27 +030088 - 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
Tatyana Leontovichecd491d2017-09-13 13:51:12 +0300103 auto ens5
104 iface ens5 inet dhcp
105 auto ens6
106 iface ens6 inet dhcp
Tatyana Leontovich4885f792017-09-25 15:16:27 +0300107
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