I'd like to use /etc/hosts to avoid the DNS propagation delays.
I don't want to do away with DNS altogether though - is it possible to lookup
a hostname and pass that IP to the hosts type? Something like:
# this gets used by several classes
$activedbhost = "mysql1.mydomain.com"
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 :)
> Does anyone have a reference on how to write functions -
> the reductive labs docs seem a little broken today.
Never mind, found it.
http://reductivelabs.com/trac/puppet/wiki/WritingYourOwnFunctions
> # this gets used by several classes
> $activedbhost = "mysql1.mydomain.com"
>
> 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. There is documentation inside the file
plugins/puppet/parser/functions/resolve_ipnets.rb.
A little note, though. If you use this to populate /etc/hosts from
DNS, and you do so on your Puppetmaster, you won't be able to change
the address of that name. The next time resolve_ipnets() is called,
it will find the address in /etc/hosts, and then you're stuck. (You
can of course remove that entry from /etc/hosts manually, and then
you'll be OK again, but that's cheating. :-)
/Bellman
>> 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:
[rasputnik@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.