Skip to content

Instantly share code, notes, and snippets.

@theikkila
Created February 16, 2015 21:34
Show Gist options
  • Save theikkila/1cba179a704eab5480ec to your computer and use it in GitHub Desktop.
Save theikkila/1cba179a704eab5480ec to your computer and use it in GitHub Desktop.
CloudInit on UpCloud
#cloud-config
write_files:
- path: /run/cloud-config.yml
permissions: '0644'
content: |
#cloud-config
ssh_authorized_keys:
- ssh-rsa AAAAB....
coreos:
update:
reboot-strategy: etcd-lock
etcd:
discovery: https://discovery.etcd.io/<token>
addr: $_private_ipv4:4001
peer-addr: $_private_ipv4:7001
fleet:
public-ip: $_public_ipv4
units:
- name: etcd.service
command: start
- name: fleet.service
command: start
- path: /run/setup-environment.sh
permissions: '0755'
content: |
#!/bin/bash
ENV="/etc/environment"
# Test for RW access to $1
touch $ENV
if [ $? -ne 0 ]; then
echo exiting, unable to modify: $ENV
exit 1
fi
# Setup environment target
sed -i -e '/^COREOS_PUBLIC_IPV4=/d' \
-e '/^COREOS_PRIVATE_IPV4=/d' \
"${ENV}"
function get_ip () {
IF=$1
IP=
while [ 1 ]; do
IP=$(ifconfig $IF | awk '/inet / {print $2}')
if [ "$IP" != "" ]; then
break
fi
sleep .1
done
echo $IP
}
echo COREOS_PUBLIC_IPV4=$(get_ip eth0) >> $ENV
echo COREOS_PRIVATE_IPV4=$(get_ip eth1) >> $ENV
coreos:
units:
- name: setup-environment.service
command: start
runtime: true
content: |
[Unit]
Description=Setup environment with private (and public) IP addresses
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/run/setup-environment.sh
- name: second-stage-cloudinit.service
runtime: true
command: start
content: |
[Unit]
Description=Run coreos-cloudinit with actual cloud-config after environment has been set up
Requires=setup-environment.service
After=setup-environment.service
Requires=user-cloudinit-proc-cmdline.service
After=user-cloudinit-proc-cmdline.service
[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/environment
ExecStartPre=/usr/bin/sed -i 's/\$_p/$p/g' /run/cloud-config.yml
ExecStart=/usr/bin/coreos-cloudinit --from-file=/run/cloud-config.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment