Class: Bolt::Config
- Inherits:
-
Object
- Object
- Bolt::Config
- Defined in:
- lib/bolt/config.rb
Constant Summary collapse
- TRANSPORT_OPTIONS =
i[password run-as sudo-password extensions private-key tty tmpdir user connect-timeout cacert token-file service-url interpreters file-protocol smb-port].freeze
Instance Attribute Summary collapse
-
#boltdir ⇒ Object
Returns the value of attribute boltdir.
-
#color ⇒ Object
Returns the value of attribute color.
-
#compile_concurrency ⇒ Object
Returns the value of attribute compile_concurrency.
-
#concurrency ⇒ Object
Returns the value of attribute concurrency.
-
#format ⇒ Object
Returns the value of attribute format.
-
#inventoryfile ⇒ Object
Returns the value of attribute inventoryfile.
-
#log ⇒ Object
Returns the value of attribute log.
- #modulepath ⇒ Object
-
#puppetdb ⇒ Object
Returns the value of attribute puppetdb.
-
#save_rerun ⇒ Object
Returns the value of attribute save_rerun.
-
#trace ⇒ Object
Returns the value of attribute trace.
-
#transport ⇒ Object
Returns the value of attribute transport.
-
#transports ⇒ Object
Returns the value of attribute transports.
Class Method Summary collapse
- .default ⇒ Object
- .from_boltdir(boltdir, overrides = {}) ⇒ Object
- .from_file(configfile, overrides = {}) ⇒ Object
Instance Method Summary collapse
- #apply_overrides(options) ⇒ Object
- #deep_clone ⇒ Object
- #default_inventoryfile ⇒ Object
- #hiera_config ⇒ Object
-
#initialize(boltdir, config_data, overrides = {}) ⇒ Config
constructor
A new instance of Config.
- #normalize_interpreters(interpreters) ⇒ Object
- #normalize_log(target) ⇒ Object
- #overwrite_transport_data(transport, transports) ⇒ Object
- #puppetfile ⇒ Object
- #rerunfile ⇒ Object
- #transport_conf ⇒ Object
- #transport_data_get ⇒ Object
- #update_from_inventory(data) ⇒ Object
- #update_logs(logs) ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(boltdir, config_data, overrides = {}) ⇒ Config
Returns a new instance of Config.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/bolt/config.rb', line 58 def initialize(boltdir, config_data, overrides = {}) @logger = Logging.logger[self] @boltdir = boltdir @concurrency = 100 @compile_concurrency = Etc.nprocessors @transport = 'ssh' @format = 'human' @puppetdb = {} @color = true @save_rerun = true # add an entry for the default console logger @log = { 'console' => {} } @transports = {} TRANSPORTS.each do |key, transport| @transports[key] = transport. end update_from_file(config_data) apply_overrides(overrides) validate end |
Instance Attribute Details
#boltdir ⇒ Object
Returns the value of attribute boltdir.
34 35 36 |
# File 'lib/bolt/config.rb', line 34 def boltdir @boltdir end |
#color ⇒ Object
Returns the value of attribute color.
34 35 36 |
# File 'lib/bolt/config.rb', line 34 def color @color end |
#compile_concurrency ⇒ Object
Returns the value of attribute compile_concurrency.
34 35 36 |
# File 'lib/bolt/config.rb', line 34 def compile_concurrency @compile_concurrency end |
#concurrency ⇒ Object
Returns the value of attribute concurrency.
34 35 36 |
# File 'lib/bolt/config.rb', line 34 def concurrency @concurrency end |
#format ⇒ Object
Returns the value of attribute format.
34 35 36 |
# File 'lib/bolt/config.rb', line 34 def format @format end |
#inventoryfile ⇒ Object
Returns the value of attribute inventoryfile.
34 35 36 |
# File 'lib/bolt/config.rb', line 34 def inventoryfile @inventoryfile end |
#log ⇒ Object
Returns the value of attribute log.
34 35 36 |
# File 'lib/bolt/config.rb', line 34 def log @log end |
#modulepath ⇒ Object
233 234 235 |
# File 'lib/bolt/config.rb', line 233 def modulepath @modulepath || @boltdir.modulepath end |
#puppetdb ⇒ Object
Returns the value of attribute puppetdb.
34 35 36 |
# File 'lib/bolt/config.rb', line 34 def puppetdb @puppetdb end |
#save_rerun ⇒ Object
Returns the value of attribute save_rerun.
34 35 36 |
# File 'lib/bolt/config.rb', line 34 def save_rerun @save_rerun end |
#trace ⇒ Object
Returns the value of attribute trace.
34 35 36 |
# File 'lib/bolt/config.rb', line 34 def trace @trace end |
#transport ⇒ Object
Returns the value of attribute transport.
34 35 36 |
# File 'lib/bolt/config.rb', line 34 def transport @transport end |
#transports ⇒ Object
Returns the value of attribute transports.
34 35 36 |
# File 'lib/bolt/config.rb', line 34 def transports @transports end |
Class Method Details
.default ⇒ Object
42 43 44 |
# File 'lib/bolt/config.rb', line 42 def self.default new(Bolt::Boltdir.new('.'), {}) end |
.from_boltdir(boltdir, overrides = {}) ⇒ Object
46 47 48 49 |
# File 'lib/bolt/config.rb', line 46 def self.from_boltdir(boltdir, overrides = {}) data = Bolt::Util.read_config_file(nil, [boltdir.config_file], 'config') || {} new(boltdir, data, overrides) end |
.from_file(configfile, overrides = {}) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/bolt/config.rb', line 51 def self.from_file(configfile, overrides = {}) boltdir = Bolt::Boltdir.new(Pathname.new(configfile)..dirname) data = Bolt::Util.read_config_file(configfile, [], 'config') || {} new(boltdir, data, overrides) end |
Instance Method Details
#apply_overrides(options) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/bolt/config.rb', line 169 def apply_overrides() i[concurrency transport format trace modulepath inventoryfile color].each do |key| send("#{key}=", [key]) if .key?(key) end @save_rerun = [:'save-rerun'] if .key?(:'save-rerun') if [:debug] @log['console'][:level] = :debug end @compile_concurrency = [:'compile-concurrency'] if [:'compile-concurrency'] TRANSPORTS.each_key do |transport| transport = @transports[transport] TRANSPORT_OPTIONS.each do |key| if [key] transport[key.to_s] = Bolt::Util.walk_keys([key], &:to_s) end end end if .key?(:ssl) # this defaults to true so we need to check the presence of the key @transports[:winrm]['ssl'] = [:ssl] end if .key?(:'ssl-verify') # this defaults to true so we need to check the presence of the key @transports[:winrm]['ssl-verify'] = [:'ssl-verify'] end if .key?(:'host-key-check') # this defaults to true so we need to check the presence of the key @transports[:ssh]['host-key-check'] = [:'host-key-check'] end end |
#deep_clone ⇒ Object
94 95 96 |
# File 'lib/bolt/config.rb', line 94 def deep_clone Bolt::Util.deep_clone(self) end |
#default_inventoryfile ⇒ Object
217 218 219 |
# File 'lib/bolt/config.rb', line 217 def default_inventoryfile [@boltdir.inventory_file] end |
#hiera_config ⇒ Object
225 226 227 |
# File 'lib/bolt/config.rb', line 225 def hiera_config @hiera_config || @boltdir.hiera_config end |
#normalize_interpreters(interpreters) ⇒ Object
98 99 100 101 102 |
# File 'lib/bolt/config.rb', line 98 def normalize_interpreters(interpreters) Bolt::Util.walk_keys(interpreters) do |key| key.chars[0] == '.' ? key : '.' + key end end |
#normalize_log(target) ⇒ Object
104 105 106 107 108 |
# File 'lib/bolt/config.rb', line 104 def normalize_log(target) return target if target == 'console' target = target[5..-1] if target.start_with?('file:') 'file:' + File.(target) end |
#overwrite_transport_data(transport, transports) ⇒ Object
85 86 87 88 |
# File 'lib/bolt/config.rb', line 85 def overwrite_transport_data(transport, transports) @transport = transport @transports = transports end |
#puppetfile ⇒ Object
229 230 231 |
# File 'lib/bolt/config.rb', line 229 def puppetfile @boltdir.puppetfile end |
#rerunfile ⇒ Object
221 222 223 |
# File 'lib/bolt/config.rb', line 221 def rerunfile @boltdir.rerunfile end |
#transport_conf ⇒ Object
212 213 214 215 |
# File 'lib/bolt/config.rb', line 212 def transport_conf { transport: @transport, transports: @transports } end |
#transport_data_get ⇒ Object
90 91 92 |
# File 'lib/bolt/config.rb', line 90 def transport_data_get { transport: @transport, transports: @transports } end |
#update_from_inventory(data) ⇒ Object
204 205 206 207 208 209 210 |
# File 'lib/bolt/config.rb', line 204 def update_from_inventory(data) update_from_file(data) if data['transport'] @transport = data['transport'] end end |
#update_logs(logs) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/bolt/config.rb', line 110 def update_logs(logs) logs.each_pair do |k, v| log_name = normalize_log(k) @log[log_name] ||= {} log = @log[log_name] next unless v.is_a?(Hash) if v.key?('level') log[:level] = v['level'].to_s end if v.key?('append') log[:append] = v['append'] end end end |
#validate ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/bolt/config.rb', line 237 def validate @log.each_pair do |name, params| if params.key?(:level) && !Bolt::Logger.valid_level?(params[:level]) raise Bolt::ValidationError, "level of log #{name} must be one of: #{Bolt::Logger.levels.join(', ')}; received #{params[:level]}" end if params.key?(:append) && params[:append] != true && params[:append] != false raise Bolt::ValidationError, "append flag of log #{name} must be a Boolean, received #{params[:append]}" end end unless @concurrency.is_a?(Integer) && @concurrency > 0 raise Bolt::ValidationError, 'Concurrency must be a positive integer' end unless @compile_concurrency.is_a?(Integer) && @compile_concurrency > 0 raise Bolt::ValidationError, 'Compile concurrency must be a positive integer' end compile_limit = 2 * Etc.nprocessors unless @compile_concurrency < compile_limit raise Bolt::ValidationError, "Compilation is CPU-intensive, set concurrency less than #{compile_limit}" end unless %w[human json].include? @format raise Bolt::ValidationError, "Unsupported format: '#{@format}'" end if @hiera_config && !(File.file?(@hiera_config) && File.readable?(@hiera_config)) raise Bolt::FileError, "Could not read hiera-config file #{@hiera_config}", @hiera_config end unless @transport.nil? || Bolt::TRANSPORTS.include?(@transport.to_sym) raise UnknownTransportError, @transport end TRANSPORTS.each do |transport, impl| impl.validate(@transports[transport]) end end |