lib/bolt/config.rb in bolt-2.13.0 vs lib/bolt/config.rb in bolt-2.14.0
- old
+ new
@@ -21,21 +21,28 @@
super(msg, 'bolt/unknown-transport')
end
end
class Config
- attr_reader :config_files, :warnings, :data, :transports, :project
+ attr_reader :config_files, :warnings, :data, :transports, :project, :modified_concurrency
TRANSPORT_CONFIG = {
'ssh' => Bolt::Config::Transport::SSH,
'winrm' => Bolt::Config::Transport::WinRM,
'pcp' => Bolt::Config::Transport::Orch,
'local' => Bolt::Config::Transport::Local,
'docker' => Bolt::Config::Transport::Docker,
'remote' => Bolt::Config::Transport::Remote
}.freeze
+ TRANSPORT_OPTION = { 'transport' => 'The default transport to use when the '\
+ 'transport for a target is not specified in the URL.' }.freeze
+
+ DEFAULT_TRANSPORT_OPTION = { 'transport' => 'ssh' }.freeze
+
+ CONFIG_IN_INVENTORY = TRANSPORT_CONFIG.merge(TRANSPORT_OPTION)
+
# NOTE: All configuration options should have a corresponding schema property
# in schemas/bolt-config.schema.json
OPTIONS = {
"apply_settings" => "A map of Puppet settings to use when applying Puppet code",
"color" => "Whether to use colored output when printing messages to the console.",
@@ -53,12 +60,12 @@
"puppetdb" => "A map containing options for configuring the Bolt PuppetDB client.",
"puppetfile" => "A map containing options for the `bolt puppetfile install` command.",
"save-rerun" => "Whether to update `.rerun.json` in the Bolt project directory. If "\
"your target names include passwords, set this value to `false` to avoid "\
"writing passwords to disk.",
- "transport" => "The default transport to use when the transport for a target is not "\
- "specified in the URL or inventory.",
+ "transport" => "The default transport to use when the transport for a target is not specified "\
+ "in the URL or inventory.",
"trusted-external-command" => "The path to an executable on the Bolt controller that can produce "\
"external trusted facts. **External trusted facts are experimental in both "\
"Puppet and Bolt and this API may change or be removed.**"
}.freeze
@@ -102,31 +109,35 @@
}.freeze
DEFAULT_DEFAULT_CONCURRENCY = 100
def self.default
- new(Bolt::Project.new('.'), {})
+ new(Bolt::Project.create_project('.'), {})
end
def self.from_project(project, overrides = {})
- data = {
- filepath: project.config_file,
- data: Bolt::Util.read_optional_yaml_hash(project.config_file, 'config')
- }
+ conf = if project.project_file == project.config_file
+ project.data
+ else
+ Bolt::Util.read_optional_yaml_hash(project.config_file, 'config')
+ end
+ data = { filepath: project.config_file, data: conf }
+
data = load_defaults(project).push(data).select { |config| config[:data]&.any? }
new(project, data, overrides)
end
def self.from_file(configfile, overrides = {})
- project = Bolt::Project.new(Pathname.new(configfile).expand_path.dirname)
-
- data = {
- filepath: project.config_file,
- data: Bolt::Util.read_yaml_hash(configfile, 'config')
- }
+ project = Bolt::Project.create_project(Pathname.new(configfile).expand_path.dirname)
+ conf = if project.project_file == project.config_file
+ project.data
+ else
+ Bolt::Util.read_yaml_hash(configfile, 'config')
+ end
+ data = { filepath: project.config_file, data: conf }
data = load_defaults(project).push(data).select { |config| config[:data]&.any? }
new(project, data, overrides)
end
@@ -156,12 +167,12 @@
unless config_data.is_a?(Array)
config_data = [{ filepath: project.config_file, data: config_data }]
end
@logger = Logging.logger[self]
- @warnings = []
@project = project
+ @warnings = @project.warnings.dup
@transports = {}
@config_files = []
default_data = {
'apply_settings' => {},
@@ -185,19 +196,13 @@
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')
- if default_concurrency != DEFAULT_DEFAULT_CONCURRENCY &&
- !ld_concurrency &&
- !override_data.key?('concurrency')
- concurrency_warning = { option: 'concurrency',
- msg: "Concurrency will default to #{default_concurrency} because ulimit "\
- "is low: #{Etc.sysconf(Etc::SC_OPEN_MAX)}. Set concurrency with "\
- "'--concurrency', or set your ulimit with 'ulimit -n <limit>'" }
- @warnings << concurrency_warning
- end
+ @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)
@@ -481,10 +486,10 @@
def default_concurrency
@default_concurrency ||= if !sc_open_max_available? || Etc.sysconf(Etc::SC_OPEN_MAX) >= 300
DEFAULT_DEFAULT_CONCURRENCY
else
- Etc.sysconf(Etc::SC_OPEN_MAX) / 3
+ Etc.sysconf(Etc::SC_OPEN_MAX) / 7
end
end
end
end