运行以下Playbook语法似乎是正确的但是获得了ERROR! - 'blockinfile'不是Play的有效属性

时间:2016-04-07 06:59:57

标签: ansible ansible-playbook ansible-2.x

运行以下Playbook语法似乎是正确的,但会出现以下错误! -

ERROR! 'blockinfile' is not a valid attribute for a Play

The error appears to have been in '/root/playbook1.yml': line 2, column 3, but may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
- name: insertupdate
  ^ here

我的Playbook文件代码是:

---
- name: insertupdate
  blockinfile:
    dest: /etc/network/interfaces
    block: |
      iface eth2 inet static
          address 192.168.0.1
          netmask 255.255.255.0        

顺便说一句,我使用的是Ansible Version 2.x

2 个答案:

答案 0 :(得分:6)

您的剧本遗失tasks。与错误一样,blockinfile不是游戏中的有效属性。你的剧本应该是这样的。举个例子,不要使用此代码。

- hosts: 127.0.0.1

  tasks:
  - name: insertupdate
    blockinfile:
      dest: /etc/network/interfaces
      block: |
        iface eth2 inet static
            address 192.168.0.1
            netmask 255.255.255.0

答案 1 :(得分:0)

-bash-4.2$ cat getUri.yml
---
- name: test playbook
  hosts: localhost
  tasks:
  - name: Check that you can connect (GET) to a page and it returns a status 200
    uri:
      url: http://www.example.com

该错误是由于您的剧本中缺少主机和任务