Question: I have a CENTOS 7 VM with ansible installed, and I am trying to install the HTTPD service with ansible on a RED HAT 8.

File content:

"hosts"

```
[ubuntuserver]
192.168.1.51
[redhat]
192.168.56.102

```

"playbook.yaml"

```
[root @ centos7 ansible] # cat playbook.yaml
---
- hosts: redhat
- remote_user: root
   tasks:
      - name: install apache
        yum: name = httpd
[root @ centos7 ansible] #

```

Error I get:

[error](https://i.stack.imgur.com/APxrd.png)

Answer: 
First of all, indent everything on the same level:

```yaml
- hosts: redhat
  remote_user: root
   tasks:
      - name: install apache
        yum: name = httpd

```

Note that there is only one `-` being used.

Secondly, the `hosts` file you created is called an [inventory](https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html).
By executing `ansible-playbook playbook.yaml` it is going to use the default inventory file located at `/etc/ansible/hosts` which may not even exist on your machine.

So all you have to do is to tell ansible to load in your inventory file by using the [`-i` option](https://docs.ansible.com/ansible/latest/cli/ansible-playbook.html):

```sh
ansible-playbook -i hosts plabook.yaml

```
The YAML in your playbook is not correct. Restructure it like below, notice the `-` that I removed. It is also a best-practise to [always define the state](https://docs.ansible.com/ansible/2.8/user_guide/playbooks_best_practices.html#always-mention-the-state) parameter.

```yaml
---

- hosts: redhat
  remote_user: root
  tasks:
    - name: Install apache
      yum:
        name: httpd
        state: present

```

You also have to specify the inventory file from which Ansible should get the hosts. If the playbook is within the same folder as your `hosts` file, you can use the command below to run the playbook.

```
$ ansible-playbook playbook.yml -i hosts

```

If the inventory file is in another location, specify the entire path instead of just the filename.