I used a case statement for 12 or so datacenters that I have to support.
 Its becomes a big file, but not so out of control to look at it or modify
(very rarely does it get modified).  Its self contained and easy to sort
through to make changes.  Something like this below works great for my
needs.  At some point this data would live in a database to centralize it,
otherwise the case statement works for the time being.

location.pp  (domain comes from the hosts domain name, but you can derive
something from a fact here).

case $domain {
  'site.com': {
    $dns_nameservers = ['192.168.100.10', '192.168.101.10']
    $dns_search      = 'site.com'
  }

  default: {
     fail('FAIL: Unable to determine site location.')
  }

Template:

domain <%= domain %>
search <%= dns_search %>
<%
  nameservers = ""
  dns_nameservers.each do |s|
    nameservers = nameservers + "nameserver #{s}\n"
  end
-%>
<%= nameservers %>



On Tue, Feb 16, 2010 at 8:44 AM, Marcello de Sousa <[email protected]>wrote:

> "if/else" alternative would make it too big (and a bit ugly).
> Don't you think cascading the conditionals should make sense ? Would be
> quite neat solution I think.
> "case" could be an option, but also didn't get it to work here. It looks
> like case only works outside the puppet "type".
>
> My (ugly) workaround now was to create all the combinations as different
> files and use the variables in the filename:
> source => "puppet:///myresolv/etc/resolv.conf_${domain}_${location}",
>
> I might just go back to the drawing board and try to use "case" to create
> what I believe Christopher means with: "detector based recipe which applied
> usable variables/arrays".
>
> Something like:
> ----------
> class resolver::resolv_location {
> case $domain {
>   "domain1.local": { $nameserv = ['10.2.38.20','10.2.38.10'] }
>   default:         { $nameserv = ['10.2.38.11','10.128.38.20'] }
>              }
>
>    resolv_conf { "location_based_resolv":
>        domainname  => "$domain",
>        searchpath  => [$domain],
>         nameservers => $nameserv,
>                }
> }
> ----------
>
> That's what you mean right Christopher ?
>
> Can I cascade "case" ? Can you post an example on how you did it?
>
> Cheers,
> Marcello
>
> > -----Original Message-----
> > From: [email protected] [mailto:puppet-
> > [email protected]] On Behalf Of Christopher Johnston
> > Sent: dinsdag 16 februari 2010 13:52
> > To: [email protected]
> > Cc: [email protected]
> > Subject: Re: [Puppet Users] Cascaded conditionals possible ?
> >
> > I found it easier to create a detector based recipe which applied
> > usable variables/arrays then passed them down into a template.
> >
> > Sent from my iPhone
> >
> > On Feb 16, 2010, at 7:05 AM, Trevor Vaughan <[email protected]>
> > wrote:
> >
> > > I haven't tried it that way, but it would seem that that wouldn't
> > > work to me.
> > >
> > > It does work with nested if/else statements.
> > >
> > > Trevor
> > >
> > > On Mon, Feb 15, 2010 at 4:12 PM, Marcello de Sousa
> > > <[email protected]> wrote:
> > >> I've been trying to use a resolv_conf recipe to setup the DNS
> > >> servers based
> > >> on $domain and $location (a custom fact).
> > >> So I cascade the 2 conditionals, but it's not working. Is it
> > >> supposed to
> > >> work ? Or should I look for an alternative ?
> > >> ------------------------------------------
> > >>    resolv_conf { "location_based_resolv":
> > >>        domainname  => "$domain",
> > >>        searchpath  => [$domain],
> > >> # Here is the cascaded conditional. If I'm in "domain1" I want to
> > >> test 3
> > >> different locations.
> > >>        nameservers => $domain ? {
> > >>           "domain1.local" => $location ? {
> > >>                "Default-First-Site-Name" =>
> > ['10.2.38.10','10.128.38.21
> > >> '],
> > >>                "HeadOffice"              =>
> > >> ['10.128.36.20','10.128.36.11'],
> > >>                default                   =>
> > ['10.128.36.10','10.2.36.21
> > >> '],
> > >>                                          }
> > >>           "domain2.local" =>  ['10.128.36.20','10.128.36.10'],
> > >>           default         =>  ['10.128.36.10','10.2.36.20'],
> > >>                                 }
> > >>                }
> > >> ------------------------------------------
> > >> ## If I test only one level it works:
> > >> #        nameservers => $location ? {
> > >> #               "Default-First-Site-Name" =>
> > ['10.2.38.10','10.128.38.21
> > >> '],
> > >> #               "HeadOffice"              =>
> > >> ['10.128.36.20','10.128.36.11'],
> > >> #               default                   =>
> > ['10.128.36.10','10.2.36.21
> > >> '],
> > >> #                                 }
> > >> ------------------------------------------
> > >>
> > >> Am I missing something ? Or should I do it differently ?
> > >>
> > >> Cheers,
> > >> Marcello
> > >>
> > >>
> > >>
> > >> --
> > >> You received this message because you are subscribed to the Google
> > >> Groups "Puppet Users" group.
> > >> To post to this group, send email to [email protected].
> > >> To unsubscribe from this group, send email to puppet-
> > [email protected]<users%[email protected]>
> > >> .
> > >> For more options, visit this group at
> > http://groups.google.com/group/puppet-users?hl=en
> > >> .
> > >>
> > >>
> > >
> > >
> > >
> > > --
> > > Trevor Vaughan
> > > Vice President, Onyx Point, Inc
> > > (410) 541-6699
> > > [email protected]
> > >
> > > -- This account not approved for unencrypted proprietary information
> > > --
> > >
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Puppet Users" group.
> > > To post to this group, send email to [email protected].
> > > To unsubscribe from this group, send email to puppet-
> > [email protected]<users%[email protected]>
> > > .
> > > For more options, visit this group at
> > http://groups.google.com/group/puppet-users?hl=en
> > > .
> > >
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Puppet Users" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to puppet-
> > [email protected]<users%[email protected]>
> .
> > For more options, visit this group at
> > http://groups.google.com/group/puppet-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<puppet-users%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/puppet-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to