本文介绍了运行以下 Playbook 语法似乎是正确的,但出现以下错误!- 'blockinfile' 不是 Play 的有效属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Running the Following Playbook syntax appears to be correct but getting following ERROR!-

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

我的剧本文件代码是:

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

顺便说一下,我使用的是 Ansible 2.x 版

By the way I am using Ansible Version 2.x

推荐答案

你的剧本缺少 tasks.就像错误所说的那样,blockinfile 在剧中不是一个有效的属性.你的剧本应该是这样的.只是一个例子,不要使用此代码.

Your playbook is missing tasks. Like the error says, blockinfile is not a valid attribute in a play. Your playbook should be something like this. Just an example, don't use this code.

- 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

这篇关于运行以下 Playbook 语法似乎是正确的,但出现以下错误!- 'blockinfile' 不是 Play 的有效属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 10:48