Skip to content

Commit

Permalink
txt_table template: Don't barf on hosts with missing information
Browse files Browse the repository at this point in the history
  • Loading branch information
fboender committed Jul 5, 2015
1 parent e38eb2b commit d8b5ee8
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/txt_table.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,28 @@ cols = [
col_longest = {}
for hostname, host in hosts.items():
for col in cols:
field_value = col['field'](host)
if len(field_value) > col_longest.get(col['title'], 0):
col_longest[col['title']] = len(field_value)
try:
field_value = col['field'](host)
if len(field_value) > col_longest.get(col['title'], 0):
col_longest[col['title']] = len(field_value)
except KeyError:
pass

# Print out headers
for col in cols:
sys.stdout.write(col['title'].ljust(col_longest[col['title']] + col_space))
sys.stdout.write('\n')

for col in cols:
sys.stdout.write('-' * col_longest[col['title']] + (' ' * col_space))
sys.stdout.write('\n')

# Print out columns
for hostname, host in hosts.items():
for col in cols:
sys.stdout.write(col['field'](host).ljust(col_longest[col['title']]) + (' ' * col_space))
if 'ansible_facts' not in host:
sys.stdout.write('{}: No info collected'.format(hostname))
else:
for col in cols:
sys.stdout.write(col['field'](host).ljust(col_longest[col['title']]) + (' ' * col_space))
sys.stdout.write('\n')
%>

0 comments on commit d8b5ee8

Please sign in to comment.