Handle errors correctly in rhn_channel (#54194)
* Handle errors correctly in rhn_channel * also fail if required info is not available
This commit is contained in:
parent
785afc7a53
commit
fee4a0df94
2 changed files with 24 additions and 4 deletions
2
changelogs/fragments/better_rhn_channel_errors.yml
Normal file
2
changelogs/fragments/better_rhn_channel_errors.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- handle xmlrpc errors in the correct fashion for rhn_channel
|
|
@ -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)
|
||||
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
|
||||
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
|
||||
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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue