Skip to content

Instantly share code, notes, and snippets.

@darkmuggle
Created September 10, 2015 15:15
Show Gist options
  • Save darkmuggle/7399da305b3725d0a5f7 to your computer and use it in GitHub Desktop.
Save darkmuggle/7399da305b3725d0a5f7 to your computer and use it in GitHub Desktop.
Example of Cloud-init Vendor data to conditionally write a per-distro mirror configuration.
#cloud-boothook
#!/bin/sh
# Make sure that we can determine if this Ubuntu or Debian
lsbrelease="/usr/bin/lsb_release"
if [ ! -e "${lsbrelease}" ]; then
exit 0
fi
# Find out if this Ubuntu
distro=$(lsb_release -i -s)
if [ "${distro}" != "Ubuntu" ]; then
exit 0
fi
# Write a cloud-config
cat > /etc/cloud/cloud.cfg.d/99-configure-mirror.cfg <<EOF
# This was written via Vendor Data
system_info:
distro: ubuntu
package_mirrors:
- arches: [i386, amd64]
failsafe:
primary: http://archive.ubuntu.com/ubuntu
security: http://security.ubuntu.com/ubuntu
search:
primary:
- http://%(region)s.utlemming.clouds.archive.ubuntu.com/ubuntu/
security: []
- arches: [armhf, armel, default]
failsafe:
primary: http://ports.ubuntu.com/ubuntu-ports
security: http://ports.ubuntu.com/ubuntu-ports
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment