Sitelet https://web.archive.org/web/20200219073549im_/https://github.com/ansible/ansible/issues/65904
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include_tasks + loop: no "=> (item=…)" output #65904

Open
tchernomax opened this issue Dec 17, 2019 · 5 comments · May be fixed by #66018
Open

include_tasks + loop: no "=> (item=…)" output #65904

tchernomax opened this issue Dec 17, 2019 · 5 comments · May be fixed by #66018

Comments

@tchernomax
Copy link
Contributor

@tchernomax tchernomax commented Dec 17, 2019 •

SUMMARY

- include_tasks: included.yml
  loop:
    - 1
    - 2

Expected output:

TASK [include_tasks] ******************************
included: …/included.yml for localhost => (item=1)
included: …/included.yml for localhost => (item=2)

Current output:

TASK [include_tasks] ******************************
included: …/included.yml for localhost
included: …/included.yml for localhost

The problem is here:

if 'item' in included_file._args:

'item' is in included_file._vars not included_file._args.
Also, ansible_loop_var should be used instead of 'item' (but I don't know how), so loop_control.loop_var could be used.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

if 'item' in included_file._args:

lib/ansible/plugins/callback/default.py

v2_playbook_on_include

ANSIBLE VERSION
ansible 2.9.2
  config file = /home/max/.ansible.cfg
  configured module search path = ['/home/max/.ansible/modules']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.8.0 (default, Oct 23 2019, 18:51:26) [GCC 9.2.0]
CONFIGURATION
ALLOW_WORLD_READABLE_TMPFILES(/home/max/.ansible.cfg) = True
DEFAULT_FORCE_HANDLERS(/home/max/.ansible.cfg) = True
DEFAULT_HOST_LIST(/home/max/.ansible.cfg) = ['/home/max/.ansible/oxalide-hosts']
DEFAULT_MODULE_PATH(/home/max/.ansible.cfg) = ['/home/max/.ansible/modules']
DEFAULT_MODULE_UTILS_PATH(/home/max/.ansible.cfg) = ['/home/max/.ansible/module_utils']
DIFF_ALWAYS(/home/max/.ansible.cfg) = True
INTERPRETER_PYTHON(/home/max/.ansible.cfg) = auto_silent
RETRY_FILES_ENABLED(/home/max/.ansible.cfg) = False
OS / ENVIRONMENT

Archlinux uptodate.

STEPS TO REPRODUCE

included.yml:

- debug:
    var: item

playbook.yml:

- hosts: localhost
  gather_facts: false
  tasks:
    - include_tasks: included.yml
      loop:
        - 1
        - 2
EXPECTED RESULTS
max@mde-oxalide % ansible-playbook playbook.yml

PLAY [localhost] ********************

TASK [include_tasks] ***************
included: /home/max/Telechargements/included.yml for localhost => (item=1)
included: /home/max/Telechargements/included.yml for localhost => (item=2)

TASK [debug] *************************
ok: [localhost] => {
    "item": 1
}

TASK [debug] ***************
ok: [localhost] => {
    "item": 2
}

PLAY RECAP ***************
localhost                  : ok=4    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
ACTUAL RESULTS
max@mde-oxalide % ansible-playbook playbook.yml

PLAY [localhost] ********************

TASK [include_tasks] ***************
included: /home/max/Telechargements/included.yml for localhost
included: /home/max/Telechargements/included.yml for localhost

TASK [debug] *************************
ok: [localhost] => {
    "item": 1
}

TASK [debug] ***************
ok: [localhost] => {
    "item": 2
}

PLAY RECAP ***************
localhost                  : ok=4    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
@ansibot

This comment has been minimized.

Copy link
Contributor

@ansibot ansibot commented Dec 17, 2019

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@sivel

This comment has been minimized.

Copy link
Member

@sivel sivel commented Dec 17, 2019

I believe the following is all that is required to get this working:

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

Feel free to put together a PR, including a changelog fragment as well.

@Yadnyawalkya

This comment has been minimized.

Copy link
Contributor

@Yadnyawalkya Yadnyawalkya commented Dec 18, 2019

I can put this together, expect PR soon, thanks @Akasurde @sivel o/

@tchernomax

This comment has been minimized.

Copy link
Contributor Author

@tchernomax tchernomax commented Dec 18, 2019

I confirm the solution proposed by @sivel works.
I will let @Yadnyawalkya do the PR.
Thanks

@Yadnyawalkya

This comment has been minimized.

Copy link
Contributor

@Yadnyawalkya Yadnyawalkya commented Dec 21, 2019

Aaand we have this ^^ PR. Sorry folks I almost forget it, Thanks for waiting! :-)

@ansibot ansibot added the has_pr label Dec 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants
You can’t perform that action at this time.