cloud-config.yml 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/bash
  2. # get the kernel and initrd
  3. URL_BASE="https://releases.rancher.com/os/latest"
  4. VMLINUX="vmlinuz"
  5. INITRD="initrd"
  6. cd /tmp
  7. curl -O -L "${URL_BASE}/${VMLINUX}"
  8. curl -O -L "${URL_BASE}/${INITRD}"
  9. # setup the host ready for kexec
  10. PUBLIC_IPV4=$(wget -qO- http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address)
  11. if [ "$(ros config get rancher.environment.installer)" == "true" ] && ros --version &>/dev/null; then
  12. cat > cloud-config.yml <<EOF
  13. #cloud-config
  14. rancher:
  15. network:
  16. interfaces:
  17. eth0:
  18. address: $(ip -4 addr show dev eth0 | awk "/${PUBLIC_IPV4}/ {print \$2}")
  19. gateway: $(ip -o route get 1 | awk '{print $3}')
  20. dhcp: false
  21. ssh_authorized_keys:
  22. EOF
  23. while read -r KEY; do
  24. echo " - ${KEY}" >> cloud-config.yml
  25. done < <(wget -qO- http://169.254.169.254/metadata/v1/public-keys; echo)
  26. yes | ros install -c cloud-config.yml -d /dev/vda
  27. exit 0
  28. fi
  29. export DEBIAN_FRONTEND=noninteractive
  30. apt-get update && apt-get install -y kexec-tools ipcalc
  31. PUBLIC_IPV4_NETMASK=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/netmask)
  32. PUBLIC_IPV4_CIDR=$(ipcalc ${PUBLIC_IPV4}/${PUBLIC_IPV4_NETMASK} | awk '/^Network/ {n=split($2, i, "/"); print i[2]};')
  33. PUBLIC_IPV4_GATEWAY=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/gateway)
  34. kexec --initrd=${INITRD} -l ${VMLINUX} -f --command-line="quiet rancher.network.interfaces.eth0.address=${PUBLIC_IPV4}/${PUBLIC_IPV4_CIDR} rancher.network.interfaces.eth0.gateway=${PUBLIC_IPV4_GATEWAY} rancher.network.interfaces.eth0.dhcp=false rancher.cloud_init.datasources=[digitalocean] rancher.environment.installer=true"