Debian Codegraph @

test/integration/targets/async_fail/library/async_test.py

raw
1 from __future__ import annotations
2
3 import time
4
5 from ansible.module_utils.basic import AnsibleModule
6
7
8 def main():
9 module = AnsibleModule(
10 argument_spec=dict(
11 fail_mode=dict(type='list', default=['success'])
12 )
13 )
14
15 result = dict(changed=True)
16
17 fail_mode = module.params['fail_mode']
18
19 try:
20 if 'leading_junk' in fail_mode:
21 print("leading junk before module output")
22
23 if 'graceful' in fail_mode:
24 module.fail_json(msg="failed gracefully")
25
26 if 'exception' in fail_mode:
27 raise Exception('failing via exception')
28
29 if 'recovered_fail' in fail_mode:
30 result = {"msg": "succeeded", "failed": False, "changed": True}
31 # Wait in the middle to setup a race where the controller reads incomplete data from our
32 # special async_status the first poll
33 time.sleep(5)
34
35 module.exit_json(**result)
36
37 finally:
38 if 'trailing_junk' in fail_mode:
39 print("trailing junk after module output")
40
41
42 main()