From 95a8bbdbda9ac85709c3ef896002dcb93b4031a7 Mon Sep 17 00:00:00 2001 From: jctanner Date: Thu, 27 Oct 2016 09:43:49 -0400 Subject: [PATCH] iterate through task results only if the key is not at the root level (#18214) Fixes https://github.com/ansible/ansible-modules-core/issues/5396 (cherry picked from commit 5a0621db554c310b110dbd8348c7ed48f11ba044) --- lib/ansible/executor/task_result.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ansible/executor/task_result.py b/lib/ansible/executor/task_result.py index 0f1967fe5c8..8de375a0267 100644 --- a/lib/ansible/executor/task_result.py +++ b/lib/ansible/executor/task_result.py @@ -62,11 +62,13 @@ class TaskResult: return self._check_key('unreachable') def _check_key(self, key): - if self._result.get('results', []): + '''get a specific key from the result or it's items''' + + if isinstance(self._result, dict) and key in self._result: + return self._result.get(key, False) + else: flag = False for res in self._result.get('results', []): if isinstance(res, dict): flag |= res.get(key, False) return flag - else: - return self._result.get(key, False)