| Dennis Dmitriev | 7b9538f | 2017-05-15 17:01:34 +0300 | [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: | 
| Artem Panchenko | db0a97f | 2017-06-27 19:09:13 +0300 | [diff] [blame] | 10 | {% for key in config.underlay.ssh_keys %} | 
|  | 11 | - ssh-rsa {{ key['public'] }} | 
|  | 12 | {% endfor %} | 
| Dennis Dmitriev | 7b9538f | 2017-05-15 17:01:34 +0300 | [diff] [blame] | 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 | # 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 |  | 
| Vladimir Khlyunev | ec6e805 | 2022-03-10 16:48:53 +0400 | [diff] [blame] | 50 | - echo "nameserver 172.18.176.6" >> /etc/resolv.conf; | 
| Dennis Dmitriev | ea7ee49 | 2017-07-14 20:16:07 +0300 | [diff] [blame] | 51 | - apt-get update | 
| Dennis Dmitriev | 7b9538f | 2017-05-15 17:01:34 +0300 | [diff] [blame] | 52 | - which wget >/dev/null || (apt-get update; apt-get install -y wget); | 
| Dennis Dmitriev | 620e26d | 2017-05-25 18:28:44 +0300 | [diff] [blame] | 53 | - apt-get install -y ntp | 
| Dennis Dmitriev | 7b9538f | 2017-05-15 17:01:34 +0300 | [diff] [blame] | 54 |  | 
| sgudz | 67f6fd4 | 2017-10-26 16:08:03 +0300 | [diff] [blame] | 55 | #Installing mysql before running formula for correct mysql status | 
|  | 56 | - DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server-5.7 python-mysqldb debconf-utils | 
|  | 57 |  | 
| Dennis Dmitriev | 7b9538f | 2017-05-15 17:01:34 +0300 | [diff] [blame] | 58 | - export IRONIC_PXE_MANAGER=dnsmasq | 
|  | 59 | - export IRONIC_PXE_INTERFACE_NAME=ens4 | 
| Dennis Dmitriev | cacce7d | 2017-05-26 22:28:22 +0300 | [diff] [blame] | 60 | - export IRONIC_PXE_INTERFACE_ADDRESS={{ os_env('IRONIC_PXE_INTERFACE_ADDRESS', '10.0.175.2') }} | 
| Dennis Dmitriev | 6dd3db7 | 2017-05-26 22:32:18 +0300 | [diff] [blame] | 61 | - export IRONIC_DHCP_POOL_NETMASK={{ os_env('IRONIC_DHCP_POOL_NETMASK', '255.255.255.0') }} | 
|  | 62 | - export IRONIC_DHCP_POOL_NETMASK_PREFIX={{ os_env('IRONIC_DHCP_POOL_NETMASK_PREFIX', '24') }} | 
| Dennis Dmitriev | cacce7d | 2017-05-26 22:28:22 +0300 | [diff] [blame] | 63 | - export IRONIC_DHCP_POOL_START={{ os_env('IRONIC_DHCP_POOL_START', '10.0.175.100') }} | 
|  | 64 | - export IRONIC_DHCP_POOL_END={{ os_env('IRONIC_DHCP_POOL_END', '10.0.175.200') }} | 
| Dennis Dmitriev | 7b9538f | 2017-05-15 17:01:34 +0300 | [diff] [blame] | 65 | - export DNSMASQ_USE_EXTERNAL_DNS=true | 
|  | 66 | - ip a a $IRONIC_PXE_INTERFACE_ADDRESS/$IRONIC_DHCP_POOL_NETMASK_PREFIX dev $IRONIC_PXE_INTERFACE_NAME | 
| Oleksii Butenko | ade9c6c | 2018-03-05 15:16:40 +0200 | [diff] [blame] | 67 | - curl https://raw.githubusercontent.com/obutenko/temp/master/bootstrap.sh -o ./bootstrap.sh && bash ./bootstrap.sh | 
| Dennis Dmitriev | 7b9538f | 2017-05-15 17:01:34 +0300 | [diff] [blame] | 68 |  | 
| Dennis Dmitriev | 80fe32d | 2017-06-02 13:47:35 +0300 | [diff] [blame] | 69 | # Disable dnsmasq in favour to external DHCP provider | 
|  | 70 | #- systemctl disable dnsmasq | 
|  | 71 | # - service dnsmasq stop | 
|  | 72 |  | 
|  | 73 | {%- if os_env('IRONIC_DNSMASQ_HOSTFILE', '') %} | 
|  | 74 | - echo "dhcp-hostsfile=/var/lib/libvirt/dnsmasq/{{ IRONIC_ENV_NAME }}.hostsfile" >> /etc/dnsmasq.conf | 
| sgudz | 4ec2696 | 2018-11-19 19:17:13 +0200 | [diff] [blame] | 75 | - service dnsmasq restart && sleep 30 | 
| Dennis Dmitriev | 80fe32d | 2017-06-02 13:47:35 +0300 | [diff] [blame] | 76 | {%- endif %} | 
|  | 77 |  | 
|  | 78 | # Enable SNAT to allow internet access for deploying nodes using ironic node as a gateway | 
| sgudz | a115b30 | 2018-03-06 14:10:56 +0200 | [diff] [blame] | 79 | - iptables -t nat -I 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 | 
|  | 80 | - iptables -I FORWARD -j ACCEPT | 
| Dennis Dmitriev | 80fe32d | 2017-06-02 13:47:35 +0300 | [diff] [blame] | 81 |  | 
| Dennis Dmitriev | 7b9538f | 2017-05-15 17:01:34 +0300 | [diff] [blame] | 82 | - echo "Building ironic agent image (stable/newton) ..." | 
|  | 83 | - apt-get install -y docker.io gzip uuid-runtime cpio findutils grep gnupg make | 
|  | 84 | - service docker start | 
|  | 85 | - git clone https://git.openstack.org/openstack/ironic-python-agent /tmp/ironic-python-agent | 
| Dennis Dmitriev | 03d05e7 | 2018-05-02 20:03:50 +0300 | [diff] [blame] | 86 | - cd /tmp/ironic-python-agent/imagebuild/coreos; git checkout newton-eol; make | 
| Dennis Dmitriev | 7b9538f | 2017-05-15 17:01:34 +0300 | [diff] [blame] | 87 | - cp /tmp/ironic-python-agent/imagebuild/coreos/UPLOAD/coreos_production_pxe_image-oem.cpio.gz /httpboot/ | 
|  | 88 | - cp /tmp/ironic-python-agent/imagebuild/coreos/UPLOAD/coreos_production_pxe.vmlinuz /httpboot/ | 
|  | 89 | - chmod a+r /httpboot/coreos_production_pxe* | 
|  | 90 |  | 
|  | 91 | - echo "Download ubuntu cloudinit image" | 
| sgudz | 839d2ce | 2018-02-08 18:23:03 +0200 | [diff] [blame] | 92 | - wget {{ os_env('IMAGE_URL1604', 'https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img') }} -O /httpboot/xenial-server-cloudimg-amd64.qcow2 | 
| Dennis Dmitriev | 7b9538f | 2017-05-15 17:01:34 +0300 | [diff] [blame] | 93 |  | 
|  | 94 | ######################################################## | 
|  | 95 | # Node is ready, allow SSH access | 
|  | 96 | - echo "Allow SSH access ..." | 
|  | 97 | - sudo iptables -D INPUT -p tcp --dport 22 -j DROP | 
|  | 98 | ######################################################## | 
|  | 99 |  | 
|  | 100 | write_files: | 
|  | 101 | - path: /etc/network/interfaces | 
|  | 102 | content: | | 
|  | 103 | auto ens3 | 
|  | 104 | iface ens3 inet dhcp | 
|  | 105 | auto ens4 | 
|  | 106 | iface ens4 inet manual | 
|  | 107 |  | 
| Dennis Dmitriev | 7b9538f | 2017-05-15 17:01:34 +0300 | [diff] [blame] | 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 | 
| Dennis Dmitriev | 80fe32d | 2017-06-02 13:47:35 +0300 | [diff] [blame] | 117 |  | 
|  | 118 | {%- if os_env('IRONIC_DNSMASQ_HOSTFILE', '') %} | 
|  | 119 | - path: /var/lib/libvirt/dnsmasq/{{ IRONIC_ENV_NAME }}.hostsfile | 
|  | 120 | permissions: '0644' | 
|  | 121 | content: | | 
|  | 122 | {%- for host in os_env('IRONIC_DNSMASQ_HOSTFILE').splitlines() %} | 
|  | 123 | {{ host }} | 
|  | 124 | {%- endfor %} | 
|  | 125 | {%- endif %} |