lib/bolt/inventory/group.rb in bolt-1.29.1 vs lib/bolt/inventory/group.rb in bolt-1.30.0

- old
+ new

@@ -3,16 +3,17 @@ module Bolt class Inventory # Group is a specific implementation of Inventory based on nested # structured data. class Group - attr_accessor :name, :nodes, :aliases, :name_or_alias, :groups, :config, :rest, :facts, :vars, :features + attr_accessor :name, :nodes, :aliases, :name_or_alias, :groups, + :config, :rest, :facts, :vars, :features, :plugin_hooks # Regex used to validate group names and target aliases. NAME_REGEX = /\A[a-z0-9_][a-z0-9_-]*\Z/.freeze - DATA_KEYS = %w[name config facts vars features].freeze + DATA_KEYS = %w[name config facts vars features plugin_hooks].freeze NODE_KEYS = DATA_KEYS + ['alias'] GROUP_KEYS = DATA_KEYS + %w[groups nodes] CONFIG_KEYS = Bolt::TRANSPORTS.keys.map(&:to_s) + ['transport'] def initialize(data) @@ -31,10 +32,11 @@ end @vars = fetch_value(data, 'vars', Hash) @facts = fetch_value(data, 'facts', Hash) @features = fetch_value(data, 'features', Array) + @plugin_hooks = fetch_value(data, 'plugin_hooks', Hash) @config = fetch_value(data, 'config', Hash) unless (unexpected_keys = @config.keys - CONFIG_KEYS).empty? msg = "Found unexpected key(s) #{unexpected_keys.join(', ')} in config for group #{@name}" @logger.warn(msg) @@ -196,28 +198,31 @@ if (data = @nodes[node_name]) { 'config' => data['config'] || {}, 'vars' => data['vars'] || {}, 'facts' => data['facts'] || {}, 'features' => data['features'] || [], + 'plugin_hooks' => data['plugin_hooks'] || {}, # groups come from group_data 'groups' => [] } end end def group_data { 'config' => @config, 'vars' => @vars, 'facts' => @facts, 'features' => @features, + 'plugin_hooks' => @plugin_hooks, 'groups' => [@name] } end def empty_data { 'config' => {}, 'vars' => {}, 'facts' => {}, 'features' => [], + 'plugin_hooks' => {}, 'groups' => [] } end def data_merge(data1, data2) if data2.nil? || data1.nil? @@ -230,9 +235,10 @@ # are assigned a new hash, rather than merging the existing value # with the value meant to replace it 'vars' => data1['vars'].merge(data2['vars']), 'facts' => Bolt::Util.deep_merge(data1['facts'], data2['facts']), 'features' => data1['features'] | data2['features'], + 'plugin_hooks' => data1['plugin_hooks'].merge(data2['plugin_hooks']), 'groups' => data2['groups'] + data1['groups'] } end # Returns all nodes contained within the group, which includes nodes from subgroups.