cloud-config.yml 1.5 KB

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