This repository was archived by the owner on Jul 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathansible-satellite.py
More file actions
executable file
·51 lines (42 loc) · 1.5 KB
/
Copy pathansible-satellite.py
File metadata and controls
executable file
·51 lines (42 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
import argparse
import ConfigParser
import json
import os
import xmlrpclib
def main():
parser = argparse.ArgumentParser(
description='Dynamic inventory from Satellite')
parser.add_argument('--config', help='configuration file',
default='%s/.ansible-satellite' % os.path.expanduser('~'))
parser.add_argument('--list', action='store_true')
parser.add_argument('--host', action='store_true')
args = parser.parse_args()
# No support for --host yet
if args.host is True:
print '{}'
return
# Parse the config file
config = ConfigParser.ConfigParser()
config.read(args.config)
# Setup the client and obtain a key
client = xmlrpclib.Server(config.get('satellite', 'url'))
key = client.auth.login(config.get('credentials', 'username'),
config.get('credentials', 'password'))
# Get the data
groups = {}
for group in client.systemgroup.listAllGroups(key):
group_safe_name = group['name'].lower().replace(' ', '_')
groups[group_safe_name] = []
for system in client.systemgroup.listSystems(key, group['name']):
groups[group_safe_name].append(system['hostname'])
# Format the data
if args.list is True:
print json.dumps(groups, indent=2)
else:
for group in groups:
print '[%s]' % group
print '\n'.join(groups[group])
print
if __name__ == '__main__':
main()