Search code examples
ansibleansible-2.xansible-inventoryansible-facts

not able call more than one roles by using include_role


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


Solution

  • 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}
      ...