# 'when not' conditional?

**URL:** <https://forum.ansible.com/t/when-not-conditional/16263>\
**Category:** Ansible Project\
**Created:** [September 17, 2014, 9:20pm UTC](https://forum.ansible.com/t/when-not-conditional/16263 "2014-09-17T21:20:34Z")\
**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:** [September 17, 2014, 9:20pm UTC](https://forum.ansible.com/t/when-not-conditional/16263/1 "2014-09-17T21:20:34Z")

</div>

I’d like to have SSL certificates uploaded and configured according to hostname, ie. host1 gets the cert and key for host1, etc.

It seems like the easiest way is to set a variable to equal ansible\_hostname, but I’d need a way to handle exceptions, so if ansible\_hostname isn’t one of an expected set of values, the variable could be set to some default value. What would be the best way to accomplish something like this?

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [September 18, 2014, 12:01am UTC](https://forum.ansible.com/t/when-not-conditional/16263/2 "2014-09-18T00:01:02Z")

</div>

Hi John, I believe

- set\_fact: foo={{ansible\_hostname|default(‘default\_ value’)}}

should do what you want.

---

<div class="post-metadata">

**Author:** ![Tomasz\_Kontusz](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@Tomasz\_Kontusz](https://forum.ansible.com/u/Tomasz_Kontusz)\
**Post date:** [September 19, 2014, 5:45am UTC](https://forum.ansible.com/t/when-not-conditional/16263/3 "2014-09-19T05:45:03Z")

</div>

John Oliver \<jnojr1@gmail.com\> napisał:

> I'd like to have SSL certificates uploaded and configured according to  
> hostname, ie. host1 gets the cert and key for host1, etc.
> 
> It seems like the easiest way is to set a variable to equal  
> ansible\_hostname, but I'd need a way to handle exceptions, so if  
> ansible\_hostname isn't one of an expected set of values, the variable  
> could  
> be set to some default value. What would be the best way to accomplish
> 
> something like this?

Try something like {{ ansible\_hostname if ansible\_hostname in list\_of\_expected\_values else the\_default }}
