make timeout decorator for facts have a configurable duration (#16551)

* Add a gather_timeout parameter
* update example ansible.cfg
* fix play level fact gathering too
This commit is contained in:
jctanner 2016-07-08 17:46:41 -04:00 committed by GitHub
parent ebd3eeec8c
commit fe8258a378
5 changed files with 24 additions and 0 deletions

View file

@ -113,15 +113,21 @@ if platform.system() != 'SunOS':
# timeout function to make sure some fact gathering
# steps do not exceed a time limit
GATHER_TIMEOUT=None
class TimeoutError(Exception):
pass
def timeout(seconds=10, error_message="Timer expired"):
def decorator(func):
def _handle_timeout(signum, frame):
raise TimeoutError(error_message)
def wrapper(*args, **kwargs):
if 'GATHER_TIMEOUT' in globals():
if GATHER_TIMEOUT:
seconds = GATHER_TIMEOUT
signal.signal(signal.SIGALRM, _handle_timeout)
signal.alarm(seconds)
try:
@ -3225,6 +3231,9 @@ def get_all_facts(module):
# Retrieve module parameters
gather_subset = module.params['gather_subset']
global GATHER_TIMEOUT
GATHER_TIMEOUT = module.params['gather_timeout']
# Retrieve all facts elements
additional_subsets = set()
exclude_subsets = set()