mirror of
				https://github.com/ansible-collections/community.general.git
				synced 2025-10-26 13:56:09 -07:00 
			
		
		
		
	* test/: PEP8 compliancy - Make PEP8 compliant * Python3 chokes on casting int to bytes (#24952) But if we tell the formatter that the var is a number, it works
		
			
				
	
	
		
			42 lines
		
	
	
	
		
			989 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
	
		
			989 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| import json
 | |
| import sys
 | |
| 
 | |
| from ansible.module_utils.basic import AnsibleModule
 | |
| 
 | |
| 
 | |
| 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"
 | |
|             )
 | |
|         ))
 | |
| 
 | |
|     module = AnsibleModule(
 | |
|         argument_spec=dict(
 | |
|             fail_mode=dict(type='list', default=['success'])
 | |
|         )
 | |
|     )
 | |
| 
 | |
|     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')
 | |
| 
 | |
|         module.exit_json(**result)
 | |
| 
 | |
|     finally:
 | |
|         if 'trailing_junk' in fail_mode:
 | |
|             print("trailing junk after module output")
 | |
| 
 | |
| main()
 |