- From: Avishai Ish-Shalom <
>
- To:
- Subject: [chef] Re: Automatically starting a new EC2 instance with Chef
- Date: Sat, 14 May 2011 22:36:12 +0300
- Organization: FewBytes Technologies
If you want to achieve this goal with the minimum amount of work, create
a launch configuration with a user data script that installs ruby,
installs chef, write the validation certificate, chef config and
bootstrap json then launch chef. Ubuntu images are bundle with
cloud-init which is able to read shell scripts from user data. In other
words, edit the attached script and use that as the user data for new
instances or autoscaling groups.
BTW, a native chef plugin for cloud-init is waiting to be merged. If and
when it's included, launching ubuntu images with chef will become
ridiculously easy.
Regards,
Avishai
On 14/05/11 16:55, Edward Sargisson wrote:
>
Hi all,
>
What tools and services are available to automatically start a new EC2
>
instance with Chef?
>
>
My site has just one server and yesterday it failed. Unfortunately, I
>
was at my day job and couldn't do anything about it. It's configured
>
with Chef so starting up a new server with knife then using Opscode
>
Platform to put the roles on was reasonably easy (it could be easier
>
but I have some issues to fix).
>
>
What I would like is for some service to realise that my server is
>
down and then call Chef to setup a new one. Amazon Auto Scaling almost
>
does this - the issue is that it merely starts an AMI and doesn't do
>
anything cleverer than that. My Chef setup assumes a brand new Ubuntu
>
image and goes from there. I suppose that, for future use, whatever
>
solution I use needs to also listen to the CloudWatch metrics to scale
>
up and down when required.
>
>
So:
>
Do I write an image which bootstraps chef automatically?
>
Or is there some other way to solve this problem?
>
>
Thanks,
>
Edward
#! /bin/sh
apt-get update
APT_GET="env DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt-get
-q"
$APT_GET -y remove ruby1.8*
$APT_GET -y install ruby1.9.1 ruby1.9.1-dev libruby1.9.1
$APT_GET -y install build-essential
gem install --no-rdoc --no-ri chef
ln -sf gem1.9.1 /usr/bin/gem
ln -sf ruby1.9.1 /usr/bin/ruby
mkdir -p /var/{log,backups,run,cache,lib}/chef
mkdir /etc/chef
ln -s /var/lib/gems/1.9.1/bin/chef-client /usr/bin/chef-client
cat - >/etc/chef/bootstrap.json <<EOF
{
"run_list": [
"role[ROLE]"
],
"default_attributes": {
},
"override_attributes": {
}
}
EOF
cat - >/etc/chef/client.rb <<EOF
log_level :info
log_location "/var/log/chef/client.log"
ssl_verify_mode :verify_none
validation_client_name "chef-validator"
validation_key "/etc/chef/validation.pem"
client_key "/etc/chef/client.pem"
chef_server_url "CHEF SERVER URL"
file_cache_path "/var/cache/chef"
file_backup_path "/var/backups/chef"
pid_file "/var/run/chef/client.pid"
Chef::Log::Formatter.show_time = true
EOF
cat - >/etc/chef/validation.pem <<EOF
-----BEGIN RSA PRIVATE KEY-----
-----END RSA PRIVATE KEY-----
EOF
/usr/bin/chef-client -j /etc/chef/bootstrap.json -s 20 -i 300 -d
begin:vcard
fn:Avishai Ish-Shalom
n:Ish-Shalom;Avishai
org:FewBytes technologies
adr:;;7 Jabotinsky St.;Ramat-Gan;;52520;Israel
email;internet:
title:IT Consultant
tel;work:+972-3-5444-230
tel;fax:+972-3-5444-720
tel;cell:+972-54-4466499
note:skype: avishaiish
x-mozilla-html:TRUE
url:http://www.fewbytes.com/
version:2.1
end:vcard
Attachment:
smime.p7s
Description: S/MIME Cryptographic Signature
Archive powered by MHonArc 2.6.16.