How to use facter variable in node definition?

126 views
Skip to first unread message

Pawel Kilian

unread,
Apr 17, 2014, 2:41:41 PM4/17/14
to puppet...@googlegroups.com
Hi,
I want to use facter scope variable to use in my manifest files for puppet

for now i have something like this:

node 'web-server' {
..
..
}


I want to be able to use if/case  definition to define nodes


root@ip-10-187-40-216:~# facter -p system_role
app-server
root@ip-10-187-40-216:~#

so in my manifest node definition i would like to use something like:

node if $::system_role == "app-server" {
..
...
include default;
}


or something similar to it.
I want to use facter variables because i want to use with ec2tags for each server and build each server based on ec2 tag

How I can approach this?

thanks

José Luis Ledesma

unread,
Apr 17, 2014, 2:55:20 PM4/17/14
to puppet...@googlegroups.com

Remove the node word and you have it

if $::system_role == "app-server" {

..

...

include default;

}

Regards,

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/3f7a87c2-cdec-42b8-88d5-25a57267ee46%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pawel Kilian

unread,
Apr 18, 2014, 9:29:28 AM4/18/14
to puppet...@googlegroups.com
thank you, I will try that

jcbollinger

unread,
Apr 18, 2014, 9:36:08 AM4/18/14
to puppet...@googlegroups.com


On Thursday, April 17, 2014 1:55:20 PM UTC-5, Jose Luis Ledesma wrote:

Remove the node word and you have it

if $::system_role == "app-server" {

..

...

include default;

}


Do note, however, that is a top-level declaration, not a node definition.  That's perfectly fine for most purposes, but there are a few corner cases where it could be an issue.

More generally, node definitions classify nodes based on their identity, in the form of their $clientcert.  Nothing else provided by the client factors in to associating client nodes with node definitions.  That's not really very limiting however, for even if you want or need node definitions (so that Jose's suggestion isn't applicable), you can put your conditional logic inside a general node declaration or into a class, or, even better, you can use hiera to assign data and classes to your nodes based on the values of their facts.


John

Reply all
Reply to author
Forward
0 new messages