2017-10-14 40 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