Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running the Following Playbook syntax appears to be correct but getting following ERROR!- 'blockinfile' is not a valid attribute for a Play

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

My Playbook file code is:

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

By the way I am using Ansible Version 2.x

like image 534
Karthik Vee Avatar asked Dec 25 '22 07:12

Karthik Vee


2 Answers

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
like image 68
helloV Avatar answered Feb 08 '23 23:02

helloV


-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

The error is due to hosts and tasks missing in your playbook

like image 44
Dharmendra Rathod Avatar answered Feb 09 '23 01:02

Dharmendra Rathod