2017-10-14 41 views
0

我有我的第一本劇本,它失敗了。我認爲這是一個語法錯誤,但由於我不是一個編碼器,我不知道爲什麼YAML失敗?它與間距有關嗎?簡單劇本中的Ansible YAML語法錯誤

以下是我有:

--- 
- name: Update all packages to the latest version 
    become: true 
    apt: 
     update_cache: yes  
     upgrade: dist 

- name: Remove useless packages from the cache 
    apt: 
     autoclean: yes 

- name: Remove dependencies that are no longer required 
    apt: 
     autoremove: yes 
ERROR! Syntax Error while loading YAML. 


The error appears to have been in '/home/pi/playbooks/update-apt.yml': line 3, column 11, but may 
be elsewhere in the file depending on the exact syntax problem. 

The offending line appears to be: 

- name: Update all packages to the latest version 
    become: true 
     ^here 

回答

1

首先:這不是劇本,因爲它不包含戲劇(其中必須包含hosts聲明),但任務。其次:你的縮進是非常糟糕的 - 在YAML中保持聲明正確對齊是非常重要的(也就是說,你看到的錯誤不是YAML語法錯誤,而是一個正確定義的錯誤數據導致的Ansible錯誤寫入YAML文件)。

如果你想在本地運行它,它看起來應該或多或少是這樣的:

--- 
- hosts: localhost 
    connection: local 
    tasks: 
    - name: Update all packages to the latest version 
     become: true 
     apt: 
     update_cache: yes  
     upgrade: dist 
     autoclean: yes 
     autoremove: yes