1#!/usr/bin/env python 2 3# (c) 2015, Dagobert Michelsen <dam@baltic-online.de> 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(['zoneadm', 'list', '-ip'], stdout=PIPE, universal_newlines=True) 28result['all']['hosts'] = [] 29for l in pipe.stdout.readlines(): 30 # 1:work:running:/zones/work:3126dc59-9a07-4829-cde9-a816e4c5040e:native:shared 31 s = l.split(':') 32 if s[1] != 'global': 33 result['all']['hosts'].append(s[1]) 34 35result['all']['vars'] = {} 36result['all']['vars']['ansible_connection'] = 'zone' 37 38if len(sys.argv) == 2 and sys.argv[1] == '--list': 39 print(json.dumps(result)) 40elif len(sys.argv) == 3 and sys.argv[1] == '--host': 41 print(json.dumps({'ansible_connection': 'zone'})) 42else: 43 sys.stderr.write("Need an argument, either --list or --host <host>\n") 44