# Add conditional logic to variable files?

**URL:** <https://forum.ansible.com/t/add-conditional-logic-to-variable-files/26267>\
**Category:** Ansible Project\
**Tags:** galaxy-ng\
**Created:** [December 12, 2017, 10:20pm UTC](https://forum.ansible.com/t/add-conditional-logic-to-variable-files/26267 "2017-12-12T22:20:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_F](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@Robert\_F](https://forum.ansible.com/u/Robert_F)\
**Post date:** [December 12, 2017, 10:20pm UTC](https://forum.ansible.com/t/add-conditional-logic-to-variable-files/26267/1 "2017-12-12T22:20:11Z")

</div>

I’ve been using Ansible Galaxy roles from Jeff Geerling. In his Github READMEs he seems to say that you can override variable settings in his default/main.yml and vars/\*.yml files by reproducing the desired settings in a /vars/main.yml file and then re-assigning them your desire values. This works well but there are times when I’d like to use the following logic in that file:

`

# vars/main.yml

enable\_setting: true  
…

if enable\_setting  
foo: bar  
else  
baz: barf  
`

Is this possible? I didn’t see this mentioned in the Ansible docs on Variables and Conditionals.

Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [December 14, 2017, 3:29am UTC](https://forum.ansible.com/t/add-conditional-logic-to-variable-files/26267/2 "2017-12-14T03:29:48Z")

</div>

data files have no logic, but you can use a templated value instead:

foo: "{{ enabled\_setting|ternary('bar', '') }}"  
baz: "{{ enabled\_setting|ternary('', 'barf') }}"
