Search code examples
ansible

Ansible. Fast way to check syntax?


Is there a way to check playbook syntax and variables?

I'm trying to dry-run (--check) but for some reasons it works really slow. It looks like it tries to perform an action instead of just checking the syntax.

I want to omit errors like this:

..."msg": "AnsibleUndefinedVariable: ERROR! 'application_name' is undefined"}

Solution

  • This is expected behaviour according to the documentation:

    When ansible-playbook is executed with --check it will not make any changes on remote systems. Instead, any module instrumented to support ‘check mode’ (which contains most of the primary core modules, but it is not required that all modules do this) will report what changes they would have made rather than making them. Other modules that do not support check mode will also take no action, but just will not report what changes they might have made.

    Old link (does not work anymore): http://docs.ansible.com/ansible/playbooks_checkmode.html

    New link: https://docs.ansible.com/ansible/latest/user_guide/playbooks_checkmode.html#using-check-mode

    If you would like to check the YAML syntax you can use syntax-check.

    ansible-playbook rds_prod.yml  --syntax-check
    playbook: rds_prod.yml