我在运行ansible playbook时遇到问题(语法错误)

我在运行ansible playbook时遇到问题(语法错误),ansible,Ansible,我遵循了多个教程,但我仍然总是得到相同的错误 第一,亚马尔 --- - hosts: all task - name: download httpd yum: - name: httpd state: latest 当我运行>ansible playbook first.yaml时 我明白了: ERROR! Syntax Error while loading YAML. mapping values are not allowed in this context The

我遵循了多个教程,但我仍然总是得到相同的错误

第一,亚马尔

---

- hosts: all
 task

 - name: download httpd
 yum:
 - name: httpd
   state: latest
当我运行>ansible playbook first.yaml时 我明白了:

ERROR! Syntax Error while loading YAML.
 mapping values are not allowed in this context

The error appears to be in '/home/ansible/Document/first.yaml': line 5, column 8, but may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- hosts: all
       ^ here
谢谢

嗨,试试这个(来自)


name:httpd
之前,所提供的示例中没有
-
字符。

第一个问题是缩进。请参见下文。
其次,关键字是tasks而不是task,在tasks之后需要一个冒号(:)

---

- hosts: all
  tasks:
  - name: download httpd
    yum:
     name: httpd
     state: latest


. 缩进在句法上是重要的。您的上述文件无效。请查看@smily-answer,这里有一个Playbook的复制/粘贴示例。这解决了我的问题,谢谢!请标记为“解决方案”,如果它对您有帮助,请向上投票。
---

- hosts: all
  tasks:
  - name: download httpd
    yum:
     name: httpd
     state: latest