Multiple server roles using hiera and facts

482 views
Skip to first unread message

Shiva Narayanaswamy

unread,
Dec 1, 2013, 11:58:34 PM12/1/13
to puppet...@googlegroups.com
I want to implement a scenario where I can mix and match multiple roles on any managed node. The particular roles played by a node are available as facts (role1=webserver, role2=appserver etc )In development all the roles will be played by one host, and in production a server might play only one role. 

I was hoping there will be some way I can implement this in hiera. Any clues or pointers would be much appreciated.

Cheers,
Shiva

Matthias Saou

unread,
Dec 2, 2013, 8:25:20 AM12/2/13
to puppet...@googlegroups.com
I've already had to do something similar, and did it the following way :

* A single "role=" fact/variable.
* Conditionals such as "if "<rolename>" in $role { ..."

It's not the prettiest way, but since facts can't be arrays, it's the
best I could think of. My role names are all 3 letter long and unique,
meaning that no role name contains another (role "app" and "app1"
would cause "app" to be found in "app1).

In hiera (or from a fact) I just need to have a role string :

role: 'role1,role2,role3'

Depending on your environment, it might also make sense to go for
completely separate variables for each role, such as:

webserver: true
appserver: true

With matching facts which exist or don't exist.

HTH,
Matthias

--
Matthias Saou ██ ██
██ ██
Web: http://matthias.saou.eu/ ██████████████
Mail/XMPP: matt...@saou.eu ████ ██████ ████
██████████████████████
GPG: 4096R/E755CC63 ██ ██████████████ ██
8D91 7E2E F048 9C9C 46AF ██ ██ ██ ██
21A9 7A51 7B82 E755 CC63 ████ ████

Chris Handy

unread,
Dec 2, 2013, 1:12:52 PM12/2/13
to puppet...@googlegroups.com
i have heard of people using json in fact values to express arrays.  

Shiva Narayanaswamy

unread,
Dec 2, 2013, 2:01:46 PM12/2/13
to puppet...@googlegroups.com
I think I kind of get what you are saying, and I was going to do some ugly if loops in my modules, but that was the second option. I was wondering if there is a more elegant solution.

Thanks for taking the time to answer.

Ger Apeldoorn

unread,
Dec 3, 2013, 3:44:54 AM12/3/13
to puppet...@googlegroups.com
I create a class for each role and use hiera_include('roles') to declare those classes. All of these classes live in a module named 'role'.

Example hiera:

roles:
  - role::app
  - role::db
  - role::proxy



Op maandag 2 december 2013 05:58:34 UTC+1 schreef Shiva Narayanaswamy:
Reply all
Reply to author
Forward
0 new messages