At ansible 1.9 I have some roles which I can make use of undefined variables (error_on_undefined_vars = False at ansible.cfg) in templates with no issues in the way:
template.yml:
{{ var1 }}{{ var2 }}{{ var3 }}
If any of these vars are not defined, then nothing is substituted. So, you can just indicate in your playbook some of these vars and not others, as desired.
But I found, after upgrading to ansible 2.2.0.0 , that if any of these vars are not defined, them none of the template's vars are substituted and the resulted template is: {{ var1 }}{{ var2 }}{{ var3 }}
E.g.:
playbook:
- hosts: myhost
vars:
var1=1
var3=3
roles:
- myrole
tasks:
- name: copy template
become: true
template: src=test.j2 dest=/tmp/test owner=user group=user
After running this playbook, the resulting /tmp/test run with ansible 1.9 is
13
and with ansible 2.2.0.0 is
{{ var1 }}{{ var2 }}{{ var3 }}
So, none vars are substituted.
But if:
playbook:
- hosts: myhost
vars:
var1=1
var2=2
var3=3
roles:
- myrole
After running this playbook, the resulting /tmp/test run with ansible 1.9 / 2.2.0.0 is
123
Has anyone dealed with this behavior before?