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

Updated:   |  Ansible articles

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

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


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