1#!/usr/bin/env python
2
3# (c) 2013, Michael Scherer <misc@zarb.org>
4#
5# This file is part of Ansible,
6#
7# Ansible is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# Ansible is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
19
20from subprocess import Popen, PIPE
21import sys
22import json
23
24result = {}
25result['all'] = {}
26
27pipe = Popen(['jls', '-q', 'name'], stdout=PIPE, universal_newlines=True)
28result['all']['hosts'] = [x[:-1] for x in pipe.stdout.readlines()]
29result['all']['vars'] = {}
30result['all']['vars']['ansible_connection'] = 'jail'
31
32if len(sys.argv) == 2 and sys.argv[1] == '--list':
33    print(json.dumps(result))
34elif len(sys.argv) == 3 and sys.argv[1] == '--host':
35    print(json.dumps({'ansible_connection': 'jail'}))
36else:
37    sys.stderr.write("Need an argument, either --list or --host <host>\n")
38