Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@domcleal
Created April 17, 2014 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save domcleal/11003111 to your computer and use it in GitHub Desktop.
Save domcleal/11003111 to your computer and use it in GitHub Desktop.
# Chef configuration snippet
#
# Uses the following parameters:
# - chef-validation-key: PEM-formatted validation key
# - chef-url: URL to the Chef server, e.g. https://chef.example.com
# - chef-runlist: comma-separated runlist, e.g. role[bootstrap],role[base]
# - chef: when 'true', runs this snippet
<% if @host.param_true?('chef') %>
curl -L https://www.opscode.com/chef/install.sh | bash
chef-client -v
/opt/chef/embedded/bin/gem install chef_handler_foreman
mkdir -p /etc/chef
if [ ! -e /etc/chef/validation.pem ]; then
cat > /etc/chef/validation.pem << EOF
<%= @host.params['chef-validation-key'] %>
EOF
fi
cat > /etc/chef/client.rb << EOF
log_level :auto
log_location STDOUT
chef_server_url "<%= @host.params['chef-url'] %>"
validation_client_name "chef-validator"
require 'chef_handler_foreman'
foreman_server_options :url => "<%= Setting['foreman_url'] %>"
foreman_facts_upload true
foreman_reports_upload true
EOF
cat > /etc/chef/bootstrap.json << EOF
{"run_list": <%= @host.params['chef-runlist'].split(',').inspect %> }
EOF
chef-client -j /etc/chef/bootstrap.json
<% end -%>
@ares
Copy link

ares commented Sep 15, 2014

if you want to use with safe_mode rendering enabled, change Setting['foreman_url'] to foreman_url on line 28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment