lib/bolt/inventory/group.rb in bolt-2.40.2 vs lib/bolt/inventory/group.rb in bolt-2.42.0

- old
+ new

@@ -1,7 +1,8 @@ # frozen_string_literal: true +require 'bolt/config/options' require 'bolt/inventory/group' require 'bolt/inventory/inventory' require 'bolt/inventory/target' module Bolt @@ -16,16 +17,24 @@ DATA_KEYS = %w[config facts vars features plugin_hooks].freeze TARGET_KEYS = DATA_KEYS + %w[name alias uri] GROUP_KEYS = DATA_KEYS + %w[name groups targets] CONFIG_KEYS = Bolt::Config::INVENTORY_OPTIONS.keys - def initialize(input, plugins) + def initialize(input, plugins, all_group: false) @logger = Bolt::Logger.logger(self) @plugins = plugins input = @plugins.resolve_top_level_references(input) if @plugins.reference?(input) + if all_group + if input.key?('name') && input['name'] != 'all' + @logger.warn("Top-level group '#{input['name']}' cannot specify a name, using 'all' instead.") + end + + input = input.merge('name' => 'all') + end + raise ValidationError.new("Group does not have a name", nil) unless input.key?('name') @name = @plugins.resolve_references(input['name']) raise ValidationError.new("Group name must be a String, not #{@name.inspect}", nil) unless @name.is_a?(String) @@ -313,10 +322,29 @@ 'vars' => @plugins.resolve_references(data.fetch('vars', {})), 'facts' => @plugins.resolve_references(data.fetch('facts', {})), 'features' => @plugins.resolve_references(data.fetch('features', [])), 'plugin_hooks' => @plugins.resolve_references(data.fetch('plugin_hooks', {})) } + validate_data_keys(result, target) + + Bolt::Config::Options::TRANSPORT_CONFIG.each_key do |transport| + next unless result['config'].key?(transport) + transport_config = result['config'][transport] + next unless transport_config.is_a?(Hash) + transport_config = Bolt::Util.postwalk_vals(transport_config) do |val| + if val.is_a?(Hash) + val = val.compact + val = nil if val.empty? + end + val + end + # the transport config is user-specified data so we + # still want to preserve it even if it exclusively + # contains nil-resolved keys + result['config'][transport] = transport_config || {} + end + result['features'] = Set.new(result['features'].flatten) result end def validate_data_keys(data, target = nil)