From ee3c9c841e466c7fed7639bf3b5e19dbbe42abba Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Fri, 5 Jun 2020 13:31:18 -0600 Subject: [PATCH] Make throttle optional Tasks did not have the concept of throttling prior to ansible 2.9 so if we want to allow this to be re-used with older versions then we need to skip the throttling code if task doesn't contain the throttle attribute. This will help if we want to backport this for upgrades. Change-Id: I01f6e3a69dec25ec69782c087d6b81ce3f33e6c0 --- .../ansible_plugins/strategy/tripleo_free.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tripleo_ansible/ansible_plugins/strategy/tripleo_free.py b/tripleo_ansible/ansible_plugins/strategy/tripleo_free.py index 8b26b6ca9..b27656b8c 100644 --- a/tripleo_ansible/ansible_plugins/strategy/tripleo_free.py +++ b/tripleo_ansible/ansible_plugins/strategy/tripleo_free.py @@ -161,14 +161,17 @@ class StrategyModule(BASE.TripleoBase): task_vars = self._variable_manager.get_vars(**vars_params) templar = Templar(loader=self._loader, variables=task_vars) - try: - throttle = int(templar.template(task.throttle)) - except Exception as e: - raise AnsibleError("Failed to throttle: {}".format(e), - obj=task._df, - orig_exc=e) - if self._check_throttle(throttle, task): - raise TripleoFreeBreak() + # if task has a throttle attribute, check throttle e.g. ansible > 2.9 + throttle = getattr(task, 'throttle', None) + if throttle is not None: + try: + throttle = int(templar.template(throttle)) + except Exception as e: + raise AnsibleError("Failed to throttle: {}".format(e), + obj=task._df, + orig_exc=e) + if self._check_throttle(throttle, task): + raise TripleoFreeBreak() # _blocked_hosts is used in the base strategy to keep track of hosts in # that have tasks in queue