2017-07-13 72 views
0

調用多個角色需要幫助以查看此include_role的錯誤。無法通過使用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 
    - name: 4 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 
     when: aws_region_name == "us-east-1" 
     with_items: 
     - "{{ region_services }}" 

這不通過調用任何額外的工作角色undefined \ n \ n錯誤似乎在

+1

我懷疑你依賴nginx角色中的'item'變量,所以playbook失敗了,因爲在第二個代碼片段中第一個'include_role'沒有'with_items'。 –

+0

感謝您的幫助!!! ....我需要with_items(item)值應該傳遞給所有角色,因爲aws區域對於所有角色都是相同的,不幸的是包括with_items:對於每個角色也是不起作用的。 –

回答

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} 
    ... 
+0

grizzthedj @收到錯誤是這樣的: - 主機「錯誤‘時,’不是一個播放有效的屬性!」本地主機 連接:本地 gather_facts:是 瓦爾: region_services: - 「美國 - 東 - 1 「 角色: - {角色:nginx的} - {角色:nginx的} 時:region_services == 」美東1「 with_items: - 」{{region_services}}「 –