Skip to content

Instantly share code, notes, and snippets.

@gembin
Forked from ForbiddenEra/whatimdoing.yaml
Created March 9, 2016 17:14
Show Gist options
  • Save gembin/3410e6343fee1aeb792b to your computer and use it in GitHub Desktop.
Save gembin/3410e6343fee1aeb792b to your computer and use it in GitHub Desktop.
my cloud-configz yo
#cloud-config
ssh_authorized_keys:
- ssh-rsa key
write_files:
- path: /opt/cloud-config.yml
permissions: 0644
content: |
#cloud-config
ssh_authorized_keys:
- ssh-rsa key
hostname: $HOSTNAME
coreos:
etcd:
name: $HOSTNAME
discovery: $DISCOVERY
addr: \$private_ipv4:4001
peer-addr: \$private_ipv4:7001
election_timeout: 1500
heartbeat_interval: 500
fleet:
public-ip: \$private_ipv4 # used for fleetctl ssh command
metadata: bandwidth_limit=$BANDWIDTH_LIMIT,cpus=$PROCESSORS,host=$HOSTNAME,memory=$MEMORY,provider=$PROVIDER,region=$REGION,storage_size=$INTERNAL_STORAGE,storage_type=$INTERNAL_STORAGE_TYPE,role=$ROLE,block_storage_size=$BLOCK_STORAGE_SIZE,block_storage_type=$BLOCK_STORAGE_TYPE
units:
- name: etcd.service
command: start
- name: fleet.service
command: start
- name: rpc-statd.service
command: start
enable: true
- name: example-setup.service
command: start
enable: true
content: |
[Unit]
Requires=network-online.target
Requires=docker.service
After=network-online.target
After=docker.service
Description=Shaped Setup
Documentation=http://shaped.ca
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStartPre=/usr/bin/wget -N -P /opt/bin \
https://gist.githubusercontent.com/ForbiddenEra/../raw/.../volume-setup
ExecStartPre=/usr/bin/chmod +x /opt/bin/volume-setup
ExecStartPre=/usr/bin/wget -N -P /opt/bin \
https://gist.githubusercontent.com/ForbiddenEra/.../volume-unmount
ExecStartPre=/usr/bin/chmod +x /opt/bin/volume-unmount
ExecStartPre=/usr/bin/wget -N -P /opt/bin \
https://gist.githubusercontent.com/ForbiddenEra/../raw/.../volume-wait
ExecStartPre=/usr/bin/chmod +x /opt/bin/volume-wait
ExecStartPre=/usr/bin/update_engine_client -check_for_update
ExecStart=/bin/bash -c 'echo x.x.x.x docker-registry > /etc/hosts'
- name: volume-storage-online-wait.service
command: start
enabled: true
content: |
[Unit]
Requires=shaped-setup.service
Requires=network-online.target
After=shaped-setup.service
After=network-online.target
Before=volume-storage.service
Description=Wait for External Attached Volumes (for GlusterFS)
Documentation=http://shaped.ca/
[Service]
Type=oneshot
ExecStart=/opt/bin/volume-wait
RemainAfterExit=yes
- name: volume-storage.service
command: start
enabled: true
content: |
[Unit]
Requires=shaped-setup.service
Requires=network-online.target
Requires=volume-storage-online-wait.service
After=shaped-setup.service
After=network-online.target
After=volume-storage-online-wait.service
Description=Setup External Attached Volumes (for GlusterFS)
Documentation=http://shaped.ca/
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/opt/bin/volume-setup
ExecStop=/opt/bin/volume-unmount
[X-Fleet]
MachineMetadata=block_storage_type=attached
- name: swap-auto.service
command: start
enabled: true
content: |
[Unit]
Description=Setup Swap Service
Documentation=http://shaped.ca
[Service]
Type=oneshot
Environment="SWAP_PATH=/swap" "SWAP_FILE=swap.fs"
ExecStartPre=-/usr/bin/rm -rf ${SWAP_PATH}
ExecStartPre=/usr/bin/mkdir ${SWAP_PATH}
ExecStartPre=/usr/bin/touch ${SWAP_PATH}/${SWAP_FILE}
ExecStartPre=/usr/bin/chattr +C ${SWAP_PATH}/${SWAP_FILE}
ExecStartPre=/bin/bash -c "fallocate -l $(free -h --si|awk '/^Mem:/{print $2}') ${SWAP_PATH}/${SWAP_FILE}"
ExecStartPre=/usr/bin/chmod 600 ${SWAP_PATH}/${SWAP_FILE}
ExecStartPre=/usr/sbin/mkswap ${SWAP_PATH}/${SWAP_FILE}
ExecStartPre=/usr/sbin/losetup -f ${SWAP_PATH}/${SWAP_FILE}
ExecStart=/usr/bin/sh -c "/sbin/swapon $(/usr/sbin/losetup -j ${SWAP_PATH}/${SWAP_FILE} | /usr/bin/cut -d : -f 1)"
ExecStop=/usr/bin/sh -c "/sbin/swapoff $(/usr/sbin/losetup -j ${SWAP_PATH}/${SWAP_FILE} | /usr/bin/cut -d : -f 1)"
ExecStopPost=/usr/bin/sh -c "/usr/sbin/losetup -d $(/usr/sbin/losetup -j ${SWAP_PATH}/${SWAP_FILE} | /usr/bin/cut -d : -f 1)"
ExecStopPost=-/usr/bin/rm -rf ${SWAP_PATH}
RemainAfterExit=true
- name: install-busybox.service
command: start
enable: true
content: |
[Unit]
Requires=docker.service
Requires=shaped-setup.service
Requires=network-online.target
After=network-online.target
After=docker.service
After=shaped-setup.service
Description=Install BusyBox (for weave)
Documentation=http://zettio.github.io/weave/
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/docker pull busybox:latest
- name: install-pipework.service
command: start
enable: true
content: |
[Unit]
Requires=docker.service
Requires=shaped-setup.service
Requires=network-online.target
After=network-online.target
After=docker.service
After=shaped-setup.service
Description=Install Pipework
Documentation=https://github.com/jpetazzo/pipework
Requires=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStartPre=/usr/bin/wget -N -P /opt/bin \
https://raw.github.com/jpetazzo/pipework/master/pipework
ExecStartPre=/usr/bin/chmod +x /opt/bin/pipework
ExecStart=/bin/echo Pipework Installed
- name: install-weave.service
command: start
enable: true
content: |
[Unit]
Requires=docker.service
Requires=shaped-setup.service
Requires=network-online.target
After=network-online.target
After=docker.service
After=shaped-setup.service
Description=Install Weave
Documentation=http://zettio.github.io/weave/
Requires=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStartPre=/usr/bin/wget -N -P /opt/bin \
https://raw.github.com/zettio/weave/master/weave
ExecStartPre=/usr/bin/chmod +x /opt/bin/weave
ExecStartPre=/usr/bin/docker pull zettio/weave:latest
ExecStart=/bin/echo Weave Installed
- name: 50-docker.network
runtime: false
content: |
[Match]
Type=bridge
Name=docker*
[Network]
Address=10.0.0.1/16
- name: dhcp.network
runtime: false
content: |
[Match]
Name=eth*
[Network]
DHCP=v4
- name: docker.netdev
runtime: false
content: |
[NetDev]
Name=docker0
Kind=bridge
- name: ethdocker.network
runtime: false
content: |
[Match]
Name=eth*
[Network]
Bridge=docker0
write_files:
- path: /home/core/.ssh/id_rsa.pub
permissions: 0600
content: |
- ssh-rsa key
- path: /home/core/.ssh/id_rsa
permissions: 0600
content: |
-----BEGIN RSA PRIVATE KEY-----
-----END RSA PRIVATE KEY-----
- path: /etc/conf.d/nfs
permissions: 0644
content: |
OPTS_RPC_MOUNTD=""
- path: /home/core/nfs/example.mount
permissions: 0644
content: |
[Mount]
What=nfshost.domain.com:/vol2/data
Where=/mnt/data
Type=nfs
- path: /etc/weave.$HOSTNAME.env
permissions: 0644
owner: core
content: |
WEAVE_LAUNCH_ARGS="-password key ip"
- path: /home/core/units/weave.service
permissions: 0644
owner: core
content: |
[Unit]
Description=Weave Network
Documentation=http://zettio.github.io/weave/
After=install-weave.service
Requires=install-weave.service
[Service]
EnvironmentFile=/etc/weave.%H.env
ExecStartPre=/opt/bin/weave launch $WEAVE_LAUNCH_ARGS
ExecStart=/usr/bin/docker logs -f weave
SuccessExitStatus=2
ExecStop=/opt/bin/weave stop
[X-Fleet]
Global=true
- 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}"
# We spin loop until the the IP addresses are set
function get_iface_ip () {
IF=$1
IP=
while [ 1 ]; do
IP=$(ifconfig $IF | awk '/inet / {print $2}')
if [ "$IP" != "" ]; then
break
fi
sleep .1
done
echo $IP
}
function get_nat_ip () {
while [ 1 ]; do
_out=$(curl -s icanhazip.com)
if [ -z "$_out" ]; then
sleep 1
else
echo $_out
exit
fi
done
}
# Echo results of IP queries to environment file as soon as network interfaces
# get assigned IPs
echo getting private ipv4 from iface eth0..
echo COREOS_PUBLIC_IPV4=$(get_iface_ip eth0) >> $ENV # Also assigned to same IP
echo getting public-facing ipv4 from icanhazip.com..
echo COREOS_PRIVATE_IPV4=$(get_nat_ip) >> $ENV #eno1 should be changed to your device name
- path: /opt/bin/node-setup-environment
permissions: 0755
owner: root
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
# we should be able to get most of this info from the
# open-stack meta-data service, however, not every providor has that
# so a. we can run our own meta-data service (lame)
# b. we can script as much meta-data as we can (current, lame)
# c. use openstack meta data (not so lame) but create our own elsewhere? (meh)
# d. figure out something better
mkdir -p /opt/bin
cd /opt
curl -s example.com/coreos/host.tgz | tar xvz
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/lib
# get list of subdomains matching core from our domain
host -l example.com example.com | grep ^core | cut -d ' ' -f 1,4 > /tmp/dns
while read l; do
_HOST=$(echo $l | cut -d ' ' -f 1)
_IP=$(echo $l | cut -d ' ' -f 2)
if [ $public_ipv4 == $_IP ]; then
echo Found my hostname: $_HOST
echo HOSTNAME=$_HOST >> $ENV
fi
done < /tmp/dns
rm /tmp/dns
export CLUSTER='dev001'
echo CLUSTER='dev001' >> $ENV
echo DISCOVERY=$(curl -s http://example.com/coreos/$CLUSTER.discovery)
echo PROCESSORS=$(nproc) >> $ENV
echo MEMORY=$(expr $(free -h --si|awk '/^Mem:/{print $2}' | cut -d '.' -f 1) \* 1024) >> $ENV
#echo INTERNAL_STORAGE=$(df -h /dev/vda1 | grep vda1 | cut -d ' ' -f 9 | cut -d 'G' -f 1) >> $ENV
echo INTERNAL_STORAGE=$(expr $(blockdev --getsize64 /dev/vda) / 1024 / 1024 / 1024) >> $ENV
echo INTERNAL_STORAGE_TYPE=ssd >> $ENV
echo BANDWIDTH_LIMIT=0 >> $ENV
echo BLOCK_STORAGE_SIZE=10 >> $ENV
echo BLOCK_STORAGE_TYPE=attached >> $ENV
echo PROVIDER=auro.io >> $ENV
echo REGION=ca-west >> $ENV
- path: /etc/resolv.conf
permissions: 0644
owner: root
content: |
nameserver 8.8.8.8
nameserver 8.8.4.4
domain example.com
hostname: intermediate
coreos:
units:
- name: setup-environment.service
command: start
runtime: true
content: |
[Unit]
Description=Setup configuration environment with private (and public) IP addresses
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStartPre=/run/setup-environment.sh
ExecStart=/opt/bin/node-setup-environment
- 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
ExecStart=/usr/bin/true
ExecStop=/usr/bin/coreos-cloudinit --from-file=/opt/cloud-config.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment