Reputation: 325
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
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
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
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