From d083307e369b968db7852d6cd2d5a9008724ab1d Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Fri, 28 Aug 2020 08:01:26 +0200 Subject: [PATCH] Set global skipped result flag for looped tasks (#67847) This allows for the skipped filter to be used on a registered looped task results. Fixes #16949 --- .../16949-global-skipped-result-flag-looped-tasks.yml | 2 ++ lib/ansible/executor/task_executor.py | 7 ++++++- test/integration/targets/lookup_subelements/tasks/main.yml | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/16949-global-skipped-result-flag-looped-tasks.yml diff --git a/changelogs/fragments/16949-global-skipped-result-flag-looped-tasks.yml b/changelogs/fragments/16949-global-skipped-result-flag-looped-tasks.yml new file mode 100644 index 00000000000..51a8cdf0af1 --- /dev/null +++ b/changelogs/fragments/16949-global-skipped-result-flag-looped-tasks.yml @@ -0,0 +1,2 @@ +minor_changes: + - Allow for the skipped filter to be used on a registered looped task results. (https://github.com/ansible/ansible/issues/16949) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 145de983a7d..169eb84bb4f 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -122,10 +122,13 @@ class TaskExecutor: # create the overall result item res = dict(results=item_results) - # loop through the item results, and set the global changed/failed result flags based on any item. + # loop through the item results and set the global changed/failed/skipped result flags based on any item. + res['skipped'] = True for item in item_results: if 'changed' in item and item['changed'] and not res.get('changed'): res['changed'] = True + if res['skipped'] and ('skipped' not in item or ('skipped' in item and not item['skipped'])): + res['skipped'] = False if 'failed' in item and item['failed']: item_ignore = item.pop('_ansible_ignore_errors') if not res.get('failed'): @@ -147,6 +150,8 @@ class TaskExecutor: if not res.get('failed', False): res['msg'] = 'All items completed' + if res['skipped']: + res['msg'] = 'All items skipped' else: res = dict(changed=False, skipped=True, skipped_reason='No items in the list', results=[]) else: diff --git a/test/integration/targets/lookup_subelements/tasks/main.yml b/test/integration/targets/lookup_subelements/tasks/main.yml index 88875968e4c..9d93cf20963 100644 --- a/test/integration/targets/lookup_subelements/tasks/main.yml +++ b/test/integration/targets/lookup_subelements/tasks/main.yml @@ -39,7 +39,7 @@ - name: verify with_subelements in subkeys results assert: that: - - _subelements_missing_subkeys.skipped is not defined + - _subelements_missing_subkeys is not skipped - _subelements_missing_subkeys.results|length == 2 - "_xk == 'k'" - "_xl == 'l'"