Rémy BRILLET
Rémy BRILLET

Reputation: 325

Ansible - ERROR! the field 'hosts' is required but was not set

I've an error when I launch a playbook but I don't found why....

ERROR! the field 'hosts' is required but was not set

There is my main.yml :

---
- hosts: hosts
- vars: 
  - elasticsearch_java_home: /usr/lib/jmv/jre-1.7.0
  - elasticsearch_http_port: 8443

- tasks: 
  - include: tasks/main.yml

- handlers:
  - include: handlers/main.yml

And my /etc/ansible/hosts :

[hosts]
10.23.108.182
10.23.108.183
10.23.108.184
10.23.108.185

When I test a ping, all is good :

[root@poste08-08-00 elasticsearch]# ansible hosts -m ping
10.23.108.183 | SUCCESS => {
    "changed": false, 
    "ping": "pong" }
10.23.108.182 | SUCCESS => {
    "changed": false, 
    "ping": "pong" }
10.23.108.185 | SUCCESS => {
    "changed": false, 
    "ping": "pong" }
10.23.108.184 | SUCCESS => {
    "changed": false, 
    "ping": "pong" }

Please, help me :) Regards,

Upvotes: 30

Views: 67015

Answers (4)

flxPeters
flxPeters

Reputation: 1542

You have a syntax error in your playbook.

---
- hosts: webservers
  vars:
    http_port: 80
    max_clients: 200

See: https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_intro.html

Upvotes: 31

Pickled
Pickled

Reputation: 485

For anyone who finds this in future, for me this was as I didn't have the hosts: line above tasks / pre_tasks. Moving it up fixed the issue...

Upvotes: 1

Mahender
Mahender

Reputation: 1

Remove hyphen sign before task since this is the part of single play:

---
hosts: hosts
- vars: 
  - elasticsearch_java_home: /usr/lib/jmv/jre-1.7.0
  - elasticsearch_http_port: 8443

- tasks: 
  - include: tasks/main.yml

- handlers:
  - include: handlers/main.yml

According to the YAML spec:

Block sequences indicate each member with a dash (“-”). Block mappings use a colon to mark each (key: value) pair.

Upvotes: -2

SJP
SJP

Reputation: 229

---
- hosts: all

  remote_user: root

  tasks:

Upvotes: 4

Related Questions