2017-12-02 187 views
0

我正试图在我的第一本剧本上进行设置。 Hovever ......不管我试图测试哪些例子..我收到类似的错误:ANSIBLE无法正常工作 - 语法检查

"xyz is not a valid attribute for a Play" 

例如:

$ cat a2.yml 
- name: Update and upgrade 
    become: true 
    apt: 
    upgrade: yes 
    update_cache: yes 


$ ansible-playbook a2.yml --syntax-check 
ERROR! 'apt' is not a valid attribute for a Play 

The error appears to have been in '/home/pi/My/ansible/a2.yml': line 1, column 3, but may 
be elsewhere in the file depending on the exact syntax problem. 

The offending line appears to be: 


- name: Update and upgrade 
^here 

的哪些错误?

PS。

$ ansible --version 
ansible 2.4.2.0 
    config file = /etc/ansible/ansible.cfg 
    configured module search path = [u'/home/pi/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] 
    ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible 
    executable location = /usr/local/bin/ansible 
    python version = 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170124] 
+1

的可能的复制[运行以下剧本的语法似乎是正确的,但越来越以下错误 - !“blockinfile”不是一个播放有效的属性(https://stackoverflow.com/questions/36468870/运行下面的剧本语法看起来是正确的,但得到下面) – tinita

回答

1

请参阅Playbooks Intro文档。 您的输入应该是task项目。

--- 
- hosts: ... 
    tasks: 
    - name: Update and upgrade 
     become: true 
     apt: 
     upgrade: yes 
     update_cache: yes 
+0

Works ;-) 我没有意识到“任务”是强制性的。 (整个概念对我来说都不清楚)。 感谢您的帮助。 – user8913714