# Conditionals with facts

**URL:** <https://forum.ansible.com/t/conditionals-with-facts/16367>\
**Category:** Ansible Project\
**Created:** [September 28, 2014, 10:48pm UTC](https://forum.ansible.com/t/conditionals-with-facts/16367 "2014-09-28T22:48:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rich\_Burroughs](https://avatars.discourse-cdn.com/v4/letter/r/9dc877/32.png) [@Rich\_Burroughs](https://forum.ansible.com/u/Rich_Burroughs)\
**Post date:** [September 28, 2014, 10:48pm UTC](https://forum.ansible.com/t/conditionals-with-facts/16367/1 "2014-09-28T22:48:40Z")

</div>

Hi,

We use Puppet when I work and we've done a bit of orchestration with both Mcollective and Fabric. I'm very interested in using Ansible instead of Fabric since I've learned it can use Facter facts.

We have a mix of Solaris and Linux nodes, and for the Solaris nodes it looks like I need to set the path to sudo specifically for that to work with sudo\_exe. This wasn't surprising as I had to do it with Fabric too.

So my question is basically, what's the best way to do that globally for all the Solaris hosts? It seems like I could leverage a fact to do that, both Facter and Ansible itself have facts I could use with a conditional somehow. But where would I put that? Or would it be better to just have a separate inventory file for them and do it there?

Another example is determining which environment (Dev/UAT/Prod) a host is in. That's a custom Facter fact we already set through Puppet, and seems like it would make sense to leverage that somehow. But the docs on the web site seem to indicate that it would be better to split my inventory into different files per environment.

I like the idea of using the same facts to make decisions in Puppet and Asible, so we know we're working off the same data with both tools.

Thanks,

Rich

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 29, 2014, 1:18pm UTC](https://forum.ansible.com/t/conditionals-with-facts/16367/2 "2014-09-29T13:18:27Z")

</div>

> Hi,
> 
> We use Puppet when I work and we've done a bit of orchestration with both  
> Mcollective and Fabric. I'm very interested in using Ansible instead of  
> Fabric since I've learned it can use Facter facts.

I'm sorry to hear about the tools you have to use. That being said, I'll  
answer the questions below 🙂

> We have a mix of Solaris and Linux nodes, and for the Solaris nodes it  
> looks like I need to set the path to sudo specifically for that to work  
> with sudo\_exe.

There's a pull request in queue to make this work as an inventory  
variable. It's not merged yet.

> So my question is basically, what's the best way to do that globally for  
> all the Solaris hosts? It seems like I could leverage a fact to do that,  
> both Facter and Ansible itself have facts I could use with a conditional  
> somehow. But where would I put that? Or would it be better to just have a  
> separate inventory file for them and do it there?

You would normally define it in a group variable but you'd need the pull  
request mentioned above as right now sudo\_exe is a global setting.

> Another example is determining which environment (Dev/UAT/Prod) a host is  
> in. That's a custom Facter fact we already set through Puppet, and seems  
> like it would make sense to leverage that somehow. But the docs on the web  
> site seem to indicate that it would be better to split my inventory into  
> different files per environment.

Ansible likes to make this statement declaratively using host groups and  
playbooks.

The playbooks describe what roles/tasks to apply to which groups of hosts.

You can also use the "group\_by" module in Ansible to create dynamic groups  
based on the values of certain variables such as the OS type.

---

<div class="post-metadata">

**Author:** ![Rich\_Burroughs](https://avatars.discourse-cdn.com/v4/letter/r/9dc877/32.png) [@Rich\_Burroughs](https://forum.ansible.com/u/Rich_Burroughs)\
**Post date:** [September 30, 2014, 5:11am UTC](https://forum.ansible.com/t/conditionals-with-facts/16367/3 "2014-09-30T05:11:37Z")

</div>

Thanks, that was very helpful 🙂

Rich
