Created
July 6, 2012 19:56
-
-
Save psi/3062423 to your computer and use it in GitHub Desktop.
My custom Chef bootstrap for Amazon Linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bash -c ' | |
| <% if ENV['ROLES'].split(",").size > 1 %> | |
| HOSTNAME_PREFIX=box | |
| <% else %> | |
| HOSTNAME_PREFIX=<%= ENV['ROLES'].gsub('_', '-') %> | |
| <% end %> | |
| yum upgrade -y | |
| yum install -y gcc gcc-c++ make zlib-devel openssl-devel patch readline-devel | |
| rpm -e --nodeps ruby ruby-libs | |
| rpm -ivh --force http://files.s--e.net/ruby-enterprise-1.8.7.2012.02.streeteasy.x86_64.rpm | |
| export PATH=/usr/local/bin:$PATH | |
| cd /tmp | |
| curl http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz | tar xz | |
| cd rubygems-1.3.7 | |
| ruby setup.rb | |
| gem install --no-ri --no-rdoc -v 0.10.8 chef | |
| # Set hostname | |
| hostname=$HOSTNAME_PREFIX-`ohai | grep instance_id | cut -d "\"" -f 4 | cut -c 3-5` | |
| ip_addr=`ifconfig eth0 | grep "inet addr:" | cut -d ":" -f 2 | cut -d " " -f 1` | |
| sed -i "s/localhost.localdomain/$hostname.s--e.net/" /etc/sysconfig/network | |
| echo $ip_addr $hostname.s--e.net $hostname >>/etc/hosts | |
| /sbin/service network restart | |
| hostname $hostname.s--e.net | |
| # Configure Chef | |
| mkdir /etc/chef | |
| cat >/etc/chef/validation.pem <<-EOF | |
| # your validation key goes here | |
| EOF | |
| cat >/etc/chef/client.rb <<-EOF | |
| log_level :info | |
| log_location "/var/log/chef.log" | |
| chef_server_url # your chef-server URL | |
| validation_client_name "chef-validator" | |
| EOF | |
| mkdir /root/.chef | |
| cat >/root/.chef/knife.rb <<-EOF | |
| log_level :info | |
| log_location STDOUT | |
| node_name "jd" | |
| client_key "/root/.chef/jd.pem" | |
| validation_client_name "chef-validator" | |
| validation_key "/etc/chef/validation.pem" | |
| chef_server_url # your chef-server URL | |
| cache_type "BasicFile" | |
| cache_options( :path => "/root/.chef/checksums" ) | |
| EOF | |
| cat >/root/.chef/jd.pem <<-EOF | |
| # your private key goes here | |
| EOF | |
| # Run chef-client to register with chef-server | |
| chef-client -E <%= ENV['ENVIRONMENT'] %> | |
| # Add roles to our run list | |
| <% ENV['ROLES'].split(",").each do |role_name| %> | |
| knife node run_list add $hostname.s--e.net "role[se_<%= role_name %>]" | |
| <% end %> | |
| # Clean up chef config | |
| rm -rf /root/.chef | |
| rm /etc/chef/validation.pem | |
| # Start chef-client | |
| chef-client --once --daemonize | |
| ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment