ansible/inventory/lxc.rb

20 lines
574 B
Ruby
Raw Normal View History

2014-08-12 15:43:00 +00:00
#!/usr/bin/env ruby
require 'json'
json = JSON.load(File.open("/etc/lxc/container.json"))
containers = {"_meta" => {"hostvars" => {}}}
json["network"].each do |host, data|
next if data["lxc"] == false
role = data["group"] || "container"
hostvars = { ansible_connection: "lxc", ansible_python_interpreter: "/usr/bin/python2" }
hostvars.merge!(data["vars"]) if data["vars"]
2014-11-15 13:59:31 +00:00
containers[role] ||= {}
containers[role]["hosts"] ||= []
containers[role]["hosts"] << host
2014-08-12 15:43:00 +00:00
containers["_meta"]["hostvars"][host] = hostvars
end
puts JSON.pretty_generate(containers)