Case statement with wildcards?


#1

I was intending to set up some Chef environments for different parts of the
network but noticed that the information is already present within the FQDN.

Taking the simple example of
node1.primary.mycompany.com
node2.secondary.mycompany.com
node3.dmz.mycompany.com

how can I write a case statement to process differently according to whether
node is in primary, secondary or dmz?


#2

Hello!

On Mon, Jul 4, 2011 at 8:18 AM, ItsMikeE chef@ernstoff.net wrote:

I was intending to set up some Chef environments for different parts of the
network but noticed that the information is already present within the FQDN.

Taking the simple example of
node1.primary.mycompany.com
node2.secondary.mycompany.com
node3.dmz.mycompany.com

how can I write a case statement to process differently according to whether
node is in primary, secondary or dmz?

I would create an ohai plugin to get the subdomain part. Something like this:

provides "subdomain"
require_plugin "#{os}::hostname"

parts = fqdn.split(/\./)

subdomain parts[1]

You can distribute this to your nodes with Opscode’s “ohai” cookbook0.

% knife cookbook site install ohai
% $EDITOR cookbooks/ohai/files/default/plugins/subdomain.rb
# paste the code above
% knife cookbook upload ohai

Then add ‘recipe[ohai]’ to your nodes, and when chef runs, they’ll
have an attribute “subdomain”.

% knife node show virt1test -a fqdn
fqdn:  virt1test.int.example.com
% knife node show virt1test -a subdomain
subdomain: int


Opscode, Inc
Joshua Timberman, Director of Training and Services
IRC, Skype, Twitter, Github: jtimberman