Nosmoht / ansible-module-foreman

Ansible module to manage configuration of Foreman
49 stars 32 forks source link

host: UnboundLocalError: local variable 'power_management_enabled' referenced before assignment #38

Closed stintel closed 8 years ago

stintel commented 8 years ago

The host module fails with the error below.

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: UnboundLocalError: local variable 'power_management_enabled' referenced before assignment

stintel commented 8 years ago

The problem is obvious:

    try:
        host_power = theforeman.get_host_power(host_id=host_id)
    except ForemanError as e:
        # http://projects.theforeman.org/projects/foreman/wiki/ERF42-9958
        if 'ERF42-9958' in e.message:
            power_management_enabled = False
        else:
            module.fail_json(
                msg='Could not get host power information: {0}'.format(e.message))
    if power_management_enabled:
        host_power_state = host_power.get('power')

If the get_host_power method doesn't fail, the power_management_enabled variable doesn't exist. And while typing this I think I know the best way to fix it. PR coming soon :-)

Nosmoht commented 8 years ago

Thanks @stintel