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