Guest User

Untitled

a guest
May 20th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. ### BEGIN INIT INFO
  3. # Provides: ec2-chef-user-data
  4. # Required-Start:
  5. # Required-Stop:
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop:
  8. # Short-Description: Start chef run baseed on user data.
  9. # Description: Configure the chef node based on the provided user data.
  10. ### END INIT INFO
  11.  
  12. require 'rubygems'
  13. gem 'ohai'
  14. gem 'json'
  15.  
  16. require 'ohai'
  17. require 'json'
  18.  
  19. o = Ohai::System.new
  20. o.all_plugins
  21. chef_config = JSON.parse(o[:ec2][:userdata])
  22. if chef_config.kind_of?(Array)
  23. chef_config = chef_config[o[:ec2][:ami_launch_index]]
  24. end
  25.  
  26. if chef_config.has_key?("attributes")
  27. File.open("/etc/chef/client-config.json", "w") do |f|
  28. f.print(JSON.pretty_generate(chef_config["attributes"]))
  29. end
  30. end
  31.  
  32. `/usr/bin/chef-client -j /etc/chef/client-config.json -t #{chef_config["validation_key"]}`
Add Comment
Please, Sign In to add comment