Skip to content

Commit

Permalink
adjusted output behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
dmccue authored and jimi-c committed Aug 7, 2015
1 parent 0ab970d commit ba6b89a
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions contrib/inventory/cobbler.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
Tested with Cobbler 2.0.11.
Changelog:
- 2015-06-21 dmccue: Heavily modified to support run-once _meta retrieval, results in
- 2015-06-21 dmccue: Modified to support run-once _meta retrieval, results in
higher performance at ansible startup. Groups are determined by owner rather than
default mgmt_classes. DNS name determined from hostname.
default mgmt_classes. DNS name determined from hostname. cobbler values are written
to a 'cobbler' fact namespace
- 2013-09-01 pgehres: Refactored implementation to make use of caching and to
limit the number of connections to external cobbler server for performance.
Expand Down Expand Up @@ -102,15 +103,14 @@ def __init__(self):
data_to_print = ""

# Data to print
#if self.args.host:
# data_to_print = self.get_host_info()

self.inventory['_meta'] = { 'hostvars': {} }
for hostname in self.cache:
self.inventory['_meta']['hostvars'][hostname] = {'cobbler': self.cache[hostname] }


data_to_print = self.json_format_dict(self.inventory, True)
if self.args.host:
data_to_print = self.get_host_info()
else:
self.inventory['_meta'] = { 'hostvars': {} }
for hostname in self.cache:
self.inventory['_meta']['hostvars'][hostname] = {'cobbler': self.cache[hostname] }

data_to_print += self.json_format_dict(self.inventory, True)

print data_to_print

Expand Down Expand Up @@ -149,7 +149,7 @@ def parse_cli_args(self):

parser = argparse.ArgumentParser(description='Produce an Ansible Inventory file based on Cobbler')
parser.add_argument('--list', action='store_true', default=True, help='List instances (default: True)')
#parser.add_argument('--host', action='store', help='Get all the variables about a specific instance')
parser.add_argument('--host', action='store', help='Get all the variables about a specific instance')
parser.add_argument('--refresh-cache', action='store_true', default=False,
help='Force refresh of cache by making API requests to cobbler (default: False - use cache files)')
self.args = parser.parse_args()
Expand Down Expand Up @@ -248,7 +248,7 @@ def load_cache_from_cache(self):

def write_to_cache(self, data, filename):
""" Writes data in JSON format to a file """
if data: print "DEBUG: data = " + str(data)
#if data: print "DEBUG: data = " + str(data)
json_data = self.json_format_dict(data, True)
cache = open(filename, 'w')
cache.write(json_data)
Expand Down

0 comments on commit ba6b89a

Please sign in to comment.