Skip to content

Commit

Permalink
Fix print_hostnames of inventory.py
Browse files Browse the repository at this point in the history
When trying to run print_hostnames of inventory.py, it outputs the following
error:

 $ CONFIG_FILE=./test-hosts.yaml python3 ./inventory.py print_hostnames
 Traceback (most recent call last):
   File "./inventory.py", line 472, in <module>
     sys.exit(main())
   File "./inventory.py", line 467, in main
     KubesprayInventory(argv, CONFIG_FILE)
   File "./inventory.py", line 92, in __init__
     self.parse_command(changed_hosts[0], changed_hosts[1:])
   File "./inventory.py", line 415, in parse_command
     self.print_hostnames()
   File "./inventory.py", line 455, in print_hostnames
     print(' '.join(self.yaml_config['all']['hosts'].keys()))
 KeyError: 'all'

because it is missed to load a hosts config file before printing hostnames.
This fixes the issue.
  • Loading branch information
Kenichi Omichi committed Feb 17, 2022
1 parent da8522a commit 23b7759
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions contrib/inventory_builder/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def __init__(self, changed_hosts=None, config_file=None):
if changed_hosts[0] == "add":
loadPreviousConfig = True
changed_hosts = changed_hosts[1:]
elif changed_hosts[0] == "print_hostnames":
loadPreviousConfig = True
else:
self.parse_command(changed_hosts[0], changed_hosts[1:])
sys.exit(0)
Expand All @@ -105,6 +107,10 @@ def __init__(self, changed_hosts=None, config_file=None):
print(e)
sys.exit(1)

if changed_hosts[0] == "print_hostnames":
self.print_hostnames()
sys.exit(0)

self.ensure_required_groups(ROLES)

if changed_hosts:
Expand Down

0 comments on commit 23b7759

Please sign in to comment.