Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- ### BEGIN INIT INFO
- # Provides: ec2-chef-user-data
- # Required-Start:
- # Required-Stop:
- # Default-Start: 2 3 4 5
- # Default-Stop:
- # Short-Description: Start chef run baseed on user data.
- # Description: Configure the chef node based on the provided user data.
- ### END INIT INFO
- require 'rubygems'
- gem 'ohai'
- gem 'json'
- require 'ohai'
- require 'json'
- o = Ohai::System.new
- o.all_plugins
- chef_config = JSON.parse(o[:ec2][:userdata])
- if chef_config.kind_of?(Array)
- chef_config = chef_config[o[:ec2][:ami_launch_index]]
- end
- if chef_config.has_key?("attributes")
- File.open("/etc/chef/client-config.json", "w") do |f|
- f.print(JSON.pretty_generate(chef_config["attributes"]))
- end
- end
- `/usr/bin/chef-client -j /etc/chef/client-config.json -t #{chef_config["validation_key"]}`
Add Comment
Please, Sign In to add comment