2017-12-18 635 views
-2

我想寫安裝Apache一個劇本,但我得到了以下錯誤:YAML語法錯誤(Ansible playboook)

The offending line appears to be: 

tasks: 
    - name: command to install apache 
    ^here 

這裏是我的YAML代碼:

--- 
- hosts: all 
    tasks: 
    - name: command to install apache 
     sudo: yes 
     yum: name=httpd state=latest 
     service: name=httpd state=running 

有什麼事情這裏錯了嗎?

回答

4

您不能將兩個操作(模塊)添加到Ansible中的單個任務。

您需要將yumservice分成兩個任務。

而且sudo宣言很久以前的過時,現在become應使用:

--- 
- hosts: all 
    tasks: 
    - name: Ensure apache is installed 
     become: yes 
     yum: name=httpd state=latest 

    - name: Ensure httpd service is running 
     become: yes 
     service: name=httpd state=running