Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible Playbook: ERROR! 'command' is not a valid attribute for a Play [duplicate]

Tags:

ansible

I'm just trying to write a basic playbook, and keep getting the error below. Tried a tonne of things but still can't get it right. I know it must be a syntax thing but no idea where.

This is the code I have:

---
# This playbook runs a basic DF command.

- hosts: nagios
  #remote_user: root

  tasks:
  - name: find disk space available.
  command: df -hPT

This is the error I get:

> ERROR! 'command' is not a valid attribute for a Play
> 
> The error appears to have been in '/root/playbooks/df.yml': line 4,
> column 3, but may be elsewhere in the file depending on the exact
> syntax problem.
> 
> The offending line appears to be:
> 
> 
> - hosts: nagios   
    ^ here

Ansible ver: 2.4.2.0

It's driving me insane. I've looked at some axamples from the Ansible docs, and it looks the same. No idea...

Anyone know?

like image 376
Cenzo Avatar asked Mar 13 '18 01:03

Cenzo


People also ask

What is Ansible playbook command?

Ansible Playbooks are lists of tasks that automatically execute against hosts. Groups of hosts form your Ansible inventory. Each module within an Ansible Playbook performs a specific task. Each module contains metadata that determines when and where a task is executed, as well as which user executes it.

How do I put playbook in Ansible?

Hi, the best way to do this would be to use Ansible's "tags" feature by applying tags to your tasks and then running your playbook with the --tags argument.

How do I run a single task in Ansible?

The easiest way to run only one task in Ansible Playbook is using the tags statement parameter of the “ansible-playbook” command. The default behavior is to execute all the tags in your Playbook with --tags all .

How do you check Ansible syntax?

Use this command to check the playbook for syntax errors: $ ansible-playbook <playbook. yml> --syntax-check.


1 Answers

The problem being that without the indentation of the command line the command directive is part of the overall play and not the task block. i.e. the command should be part of the task block.

--- # This playbook runs a basic DF command.  - hosts: nagios   #remote_user: root    tasks:   - name: find disk space available.     command: df -hPT 
like image 78
Jesse Avatar answered Oct 01 '22 02:10

Jesse