You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
ansible/inventory/lxc.rb

19 lines
574 B

#!/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"]
containers[role] ||= {}
containers[role]["hosts"] ||= []
containers[role]["hosts"] << host
containers["_meta"]["hostvars"][host] = hostvars
end
puts JSON.pretty_generate(containers)