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_role does not work with with_items #17966

Closed
trondhindenes opened this issue Oct 11, 2016 · 12 comments
Closed

include_role does not work with with_items #17966

trondhindenes opened this issue Oct 11, 2016 · 12 comments
Assignees
Labels
bug This issue/PR relates to a bug. P2 Priority 2 - Issue Blocks Release
Milestone

Comments

@trondhindenes
Copy link
Contributor

ISSUE TYPE
  • Bug Report
COMPONENT NAME

include_role

ANSIBLE VERSION
2.3.0
SUMMARY

The new "include_role" task does not work with with_items

STEPS TO REPRODUCE

In the example playbook below, the role "myrole" is first run stand-alone, and then as a with_items loop.


---
- name: Do stuff to stuff
  hosts: localhost
  tasks:
    - name: set fact
      set_fact:
        thing: otherstuff
    - name: myrole
      include_role:
        name: myrole
      vars:
        thing: "asdf"
    - name: myrole
      with_items:
        - "aone"
        - "atwo"
      include_role:
        name: myrole
      vars:
        thing: "{{ item }}"
EXPECTED RESULTS

Success

ACTUAL RESULTS

Error part of the output

TASK [myrole] ******************************************************************
task path: /mnt/c/Users/trond/Documents/projects/ansibledev/rolestesting/main.yml:13
failed: [localhost] (item=aone) => {
    "failed": true,
    "item": "aone",
    "msg": "No role was specified to include"
}
failed: [localhost] (item=atwo) => {
    "failed": true,
    "item": "atwo",
    "msg": "No role was specified to include"
}
ERROR! Unexpected Exception: 'results'
@ansibot
Copy link
Contributor

ansibot commented Oct 11, 2016

@trondhindenes: Thanks for taking the time to open this issue, but it was filed under the wrong github repository. Please create a new issue at https://github.com/ansible/ansible-modules-core/issues
click here for bot help

@ansibot ansibot closed this as completed Oct 11, 2016
@detiber
Copy link

detiber commented Oct 13, 2016

@bcoca was this closed in error?

@trondhindenes
Copy link
Contributor Author

@detiber I opened it in modules-core instead.

@detiber
Copy link

detiber commented Oct 13, 2016

@trondhindenes indeed, I posted that prior to realizing that include_role is actually implemented in ansible-modules-core. Apologies for the noise.

@bcoca
Copy link
Member

bcoca commented Oct 13, 2016

actually its not a module but coded inside the core interpreter, sadly the bot does not realize this and takes the documentation stub in core as a sign that it is a module. bot_skip

the repo unification will make all this go away.

@bcoca bcoca reopened this Oct 13, 2016
@bcoca bcoca added this to the 2.2.0 milestone Oct 13, 2016
@bcoca bcoca added the P2 Priority 2 - Issue Blocks Release label Oct 13, 2016
@trondhindenes
Copy link
Contributor Author

closed the issue I opened in modules-core, tracking here instead

bcoca added a commit that referenced this issue Oct 18, 2016
fixes #17966

(cherry picked from commit 01b75f9)
@bcoca bcoca closed this as completed in 01b75f9 Oct 18, 2016
@trondhindenes
Copy link
Contributor Author

@bcoca thanks! Looping now works, but it doesn't look like the role inside the loop is able to access the "item" dynamic var in a with_items loop. Do you want me to post some example code here, or open a new issue?

bcoca added a commit that referenced this issue Oct 18, 2016
fixes #17966

(cherry picked from commit 99220a5)
bcoca added a commit that referenced this issue Oct 18, 2016
@bcoca
Copy link
Member

bcoca commented Oct 18, 2016

already pushed 2nd part of fix that takes care of that

@detiber
Copy link

detiber commented Oct 18, 2016

@twiest @mwoodson fyi

@trondhindenes
Copy link
Contributor Author

sweet, thanks!

@twiest
Copy link

twiest commented Oct 18, 2016

@detiber thanks for the heads up

@orischwartz
Copy link

orischwartz commented Dec 13, 2016

Is loop variable interpolation supported in the role name? I'm seeing the following on the latest version from devel:

- include_role:
    name: "{{ item }}"
  with_items:
    - "x"
    - "y"
ERROR! 'item' is undefined

sereinity pushed a commit to sereinity-forks/ansible that referenced this issue Jan 25, 2017
fixes ansible#17966

(cherry picked from commit 01b75f9)
sereinity pushed a commit to sereinity-forks/ansible that referenced this issue Jan 25, 2017
fixes ansible#17966

(cherry picked from commit 99220a5)
@ansibot ansibot removed the bug_report label Mar 7, 2018
@ansibot ansibot added the bug This issue/PR relates to a bug. label Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug. P2 Priority 2 - Issue Blocks Release
Projects
None yet
Development

No branches or pull requests

7 participants