On Wed, Feb 24, 2010 at 2:07 PM, Thomas Bellman <bell...@nsc.liu.se> wrote:
> Dick Davies wrote:

>> host { "db.hosting.mydomain.com":
>>   ensure => present,
>>   ip          => ip_of($activedbhost)
>> }
>>
>> 'ip_of()' is what Puppet calls a 'function', right?
>> Does anyone have a reference on how to write them -
>> the reductive labs docs seem a little broken today.
>>
>> Or better still, has someone already written such a thing :)
>
> As a matter of fact, yes, I have. :-)
>
> In my "nsc-puppet-utils" module, I have a function resolve_ipnets()
> which does that.  (It does have some additional features as well.
> For example, it resolves names on the form "foo.example.com/24"
> to "10.20.30.17/24", and it handles lists of hostnames as well.)
>
> Do a 'git clone http://www.nsc.liu.se/~bellman/nsc-puppet-utils.git'
> to get my module.

Nice, thanks - lot of useful stuff there. I went for a dirt simple:

[rasput...@puppet lamp]# cat plugins/puppet/parser/functions/ip_of.rb
module Puppet::Parser::Functions
  require 'resolv'
  newfunction(:ip_of, :type => :rvalue) do  |args|
    hostname = args[0]
    Resolv.getaddress(hostname)
  end
end

So I can now do:

class webserver {
  ...
  host { "$lamp::cfg::mysql_alias":
    ensure => present,
    ip         => ip_of("$lamp::cfg::mysql_master")
  }
  ...
}

and the webservers all get an /etc/hosts entry for
whichever mysql backend is set to be active in my settings class
(to avoid having to edit 150+ wp-config.phps).

A 2:5 useful code to boilerplate ratio is pretty good for a plugin
framework, so I think I'll stick with mine for now (and maybe pinch
yours if we need to generalize things :) )

Thanks again for the other functions, though. I'll use them as a reference
when we start getting more heavily into custom functions.

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

Reply via email to