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

Kar*_*Vee 3 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
Run Code Online (Sandbox Code Playgroud)

我的Playbook文件代码是:

---
- name: insertupdate
  blockinfile:
    dest: /etc/network/interfaces
    block: |
      iface eth2 inet static
          address 192.168.0.1
          netmask 255.255.255.0        
Run Code Online (Sandbox Code Playgroud)

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

hel*_*loV 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
Run Code Online (Sandbox Code Playgroud)