YAML语法错误(Ansible playboook)

时间:2017-12-18 14:23:59

标签: 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=latest
       service: name=httpd state=running

这里可能有什么问题?

1 个答案:

答案 0 :(得分:4)

您无法在Ansible中向单个任务添加两个操作(模块)。

您需要将yumservice分成两个任务。

同样sudo声明很久以前就已被弃用,现在应该使用become

---
- 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