Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

2 Answers

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

An example is provided to do exactly that:

tasks:
    - 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 comment

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
add comment

Your Answer

 
discard

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.