mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 13:20:23 -07:00
linode_v4: correct usage of module.fail_json (#48882)
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
652da82558
commit
a32902427c
1 changed files with 7 additions and 13 deletions
|
@ -181,9 +181,7 @@ def create_linode(module, client, **kwargs):
|
||||||
try:
|
try:
|
||||||
response = client.linode.instance_create(**kwargs)
|
response = client.linode.instance_create(**kwargs)
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
raise module.fail_json(msg=(
|
module.fail_json(msg='Unable to query the Linode API. Saw: %s' % exception)
|
||||||
'Unable to query the Linode API. Saw: %s'
|
|
||||||
) % exception)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if isinstance(response, tuple):
|
if isinstance(response, tuple):
|
||||||
|
@ -194,11 +192,10 @@ def create_linode(module, client, **kwargs):
|
||||||
else:
|
else:
|
||||||
return response._raw_json
|
return response._raw_json
|
||||||
except TypeError:
|
except TypeError:
|
||||||
raise module.fail_json(msg=(
|
module.fail_json(msg='Unable to parse Linode instance creation'
|
||||||
'Unable to parse Linode instance creation '
|
' response. Please raise a bug against this'
|
||||||
'response. Please raise a bug against this '
|
' module on https://github.com/ansible/ansible/issues'
|
||||||
'module on https://github.com/ansible/ansible/issues'
|
)
|
||||||
))
|
|
||||||
|
|
||||||
|
|
||||||
def maybe_instance_from_label(module, client):
|
def maybe_instance_from_label(module, client):
|
||||||
|
@ -210,9 +207,7 @@ def maybe_instance_from_label(module, client):
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return None
|
return None
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
raise module.fail_json(msg=(
|
module.fail_json(msg='Unable to query the Linode API. Saw: %s' % exception)
|
||||||
'Unable to query the Linode API. Saw: %s'
|
|
||||||
) % exception)
|
|
||||||
|
|
||||||
|
|
||||||
def initialise_module():
|
def initialise_module():
|
||||||
|
@ -262,8 +257,7 @@ def main():
|
||||||
module = initialise_module()
|
module = initialise_module()
|
||||||
|
|
||||||
if not HAS_LINODE_DEPENDENCY:
|
if not HAS_LINODE_DEPENDENCY:
|
||||||
msg = 'The linode_v4 module requires the linode_api4 package'
|
module.fail_json(msg='The linode_v4 module requires the linode_api4 package')
|
||||||
raise module.fail_json(msg=msg)
|
|
||||||
|
|
||||||
client = build_client(module)
|
client = build_client(module)
|
||||||
instance = maybe_instance_from_label(module, client)
|
instance = maybe_instance_from_label(module, client)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue