FreeKB - Ansible ansible-playbook --syntax-check flag
Ansible - ansible-playbook --syntax-check flag

The ansible-playbook command with the --syntax-check flag can be used to determine if there are syntax errors in the playbook file being used. For example, let's say you have a file named ping.yml that contains the following.

---
- hosts: all
  tasks:
    - name: ping
    ping:
...

 

Here is how you would use the --syntax-check flag.

ansible-playbook ping.yml --syntax-check

 

Which should return something like this.

ERROR! We were unable to read either as JSON nor YAML, these are the errors we got from each:
JSON: No JSON object could be decoded

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

The error appears to be in '/usr/local/ansible/playbooks/ping.yml': line 5, column 5, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

    - name: ping
    ping:
    ^ here

 

This error is returned because line 5 in ping.yml is not properly formatted. Line 5 should be indented like this.

---
- hosts: all
  tasks:
    - name: ping
      ping:
...

 

After correcting the syntax error and rerunning the command, the following should be returned. When no errors or warnings are displayed, this means the playbook syntax is correct.

~]# ansible-playbook ping.yml --syntax-check

playbook: ping.yml

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter b2100 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |