Parse and insert group variables into the generated inventory.
This commit is contained in:
parent
3fbbfeb862
commit
dd4ae1a51c
|
@ -88,21 +88,27 @@ module VagrantPlugins
|
||||||
# Write out groups information.
|
# Write out groups information.
|
||||||
# All defined groups will be included, but only supported
|
# All defined groups will be included, but only supported
|
||||||
# machines and defined child groups will be included.
|
# machines and defined child groups will be included.
|
||||||
# Group variables are intentionally skipped.
|
|
||||||
def generate_inventory_groups
|
def generate_inventory_groups
|
||||||
groups_of_groups = {}
|
groups_of_groups = {}
|
||||||
defined_groups = []
|
defined_groups = []
|
||||||
|
group_vars = {}
|
||||||
inventory_groups = ""
|
inventory_groups = ""
|
||||||
|
|
||||||
config.groups.each_pair do |gname, gmembers|
|
config.groups.each_pair do |gname, gmembers|
|
||||||
# Require that gmembers be an array
|
if gmembers.is_a?(String)
|
||||||
# (easier to be tolerant and avoid error management of few value)
|
gmembers = gmembers.split(/\s+/)
|
||||||
gmembers = [gmembers] if !gmembers.is_a?(Array)
|
elsif gmembers.is_a?(Hash)
|
||||||
|
gmembers = gmembers.each.collect{ |k, v| "#{k}=#{v}" }
|
||||||
|
elsif !gmembers.is_a?(Array)
|
||||||
|
gmembers = []
|
||||||
|
end
|
||||||
|
|
||||||
if gname.end_with?(":children")
|
if gname.end_with?(":children")
|
||||||
groups_of_groups[gname] = gmembers
|
groups_of_groups[gname] = gmembers
|
||||||
defined_groups << gname.sub(/:children$/, '')
|
defined_groups << gname.sub(/:children$/, '')
|
||||||
elsif !gname.include?(':vars')
|
elsif gname.end_with?(":vars")
|
||||||
|
group_vars[gname] = gmembers
|
||||||
|
else
|
||||||
defined_groups << gname
|
defined_groups << gname
|
||||||
inventory_groups += "\n[#{gname}]\n"
|
inventory_groups += "\n[#{gname}]\n"
|
||||||
gmembers.each do |gm|
|
gmembers.each do |gm|
|
||||||
|
@ -119,6 +125,12 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
group_vars.each_pair do |gname, gmembers|
|
||||||
|
if defined_groups.include?(gname.sub(/:vars$/, ""))
|
||||||
|
inventory_groups += "\n[#{gname}]\n" + gmembers.join("\n") + "\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return inventory_groups
|
return inventory_groups
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue