Simple YAMl File syntax errors

2,953 views
Skip to first unread message

Mallireddy Gangadhar Reddy

unread,
Jan 28, 2018, 4:39:22 AM1/28/18
to Ansible Project
Hi ,

I have written a simple yaml file to install httpd package

--- 
hosts: all
tasks: 
  yum: "name=httpd state=installed"




i checked the syntax at http://www.yamllint.com/ , and it looks good. But when i run it in the system it throws errors

[root@appserver ~]# ansible-playbook Play_Tomcat.yml 
ERROR! playbooks must be a list of plays

The error appears to have been in '/root/Play_Tomcat.yml': line 2, column 1, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
hosts: all
^ here



Can you please let me know what is missing , i am able to run the ad-hoc commands...


Regards
Gangadhar M

Dave Cottlehuber

unread,
Jan 28, 2018, 5:19:33 AM1/28/18
to ansible...@googlegroups.com
On Sun, 28 Jan 2018, at 10:39, Mallireddy Gangadhar Reddy wrote:
> Hi ,
>
> I have written a simple yaml file to install httpd package
>
> ---
> hosts: all
> tasks:
> yum: "name=httpd state=installed"
>
>
> i checked the syntax at http://www.yamllint.com/ , and it looks good. But
> when i run it in the system it throws errors
>
> [root@appserver ~]# ansible-playbook Play_Tomcat.yml
> ERROR! playbooks must be a list of plays

Welcome Mallireddy.

Your yaml file is a _role_ and the playbook command requires a _playbook_ as well as an inventory file. You just need to add a playbook (lets call that site.yml) and include your role from above (web.yml).

I tweaked your role a little (use separate lines so that git diffs are easy to read, add a name for readability during playbook runs, and tags to allow targeting tasks easily) but its basically the same as what you already have. I keep all of this together in a single git repo, along with ansible.cfg and hosts inventory file.

Your ansible structure should look like this inside your ansible repo:

```
# ./site.yml:
---
- hosts: all
roles:
- web

# ./roles/web/tasks/main.yml:
---
- name: ensure web server is installed
yum:
name: httpd
state: installed
tags:
- web
- yum
```

I use the following a lot - what would the play change, and then actually apply it:

ansible-playbook site.yml --diff -v --check
ansible-playbook site.yml --diff -v

https://github.com/ansible/ansible-examples/tree/master/lamp_simple is a nice simple example pretty close to what you are using - enjoy.

A+
Dave

Brian Coca

unread,
Feb 5, 2018, 10:29:01 PM2/5/18
to Ansible Project
Boht plays are tasks are lists, you are passing a dictionaries, just
need 1 character to 'fix it'

- hosts: all
tasks:
- yum: "name=httpd state=installed"

^ see the dashes?

That is what 'playbook must be a list of plays' means, if you only fix
- hosts, next would be 'tasks needs to be a list of tasks'.

Your file is still valid YAML, it just does not return the data types
Ansible expects for plays and tasks.


--
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages