more weirdness when testing include_role

368 views
Skip to first unread message

Trond Hindenes

unread,
Oct 3, 2016, 4:36:52 PM10/3/16
to Ansible Project
Here's another oddity. As far as I can see from the docs, this should work ("myrole" lives in roles/myrole in the plabook folder)
---
- name: Do stuff to stuff
  hosts: localhost
  tasks:
    - name: set fact
      set_fact:
        thing: otherstuff

    - name: myrole
      with_items:
        - "aone"
        - "atwo"
      include_role:
        name: myrole
      vars:
        thing: "{{ item }}"

However, it throws an error I haven't seen before: 'IncludeRole' object has no attribute '_role_name'
Shouldn't this work?

Brian Coca

unread,
Oct 3, 2016, 7:22:54 PM10/3/16
to ansible...@googlegroups.com
I just updated it to add _role_name and use that instead of name (which it was conflating with the task level one), make sure you don't have old .pyc files.


----------
Brian Coca

Trond Hindenes

unread,
Oct 4, 2016, 2:03:20 AM10/4/16
to Ansible Project
Sweet! Will retest

Trond Hindenes

unread,
Oct 4, 2016, 8:18:03 AM10/4/16
to Ansible Project
So, I'm testing on the latest devel (up to date as of right now). If I omit the "name" prop I get the error "ERROR! 'name' is a required field."

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

On Tuesday, October 4, 2016 at 8:03:20 AM UTC+2, Trond Hindenes wrote:
Sweet! Will retest

Brian Coca

unread,
Oct 4, 2016, 9:37:17 AM10/4/16
to ansible...@googlegroups.com
Sorry for the confusion, _role_name is internal, you need to set name:



- include_role:
     name: myrole


​and this should also work now:

- name: not a role name
   - include_role:
        name: myrole
  ​

----------
Brian Coca

Trond Hindenes

unread,
Oct 4, 2016, 9:54:53 AM10/4/16
to Ansible Project
Ah, gotcha. Thanks.

I'm still struggling to get with_items to work tho. Trying this:
---
- 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 }}"

causes this error: failed: [localhost] (item=aone) => {"failed": true, "item": "aone", "msg": "No role was specified to include"}.
The first (non-loop) task runs fine.

Trond Hindenes

unread,
Oct 6, 2016, 5:12:35 PM10/6/16
to Ansible Project
Just tested this with the latest devel and still no luck. Should this work?
Reply all
Reply to author
Forward
0 new messages