Concerning Ansible, this should be fairly straightforwards I hope:


I have 3 servers, red, green, and blue.

I have a task created for ansible to use yum in linux to install a random package in a playbook.

In this same playbook, below the yum task are 2 other random tasks, their content is not important.

When I run this playbook, the yum task runs just fine on servers red, and green, but on blue it will hang up to 3 minutes before failing out. This is bad because it "can" hold up other plays/tasks, even if I were to utilize forks.

My goal is to find a way to force ansible to give up on a particular task if it takes more than "x" number of seconds to complete, either by closing the ssh session, or whatever, and then hopefully reporting that it failed, and/or the reason that server in the task was skipped.

This is different than ansible "waiting" for a task to complete, I can't do that in this situation because the task would never complete, and/or just take far too long to fail. Also, on subsequent runs it would still just repeat the behavior of hanging for 10 minutes. Thus, I would rather it either fail out after a timeout, or skip the task after a timeout. (preferably with a custom message.)

I've looked around in the docs and online, and can't quite find the solution I am looking for as the answer to this. Does anyone have any idea on how this might be accomplished? (No, I can't actually fix the underlying issue, that would cause a break in the policy for my customer, and I'd prefer to not have to exclude the problem servers from the run just because of this.)

Thanks in advance!

  • Some webbing and a brief look in the "Ansible Up & Running" book indicates that calling a shell script that runs timeout 30s yum ... would be one way. – thrig Nov 11 '16 at 0:16
  • Thanks thrig, but I already sorta figured on that, and I would have to add a gigantic amount of conditions and exit code reading into ansible to make it act appropriately using that method. I was hoping that there was a way to do it in ansible natively without the use of a bash/perl/whatever script. – Viscosity Nov 11 '16 at 14:34
  • There is an ANSIBLE_TIMEOUT though that looks global. Maybe make a feature request to the ansible folks? – thrig Nov 11 '16 at 14:44
  • I'd consider making a feature request, but sadly it seems calling a custom script using the timeout built into bash is "probably" the best solution as thrig already mentioned. The reason I brought this up is that it can be useful if say yum is blocked in a DMZ, and there isn't any proxy to make it work. You don't want the task hanging forever. But I suppose you could also define group/host variables in your ansible hosts file such that ansible could be coded to skip this step on certain servers. Gotta get those internal repos going.. – Viscosity Nov 29 '16 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.