2013-09-08 21:59:38 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# (c) 2013, Michael Scherer <misc@zarb.org>
|
|
|
|
#
|
|
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-05-09 21:38:08 +00:00
|
|
|
from subprocess import Popen, PIPE
|
2013-09-08 21:59:38 +00:00
|
|
|
import sys
|
|
|
|
import json
|
|
|
|
|
|
|
|
result = {}
|
|
|
|
result['all'] = {}
|
|
|
|
|
|
|
|
pipe = Popen(['virsh', '-q', '-c', 'lxc:///', 'list', '--name', '--all'], stdout=PIPE, universal_newlines=True)
|
|
|
|
result['all']['hosts'] = [x[:-1] for x in pipe.stdout.readlines()]
|
|
|
|
result['all']['vars'] = {}
|
2015-11-12 20:19:40 +00:00
|
|
|
result['all']['vars']['ansible_connection'] = 'libvirt_lxc'
|
2013-09-08 21:59:38 +00:00
|
|
|
|
|
|
|
if len(sys.argv) == 2 and sys.argv[1] == '--list':
|
2015-08-28 06:18:13 +00:00
|
|
|
print(json.dumps(result))
|
2013-09-08 21:59:38 +00:00
|
|
|
elif len(sys.argv) == 3 and sys.argv[1] == '--host':
|
2015-11-12 20:19:40 +00:00
|
|
|
print(json.dumps({'ansible_connection': 'libvirt_lxc'}))
|
2013-09-08 21:59:38 +00:00
|
|
|
else:
|
2016-08-23 15:09:23 +00:00
|
|
|
sys.stderr.write("Need an argument, either --list or --host <host>\n")
|