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

18,145

Solution 1

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

Solution 2

-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

Share:
18,145
Karthik Vee
Author by

Karthik Vee

Updated on June 26, 2022

Comments

  • Karthik Vee
    Karthik Vee almost 2 years

    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

  • Yogesh D
    Yogesh D over 7 years
    I am getting the similar error: 'uri' is not a valid attribute for a Play. can you please help?