Force Ansible to throw out error when vars is missing in yml

ansible

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?

Best Answer

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
Related Topic