Required variables in var in inline vars

19 views
Skip to first unread message

Andrew Wade

unread,
Sep 14, 2015, 8:20:07 AM9/14/15
to Ansible Project
Hey,

(I'm using Ansible 1.9.2)

I've got a playbook like this:

- hosts:
  vars
:
    var_required_by_role
:
     
- name: "{{ variable }}"
        user
: "foo"
  roles:
   
- myrole


My issue is that no error is raised if 'variable' is undefined; Ansible outputs a changed line like:

=> ... 'name': u'{# variable #}'

I'm constructing a more complex variable form a simple value passed in with -e and I don't want to define the complex variable on the command line.

Is there a better way to do this, or to force error checking? I tried the mandatory filter, but I don't think it gets parsed.

Thanks.

Frank Perks

unread,
Sep 14, 2015, 12:03:50 PM9/14/15
to Ansible Project
You make an variable mandatory to throw an error if a var is not defined:

- hosts:
  vars
:
    var_required_by_role
:
     
- name: "{{ variable | mandatory }}"

        user
: "foo"
  roles
:
   
- myrole

Alternatively you can edit ansible.cfg to change this setting to True

error_on_undefined_vars = False
Reply all
Reply to author
Forward
0 new messages