From a6be1edd96ed304d70d26548d331f71966ef1784 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Sun, 15 Sep 2013 17:41:20 +0200 Subject: [PATCH] add inventory script for listing jails on *bsd --- plugins/inventory/jail.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 plugins/inventory/jail.py diff --git a/plugins/inventory/jail.py b/plugins/inventory/jail.py new file mode 100755 index 00000000000..c6caf38289a --- /dev/null +++ b/plugins/inventory/jail.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +# (c) 2013, Michael Scherer +# +# This file is part of Ansible, +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +from subprocess import Popen,PIPE +import sys +import json + +result = {} +result['all'] = {} + +pipe = Popen(['jls', '-q', 'name'], stdout=PIPE, universal_newlines=True) +result['all']['hosts'] = [x[:-1] for x in pipe.stdout.readlines()] +result['all']['vars'] = {} +result['all']['vars']['ansible_connection'] = 'jail' + +if len(sys.argv) == 2 and sys.argv[1] == '--list': + print json.dumps(result) +elif len(sys.argv) == 3 and sys.argv[1] == '--host': + print json.dumps({'ansible_connection': 'jail'}) +else: + print "Need a argument, either --list or --host "