Conditionals with facts

57 views
Skip to first unread message

Rich Burroughs

unread,
Sep 28, 2014, 6:48:40 PM9/28/14
to ansible...@googlegroups.com
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

Michael DeHaan

unread,
Sep 29, 2014, 9:18:32 AM9/29/14
to ansible...@googlegroups.com
On Sun, Sep 28, 2014 at 6:48 PM, Rich Burroughs <ri...@richburroughs.com> wrote:
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.
 

Rich Burroughs

unread,
Sep 30, 2014, 1:11:37 AM9/30/14
to ansible...@googlegroups.com
Thanks, that was very helpful :)


Rich
Reply all
Reply to author
Forward
0 new messages