使用include_role

时间:2017-07-13 14:24:45

标签: ansible ansible-2.x ansible-inventory ansible-facts

需要帮助才能看出这个include_role有什么问题。

这项工作没有任何问题:

#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 }}"

通过调用任何额外的角色,这不起作用:

#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 }}"

错误我得到这样的

  

'项目'未定义\ n \ n错误似乎已在

1 个答案:

答案 0 :(得分:0)

你也可以在你的剧本中加入角色。

# US East (N. Virginia)
- hosts: localhost
  gather_facts: false
  connection: local
  vars:
    region_services:
      - "us-east-1"
  roles:  
    - {role: ../roles/nginx}
    - {role: ../roles/other}
  ...