ansible / proposals

Repository for sharing and tracking progress on enhancement proposals for Ansible.
Creative Commons Zero v1.0 Universal
93 stars 19 forks source link

Ansible needs a native task timeout support #159

Closed ssbarnea closed 4 years ago

ssbarnea commented 5 years ago

Proposal: native timeout support for tasks

Author: Sorin Sbarnea <@ssbarnea> IRC: zbr

Date: 2019-03-12

Motivation

The current use pattern is to run with async but this means adding at least one additional task for each task where you want to implement a timeout, it just does not scale at all, making playbooks more verbose, harder to read and debug.

We just need a simple way to declare a task failed if it exceeded an maximum runtime lenght, with a default of 0 which disables the timeout (backwards compatibe).

Problems

What problems exist that this proposal will solve?

Solution proposal

As seen in this example the module execution would be stopped if it exceeds 10s (seconds is the SI unit of measure for time). This would not be an argument for a specific module, it should apply to most modules.

    - shell: pause
      timeout: 10

Testing (optional)

TBH

Documentation (optional)

TBH

jborean93 commented 5 years ago

The current use pattern is to run with async but this means adding at least one additional task for each task where you want to implement a timeout

Not sure what you mean, the below will run just like any other module and time out after 10 seconds, exactly the same as your example just with the async key.

- shell: pause
  async: 10
ansiblejunky commented 4 years ago

We have the command_timeout option in the ansible.cfg that controls the general timeout for commands:

# The command timeout value defines the amount of time to wait for a command
# or RPC call before timing out. The value for the command timeout must
# be less than the value of the persistent connection idle timeout (connect_timeout)
# The default value is 30 second.
command_timeout = 30

Also, for those modules that are more time-sensitive, they seem to have a timeout argument.

So I am not sure with these 2 points, whether we also need timeout as something standard for any task - which I would assume would override the ansible.cfg option? That could be dangerous though. You might grab a role from Galaxy or somewhere else that set some crazy timeout value on the task and then you run it and it doesn't run as expected.

bcoca commented 4 years ago

@ansiblejunky command_timeout is not what it says it is, it is mostly another 'connection timeout' and it does not apply to all tasks, just those that are 'persistent' and use ansible-connection indirectly via selection of certain connection plugins (mostly related to networking appliances).

bcoca commented 4 years ago

done https://github.com/ansible/ansible/pull/69284