Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to force Ansible when replacing the var in yml files, which is undefined, throw out an error instead silently replaced by an empty string?

share|improve this question

Yes, it is possible. Check the online documentation, under accessing complex variable data.

An example is provided to do exactly that:

    - shell: echo "I've got '{{ foo }}' and am not afraid to use it!"
      when: foo is defined

    - fail: msg="Bailing out: this play requires 'bar'"
      when: bar is not defined
share|improve this answer

Add this line to the [defaults] section of your ansible.cfg:

error_on_undefined_vars = True

You'll now get an error message if a variable is undefined.

share|improve this answer
I believe that option requires 1.3, which is coming soon but has not yet been released. – mblakele Aug 16 '13 at 15:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.