add inventory script

This commit is contained in:
Jörg Thalheim 2014-08-12 17:43:00 +02:00
parent a9ee3ee437
commit 40a979babd
3 changed files with 20 additions and 4 deletions

View File

@ -1,4 +0,0 @@
---
# Variables listed here are applicable to all host groups.
ansible_python_interpreter: /usr/bin/python2

2
inventory/localhost Normal file
View File

@ -0,0 +1,2 @@
[host]
localhost ansible_connection=local ansible_python_interpreter="/usr/bin/python2"

18
inventory/lxc.rb Executable file
View File

@ -0,0 +1,18 @@
#!/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] << host
containers["_meta"]["hostvars"][host] = hostvars
end
puts JSON.pretty_generate(containers)