Method: Bolt::Config#initialize

Defined in:
lib/bolt/config.rb

#initialize(project, config_data, overrides = {}) ⇒ Config

Returns a new instance of Config.



161
162
163
164
165
166
167
168
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/bolt/config.rb', line 161

def initialize(project, config_data, overrides = {})
  unless config_data.is_a?(Array)
    config_data = [{ filepath: project.project_file, data: config_data }]
  end

  @logger       = Bolt::Logger.logger(self)
  @project      = project
  @transports   = {}
  @config_files = []

  default_data = {
    'analytics'           => true,
    'apply-settings'      => {},
    'color'               => true,
    'compile-concurrency' => Etc.nprocessors,
    'concurrency'         => default_concurrency,
    'disable-warnings'    => [],
    'format'              => 'human',
    'log'                 => { 'console' => {} },
    'module-install'      => {},
    'plugin-hooks'        => {},
    'plugins'             => {},
    'puppetdb'            => {},
    'save-rerun'          => true,
    'spinner'             => true,
    'transport'           => 'ssh'
  }

  if project.path.directory?
    default_data['log']['bolt-debug.log'] = {
      'level' => 'debug',
      'append' => false
    }
  end

  loaded_data = config_data.each_with_object([]) do |data, acc|
    if data[:data].any?
      @config_files.push(data[:filepath])
      acc.push(data[:data])
    end
  end

  override_data = normalize_overrides(overrides)

  # If we need to lower concurrency and concurrency is not configured
  ld_concurrency = loaded_data.map(&:keys).flatten.include?('concurrency')
  @modified_concurrency = default_concurrency != DEFAULT_DEFAULT_CONCURRENCY &&
                          !ld_concurrency &&
                          !override_data.key?('concurrency')

  @data = merge_config_layers(default_data, *loaded_data, override_data)

  TRANSPORT_CONFIG.each do |transport, config|
    @transports[transport] = config.new(@data.delete(transport), @project.path)
  end

  finalize_data
  validate
end