lib/bolt/inventory/group.rb in bolt-0.16.4 vs lib/bolt/inventory/group.rb in bolt-0.17.0
- old
+ new
@@ -6,12 +6,12 @@
attr_accessor :name, :nodes, :groups, :config, :rest
def initialize(data)
@logger = Logging.logger[self]
@name = data['name']
-
@nodes = {}
+
if data['nodes']
data['nodes'].each do |n|
n = { 'name' => n } if n.is_a? String
if @nodes.include? n['name']
@logger.warn("Ignoring duplicate node in #{@name}: #{n}")
@@ -19,10 +19,11 @@
@nodes[n['name']] = n
end
end
end
+ @vars = data['vars'] || {}
@config = data['config'] || {}
@groups = if data['groups']
data['groups'].map { |g| Group.new(g) }
else
[]
@@ -30,10 +31,18 @@
# this allows arbitrary info for the top level
@rest = data.reject { |k, _| %w[name nodes config groups].include? k }
end
+ def check_deprecated_config(context, name, config)
+ if config && config['transports']
+ msg = "#{context} #{name} contains invalid config option 'transports', see " \
+ "https://puppet.com/docs/bolt/0.x/inventory_file.html for the updated format"
+ raise ValidationError.new(msg, @name)
+ end
+ end
+
def validate(used_names = Set.new, node_names = Set.new, depth = 0)
raise ValidationError.new("Group does not have a name", nil) unless @name
if used_names.include?(@name)
raise ValidationError.new("Tried to redefine group #{@name}", @name)
end
@@ -42,10 +51,12 @@
if node_names.include?(@name)
raise ValidationError.new("Group #{@name} conflicts with node of the same name", @name)
end
raise ValidationError.new("Group #{@name} is too deeply nested", @name) if depth > 1
+ check_deprecated_config('Group', @name, @config)
+
used_names << @name
@nodes.each_value do |n|
# Require nodes to be parseable as a Target.
begin
@@ -58,10 +69,12 @@
raise ValidationError.new("Node #{n['name']} does not have a name", n['name']) unless n['name']
if used_names.include?(n['name'])
raise ValidationError.new("Group #{n['name']} conflicts with node of the same name", n['name'])
end
+ check_deprecated_config('Node', n['name'], n['config'])
+
node_names << n['name']
end
@groups.each do |g|
begin
@@ -74,40 +87,47 @@
nil
end
# The data functions below expect and return nil or a hash of the schema
- # { 'config' => Hash , groups => Array }
+ # { 'config' => Hash , 'vars' => Hash, groups => Array }
# As we add more options beyond config this schema will grow
def data_for(node_name)
data_merge(group_collect(node_name), node_collect(node_name))
end
def node_data(node_name)
if (data = @nodes[node_name])
{ 'config' => data['config'] || {},
+ 'vars' => data['vars'] || {},
# groups come from group_data
'groups' => [] }
end
end
def group_data
{ 'config' => @config,
+ 'vars' => @vars,
'groups' => [@name] }
end
def empty_data
{ 'config' => {},
+ 'vars' => {},
'groups' => [] }
end
def data_merge(data1, data2)
if data2.nil? || data1.nil?
return data2 || data1
end
{
'config' => Bolt::Util.deep_merge(data1['config'], data2['config']),
+ # Shallow merge instead of deep merge so that vars with a hash value
+ # are assigned a new hash, rather than merging the existing value
+ # with the value meant to replace it
+ 'vars' => data2['vars'].merge(data1['vars']),
'groups' => data2['groups'] + data1['groups']
}
end
# Returns all nodes contained within the group, which includes nodes from subgroups.