Class: DeployRubygem::Workstation
- Inherits:
-
Object
- Object
- DeployRubygem::Workstation
- Defined in:
- lib/deploy_rubygem/workstation.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_knife_key ⇒ Object
readonly
Returns the value of attribute chef_knife_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.
-
#user_folder ⇒ Object
readonly
Returns the value of attribute user_folder.
Instance Method Summary collapse
- #boostrap_workstation ⇒ Object
- #clientrb ⇒ Object
- #credential ⇒ Object
-
#initialize(options) ⇒ Workstation
constructor
A new instance of Workstation.
- #read_file(file_path) ⇒ Object
Constructor Details
#initialize(options) ⇒ Workstation
Returns a new instance of Workstation.
13 14 15 16 17 18 19 20 21 |
# File 'lib/deploy_rubygem/workstation.rb', line 13 def initialize() @chef_server_url = ['chef_server_url'] @nodename = ['node_name'] @policyname = ['policyname'] @policygroup = ['policygroup'] @knife_name = ['knife_name'] @chef_knife_key = ['chef_knife_key'] @user_folder = ['user_folder'] end |
Instance Attribute Details
#chef_client_key ⇒ Object (readonly)
Returns the value of attribute chef_client_key.
11 12 13 |
# File 'lib/deploy_rubygem/workstation.rb', line 11 def chef_client_key @chef_client_key end |
#chef_knife_key ⇒ Object (readonly)
Returns the value of attribute chef_knife_key.
11 12 13 |
# File 'lib/deploy_rubygem/workstation.rb', line 11 def chef_knife_key @chef_knife_key end |
#chef_server_url ⇒ Object (readonly)
Returns the value of attribute chef_server_url.
11 12 13 |
# File 'lib/deploy_rubygem/workstation.rb', line 11 def chef_server_url @chef_server_url end |
#knife_name ⇒ Object (readonly)
Returns the value of attribute knife_name.
11 12 13 |
# File 'lib/deploy_rubygem/workstation.rb', line 11 def knife_name @knife_name end |
#nodename ⇒ Object (readonly)
Returns the value of attribute nodename.
11 12 13 |
# File 'lib/deploy_rubygem/workstation.rb', line 11 def nodename @nodename end |
#policygroup ⇒ Object (readonly)
Returns the value of attribute policygroup.
11 12 13 |
# File 'lib/deploy_rubygem/workstation.rb', line 11 def policygroup @policygroup end |
#policyname ⇒ Object (readonly)
Returns the value of attribute policyname.
11 12 13 |
# File 'lib/deploy_rubygem/workstation.rb', line 11 def policyname @policyname end |
#user_folder ⇒ Object (readonly)
Returns the value of attribute user_folder.
11 12 13 |
# File 'lib/deploy_rubygem/workstation.rb', line 11 def user_folder @user_folder end |
Instance Method Details
#boostrap_workstation ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/deploy_rubygem/workstation.rb', line 57 def boostrap_workstation extend DeployRubygem knife_file = File.join(user_folder, '.chef', 'knife.rb') cicdpem_file = File.join(user_folder, '.chef', 'cicd.pem') cicdcredential_file = File.join(user_folder, '.chef', 'credentials') chef_home = File.join(user_folder, '.chef') FileUtils.mkdir_p(chef_home) File.write(knife_file, clientrb) unless File.exist?(knife_file) File.write(cicdpem_file, chef_knife_key.split('\\n').join("\n")) unless File.exist?(cicdpem_file) File.write(cicdcredential_file, credential) unless File.exist?(cicdcredential_file) [knife_file, cicdpem_file, cicdcredential_file].each do |file_path| FileUtils.chmod(0o600, file_path) # read_file(file_path) end system(chef_accept_cmd) end |
#clientrb ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/deploy_rubygem/workstation.rb', line 23 def clientrb { log_location: File.join(Dir.home, '.chef', 'chef-client.log'), chef_server_url: chef_server_url, chef_license: 'accept', file_cache_path: File.join(Dir.home, '.chef', 'cache'), file_backup_path: File.join(Dir.home, '.chef', 'backup'), node_name: nodename, policy_name: policyname, policy_group: policygroup }.map do |key, value| abort("key #{key} need to have a value :: #{ARGV}") if value.nil? || value.empty? key_pair = [key, "'#{value}'"] key_pair.join(' ') end.join("\n") end |
#credential ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/deploy_rubygem/workstation.rb', line 40 def credential (['[default]'] + { client_name: knife_name, client_key: File.join(user_folder, '.chef', 'cicd.pem'), chef_server_url: chef_server_url # secret_file: File.join(user_folder, '.chef', 'cicd.secret') }.map do |key, value| [key, '=', "'#{value}'"].join(' ') end).join("\n") end |
#read_file(file_path) ⇒ Object
51 52 53 54 55 |
# File 'lib/deploy_rubygem/workstation.rb', line 51 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 |