From 40a979babd8a3da7592d19291f0af58289e8d415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 12 Aug 2014 17:43:00 +0200 Subject: [PATCH] add inventory script --- group_vars/all | 4 ---- inventory/localhost | 2 ++ inventory/lxc.rb | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) delete mode 100644 group_vars/all create mode 100644 inventory/localhost create mode 100755 inventory/lxc.rb diff --git a/group_vars/all b/group_vars/all deleted file mode 100644 index 2f21a2f..0000000 --- a/group_vars/all +++ /dev/null @@ -1,4 +0,0 @@ ---- -# Variables listed here are applicable to all host groups. - -ansible_python_interpreter: /usr/bin/python2 diff --git a/inventory/localhost b/inventory/localhost new file mode 100644 index 0000000..b0d2c91 --- /dev/null +++ b/inventory/localhost @@ -0,0 +1,2 @@ +[host] +localhost ansible_connection=local ansible_python_interpreter="/usr/bin/python2" diff --git a/inventory/lxc.rb b/inventory/lxc.rb new file mode 100755 index 0000000..1f0d37f --- /dev/null +++ b/inventory/lxc.rb @@ -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)