0

needed help to see what is wrong with this include_role.

This work without any problem:

#US East (N. Virginia)
- hosts: localhost
  gather_facts: false
  connection: local
  vars:
    region_services:
      - "us-east-1"
  tasks:
    - name: 3 run - should loop and print dynamic var
      include_role: name=nginx
      when: aws_region_name == "us-east-1"
      with_items:
        - "{{ region_services }}"

This doesn't work by calling any extra roles:

#US East (N. Virginia)
- hosts: localhost
  gather_facts: false
  connection: local
  vars:
    region_services:
      - "us-east-1"
  tasks:
    - name: 3 run - should loop and print dynamic var
      include_role: name=nginx
    - name: 4 run - should loop and print dynamic var
      include_role: name=nginx
      when: aws_region_name == "us-east-1"
      with_items:
        - "{{ region_services }}"

error I get like this

'item' is undefined\n\nThe error appears to have been in

Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193
Vadiraj k.s
  • 55
  • 1
  • 8
  • 1
    I suspect you rely on `item` variable inside nginx role, so playbook fails because there is no `with_items` for the first `include_role` in the second code snippet. – Konstantin Suvorov Jul 13 '17 at 14:43
  • thanks for the help!!!....I need with_items(item) values should be passed to all roles as the aws region is same for all the roles and unfortunately including with_items: for every roles is also not working. – Vadiraj k.s Jul 13 '17 at 16:41

1 Answers1

0

You can also include roles in your playbook like this.

# US East (N. Virginia)
- hosts: localhost
  gather_facts: false
  connection: local
  vars:
    region_services:
      - "us-east-1"
  roles:  
    - {role: ../roles/nginx}
    - {role: ../roles/other}
  ...
grizzthedj
  • 7,131
  • 16
  • 42
  • 62
  • grizzthedj@ getting error like this: "ERROR! 'when' is not a valid attribute for a Play" - hosts: localhost connection: local gather_facts: yes vars: region_services: - "us-east-1" roles: - { role: nginx } - { role: nginx } when: region_services == "us-east-1" with_items: - "{{ region_services }}" – Vadiraj k.s Jul 13 '17 at 17:34