Skip to content

Instantly share code, notes, and snippets.

@neilmillard
Last active February 17, 2016 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neilmillard/ac9d81a37c14cfb38e4a to your computer and use it in GitHub Desktop.
Save neilmillard/ac9d81a37c14cfb38e4a to your computer and use it in GitHub Desktop.
Content-Type: multipart/mixed; boundary="===============0035287898381899620=="
MIME-Version: 1.0
--===============0035287898381899620==
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
#cloud-config
# Cloud-Init Hints:
# * Some default settings are in /etc/cloud/cloud.cfg
# * Some examples at: http://bazaar.launchpad.net/~cloud-init-dev/cloud-init/trunk/files/head:/doc/examples/
# * CloudInit Module sourcecode at: http://bazaar.launchpad.net/~cloud-init-dev/cloud-init/trunk/files/head:/cloudinit/config/
preserve_hostname: true
manage_etc_hosts: false
# dynamically set hostname using the instance's instanceid
bootcmd:
- cloud-init-per instance my_set_hostname sh -xc "echo uberweb-$INSTANCE_ID > /etc/hostname; hostname -F /etc/hostname"
- cloud-init-per instance my_etc_hosts sh -xc "sed -i -e '/^127.0.1.1/d' /etc/hosts; echo 127.0.1.1 uberweb-$INSTANCE_ID.uberapp.com uberweb-$INSTANCE_ID >> /etc/hosts"
# Add apt repositories
apt_sources:
# Enable "multiverse" repos
- source: deb $MIRROR $RELEASE multiverse
- source: deb-src $MIRROR $RELEASE multiverse
- source: deb $MIRROR $RELEASE-updates multiverse
- source: deb-src $MIRROR $RELEASE-updates multiverse
- source: deb http://security.ubuntu.com/ubuntu $RELEASE-security multiverse
- source: deb-src http://security.ubuntu.com/ubuntu $RELEASE-security multiverse
# Enable "partner" repos
- source: deb http://archive.canonical.com/ubuntu $RELEASE partner
- source: deb-src http://archive.canonical.com/ubuntu $RELEASE partner
# Enable PuppetLabs repos (for latest version of puppet)
- source: deb http://apt.puppetlabs.com $RELEASE main dependencies
keyid: 4BD6EC30 # GPG key ID published on a key server
filename: puppetlabs.list
- source: deb-src http://apt.puppetlabs.com $RELEASE main dependencies
keyid: 4BD6EC30 # GPG key ID published on a key server
filename: puppetlabs.list
# Run 'apt-get update' on first boot
apt_update: true
# Run 'apt-get upgrade' on first boot
apt_upgrade: true
# Reboot after package install/upgrade if needed (e.g. if kernel update)
apt_reboot_if_required: True
# Install additional packages on first boot
packages:
- wget
- git
- puppet
- rubygems # Used to install librarian-puppet
- python-pip # Used to install awscli
# run commands
# runcmd contains a list of either lists or a string
# each item will be executed in order
runcmd:
# Install AWS CLI
- pip install awscli
# Install librarian-puppet for retrieving dependent puppet modules from github
- gem install librarian-puppet
# Get the github ssh key out of s3 (IAM providing access to S3)
# so we can clone from our private github repos
- aws --region us-east-1 s3 cp s3://uberappaccount.bootstrap-bucket/github-rsa-key /root/.ssh/id_rsa && chmod 600 /root/.ssh/id_rsa
# Add github.com to known_hosts
- ssh -T -oStrictHostKeyChecking=no git@github.com
# set the locale
locale: en_US.UTF-8
# timezone: set the timezone for this instance (ALWAYS user UTC!)
timezone: UTC
# Log all cloud-init process output (info & errors) to a logfile
output: {all: ">> /var/log/cloud-init-output.log"}
# final_message written to log when cloud-init processes are finished
final_message: "System boot (via cloud-init) is COMPLETE, after $UPTIME seconds. Finished at $TIMESTAMP"
--===============0035287898381899620==
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="user-script.txt"
#!/bin/bash
git clone -b master git@github.com:uberco/puppet-uberapp.git /etc/puppet/
# Run librarian-puppet
cd /etc/puppet && HOME=/root librarian-puppet install
# Get hiera data files for puppet
mkdir -p /etc/puppet/hieradata && aws --region us-east-1 s3 cp s3://uberappaccount.bootstrap-bucket/hieradata/ /etc/puppet/hieradata/ --recursive && chmod 600 /etc/puppet/hieradata/*
# set up custom Puppet Facter facts
mkdir -p /etc/facter/facts.d
cat << 'EOF' > /etc/facter/facts.d/uberapp
#!/usr/bin/env python
facts = {
"node_type":"uber-web", # 'uber-web' OR uber-producer' OR 'uber-worker'
"bootstrap_s3path":"uberappaccount.bootstrap-bucket", # no trailing slash
"uber_queue_high":"uber-hpq",
"uber_queue_low":"uber-lpq",
"uber_dead_letter_queue":"uber-dlq",
"uber_log_level":"INFO",
"uber_deploy":"uber-web-1.0.3.war",
"uber_notification_email":"admin@uberapp.com",
"lumberjack_files":'{ "apache-logs": { "paths": ["/var/log/apache2/*.log"], "fields": {"type": "apache"} }, "syslog": { "paths": ["/var/log/syslog"], "fields": { "type": "syslog" } } }',
"lumberjack_deb":"lumberjack_0.1.2_amd64.deb",
"lumberjack_ensure":"present"
}
for k in facts:
print "%s=%s" % (k,facts[k])
EOF
chmod +x /etc/facter/facts.d/uberapp
# Run puppet
puppet apply /etc/puppet/manifests/site.pp
--===============0035287898381899620==--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment