summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Martz <matt@sivel.net>2020-04-09 13:27:58 -0500
committerGitHub <noreply@github.com>2020-04-09 13:27:58 -0500
commitd86d20a378ef10fbcdff5174f58e4c94246f8aab (patch)
tree34290da252edb5ac7165ec59abf0df2d558596a7
parenta681810b2f271abcc504629f944a7529d376791b (diff)
downloadansible-d86d20a378ef10fbcdff5174f58e4c94246f8aab.tar.gz
Fix label lookup in the default callback for includes (#68822)
* Replace included_file._args w/ included_file._vars * Fix item value in output of include_tasks loop Signed-off-by: Yadnyawalk Tale <ytale@redhat.com> * Update tests for loop callback fix. Add changelog Co-authored-by: Yadnyawalk Tale <ytale@redhat.com> Fixes #65904 Fixes #66018
-rw-r--r--changelogs/fragments/65904-fix-loop-label.yml2
-rw-r--r--lib/ansible/plugins/callback/default.py5
-rw-r--r--test/integration/targets/callback_default/callback_default.out.default.stdout10
-rw-r--r--test/integration/targets/callback_default/callback_default.out.failed_to_stderr.stdout10
-rw-r--r--test/integration/targets/callback_default/callback_default.out.hide_ok.stdout3
-rw-r--r--test/integration/targets/callback_default/callback_default.out.hide_skipped.stdout8
-rw-r--r--test/integration/targets/callback_default/callback_default.out.hide_skipped_ok.stdout3
-rw-r--r--test/integration/targets/callback_default/include_me.yml2
-rwxr-xr-xtest/integration/targets/callback_default/runme.sh2
-rw-r--r--test/integration/targets/callback_default/test.yml4
10 files changed, 42 insertions, 7 deletions
diff --git a/changelogs/fragments/65904-fix-loop-label.yml b/changelogs/fragments/65904-fix-loop-label.yml
new file mode 100644
index 0000000000..23a68ed0e8
--- /dev/null
+++ b/changelogs/fragments/65904-fix-loop-label.yml
@@ -0,0 +1,2 @@
+bugfixes:
+- Fix label lookup in the default callback for includes (https://github.com/ansible/ansible/issues/65904)
diff --git a/lib/ansible/plugins/callback/default.py b/lib/ansible/plugins/callback/default.py
index c68010959d..8147cb6aa2 100644
--- a/lib/ansible/plugins/callback/default.py
+++ b/lib/ansible/plugins/callback/default.py
@@ -350,8 +350,9 @@ class CallbackModule(CallbackBase):
def v2_playbook_on_include(self, included_file):
msg = 'included: %s for %s' % (included_file._filename, ", ".join([h.name for h in included_file._hosts]))
- if 'item' in included_file._args:
- msg += " => (item=%s)" % (self._get_item_label(included_file._args),)
+ label = self._get_item_label(included_file._vars)
+ if label:
+ msg += " => (item=%s)" % label
self._display.display(msg, color=C.COLOR_SKIP)
def v2_playbook_on_stats(self, stats):
diff --git a/test/integration/targets/callback_default/callback_default.out.default.stdout b/test/integration/targets/callback_default/callback_default.out.default.stdout
index b9d1b8a171..05f90beb12 100644
--- a/test/integration/targets/callback_default/callback_default.out.default.stdout
+++ b/test/integration/targets/callback_default/callback_default.out.default.stdout
@@ -42,6 +42,14 @@ fatal: [testhost]: FAILED! => {"changed": false, "msg": "Failed as requested fro
TASK [Rescue task] *************************************************************
changed: [testhost]
+TASK [include_tasks] ***********************************************************
+included: .../test/integration/targets/callback_default/include_me.yml for testhost => (item=1)
+
+TASK [debug] *******************************************************************
+ok: [testhost] => {
+ "item": 1
+}
+
RUNNING HANDLER [Test handler 1] ***********************************************
changed: [testhost]
@@ -60,5 +68,5 @@ TASK [Second free task] ********************************************************
changed: [testhost]
PLAY RECAP *********************************************************************
-testhost : ok=12 changed=9 unreachable=0 failed=0 skipped=1 rescued=1 ignored=2
+testhost : ok=14 changed=9 unreachable=0 failed=0 skipped=1 rescued=1 ignored=2
diff --git a/test/integration/targets/callback_default/callback_default.out.failed_to_stderr.stdout b/test/integration/targets/callback_default/callback_default.out.failed_to_stderr.stdout
index 58c4e1039b..fe990d421b 100644
--- a/test/integration/targets/callback_default/callback_default.out.failed_to_stderr.stdout
+++ b/test/integration/targets/callback_default/callback_default.out.failed_to_stderr.stdout
@@ -39,6 +39,14 @@ TASK [EXPECTED FAILURE Failed task to be rescued] ******************************
TASK [Rescue task] *************************************************************
changed: [testhost]
+TASK [include_tasks] ***********************************************************
+included: .../test/integration/targets/callback_default/include_me.yml for testhost => (item=1)
+
+TASK [debug] *******************************************************************
+ok: [testhost] => {
+ "item": 1
+}
+
RUNNING HANDLER [Test handler 1] ***********************************************
changed: [testhost]
@@ -57,5 +65,5 @@ TASK [Second free task] ********************************************************
changed: [testhost]
PLAY RECAP *********************************************************************
-testhost : ok=12 changed=9 unreachable=0 failed=0 skipped=1 rescued=1 ignored=2
+testhost : ok=14 changed=9 unreachable=0 failed=0 skipped=1 rescued=1 ignored=2
diff --git a/test/integration/targets/callback_default/callback_default.out.hide_ok.stdout b/test/integration/targets/callback_default/callback_default.out.hide_ok.stdout
index b9dad40c0d..c1e1846bc5 100644
--- a/test/integration/targets/callback_default/callback_default.out.hide_ok.stdout
+++ b/test/integration/targets/callback_default/callback_default.out.hide_ok.stdout
@@ -35,6 +35,7 @@ fatal: [testhost]: FAILED! => {"changed": false, "msg": "Failed as requested fro
TASK [Rescue task] *************************************************************
changed: [testhost]
+included: .../test/integration/targets/callback_default/include_me.yml for testhost => (item=1)
RUNNING HANDLER [Test handler 1] ***********************************************
changed: [testhost]
@@ -51,5 +52,5 @@ TASK [Second free task] ********************************************************
changed: [testhost]
PLAY RECAP *********************************************************************
-testhost : ok=12 changed=9 unreachable=0 failed=0 skipped=1 rescued=1 ignored=2
+testhost : ok=14 changed=9 unreachable=0 failed=0 skipped=1 rescued=1 ignored=2
diff --git a/test/integration/targets/callback_default/callback_default.out.hide_skipped.stdout b/test/integration/targets/callback_default/callback_default.out.hide_skipped.stdout
index 3c6ba0d3cf..660c728548 100644
--- a/test/integration/targets/callback_default/callback_default.out.hide_skipped.stdout
+++ b/test/integration/targets/callback_default/callback_default.out.hide_skipped.stdout
@@ -37,6 +37,12 @@ fatal: [testhost]: FAILED! => {"changed": false, "msg": "Failed as requested fro
TASK [Rescue task] *************************************************************
changed: [testhost]
+included: .../test/integration/targets/callback_default/include_me.yml for testhost => (item=1)
+
+TASK [debug] *******************************************************************
+ok: [testhost] => {
+ "item": 1
+}
RUNNING HANDLER [Test handler 1] ***********************************************
changed: [testhost]
@@ -56,5 +62,5 @@ TASK [Second free task] ********************************************************
changed: [testhost]
PLAY RECAP *********************************************************************
-testhost : ok=12 changed=9 unreachable=0 failed=0 skipped=1 rescued=1 ignored=2
+testhost : ok=14 changed=9 unreachable=0 failed=0 skipped=1 rescued=1 ignored=2
diff --git a/test/integration/targets/callback_default/callback_default.out.hide_skipped_ok.stdout b/test/integration/targets/callback_default/callback_default.out.hide_skipped_ok.stdout
index 181f56fdf5..13948b9f22 100644
--- a/test/integration/targets/callback_default/callback_default.out.hide_skipped_ok.stdout
+++ b/test/integration/targets/callback_default/callback_default.out.hide_skipped_ok.stdout
@@ -31,6 +31,7 @@ fatal: [testhost]: FAILED! => {"changed": false, "msg": "Failed as requested fro
TASK [Rescue task] *************************************************************
changed: [testhost]
+included: .../test/integration/targets/callback_default/include_me.yml for testhost => (item=1)
RUNNING HANDLER [Test handler 1] ***********************************************
changed: [testhost]
@@ -47,5 +48,5 @@ TASK [Second free task] ********************************************************
changed: [testhost]
PLAY RECAP *********************************************************************
-testhost : ok=12 changed=9 unreachable=0 failed=0 skipped=1 rescued=1 ignored=2
+testhost : ok=14 changed=9 unreachable=0 failed=0 skipped=1 rescued=1 ignored=2
diff --git a/test/integration/targets/callback_default/include_me.yml b/test/integration/targets/callback_default/include_me.yml
new file mode 100644
index 0000000000..51470f3cdf
--- /dev/null
+++ b/test/integration/targets/callback_default/include_me.yml
@@ -0,0 +1,2 @@
+- debug:
+ var: item
diff --git a/test/integration/targets/callback_default/runme.sh b/test/integration/targets/callback_default/runme.sh
index d394c7c561..3e88b3b10e 100755
--- a/test/integration/targets/callback_default/runme.sh
+++ b/test/integration/targets/callback_default/runme.sh
@@ -23,6 +23,7 @@ run_test() {
2> >(set +x; tee "${OUTFILE}.${testname}.stderr" >&2)
# Scrub deprication warning that shows up in Python 2.6 on CentOS 6
sed -i -e '/RandomPool_DeprecationWarning/d' "${OUTFILE}.${testname}.stderr"
+ sed -i -e 's/included: .*\/test\/integration/included: ...\/test\/integration/g' "${OUTFILE}.${testname}.stdout"
diff -u "${ORIGFILE}.${testname}.stdout" "${OUTFILE}.${testname}.stdout" || diff_failure
diff -u "${ORIGFILE}.${testname}.stderr" "${OUTFILE}.${testname}.stderr" || diff_failure
@@ -143,6 +144,7 @@ run_test failed_to_stderr
export ANSIBLE_DISPLAY_SKIPPED_HOSTS=1
export ANSIBLE_DISPLAY_OK_HOSTS=1
export ANSIBLE_DISPLAY_FAILED_STDERR=1
+export ANSIBLE_TIMEOUT=1
# Check if UNREACHBLE is available in stderr
set +e
diff --git a/test/integration/targets/callback_default/test.yml b/test/integration/targets/callback_default/test.yml
index 71ff909e99..b31787bffe 100644
--- a/test/integration/targets/callback_default/test.yml
+++ b/test/integration/targets/callback_default/test.yml
@@ -57,6 +57,10 @@
- name: Rescue task
command: echo rescued
+ - include_tasks: include_me.yml
+ loop:
+ - 1
+
handlers:
- name: Test handler 1
command: echo foo