Icinga2 mit puppet clients

Aus xinux.net
Zur Navigation springen Zur Suche springen

puppet zertifikate verteilen

ein modul erstellen wie unten im beispiel


class cert {
$cert = "${fqdn}.crt"
$key = "${fqdn}.key"


2 variablen setzen

damit wir die zertifikate richtig benen können

fqnd steht hier für fully qualified domain name

alls string würde der inhalt so ausehen

$key = irgendwas.xinux.org.key


file { '/etc/ssl/xin-ca.crt':
  ensure => file,
      mode   => 664,
      owner => root,
      group => root,
      source => 'puppet:///modules/cert/xin-ca.crt'
}
file { "/etc/ssl/$cert":
  ensure => file,
      mode   => 664,
      owner => root,
      group => root,
      source => "puppet:///modules/cert/$cert"
}
file { "/etc/ssl/$key":
 ensure => file,
      mode   => 664,
     owner => root,
      group => root,
      source => "puppet:///modules/cert/$key"
}

die source zeigt was kopiert werden soll

und file{wo es auf dem client landen soll}

mode,owner,group die rechte die auf dem client gesetzt werden sollen

icinga2 installation restart & verlinken

mkdir /etc/puppet/modules/icinga2-client

den ordner so strukturiern

Treeicinga2.png


  • die init.pp
class icinga2-client {
Exec { path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ] }
  package { "icinga2":
    ensure => present,
    require => Exec["icinga_repository"],
  }
  exec { "add-apt-repository ppa:formorer/icinga && apt-get update":
    alias => "icinga_repository",
    creates => "/etc/apt/sources.list.d/formorer-icinga-trusty.list",
    require => Package["software-properties-common"]
} 

  package { "software-properties-common":
    ensure => present
  }


alles was in dieser classe berücksichticht werden soll mus in den ersten {} stehen

also aufpassen das am schlus die datei mit } abgeschlosen ist

wir prüfen ob icinga2 installiert ist wenn nicht wird es installier sofern die repository stimmen

falls nicht fügen wird die repository hinzu wen software-properties-common installiert ist wen nicht installieren wir dies


  • verlinken der certifikate und kopieren der konfigurationsdatein auf den server
file { '/etc/icinga2/pki/ca.crt':
  ensure => 'link',
  target => '/etc/ssl/xin-ca.crt',
  require => Package["icinga2"]
}
file { "/etc/icinga2/pki/${fqdn}.crt":
  ensure => 'link',
  target => "/etc/ssl/${fqdn}.crt",
  require => Package["icinga2"]
}
file { "/etc/icinga2/pki/${fqdn}.key":
  ensure => 'link',
  target => "/etc/ssl/${fqdn}.key",
  require => Package["icinga2"]
}
file { "/etc/icinga2/pki/trusted-master.crt":
 ensure => file,
     mode   => "664",
     owner => root,
     group => root,
     source => "puppet:///modules/icinga2client/trusted-master.crt",
     require => Package["icinga2"]
}
file {  '/etc/icinga2/zones.conf':
   content  => template('icinga2client/zones.conf'),
   mode => "0644",
   owner => root, group => root,
   require => Package["icinga2"]
}
file {  '/etc/icinga2/constants.conf':
   content  => template('icinga2client/constants.conf'),
   mode => "0644",
   owner => root, group => root,
   require => Package["icinga2"]
}
file {'/etc/icinga2/features-available/api.conf':
  ensure => file,
  mode => "0644",
  owner => root, group => root,
  source => "puppet:///modules/icinga2client/api.conf",
  require => Package['icinga2'];
}
file { "/etc/icinga2/features-enabled/api.conf":
  ensure => 'link',
  target => "/etc/icinga2/features-available/api.conf",
  require => Package["icinga2"]
}

wier sorgen dafür das das icinga neustartet da beim nechsten run die datei icinga2-restart-20151001 schon existiert wird er nur bei der erstinstalation den reload ausführen

$date = "icinga2-restart-20151001"
exec { "icinga2-reload":
   command => "service icinga2 restart > /var/run/$date",
   creates  =>  "/var/run/$date",
   require => File["/etc/icinga2/features-enabled/api.conf"]
}
}

die ssl zertifikate werden in unserm besipielt im ordner /etc/puppet/modules/cert/files abgelegt

bis auf den trusted master den wir in /etc/puppet/modules/icinga2client/files/ ablegen

die api.conf legen wir in /etc/puppet/modules/icinga2client/files/

die constants.conf und die zones.conf sind dynmaish und liegen deshalb in in /etc/puppet/modules/icinga2client/templates

Auf dem Icinga Server

  • icinga2 node list
Node 'nogger.xinux.org' (last seen: Fri Jun 24 05:46:29 2016)
    * Host 'nogger.xinux.org'
        * Service 'disk'
        * Service 'disk /'
        * Service 'http'
        * Service 'icinga'
        * Service 'load'
        * Service 'ping4'
        * Service 'ping6'
        * Service 'procs'
        * Service 'ssh'
        * Service 'swap'
        * Service 'users'

check

  • find /etc/icinga2/repository.d -name "nogger.xinux.org*"

er findet nichts

update config

  • icinga2 node update-config

check

  • find /etc/icinga2/repository.d -name "nogger.xinux.org*"
./zones/nogger.xinux.org.conf
./hosts/nogger.xinux.org.conf
./hosts/nogger.xinux.org
./endpoints/nogger.xinux.org.conf

icinga2 neutstarten

  • systemctl restart icinga2.service