Created
March 9, 2016 17:14
-
-
Save gembin/8a345cf32e3c664546fe to your computer and use it in GitHub Desktop.
Custom IP Resolution with Cloud-Config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
workdir=$(mktemp --directory) | |
trap "rm --force --recursive ${workdir}" SIGINT SIGTERM EXIT | |
cat >"${workdir}/cloud-config.yml" <<EOF | |
#cloud-config | |
coreos: | |
etcd: | |
discovery: | |
addr: \\$public_ipv4:4001 | |
peer-addr: \\$private_ipv4:7001 | |
units: | |
- name: etcd.service | |
command: start | |
- name: fleet.service | |
command: start | |
EOF | |
get_ipv4() { | |
IFACE="${1}" | |
local ip | |
while [ -z "${ip}" ]; do | |
ip=$(ip -4 -o addr show dev "${IFACE}" scope global | gawk '{split ($4, out, "/"); print out[1]}') | |
sleep .1 | |
done | |
echo "${ip}" | |
} | |
export COREOS_PUBLIC_IPV4=$(get_ipv4 eth0) | |
export COREOS_PRIVATE_IPV4=$(get_ipv4 eth1) | |
coreos-cloudinit --from-file="${workdir}/cloud-config.yml" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment