Class: Ridley::Bootstrapper::Context
- Inherits:
-
Object
- Object
- Ridley::Bootstrapper::Context
- Defined in:
- lib/ridley/bootstrapper/context.rb
Overview
Instance Attribute Summary collapse
- #bootstrap_proxy ⇒ String readonly
- #chef_version ⇒ String readonly
- #environment ⇒ String readonly
- #hints ⇒ Hash readonly
- #host ⇒ String readonly
- #node_name ⇒ String readonly
- #server_url ⇒ String readonly
- #validator_client ⇒ String readonly
Class Method Summary collapse
-
.default_options ⇒ Hash
A hash of default options to be used in the Context initializer.
- .validate_options(options = {}) ⇒ Object
Instance Method Summary collapse
- #boot_command ⇒ String
- #chef_config ⇒ String
- #chef_run ⇒ String
- #clean_command ⇒ String
- #encrypted_data_bag_secret ⇒ String?
- #first_boot ⇒ String
-
#initialize(host, options = {}) ⇒ Context
constructor
A new instance of Context.
-
#validation_key ⇒ String
The validation key to create a new client for the node.
Constructor Details
#initialize(host, options = {}) ⇒ Context
Returns a new instance of Context.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/ridley/bootstrapper/context.rb', line 79 def initialize(host, = {}) = self.class..merge() self.class.() @host = host @server_url = [:server_url] @validator_path = [:validator_path] @node_name = [:node_name] @validator_client = [:validator_client] @bootstrap_proxy = [:bootstrap_proxy] @encrypted_data_bag_secret_path = [:encrypted_data_bag_secret_path] @hints = [:hints] @attributes = [:attributes] @run_list = [:run_list] @chef_version = [:chef_version] @environment = [:environment] @sudo = [:sudo] @template_file = [:template] end |
Instance Attribute Details
#bootstrap_proxy ⇒ String (readonly)
46 47 48 |
# File 'lib/ridley/bootstrapper/context.rb', line 46 def bootstrap_proxy @bootstrap_proxy end |
#chef_version ⇒ String (readonly)
50 51 52 |
# File 'lib/ridley/bootstrapper/context.rb', line 50 def chef_version @chef_version end |
#environment ⇒ String (readonly)
52 53 54 |
# File 'lib/ridley/bootstrapper/context.rb', line 52 def environment @environment end |
#hints ⇒ Hash (readonly)
48 49 50 |
# File 'lib/ridley/bootstrapper/context.rb', line 48 def hints @hints end |
#host ⇒ String (readonly)
36 37 38 |
# File 'lib/ridley/bootstrapper/context.rb', line 36 def host @host end |
#node_name ⇒ String (readonly)
38 39 40 |
# File 'lib/ridley/bootstrapper/context.rb', line 38 def node_name @node_name end |
#server_url ⇒ String (readonly)
40 41 42 |
# File 'lib/ridley/bootstrapper/context.rb', line 40 def server_url @server_url end |
#validator_client ⇒ String (readonly)
42 43 44 |
# File 'lib/ridley/bootstrapper/context.rb', line 42 def validator_client @validator_client end |
Class Method Details
.default_options ⇒ Hash
A hash of default options to be used in the Context initializer
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ridley/bootstrapper/context.rb', line 21 def @default_options ||= { validator_client: "chef-validator", hints: Hash.new, attributes: Hash.new, run_list: Array.new, chef_version: Ridley::CHEF_VERSION, environment: "_default", sudo: true, template: Bootstrapper.default_template } end |
.validate_options(options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/ridley/bootstrapper/context.rb', line 8 def ( = {}) if [:server_url].nil? raise Errors::ArgumentError, "A server_url is required for bootstrapping" end if [:validator_path].nil? raise Errors::ArgumentError, "A path to a validator is required for bootstrapping" end end |
Instance Method Details
#boot_command ⇒ String
100 101 102 103 104 105 106 107 108 |
# File 'lib/ridley/bootstrapper/context.rb', line 100 def boot_command cmd = template.evaluate(self) if sudo cmd = "sudo #{cmd}" end cmd end |
#chef_config ⇒ String
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/ridley/bootstrapper/context.rb', line 121 def chef_config body = <<-CONFIG log_level :info log_location STDOUT chef_server_url "#{server_url}" validation_client_name "#{validator_client}" CONFIG if node_name.present? body << %Q{node_name "#{node_name}"\n} else body << "# Using default node name (fqdn)\n" end if bootstrap_proxy.present? body << %Q{http_proxy "#{bootstrap_proxy}"\n} body << %Q{https_proxy "#{bootstrap_proxy}"\n} end if encrypted_data_bag_secret.present? body << %Q{encrypted_data_bag_secret "/etc/chef/encrypted_data_bag_secret"\n} end body end |
#chef_run ⇒ String
116 117 118 |
# File 'lib/ridley/bootstrapper/context.rb', line 116 def chef_run "chef-client -j /etc/chef/first-boot.json -E #{environment}" end |
#clean_command ⇒ String
111 112 113 |
# File 'lib/ridley/bootstrapper/context.rb', line 111 def clean_command "rm /etc/chef/first-boot.json; rm /etc/chef/validation.pem" end |
#encrypted_data_bag_secret ⇒ String?
166 167 168 169 170 171 172 |
# File 'lib/ridley/bootstrapper/context.rb', line 166 def encrypted_data_bag_secret return nil if encrypted_data_bag_secret_path.nil? IO.read(encrypted_data_bag_secret_path).chomp rescue Errno::ENOENT => encrypted_data_bag_secret raise Errors::EncryptedDataBagSecretNotFound, "Error bootstrapping: Encrypted data bag secret provided but not found at '#{encrypted_data_bag_secret_path}'" end |
#first_boot ⇒ String
148 149 150 |
# File 'lib/ridley/bootstrapper/context.rb', line 148 def first_boot attributes.merge(run_list: run_list).to_json end |
#validation_key ⇒ String
The validation key to create a new client for the node
157 158 159 160 161 |
# File 'lib/ridley/bootstrapper/context.rb', line 157 def validation_key IO.read(validator_path).chomp rescue Errno::ENOENT raise Errors::ValidatorNotFound, "Error bootstrapping: Validator not found at '#{validator_path}'" end |