| # All the data below will be stored as a string object | |
#cloud-config, see http://cloudinit.readthedocs.io/en/latest/topics/examples.html | |
ssh_pwauth: True | |
users: | |
- name: root | |
sudo: ALL=(ALL) NOPASSWD:ALL | |
shell: /bin/bash | |
ssh_authorized_keys: | |
{% for key in config.underlay.ssh_keys %} | |
- ssh-rsa {{ key['public'] }} | |
{% endfor %} | |
disable_root: false | |
chpasswd: | |
list: | | |
root:r00tme | |
expire: False | |
bootcmd: | |
# Block access to SSH while node is preparing | |
- cloud-init-per once sudo iptables -A INPUT -p tcp --dport 22 -j DROP | |
# Enable root access | |
- sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin yes/' /etc/ssh/sshd_config | |
- service sshd restart | |
output: | |
all: '| tee -a /var/log/cloud-init-output.log /dev/tty0' | |
runcmd: | |
# Configure dhclient | |
- sudo echo "nameserver {gateway}" >> /etc/resolvconf/resolv.conf.d/base | |
- sudo resolvconf -u | |
# Prepare network connection | |
- sudo ifup ens3 | |
#- sudo route add default gw {gateway} {interface_name} | |
- sudo ifup ens4 | |
# Create swap | |
- fallocate -l 4G /swapfile | |
- chmod 600 /swapfile | |
- mkswap /swapfile | |
- swapon /swapfile | |
- echo "/swapfile none swap defaults 0 0" >> /etc/fstab | |
############## TCP Cloud cfg01 node ################## | |
#- sleep 120 | |
- echo "Preparing base OS" | |
- echo "nameserver 172.18.208.44" >> /etc/resolv.conf; | |
- echo "nameserver 8.8.8.8" >> /etc/resolv.conf; | |
- apt-get update | |
- which wget >/dev/null || (apt-get update; apt-get install -y wget); | |
- apt-get install -y ntp | |
#Installing mysql before running formula for correct mysql status | |
- DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server-5.7 python-mysqldb debconf-utils | |
- export IRONIC_PXE_MANAGER=dnsmasq | |
- export IRONIC_PXE_INTERFACE_NAME=ens4 | |
- export IRONIC_PXE_INTERFACE_ADDRESS={{ os_env('IRONIC_PXE_INTERFACE_ADDRESS', '10.0.175.2') }} | |
- export IRONIC_DHCP_POOL_NETMASK={{ os_env('IRONIC_DHCP_POOL_NETMASK', '255.255.255.0') }} | |
- export IRONIC_DHCP_POOL_NETMASK_PREFIX={{ os_env('IRONIC_DHCP_POOL_NETMASK_PREFIX', '24') }} | |
- export IRONIC_DHCP_POOL_START={{ os_env('IRONIC_DHCP_POOL_START', '10.0.175.100') }} | |
- export IRONIC_DHCP_POOL_END={{ os_env('IRONIC_DHCP_POOL_END', '10.0.175.200') }} | |
- export DNSMASQ_USE_EXTERNAL_DNS=true | |
- ip a a $IRONIC_PXE_INTERFACE_ADDRESS/$IRONIC_DHCP_POOL_NETMASK_PREFIX dev $IRONIC_PXE_INTERFACE_NAME | |
- curl https://raw.githubusercontent.com/dis-xcom/underpillar/master/bootstrap.sh -o ./bootstrap.sh && bash ./bootstrap.sh | |
# Disable dnsmasq in favour to external DHCP provider | |
#- systemctl disable dnsmasq | |
# - service dnsmasq stop | |
{%- if os_env('IRONIC_DNSMASQ_HOSTFILE', '') %} | |
- echo "dhcp-hostsfile=/var/lib/libvirt/dnsmasq/{{ IRONIC_ENV_NAME }}.hostsfile" >> /etc/dnsmasq.conf | |
- service dnsmasq restart | |
{%- endif %} | |
# Enable SNAT to allow internet access for deploying nodes using ironic node as a gateway | |
- 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 | |
- echo "Building ironic agent image (stable/newton) ..." | |
- apt-get install -y docker.io gzip uuid-runtime cpio findutils grep gnupg make | |
- service docker start | |
- git clone https://git.openstack.org/openstack/ironic-python-agent /tmp/ironic-python-agent | |
- cd /tmp/ironic-python-agent/imagebuild/coreos; git checkout stable/newton; make | |
- cp /tmp/ironic-python-agent/imagebuild/coreos/UPLOAD/coreos_production_pxe_image-oem.cpio.gz /httpboot/ | |
- cp /tmp/ironic-python-agent/imagebuild/coreos/UPLOAD/coreos_production_pxe.vmlinuz /httpboot/ | |
- chmod a+r /httpboot/coreos_production_pxe* | |
- echo "Download ubuntu cloudinit image" | |
- 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 | |
######################################################## | |
# Node is ready, allow SSH access | |
- echo "Allow SSH access ..." | |
- sudo iptables -D INPUT -p tcp --dport 22 -j DROP | |
######################################################## | |
write_files: | |
- path: /etc/network/interfaces | |
content: | | |
auto ens3 | |
iface ens3 inet dhcp | |
auto ens4 | |
iface ens4 inet manual | |
- path: /root/.ssh/config | |
owner: root:root | |
permissions: '0600' | |
content: | | |
Host * | |
ServerAliveInterval 300 | |
ServerAliveCountMax 10 | |
StrictHostKeyChecking no | |
UserKnownHostsFile /dev/null | |
{%- if os_env('IRONIC_DNSMASQ_HOSTFILE', '') %} | |
- path: /var/lib/libvirt/dnsmasq/{{ IRONIC_ENV_NAME }}.hostsfile | |
permissions: '0644' | |
content: | | |
{%- for host in os_env('IRONIC_DNSMASQ_HOSTFILE').splitlines() %} | |
{{ host }} | |
{%- endfor %} | |
{%- endif %} |