Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 check the syntax

I want to omit en errors like this:

..."msg": "AnsibleUndefinedVariable: ERROR! 'application_name' is undefined"} 
like image 638
kharandziuk Avatar asked Feb 11 '16 12:02

kharandziuk


People also ask

What is one option that ansible gives you to check your playbook for syntax errors?

You may want to verify your playbooks to catch syntax errors and other problems before you run them. The ansible-playbook command offers several options for verification, including --check , --diff , --list-hosts , --list-tasks , and --syntax-check .

How do I run ansible in check mode?

To force a task to run in check mode, even when the playbook is called without --check , set check_mode: yes . To force a task to run in normal mode and make changes to the system, even when the playbook is called with --check , set check_mode: no .

How do I use the dry run in ansible?

The easiest way to do a dry run in Ansible is to use the check mode . This mode works like the --syntax-check command, but on a playbook level.


1 Answers

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.

http://docs.ansible.com/ansible/playbooks_checkmode.html

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 
like image 55
Istvan Avatar answered Sep 20 '22 16:09

Istvan