Prevent ansible from evaluating variable when skipping a task -
i have conditionally run role in playbook. this:
- { role: some_role, when: "some_var == 'blah'" } it's annoying though conditional on role, ansible still decides go through every task in role , mention:
task: [some_role | something] ******************************** skipping: [some_host] why needs go each task in role beyond me, that's been i've lived with. until now. added task some_role looks this:
- name: some_module: something: "{{ item.0.some_sub_attr }}" something_else: "{{ item.1 }}" with_subelements: - elem1 - elem2 now, ungodly reason ansible trying evaluate elem1 (even though it's skipping task) , because elem1 undefined, it's erroring out whole thing with:
fatal: [some_host] => subelements lookup expects dictionary, got 'elem1' how can avoid happening? ideally, i'd love rid of skips on tasks , have tell me it's skipping role, if that's unavoidable, can @ least stop having evaluate variables on tasks being skipped anyway?
first, reason shows "skipped" instead of silently not executing because (at least in ansible 1.x) task execution order determined before evaluated (same reason vars in task names don't work), , each host has own set of variables. because conditional caused skipped 1 host doesn't mean might not another, therefore, tasks show up, if they're skipped hosts. playbook runner has been largely rewritten 2.x, , true conditional includes/roles on roadmap (though haven't looked lately see if current 2.0 code has or not)- solve issue.
assuming want that'll work in 1.x- have considered using either role defaults or default filter on problem variables prevent them breaking? there's big hammer of setting error_on_undefined_vars=false in ansible.cfg, wouldn't recommend that...
Comments
Post a Comment