Created
April 8, 2015 17:33
-
-
Save darron/5f0b869d5e309db26ad3 to your computer and use it in GitHub Desktop.
AWS user-data for automatically registering with a Chef Server.
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
| #!/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