On Wednesday, January 12, 2011 5:08:07 PM UTC+1, Robin Lee Powell wrote:
>
> On Tue, Jan 11, 2011 at 12:07:30PM -0800, Robin Lee Powell wrote:
> > On Tue, Jan 11, 2011 at 05:20:38AM -0800, Al @ Lab42 wrote:
> > >
> > > You can build a file based on different "fragments" at least in
> > > 2 ways:
> > >
> > > - When you specify an array of templates , when using the
> > > content => argument, these templates are actually appended in
> > > the defined order.
> >
> > Can you use exported resources to generate such an array?
>
> Anybody? I can see how to generate resources from lots of hosts and
> run it on one host, but I can't see how to generate a config file
> out of all of that information.
>
> -Robin
>
I give you an example I use for Nagios.
On each node I've something like:
nagios::host { $ fqdn }
This calls the custom define (ignore the various frills such the grouptag
selector that manages different Nagios servers according to custom logic or
the various nagios::params variables, that are just module's internal
variables defined in the separated nagios::params class and concentrate on
the fact this this defines just exports a file resource: @@file ):
define nagios::host (
$ip = $fqdn,
$short_alias = $fqdn,
$use = 'generic-host',
$nagios_parent = '',
$ensure = 'present',
$hostgroups = 'all' ) {
require nagios::params
@@file { "${nagios::params::customconfigdir}/hosts/${name}.cfg":
mode => "${nagios::params::configfile_mode}",
owner => "${nagios::params::configfile_owner}",
group => "${nagios::params::configfile_group}",
ensure => "${ensure}",
require => Class["nagios::extra"],
notify => Service["nagios"],
content => template( "nagios/host.erb" ),
tag => "${nagios::params::grouptag}" ? {
'' => "nagios_host",
default => "nagios_host_$nagios::params::grouptag",
},
}
}
On the Nagios server I 've (in order to collect all the exported reources
with the relevant tag)
case $nagios::params::grouptag {
"": {
File <<| tag == "nagios_host" |>>
File <<| tag == "nagios_service" |>>
# File <<| tag == "nagios_hostgroup" |>>
}
default: {
File <<| tag == "nagios_host_$nagios::params::grouptag" |>>
File <<| tag == "nagios_service_$nagios::params::grouptag" |>>
# File <<| tag == "nagios_hostgroup_$nagios::params::grouptag" |>>
}
}
Now, I could place (and maybe I will) , in the nagios::host define something
like:
@@concat::fragment { "nagios_hosts_${name}.cfg":
target =>
"${nagios::params::customconfigdir}/hosts/nagios_hosts.cfg",
ensure => "${ensure}",
notify => Service["nagios"],
content => template( "nagios/host.erb" ),
tag => "${nagios::params::grouptag}" ? {
'' => "nagios_host",
default => "nagios_host_$nagios::params::grouptag",
},
and in the nagios server class collect these fragments with:
case $nagios::params::grouptag {
"": {
Concat::fragment <<| tag == "nagios_host" |>>
Concat::fragment <<| tag == "nagios_service" |>>
# Concat::fragment <<| tag == "nagios_hostgroup" |>>
}
default: {
Concat::fragment <<| tag == "nagios_host_$nagios::params::grouptag"
|>>
Concat::fragment <<| tag ==
"nagios_service_$nagios::params::grouptag" |>>
# Concat::fragment <<| tag ==
"nagios_hostgroup_$nagios::params::grouptag" |>>
}
}
In the same server I should also define the base concat file with something
like:
concat { "${nagios::params::customconfigdir}/hosts/nagios_hosts.cfg":
mode => 644,
owner => root,
group => root,
}
Consider that I've not tested this , and there could be syntax or other
errors around .
Also I'm not so sure that is safe to have the double colons in the define
name when collecting it ( Concat::fragment ) but the principle is that.
Remember also that all the variable or facts you use when exporting a
resource (such as $fqdn ) are referred and valued on host that exports it
and not to the one that collects them.
Hope it helped without adding confusion
Al
--
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.