2020-06-23 04:05:30 +02:00
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
|
|
|
|
2016-10-02 17:03:42 +02:00
|
|
|
import json
|
2017-05-30 19:05:19 +02:00
|
|
|
import sys
|
|
|
|
|
2016-10-02 17:03:42 +02:00
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
|
2017-05-30 19:05:19 +02:00
|
|
|
|
2016-10-02 17:03:42 +02:00
|
|
|
def main():
|
|
|
|
if "--interactive" in sys.argv:
|
|
|
|
import ansible.module_utils.basic
|
|
|
|
ansible.module_utils.basic._ANSIBLE_ARGS = json.dumps(dict(
|
|
|
|
ANSIBLE_MODULE_ARGS=dict(
|
|
|
|
fail_mode="graceful"
|
|
|
|
)
|
|
|
|
))
|
|
|
|
|
2017-05-30 19:05:19 +02:00
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec=dict(
|
|
|
|
fail_mode=dict(type='list', default=['success'])
|
2016-10-02 17:03:42 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
result = dict(changed=True)
|
|
|
|
|
|
|
|
fail_mode = module.params['fail_mode']
|
|
|
|
|
|
|
|
try:
|
|
|
|
if 'leading_junk' in fail_mode:
|
|
|
|
print("leading junk before module output")
|
|
|
|
|
|
|
|
if 'graceful' in fail_mode:
|
|
|
|
module.fail_json(msg="failed gracefully")
|
|
|
|
|
|
|
|
if 'exception' in fail_mode:
|
|
|
|
raise Exception('failing via exception')
|
|
|
|
|
2020-07-13 18:58:14 +02:00
|
|
|
if 'stderr' in fail_mode:
|
|
|
|
print('printed to stderr', file=sys.stderr)
|
|
|
|
|
2016-10-02 17:03:42 +02:00
|
|
|
module.exit_json(**result)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
if 'trailing_junk' in fail_mode:
|
|
|
|
print("trailing junk after module output")
|
|
|
|
|
2018-07-29 13:46:06 +02:00
|
|
|
|
2017-01-27 22:04:59 +01:00
|
|
|
main()
|