Class: DeployRubygem::ChefAdmin
- Inherits:
-
Object
- Object
- DeployRubygem::ChefAdmin
- Defined in:
- lib/deploy_rubygem/chef_admin.rb
Overview
Using Project to deploy and manage Project
Instance Attribute Summary collapse
-
#chef_client_key ⇒ Object
readonly
Returns the value of attribute chef_client_key.
-
#chef_server_url ⇒ Object
readonly
Returns the value of attribute chef_server_url.
-
#knife_name ⇒ Object
readonly
Returns the value of attribute knife_name.
-
#nodename ⇒ Object
readonly
Returns the value of attribute nodename.
-
#policygroup ⇒ Object
readonly
Returns the value of attribute policygroup.
-
#policyname ⇒ Object
readonly
Returns the value of attribute policyname.
Instance Method Summary collapse
- #boostrap ⇒ Object
- #clientrb ⇒ Object
-
#initialize(options) ⇒ ChefAdmin
constructor
A new instance of ChefAdmin.
- #read_file(file_path) ⇒ Object
Constructor Details
#initialize(options) ⇒ ChefAdmin
Returns a new instance of ChefAdmin.
12 13 14 15 16 17 18 19 |
# File 'lib/deploy_rubygem/chef_admin.rb', line 12 def initialize() @chef_server_url = ['chef_server_url'] @nodename = ['node_name'] @policyname = ['policyname'] @policygroup = ['policygroup'] @knife_name = ['knife_name'] @chef_client_key = ['chef_client_key'] end |
Instance Attribute Details
#chef_client_key ⇒ Object (readonly)
Returns the value of attribute chef_client_key.
10 11 12 |
# File 'lib/deploy_rubygem/chef_admin.rb', line 10 def chef_client_key @chef_client_key end |
#chef_server_url ⇒ Object (readonly)
Returns the value of attribute chef_server_url.
10 11 12 |
# File 'lib/deploy_rubygem/chef_admin.rb', line 10 def chef_server_url @chef_server_url end |
#knife_name ⇒ Object (readonly)
Returns the value of attribute knife_name.
10 11 12 |
# File 'lib/deploy_rubygem/chef_admin.rb', line 10 def knife_name @knife_name end |
#nodename ⇒ Object (readonly)
Returns the value of attribute nodename.
10 11 12 |
# File 'lib/deploy_rubygem/chef_admin.rb', line 10 def nodename @nodename end |
#policygroup ⇒ Object (readonly)
Returns the value of attribute policygroup.
10 11 12 |
# File 'lib/deploy_rubygem/chef_admin.rb', line 10 def policygroup @policygroup end |
#policyname ⇒ Object (readonly)
Returns the value of attribute policyname.
10 11 12 |
# File 'lib/deploy_rubygem/chef_admin.rb', line 10 def policyname @policyname end |
Instance Method Details
#boostrap ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/deploy_rubygem/chef_admin.rb', line 44 def boostrap extend DeployRubygem clientrb_file = '/etc/chef/client.rb' clientpem_file = '/etc/chef/client.pem' FileUtils.mkdir_p('/etc/chef') File.write(clientrb_file, clientrb) File.write(clientpem_file, chef_client_key.split('\\n').join("\n")) [clientrb_file, clientpem_file].each do |file_path| FileUtils.chmod(0o600, file_path) # read_file(file_path) end system('curl -L https://omnitruck.chef.io/install.sh > chef_install.sh') system('bash chef_install.sh -P chef-workstation -s once') || abort('Chef not installable') system(chef_accept_cmd) end |
#clientrb ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/deploy_rubygem/chef_admin.rb', line 21 def clientrb { log_location: '/var/log/chef-client.log', chef_server_url: chef_server_url, chef_license: 'accept', file_cache_path: '/var/chef/cache', file_backup_path: '/var/chef/backup', node_name: nodename, policy_name: policyname, policy_group: policygroup }.map do |key, value| abort("key #{key} need to have a value :: #{value.class}") if value.nil? || value.empty? key_pair = [key, "'#{value}'"] key_pair.join(' ') end.join("\n") end |
#read_file(file_path) ⇒ Object
38 39 40 41 42 |
# File 'lib/deploy_rubygem/chef_admin.rb', line 38 def read_file(file_path) puts "REading file #{file_path}" puts File.read(file_path) puts "Had read #{File.read(file_path).split('\n').length} lines" end |