blob: 377713ce44d6a815739e27d64aa51a21d90b7a92 [file] [log] [blame]
Dennis Dmitriev7b9538f2017-05-15 17:01:34 +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:
Artem Panchenkodb0a97f2017-06-27 19:09:13 +030010 {% for key in config.underlay.ssh_keys %}
11 - ssh-rsa {{ key['public'] }}
12 {% endfor %}
Dennis Dmitriev7b9538f2017-05-15 17:01:34 +030013
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 # Configure dhclient
31 - sudo echo "nameserver {gateway}" >> /etc/resolvconf/resolv.conf.d/base
32 - sudo resolvconf -u
33
34 # Prepare network connection
35 - sudo ifup ens3
36 #- sudo route add default gw {gateway} {interface_name}
37 - sudo ifup ens4
38
39 # Create swap
40 - fallocate -l 4G /swapfile
41 - chmod 600 /swapfile
42 - mkswap /swapfile
43 - swapon /swapfile
44 - echo "/swapfile none swap defaults 0 0" >> /etc/fstab
45
46 ############## TCP Cloud cfg01 node ##################
47 #- sleep 120
48 - echo "Preparing base OS"
49
50 - echo "172.18.248.114 jenkins.mcp.mirantis.net gerrit.mcp.mirantis.net" >> /etc/hosts;
51 - echo "185.135.196.10 apt-mk.mirantis.com" >> /etc/hosts;
Dennis Dmitriev80fe32d2017-06-02 13:47:35 +030052 - echo "nameserver 172.18.208.44" >> /etc/resolv.conf;
53 - echo "nameserver 8.8.8.8" >> /etc/resolv.conf;
Dennis Dmitriev7b9538f2017-05-15 17:01:34 +030054 - which wget >/dev/null || (apt-get update; apt-get install -y wget);
Dennis Dmitriev620e26d2017-05-25 18:28:44 +030055 - apt-get install -y ntp
Dennis Dmitriev7b9538f2017-05-15 17:01:34 +030056
57 - export IRONIC_PXE_MANAGER=dnsmasq
58 - export IRONIC_PXE_INTERFACE_NAME=ens4
Dennis Dmitrievcacce7d2017-05-26 22:28:22 +030059 - export IRONIC_PXE_INTERFACE_ADDRESS={{ os_env('IRONIC_PXE_INTERFACE_ADDRESS', '10.0.175.2') }}
Dennis Dmitriev6dd3db72017-05-26 22:32:18 +030060 - export IRONIC_DHCP_POOL_NETMASK={{ os_env('IRONIC_DHCP_POOL_NETMASK', '255.255.255.0') }}
61 - export IRONIC_DHCP_POOL_NETMASK_PREFIX={{ os_env('IRONIC_DHCP_POOL_NETMASK_PREFIX', '24') }}
Dennis Dmitrievcacce7d2017-05-26 22:28:22 +030062 - export IRONIC_DHCP_POOL_START={{ os_env('IRONIC_DHCP_POOL_START', '10.0.175.100') }}
63 - export IRONIC_DHCP_POOL_END={{ os_env('IRONIC_DHCP_POOL_END', '10.0.175.200') }}
Dennis Dmitriev7b9538f2017-05-15 17:01:34 +030064 - export DNSMASQ_USE_EXTERNAL_DNS=true
65 - ip a a $IRONIC_PXE_INTERFACE_ADDRESS/$IRONIC_DHCP_POOL_NETMASK_PREFIX dev $IRONIC_PXE_INTERFACE_NAME
66 - curl https://raw.githubusercontent.com/dis-xcom/underpillar/master/bootstrap.sh -o ./bootstrap.sh && bash ./bootstrap.sh
67
Dennis Dmitriev80fe32d2017-06-02 13:47:35 +030068 # Disable dnsmasq in favour to external DHCP provider
69 #- systemctl disable dnsmasq
70 # - service dnsmasq stop
71
72 {%- if os_env('IRONIC_DNSMASQ_HOSTFILE', '') %}
73 - echo "dhcp-hostsfile=/var/lib/libvirt/dnsmasq/{{ IRONIC_ENV_NAME }}.hostsfile" >> /etc/dnsmasq.conf
74 - service dnsmasq restart
75 {%- endif %}
76
77 # Enable SNAT to allow internet access for deploying nodes using ironic node as a gateway
78 - iptables -t nat -A POSTROUTING -s {{ os_env('IRONIC_DHCP_POOL_START', '10.0.175.100') }}/{{ os_env('IRONIC_DHCP_POOL_NETMASK_PREFIX', '24') }} ! -d {{ os_env('IRONIC_DHCP_POOL_START', '10.0.175.100') }}/{{ os_env('IRONIC_DHCP_POOL_NETMASK_PREFIX', '24') }} -j MASQUERADE
79
Dennis Dmitriev7b9538f2017-05-15 17:01:34 +030080 - echo "Building ironic agent image (stable/newton) ..."
81 - apt-get install -y docker.io gzip uuid-runtime cpio findutils grep gnupg make
82 - service docker start
83 - git clone https://git.openstack.org/openstack/ironic-python-agent /tmp/ironic-python-agent
84 - cd /tmp/ironic-python-agent/imagebuild/coreos; git checkout stable/newton; make
85 - cp /tmp/ironic-python-agent/imagebuild/coreos/UPLOAD/coreos_production_pxe_image-oem.cpio.gz /httpboot/
86 - cp /tmp/ironic-python-agent/imagebuild/coreos/UPLOAD/coreos_production_pxe.vmlinuz /httpboot/
87 - chmod a+r /httpboot/coreos_production_pxe*
88
89 - echo "Download ubuntu cloudinit image"
90 - wget https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img -O /httpboot/xenial-server-cloudimg-amd64.qcow2
91
92 ########################################################
93 # Node is ready, allow SSH access
94 - echo "Allow SSH access ..."
95 - sudo iptables -D INPUT -p tcp --dport 22 -j DROP
96 ########################################################
97
98 write_files:
99 - path: /etc/network/interfaces
100 content: |
101 auto ens3
102 iface ens3 inet dhcp
103 auto ens4
104 iface ens4 inet manual
105
Dennis Dmitriev7b9538f2017-05-15 17:01:34 +0300106 - path: /root/.ssh/config
107 owner: root:root
108 permissions: '0600'
109 content: |
110 Host *
111 ServerAliveInterval 300
112 ServerAliveCountMax 10
113 StrictHostKeyChecking no
114 UserKnownHostsFile /dev/null
Dennis Dmitriev80fe32d2017-06-02 13:47:35 +0300115
116 {%- if os_env('IRONIC_DNSMASQ_HOSTFILE', '') %}
117 - path: /var/lib/libvirt/dnsmasq/{{ IRONIC_ENV_NAME }}.hostsfile
118 permissions: '0644'
119 content: |
120 {%- for host in os_env('IRONIC_DNSMASQ_HOSTFILE').splitlines() %}
121 {{ host }}
122 {%- endfor %}
123 {%- endif %}