Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic inventory fails if a server has no boot device #27

Closed
jbuchhammer opened this issue May 20, 2019 · 1 comment
Closed

Dynamic inventory fails if a server has no boot device #27

jbuchhammer opened this issue May 20, 2019 · 1 comment

Comments

@jbuchhammer
Copy link

jbuchhammer commented May 20, 2019

Description

If the group_by_image_name configuration option is True, getting the inventory fails with a KeyError if a server has no boot device.

Expected Behaviour

Servers without boot device must be skipped in the generation of the image group.

Error Details

root@debian:/Ansible# profitbricks_inventory.py –i
Traceback (most recent call last):
  File "/usr/local/lib/profitbricks-module-ansible/inventory/profitbricks_inventory.py", line 529, in <module>
    ProfitBricksInventory()
  File "/usr/local/lib/profitbricks-module-ansible/inventory/profitbricks_inventory.py", line 155, in __init__
    self.build_inventory()
  File "/usr/local/lib/profitbricks-module-ansible/inventory/profitbricks_inventory.py", line 414, in build_inventory
    if image_key in boot_device['properties']:
KeyError: 'properties'

The cause is in the incomplete if/elif clause in line 407 to 413:

boot_device = {}
image_key = 'image'
if server['properties']['bootVolume'] is not None:
   boot_device = server['properties']['bootVolume']
elif server['properties']['bootCdrom'] is not None:
   boot_device = server['properties']['bootCdrom']
   image_key = 'name'

The case that bootVolume and bootCdrom are None is not considered.
Either an additional elif clause is needed or boot_device needs to be tested to avoid this error.

Note: group_by_licence_type does not run into this error because this case is tested too.

@jbuchhammer jbuchhammer changed the title Dynamic inventory fails if a server has no boot volume Dynamic inventory fails if a server has no boot device May 20, 2019
@pennycoders
Copy link
Contributor

Hi @jbuchhammer ,

Can you please check this fix?

Regards,

Alex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants