YAML语法错误(Ansible Playbook)

YAML语法错误(Ansible Playbook),ansible,yaml,Ansible,Yaml,我正试图编写一个安装Apache的剧本,但出现以下错误: The offending line appears to be: tasks: - name: command to install apache ^ here 这是我的YAML代码: --- - hosts: all tasks: - name: command to install apache sudo: yes yum: name=httpd state=la

我正试图编写一个安装Apache的剧本,但出现以下错误:

The offending line appears to be:

tasks:
     - name: command to install apache
       ^ here
这是我的YAML代码:

---
- hosts: all
  tasks:
     - name: command to install apache
       sudo: yes
       yum: name=httpd state=latest
       service: name=httpd state=running

这里可能有什么问题?

您不能在Ansible中向单个任务添加两个操作(模块)

您需要将
yum
service
分为两个任务

另外,
sudo
声明早就被弃用了,现在应该使用
been

---
- hosts: all
  tasks:
    - name: Ensure apache is installed
      become: yes
      yum: name=httpd state=latest

    - name: Ensure httpd service is running
      become: yes
      service: name=httpd state=running