Class: DeployRubygem::ChefAdmin

Inherits:
Object
  • Object
show all
Defined in:
lib/deploy_rubygem/chef_admin.rb

Overview

Using Project to deploy and manage Project

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options)
  @chef_server_url = options['chef_server_url']
  @nodename = options['node_name']
  @policyname = options['policyname']
  @policygroup = options['policygroup']
  @knife_name = options['knife_name']
  @chef_client_key = options['chef_client_key']
end

Instance Attribute Details

#chef_client_keyObject (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_urlObject (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_nameObject (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

#nodenameObject (readonly)

Returns the value of attribute nodename.



10
11
12
# File 'lib/deploy_rubygem/chef_admin.rb', line 10

def nodename
  @nodename
end

#policygroupObject (readonly)

Returns the value of attribute policygroup.



10
11
12
# File 'lib/deploy_rubygem/chef_admin.rb', line 10

def policygroup
  @policygroup
end

#policynameObject (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

#boostrapObject



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

#clientrbObject



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