How to use concat in puppet for combining two files into same file? -
define nagios::iconf( $host_name='', $ip='', $short_alias='',$service_name='',$remote_host_name='',$port=''){ $reconfigure = "/usr/local/nagios/etc/import/${host_name}.cfg" concat{$reconfigure: owner => nagios, group => nagios, mode => 755 } concat::fragment{"hosttemplate": target => $reconfigure, source => template('nagios/host.erb'), order => 01, } concat::fragment{"servicetemplate": target => $reconfigure, ensure => template("nagios/${service_name}.erb"), order => 15 } } include nagios
when declare in site.pp
node "blahblahhostname"{ nagios::iconf{'name1': host_name => 'localhost' remote_host_name => 'blahblah1', ip => '32.232.434.323', port => '111', short_alias => 'random', service_name => 'servicename1' } nagios::iconf{'name2': host_name => 'localhost' remote_host_name => 'blahblah1', ip => '32.232.434.323', port => '111', short_alias => 'random', service_name => 'servicename2' } include nagios }
i duplicate declaration error. did go wrong?
problem here
concat{"/usr/local/nagios/etc/import/localhost.cfg" owner => nagios, group => nagios, mode => 755 }
is defined twice because of host_name
. when calling define
type in manifest causing duplicate warnings.
you have define once, outside of define
type. may in class or in manifests
itself. like:
concat{"/usr/local/nagios/etc/import/localhost.cfg" ..... .....
and then, rest of code, i.e. concat::fragments
can go inside define
type.
define nagios::iconf( $host_name='', $ip='', $short_alias='',$service_name='',$remote_host_name='',$port=''){ $reconfigure = "/usr/local/nagios/etc/import/${host_name}.cfg" concat::fragment{"hosttemplate": target => $reconfigure, source => template('nagios/host.erb'), order => 01, } concat::fragment{"servicetemplate": target => $reconfigure, ensure => template("nagios/${service_name}.erb"), order => 15 } }
Comments
Post a Comment