Skip to content

Instantly share code, notes, and snippets.

@przygode
Created September 21, 2012 05:07
Show Gist options
  • Select an option

  • Save przygode/3759817 to your computer and use it in GitHub Desktop.

Select an option

Save przygode/3759817 to your computer and use it in GitHub Desktop.
auto-scaling-launchconfiguration
{
"ChefClient": {
"Type": "AWS::AutoScaling::LaunchConfiguration",
"DependsOn": "BucketPolicy",
"Metadata": {
"AWS::CloudFormation::Init": {
"config": {
"packages": {
"rubygems": {
"chef": [
"10.14.2"
],
"ohai": [
"0.6.4"
]
},
"apt": {
"build-essential": [],
"curl": [],
"irb": [],
"libopenssl-ruby": [],
"libreadline-ruby1.8": [],
"libruby1.8": [],
"libxslt-dev": [],
"libxml2-dev": [],
"libxml2": [],
"rdoc": [],
"ri": [],
"ruby": [],
"ruby-dev": [],
"rubygems": [],
"s3cmd": [],
"ssl-cert": [],
"wget": []
}
},
"files": {
"/etc/chef/first-boot.json": {
"content": {
"run_list": {
"Ref": "ChefRunList"
},
"mode": "000644",
"owner": "root",
"group": "root"
}
},
"/home/ubuntu/.s3cfg": {
"content": {
"Fn::Join": [
"",
[
"[default]\n",
"access_key = ",
{
"Ref": "HostKeys"
},
"\n",
"secret_key = ",
{
"Fn::GetAtt": [
"HostKeys",
"SecretAccessKey"
]
},
"\n",
"use_https = True\n"
]
]
},
"mode": "000644",
"owner": "ubuntu",
"group": "ubuntu"
},
"/var/lib/gems/1.8/gems/ohai-0.6.4/lib/ohai/plugins/cfn.rb": {
"source": "https://s3.amazonaws.com/cloudformation-examples/cfn.rb",
"mode": "000644",
"owner": "root",
"group": "root"
}
}
}
}
},
"Properties": {
"SecurityGroups": [
{
"Ref": "AppServerAccess"
}
],
"ImageId": {
"Fn::FindInMap": [
"AWSRegionArch2AMI",
{
"Ref": "AWS::Region"
},
{
"Fn::FindInMap": [
"AWSInstanceType2Arch",
{
"Ref": "InstanceType"
},
"Arch"
]
}
]
},
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"",
[
"#!/bin/bash -v\n",
"function error_exit\n",
"{\n",
" cfn-signal -e 1 -r \"$1\" '",
{
"Ref": "ChefClientWaitHandle"
},
"'\n",
" exit 1\n",
"}\n",
"apt-get update; apt-get upgrade -y; apt-get -y remove apparmor libapparmor1 ; apt-get -y install python-setuptools\n",
"easy_install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-1.0-6.tar.gz\n",
"cfn-init --region ",
{
"Ref": "AWS::Region"
},
" -s ",
{
"Ref": "AWS::StackName"
},
" -r ChefClient ",
" --access-key ",
{
"Ref": "HostKeys"
},
" --secret-key ",
{
"Fn::GetAtt": [
"HostKeys",
"SecretAccessKey"
]
},
" --region ",
{
"Ref": "AWS::Region"
},
" || error_exit 'Failed to run cfn-init'\n",
"# Fixup path and links for the bootstrap script\n",
"export PATH=$PATH:/var/lib/gems/1.8/bin\n",
"s3cmd -c /home/ubuntu/.s3cfg get s3://",
{
"Ref": "StrataluxBucket"
},
"/chef_init.rb /etc/chef/chef_init.rb > /tmp/get_chef_init.log 2>&1 || error_exit 'Failed to get Chef initialization script.'\n",
"ruby /etc/chef/chef_init.rb ",
{
"Ref": "DomainName"
},
" ",
{
"Ref": "ChefEnvironment"
},
" ",
{
"Ref": "ChefOrganization"
},
" >> /tmp/get_chef_init.log 2>&1 || error_exit 'Failed to run chef_init script.'\n",
"# Fixup the server URL in client.rb\n",
"s3cmd -c /home/ubuntu/.s3cfg get s3://",
{
"Ref": "StrataluxBucket"
},
"/validation.pem /etc/chef/validation.pem > /tmp/get_validation_key.log 2>&1 || error_exit 'Failed to get Chef Server validation key'\n",
"s3cmd -c /home/ubuntu/.s3cfg get s3://",
{
"Ref": "StrataluxBucket"
},
"/encrypted_data_bag_secret /etc/chef/encrypted_data_bag_secret > /tmp/encrypted_data_bag_secret.log 2>&1 || error_exit 'Failed to get Chef encrypted data bag secret.'\n",
"chmod 600 /etc/chef/encrypted_data_bag_secret \n",
"chef-client -j /etc/chef/first-boot.json > /tmp/initialize_client.log 2>&1 || error_exit 'Failed to initialize host via chef client' \n",
"# If all went well, signal success\n",
"cfn-signal -e $? -r 'Chef Server configuration' '",
{
"Ref": "ChefClientWaitHandle"
},
"'\n"
]
]
}
},
"KeyName": {
"Ref": "KeyName"
},
"InstanceType": {
"Ref": "InstanceType"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment