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
This commit is contained in:
Matt Martz 2020-04-09 13:27:58 -05:00 committed by GitHub
parent a681810b2f
commit d86d20a378
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 42 additions and 7 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- Fix label lookup in the default callback for includes (https://github.com/ansible/ansible/issues/65904)

View file

@ -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):

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,2 @@
- debug:
var: item

View file

@ -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

View file

@ -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