|
|
@ -40,6 +40,8 @@ Tested with Ansible 1.9.2 and spacewalk 2.3
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import time
|
|
|
|
import time
|
|
|
@ -60,7 +62,7 @@ INI_FILE = os.path.join(base_dir, "spacewalk.ini")
|
|
|
|
|
|
|
|
|
|
|
|
# Sanity check
|
|
|
|
# Sanity check
|
|
|
|
if not os.path.exists(SW_REPORT):
|
|
|
|
if not os.path.exists(SW_REPORT):
|
|
|
|
print >> sys.stderr, 'Error: %s is required for operation.' % (SW_REPORT)
|
|
|
|
print('Error: %s is required for operation.' % (SW_REPORT), file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
# Pre-startup work
|
|
|
|
# Pre-startup work
|
|
|
@ -133,8 +135,8 @@ try:
|
|
|
|
org_groups[group['spacewalk_group_id']] = group['spacewalk_org_id']
|
|
|
|
org_groups[group['spacewalk_group_id']] = group['spacewalk_org_id']
|
|
|
|
|
|
|
|
|
|
|
|
except (OSError) as e:
|
|
|
|
except (OSError) as e:
|
|
|
|
print >> sys.stderr, 'Problem executing the command "%s system-groups": %s' % \
|
|
|
|
print('Problem executing the command "%s system-groups": %s' %
|
|
|
|
(SW_REPORT, str(e))
|
|
|
|
(SW_REPORT, str(e)), file=sys.stderr)
|
|
|
|
sys.exit(2)
|
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -149,8 +151,8 @@ if options.list:
|
|
|
|
host_vars[ item['spacewalk_profile_name'] ] = dict( ( key, ( value.split(';') if ';' in value else value) ) for key, value in item.items() )
|
|
|
|
host_vars[ item['spacewalk_profile_name'] ] = dict( ( key, ( value.split(';') if ';' in value else value) ) for key, value in item.items() )
|
|
|
|
|
|
|
|
|
|
|
|
except (OSError) as e:
|
|
|
|
except (OSError) as e:
|
|
|
|
print >> sys.stderr, 'Problem executing the command "%s inventory": %s' % \
|
|
|
|
print('Problem executing the command "%s inventory": %s' %
|
|
|
|
(SW_REPORT, str(e))
|
|
|
|
(SW_REPORT, str(e)), file=sys.stderr)
|
|
|
|
sys.exit(2)
|
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
|
|
|
|
groups = {}
|
|
|
|
groups = {}
|
|
|
@ -186,18 +188,18 @@ if options.list:
|
|
|
|
meta[ "hostvars" ][ system['spacewalk_server_name'] ] = host_vars[ system['spacewalk_server_name'] ]
|
|
|
|
meta[ "hostvars" ][ system['spacewalk_server_name'] ] = host_vars[ system['spacewalk_server_name'] ]
|
|
|
|
|
|
|
|
|
|
|
|
except (OSError) as e:
|
|
|
|
except (OSError) as e:
|
|
|
|
print >> sys.stderr, 'Problem executing the command "%s system-groups-systems": %s' % \
|
|
|
|
print('Problem executing the command "%s system-groups-systems": %s' %
|
|
|
|
(SW_REPORT, str(e))
|
|
|
|
(SW_REPORT, str(e)), file=sys.stderr)
|
|
|
|
sys.exit(2)
|
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
|
|
|
|
if options.human:
|
|
|
|
if options.human:
|
|
|
|
for group, systems in groups.iteritems():
|
|
|
|
for group, systems in groups.iteritems():
|
|
|
|
print '[%s]\n%s\n' % (group, '\n'.join(systems))
|
|
|
|
print('[%s]\n%s\n' % (group, '\n'.join(systems)))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
final = dict( [ (k, list(s)) for k, s in groups.iteritems() ] )
|
|
|
|
final = dict( [ (k, list(s)) for k, s in groups.iteritems() ] )
|
|
|
|
final["_meta"] = meta
|
|
|
|
final["_meta"] = meta
|
|
|
|
print json.dumps( final )
|
|
|
|
print(json.dumps( final ))
|
|
|
|
#print json.dumps(groups)
|
|
|
|
#print(json.dumps(groups))
|
|
|
|
sys.exit(0)
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -213,16 +215,16 @@ elif options.host:
|
|
|
|
break
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
except (OSError) as e:
|
|
|
|
except (OSError) as e:
|
|
|
|
print >> sys.stderr, 'Problem executing the command "%s inventory": %s' % \
|
|
|
|
print('Problem executing the command "%s inventory": %s' %
|
|
|
|
(SW_REPORT, str(e))
|
|
|
|
(SW_REPORT, str(e)), file=sys.stderr)
|
|
|
|
sys.exit(2)
|
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
|
|
|
|
if options.human:
|
|
|
|
if options.human:
|
|
|
|
print 'Host: %s' % options.host
|
|
|
|
print('Host: %s' % options.host)
|
|
|
|
for k, v in host_details.iteritems():
|
|
|
|
for k, v in host_details.iteritems():
|
|
|
|
print ' %s: %s' % (k, '\n '.join(v.split(';')))
|
|
|
|
print(' %s: %s' % (k, '\n '.join(v.split(';'))))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print json.dumps( dict( ( key, ( value.split(';') if ';' in value else value) ) for key, value in host_details.items() ) )
|
|
|
|
print( json.dumps( dict( ( key, ( value.split(';') if ';' in value else value) ) for key, value in host_details.items() ) ) )
|
|
|
|
sys.exit(0)
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|