diff --git a/changelogs/fragments/better_rhn_channel_errors.yml b/changelogs/fragments/better_rhn_channel_errors.yml new file mode 100644 index 00000000000..2e421fdee93 --- /dev/null +++ b/changelogs/fragments/better_rhn_channel_errors.yml @@ -0,0 +1,2 @@ +bugfixes: + - handle xmlrpc errors in the correct fashion for rhn_channel diff --git a/lib/ansible/modules/packaging/os/rhn_channel.py b/lib/ansible/modules/packaging/os/rhn_channel.py index 2c49090cb38..ca725a5aa04 100644 --- a/lib/ansible/modules/packaging/os/rhn_channel.py +++ b/lib/ansible/modules/packaging/os/rhn_channel.py @@ -59,6 +59,7 @@ EXAMPLES = ''' delegate_to: localhost ''' +from ansible.module_utils._text import to_text from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six.moves import xmlrpc_client @@ -114,14 +115,29 @@ def main(): password = module.params['password'] # initialize connection - client = xmlrpc_client.Server(saturl) - session = client.auth.login(user, password) + client = xmlrpc_client.ServerProxy(saturl) + try: + session = client.auth.login(user, password) + except Exception as e: + module.fail_json(msg="Unable to establish session with Sattelite server: %s " % to_text(e)) + + if not session: + module.fail_json(msg="Failed to establish session with Sattelite server.") # get systemid - sys_id = get_systemid(client, session, systname) + try: + sys_id = get_systemid(client, session, systname) + except Exception as e: + module.fail_json(msg="Unable to get system id: %s " % to_text(e)) + + if not sys_id: + module.fail_json(msg="Failed to get system id.") # get channels for system - chans = base_channels(client, session, sys_id) + try: + chans = base_channels(client, session, sys_id) + except Exception as e: + module.fail_json(msg="Unable to get channel information: %s " % to_text(e)) try: if state == 'present': @@ -137,6 +153,8 @@ def main(): else: unsubscribe_channels(channelname, client, session, systname, sys_id) module.exit_json(changed=True, msg="Channel %s removed" % channelname) + except Exception as e: + module.fail_json('Unable to %s channel (%s): %s' % ('add' if state == 'present' else 'remove', channelname, to_text(e))) finally: client.auth.logout(session)