2017-12-02 140 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