Servermanagement with puppet – Part 4

Puppet facts

Note: This article based on Part 1 – Part 3 of my puppet articles. Please read them first !

Factor allows to you add information from your nodes to your puppet configuration.
Facts are available as variables. Execute the “facter” command and you get a full list of facts an their values:

sebastian@pc1:~$ facter
architecture => i386
domain => domain.local
facterversion => 1.5.1
fqdn => pc1.domain.local
hardwaremodel => i686
hostname => pc1
interfaces => eth0
ipaddress => 192.168.0.2
ipaddress_eth0 => 192.168.0.2
kernel => Linux
kernelrelease => 2.6.28-11-server
kernelversion => 2.6.28
lsbdistcodename => jaunty
lsbdistdescription => Ubuntu 9.04
lsbdistid => Ubuntu
lsbdistrelease => 9.04
macaddress => 00:0c:29:7a:37:37
macaddress_eth0 => 00:0c:29:7a:37:37
memoryfree => 417.25 MB
memorysize => 497.37 MB
netmask => 255.255.255.0
netmask_eth0 => 255.255.255.0
operatingsystem => Ubuntu
operatingsystemrelease => 9.04
processor0 => Intel(R) Xeon(TM) CPU 2.80GHz
processorcount => 1
ps => ps -ef
puppetversion => 0.24.5
rubysitedir => /usr/local/lib/site_ruby/1.8
rubyversion => 1.8.7
swapfree => 883.99 MB
swapsize => 883.99 MB
virtual => vmware

You see that my “pc1” is a 32-Bit virtual machine with Ubuntu 9.04. Now we want to extend our “baseclass template” to install the vmware-tools on all virtual machines.

Edit “/etc/puppet/manifests/templates.pp”:

#
# templates.pp
#

class baseclass {
include user::admins
include munin::client
include ntp

if $virtual == "vmware" {
include vmware::client
}
case $virtual {
vmware: { include vmware::client }
}

}

Create vmware module:

mkdir -p /etc/puppet/modules/vmware/manifests/

Create “/etc/puppet/modules/vmware/manifests/init.pp”file:

#
# init.pp
#

class vmware{

}

Create “/etc/puppet/modules/vmware/manifests/client.pp” file:

#
# client.pp
#

class vmware::client inherits vmware{

package { open-vm-tools: ensure => installed }

}

Note: This is a simple example. If you have more than one operating system in your environment, you need the “operatingsystem” variable for a second condition.
http://reductivelabs.com/trac/puppet/wiki/LanguageTutorial#conditionals

Custom Facts

You can also define your own facts in puppet.

http://reductivelabs.com/trac/puppet/wiki/AddingFacts

This Post Has 3 Comments

  1. Hallo Herr Mogilowski,

    ich fand den Puppet – Artikel sehr lehrreich, obwohl schon einige jahre ins Land gegangen sind.
    Gibt es beim Setzen von Paßwörten auch die Möglichkeit, den PW-String aus einer Datei auszulesen und dann z.B. über
    password => ‘sha-256’
    als PW für den User zu setzen? Ich fand dazu leider noch keine Möglichkeit.
    Danke für die Hilfe

    1. Hallo,

      vielen Dank. Es gibt sogar mehrere Möglichkeiten.

      Eine wäre ein custom fact.
      https://docs.puppet.com/facter/3.1/custom_facts.html

      Die andere verwende ich zum auslesen des ssh-keys:

      sshpubkey => file('user/sebastian.ssh'),
      

      Alternativ kann man auch sowas machen:

      sshpubkey => file("user/${name}.ssh"),
      

      Dazu braucht man für jedes Passwort/User eine eigene Datei mit dem Inhalt den man möchte.

      Die 3. Möglichkeit welche mir einfällt wäre mit ‘generate’:

      password => generate('/usr/bin/head -1 /path/to/passwordlist.txt | tail -2'),
      

      Würde die “nur” 2. Zeile aus der Datei lesen. Ist jetzt mal nur ein Beispiel ich würde nicht empfehlen es genau so zu machen.
      Mit “generate” kann ein beliebiger Befehl ausgeführt werden um an den Wert für die Variable zu kommen.
      Ich würde etwas stabileres und leichter zu pflegendes anstatt head und tail empfehlen.

      Gruß

      Sebastian

  2. Hallo Sebastian,

    danke für die schnelle Reaktion.
    “generate” hatte ich auch mit der password-Datei /tmp/pw_alibaba getestet, einfach mit cat (aber bei head kommt die selbe Fehlermeldung)

    user { “alibaba”:
    ensure => “present”,
    password => generate(‘/bin/cat /tmp/pw_alibaba’)
    }

    err: Could not retrieve catalog from remote server: Error 400 on SERVER: Generators can only contain alphanumerics, file separators, and dashes at
    /etc/puppet/manifests/users/alibaba_user.pp:270 on node testnode.domain1.priv

    siehe auch:
    https://projects.puppetlabs.com/issues/5481

    nehme ich dieses vorgeschlagene Konstrukt (lief mit cat nicht anders)
    password => generate(“/bin/bash”,”-c”,'”/usr/bin/sed -ne 1p /tmp/pw_alibaba”‘)

    err: Could not retrieve catalog from remote server: Error 400 on SERVER: Failed to execute generator /bin/bash: Execution of ‘/bin/bash -c “/usr/bin/sed -ne 1p /tmp/pw_alibaba”‘ returned 127: /bin/bash: /usr/bin/sed -ne 1p /tmp/pw_alibaba: No such file or directory at /etc/puppet/manifests/users/alibaba_user.pp:255 …

    Das reine Ausführen des Kommandos in der Befehlszeile gibt das PW aber zurück.

    Gruß
    Uwe

Schreibe einen Kommentar

eMail-Benachrichtigung bei weiteren Kommentaren.
Auch möglich: Abo ohne Kommentar.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.