Ansible – Command to check playbook syntax

Ansible playbooks are one of the best available tools for system/server configuration management, but often we get YAML syntax errors that keep us away from writing the playbooks.

Ansible does provide us with a command to validate the syntax of our playbook for any errors prior to running the Ansible playbook.

Syntax

> ansible-playbook pkg_install.yml --syntax-check

Ansible syntax-check throwing error for a space error in the playbook file.

Ansible-playbook syntax-check error

Ansible syntax-check command output for syntactically correct playbook.

ansible-playbook syntax-check no error