2017-09-20 49 views
2

我有以下劇本Ansible標籤include_role不工作ansible 2.3版本

- name: Restart Apache Server 
    hosts: "{{ host }}" 
    include_role: 
    name: root 
    tasks_from: apache-restart.yml 
    become: true 
    become_user: root 

當我運行這個劇本是扔我下面的錯誤

ERROR! 'include_role' is not a valid attribute for a Play 

The error appears to have been in '/Users/Atul/Workplace/infra-automation/deployments/LAMP/site.yml': line 18, column 3, but may 
be elsewhere in the file depending on the exact syntax problem. 

The offending line appears to be: 


- name: Restart Apache Server 
^here 

以下是ansible的安裝細節我的筆記本電腦。

ansible 2.3.1.0 
    config file = /Users/Atul/Workplace/infra-automation/ansible.cfg 
    configured module search path = Default w/o overrides 
    python version = 2.7.13 (default, Apr 4 2017, 08:47:57) [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)] 

我google了這個它說的最低版本的ansible應該是2.2,但我使用2.3,但仍然會拋出我的錯誤。

回答

4

include_role是一個用於任務的動作模塊。

對於戲劇,你應該使用role指令。

2

techraf是正確的,你可以在任務中使用include_role。這是來自tasks/main.yml中的一個工作示例:

- name: intranet is a plone3 application 
    include_role: 
    name: plone3 
    private: yes 
    vars: 
    plone3_version: "{{intranet_plone3_version}}"