Search code examples
pythonansiblemulti-factor-authenticationansible-api

How to set an Ansible API tqm.run() timeout for MFA Users?


When 'ansible_user' is mistakenly set to an MFA user, tqm hangs indefinitely.
I set a break point in 'task_queue_manager.py' here:

play_return = strategy.run(iterator, play_context)

But I can't find anything I can use to stop, end, or error out the process.
Below is sudo code representing a guess to how it could work.

timeout = 300
result = tqm.run(play)
if not result and timeout and tqm is not None:
    tqm.cleanup()

Does anyone know of a solution directly using tqm or even a workaround like what I've eluded to above?


Solution

  • I found a way around this by using the func_timeout lib. wrapping the tqm.run in a try block and sending it into the timeout fcn worked for me.

    try: exitstatus = func_timeout(self.tqm_timeout, tqm.run, args=(play,)) except FunctionTimedOut: msg = "tqm.run could not complete within {} seconds and was terminated.".format(self.tqm_timeout) raise Exception(msg) except Exception as e: raise Exception('exception in tqm was {}'.format(e))