Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AWS user-data for automatically registering with a Chef Server.
#!/bin/bash
apt-get update
apt-get -y upgrade
# Install s3cmd to get the validation.pem
pip install python-dateutil
cd /tmp
wget https://github.com/s3tools/s3cmd/releases/download/v1.5.2/s3cmd-1.5.2.tar.gz
tar -xf s3cmd-1.5.2.tar.gz
cd s3cmd-1.5.2
./s3cmd get s3://your-s3-bucket/validation.pem /etc/chef/validation.pem
chmod 600 /etc/chef/validation.pem
# write first-boot.json
(
cat << 'EOP'
{"run_list":["role[role-goes-here]"]}
EOP
) > /etc/chef/first-boot.json
# write client.rb
(
cat << 'EOP'
chef_server_url 'https://chef-server-url'
environment 'environment-goes-here'
validation_client_name 'chef-validator'
client_fork true
log_location '/var/log/chef/client.log'
Ohai::Config[:plugin_path].push '/etc/chef/ohai_plugins'
# Using default node name (fqdn)
Dir.glob(File.join('/etc/chef', 'client.d', "*.rb")).each do |conf|
Chef::Config.from_file(conf)
end
EOP
) > /etc/chef/client.rb
# Bootstrap chef
chef-client -j /etc/chef/first-boot.json
chef-client # Run it again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment