-1

i have below detail in /etc/ansible/hosts

[dev] 10.13.212.32

and i am able ping this hosts as below:

# ansible dev -m ping

Output:

[root@localhost ~]# ansible dev -m ping
10.13.212.32 | SUCCESS => {
    "changed": false,
    "ping": "pong"

when i check syntax of *.yml file .

# ansible-playbook --syntax-check --list-tasks -i hosts ./nginx.yml

or

# ansible-playbook nginx.yml --check**
 [WARNING]: Unable to parse /root/hosts as an inventory source

 [WARNING]: No inventory was parsed, only implicit localhost is available

 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

ERROR! Syntax Error while loading YAML.
  did not find expected '-' indicator

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

The offending line appears to be:

- name: install and start nginx
hosts: localhost
^ here

help me out with the issue.

  • can u check the host declaration? – msp9011 Aug 3 '18 at 10:50
0

The error is exactly what is says, there is no /root/hosts file!

ansible-playbook --syntax-check --list-tasks -i hosts ./nginx.yml

With the -i switch (--inventory-file), you are pointing to the file /root/hosts (since you are running as root, from root's $HOME) instead of the file:

/etc/ansible/hosts

So, try again with:

ansible-playbook --syntax-check --list-tasks -i /etc/ansible/hosts ./nginx.yml

And your playbook fails due to incorrect syntax and indentation. Check this example for starters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.