Unit Testing Ansible Modules — Ansible Documentation
docs.ansible.com › testing_units_modulesDec 21, 2021 · class AnsibleExitJson (Exception): """Exception class to be raised by module.exit_json and caught by the test case""" pass # you may also do the same to fail json module = MagicMock module. exit_json. side_effect = AnsibleExitJson (Exception) with self. assertRaises (AnsibleExitJson) as result: return = my_module. test_this_function (module, argument) module. fail_json. assert_not_called assert return ["changed"] == True
module.exit_json doen't display any msg · Issue #16451 ...
github.com › ansible › ansibleJun 27, 2016 · name='' (rc, out, err) = module.run_command(ocsh_cmd,check_rc=True) print out print err if rc == 1: module.fail_json(msg = out) # else: # module.exit_json(changed=True, name=name, # ansible_facts=dict(ansible_hostname=name.split(','), # ansible_nodename=name, # ansible_fqdn=socket.getfqdn(), # ansible_domain='.'.join(socket.getfqdn().split('.')[1:]))) # module.fail_json(changed=True, msg=out) result={} if rc is None: result['changed']=False else: result['changed']=True if out: result['stdout ...