merge / extend variable hiera_hash() + inline_template

20 views
Skip to first unread message

Denny Fuchs

unread,
Apr 18, 2017, 8:21:19 AM4/18/17
to Puppet Users
Hello,

I have the following construct

class profile::icinga2::agent (
  String  $monitoring_host = "mon-01.example.com",
  String  $monitoring_ip = "192.168.1.1",
){

...
    @@::icinga2::object::host { $::fqdn:
      display_name  => $::fqdn,
      address       => $::ipaddress,
      check_command => 'hostalive',
      vars          => hiera_hash('icinga_vars', {} ),
      target        => "/etc/icinga2/zones.d/master/${::fqdn}.conf"
    }
...
}


That works fine, to get my values out my hieradata/common.yaml. Now I need to extend the variable "vars" with:

...
vars => {
  puppet_classes => inline_template ('<%= classes.sort.join(" ") %>'),
},


How can I get both in "vars" ?

cu denny

Denny Fuchs

unread,
Apr 18, 2017, 2:47:57 PM4/18/17
to Puppet Users

hi,

solved by switching to a custom fact function:

classes_file  = '/var/lib/puppet/state/classes.txt'
classes_hash  = {}
modules_array = []
File.foreach(classes_file) do |l|
  modules_array << l.chomp.gsub(/::.*/, '')
end
modules_array = modules_array.sort.uniq
modules_array.each do |i|
  classes_array = []
  classes_array << i
  File.foreach(classes_file) do |l|
    classes_array << l.chomp if l =~ /^#{i}/
    classes_array = classes_array.sort.uniq
  end
  classes_hash[i] = classes_array
end

Facter.add(:puppet_modules, :timeout => 10) do
  confine :kernel => 'Linux'
  setcode do
    modules_array.sort.uniq.join(', ').to_s
  end
end
Facter.add(:puppet_classes, :timeout => 10) do
  confine :kernel => 'Linux'
  setcode do
    classes_hash.map { |_k, v| v }.sort.uniq.join(', ').to_s
  end
end



from https://www.netways.de/fileadmin/images/Events_Trainings/Events/OSMC/2015/Slides_2015/The_Road_to_lazy_Monitoring_with_Icinga2_and_Puppet-Tom_De_Vylder.pdf

which gives me a hash back, instead of an array.

cu denny
Reply all
Reply to author
Forward
0 new messages