# Conditional upon variable

**URL:** <https://forum.ansible.com/t/conditional-upon-variable/15794>\
**Category:** Ansible Project\
**Created:** [July 28, 2014, 10:32pm UTC](https://forum.ansible.com/t/conditional-upon-variable/15794 "2014-07-28T22:32:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Oliver](https://avatars.discourse-cdn.com/v4/letter/j/97f17d/32.png) [@John\_Oliver](https://forum.ansible.com/u/John_Oliver)\
**Post date:** [July 28, 2014, 10:32pm UTC](https://forum.ansible.com/t/conditional-upon-variable/15794/1 "2014-07-28T22:32:35Z")

</div>

I tried to:

command: /usr/sbin/setsebool -P httpd\_can\_network\_connect\_db 1  
when: “{{rc\_db\_host}}” = “localhost”

Ansible exploded in rage. I’ve never sent his much red text, even from python errors 🙂 I tried with quotes, without, ‘=’, ‘==’… It looks like there’s duplication in the error message, too:

ERROR: Syntax Error while loading YAML script, roundcube.yml  
Note: The error may actually appear before this position: line 129, column 28

command: /usr/sbin/setsebool -P httpd\_can\_network\_connect\_db 1  
when: “{{rc\_db\_host}}” == “localhost”  
^  
We could be wrong, but this one looks like it might be an issue with  
unbalanced quotes. If starting a value with a quote, make sure the  
line ends with the same set of quotes. For instance this arbitrary  
example:

foo: “bad” “wolf”

Could be written as:

foo: ‘“bad” “wolf”’

We could be wrong, but this one looks like it might be an issue with  
missing quotes. Always quote template expression brackets when they  
start a value. For instance:

with\_items:

- {{ foo }}

Should be written as:

with\_items:

- “{{ foo }}”

We could be wrong, but this one looks like it might be an issue with  
unbalanced quotes. If starting a value with a quote, make sure the  
line ends with the same set of quotes. For instance this arbitrary  
example:

foo: “bad” “wolf”

Could be written as:

foo: ‘“bad” “wolf”’

---

<div class="post-metadata">

**Author:** ![Michael\_Peters](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Michael\_Peters](https://forum.ansible.com/u/Michael_Peters)\
**Post date:** [July 28, 2014, 10:36pm UTC](https://forum.ansible.com/t/conditional-upon-variable/15794/2 "2014-07-28T22:36:35Z")

</div>

Try something like this:

&nbsp;&nbsp;&nbsp;&nbsp;command: /usr/sbin/setsebool -P httpd\_can\_network\_connect\_db 1  
&nbsp;&nbsp;&nbsp;&nbsp;when: rc\_db\_host == "localhost"

You don't need to use templating in the when clauses.

---

<div class="post-metadata">

**Author:** ![John\_Oliver](https://avatars.discourse-cdn.com/v4/letter/j/97f17d/32.png) [@John\_Oliver](https://forum.ansible.com/u/John_Oliver)\
**Post date:** [July 28, 2014, 10:45pm UTC](https://forum.ansible.com/t/conditional-upon-variable/15794/3 "2014-07-28T22:45:15Z")

</div>

Thanks!!!
