Puppet Dashboard : Mise en place d'une interface graphique pour Puppet

From Deimos.fr / Bloc Notes Informatique
Jump to: navigation, search
Puppet Dashboard

Software version 1.2.17
Operating System Debian 7
Website Puppet Dashboard Website
Last Update 05/01/2013
Others Clients OS:
Debian 6/7
RHEL 6

1 Introduction

Puppet c'est génial, mais pour autant, une petite interface web, ça serait royale pour voir l'état des machines, des synchro etc...

Je vous propose donc la mise en place de Puppet Dashboard.

2 Installation

Pour Debian, nous allons utiliser le repository officiel :

Command
wget http://apt.puppetlabs.com/puppetlabs-release-stable.deb
dpkg -i puppetlabs-release-stable.deb

Et ensuite, nous mettez à jour :

Command aptitude
aptitude update

Ensuite, nous allons pouvoir installer simplement le dashboard avec toutes ses dépendances :

Command
aptitude install puppet-dashboard mysql-server

3 Configuration

3.1 Démon

Nous allons activer Puppet Dashboard pour qu'il s'exécute seul au démarrage en décommentant la ligne "start" :

Configuration File /etc/default/puppet-dashboard
# IMPORTANT: Be sure you have checked the values below, appropriately
# configured 'config/database.yml' in your DASHBOARD_HOME, and
# created and migrated the database.
 
# Uncomment the line below to start Puppet Dashboard.
START=yes 
# Location where puppet-dashboard is installed:
DASHBOARD_HOME=/usr/share/puppet-dashboard
 
# User which runs the puppet-dashboard program:
DASHBOARD_USER=www-data
 
# Ruby version to run the puppet-dashboard as:
DASHBOARD_RUBY=/usr/bin/ruby
 
# Rails environment in which puppet-dashboard runs:
DASHBOARD_ENVIRONMENT=production
 
# Network interface which puppet-dashboard web server is running at:
DASHBOARD_IFACE=0.0.0.0
 
# Port on which puppet-dashboard web server is running at, note that if the
# puppet-dashboard user is not root, it has to be a > 1024:
DASHBOARD_PORT=3000

Nous allons également utiliser les Delayed Job Workers afin de s'assurer que les données arriveront en entier s'il y a une forte demande sur le Dashboard :

Configuration File /etc/default/puppet-dashboard-workers
# IMPORTANT: Be sure you have checked the values below, appropriately
# configured 'config/database.yml' in your DASHBOARD_HOME, and
# created and migrated the database.
. /etc/default/puppet-dashboard
START=yes 
#  Number of dashboard workers to start.  This will be the number of jobs that
#  can be concurrently processed.  A simple recommendation would be to start
#  with the number of cores you have available.
NUM_DELAYED_JOB_WORKERS=2

Vous pouvez également tenter de toucher le paramètre NUM_DELAYED_JOB_WORKERS si ça ne suffit pas.

3.2 MySQL

Pour commencer, il nous faut initialiser la base de donnée avec la commande mysql_secure_installation (pour plus d'informations, allez voir cette documentation). Maintenant, nous pouvons créer une base MySQL, ainsi qu'un utilisateur dédié :

Command mysql
CREATE DATABASE puppet_dashboard CHARACTER SET utf8;
CREATE USER 'puppetdash_user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON puppet_dashboard.* TO 'puppetdash_user'@'localhost';
flush privileges;

Nous allons modifier la configuration de MySQL pour augmenter la taille maximale des packets en ajustant une valeur. Editez votre configuration MySQL dans la partie 'mysqld' et mettez max_allowed_packet à au moins 32M :

Configuration File /etc/mysql/my.cnf
[...]
[mysqld]
# Puppet Dashboard requirements:# Allowing 32MB allows an occasional 17MB row with plenty of spare roommax_allowed_packet = 32M[...]

Redémarrez ensuite MySQL.

Puis nous allons modifier la configuration par défaut pour qu'elle corresponde à notre nouvelle base et utilisateur MySQL. Pour cela, modifiez la partie production dans le fichier de configuration suivant :

Configuration File /etc/puppet-dashboard/database.yml
...
production:
  database: puppet_dashboard
  username: puppetdash_user
  password: password
  host: localhost
  encoding: utf8
  adapter: mysql
...

Maintenant on va pouvoir initialiser la base de donnée :

Command rake
cd /usr/share/puppet-dashboard
rake RAILS_ENV=production db:migrate

Vous pouvez maintenant démarrer le service puppet-dashboard si vous souhaitez, et la console est accessible http://puppet-dashboard:3000

3.3 Puppet Master

Pour Puppet Master, il va falloir lui indiquer d'envoyer les rapports, plus seulement en version fichiers (dans le dossier /var/lib/puppet/reports), mais aussi dans la base MySQL. Pour cela, éditez le fichier de configuration et rajoutez ceci dans le fichier de configuration :

Configuration File /etc/puppet/puppet.conf
[...]
[master]
reportdir = /var/lib/puppet/reports
reporturl = http://localhost:3000/reports/upload
reports = http,store,lognode_terminus = exec
external_nodes = /usr/bin/env PUPPET_DASHBOARD_URL=http://localhost:3000 /usr/share/puppet-dashboard/bin/external_node[...]

Remplacez localhost par votre nom de serveur.

Redémarrez ensuite les services puppetmaster et puppet-dashboard.

3.4 Puppet Clients

Pour la partie cliente, il faut dire à celui ci d'envoyer un rapport au serveur :

Configuration File /etc/puppet/puppet.conf
...
[agent]
report = true
...

3.5 Nginx

Si comme moi vous utilisez votre Puppet Dashboard sur la même machine que Puppet Master, il est plus propre de cacher le port 3000 de puppet dashboard. Pour cela, nous allons proxyfier sur Nginx :

Configuration File /etc/nginx/sites-available/puppet-dashboard
upstream puppet-prd-dash.deimos.fr:3000 {  server unix:/usr/share/puppet-dashboard/tmp/sockets/dashboard.0.sock;
  server unix:/usr/share/puppet-dashboard/tmp/sockets/dashboard.1.sock;
  server unix:/usr/share/puppet-dashboard/tmp/sockets/dashboard.2.sock;
}
 
server {
  root /usr/share/puppet-dashboard/public;
 
  location / {
    proxy_pass http://puppet-prd-dash.deimos.fr:3000;  }
}

Et on active la nouvelle configuration :

Command
cd /etc/nginx/sites-available
ln -s /etc/nginx/sites-enabled/puppet-dashboard .
/etc/init.d/nginx restart

Redémarrez ensuite Nginx.

3.6 Crontab

Pour ne pas souffir de problèmes de performances au fur et à mesure que la base de donnée se rempli, il est préférable de la purger et faire une optimisation derrière. Nous allons donc créer une crontab pour que tout les mois ce travail ce se fasse :

Configuration File /etc/cron.monthly/puppet-dashboard
#!/bin/sh
#
# puppet-dashboard cron monthly
 
set -e
 
PUPPETDASH_HOME=/usr/share/puppet-dashboard
 
cd $PUPPETDASH_HOME
# Flush DB old reports older than 1 month
su - www-data -c "cd $PUPPETDASH_HOME ; rake RAILS_ENV=production reports:prune upto=1 unit=mon"
# Optmize table
rake RAILS_ENV=production db:raw:optimize
 
exit 0

Nous lui attribuons les bons droits :

Command chmod
chmod 755 /etc/cron.monthly/puppet-dashboard

4 Importations

4.1 Noeuds Puppet

Si vous souhaitez importer tous les noeuds Puppet d'un coup dans votre Dashboard sans attendre une synchronisation :

Command
cd /usr/share/puppet-dashboard
for i in $(puppetca -la | awk -F\" '{ print $2 }' | grep -v `hostname`) ; do rake RAILS_ENV=production node:add name=$i ; done

4.2 Reports

Si vous voulez importer les reports fichiers que vous avez actuellement en base, rien de plus simple :

Command
cd /usr/share/puppet-dashboard
rake RAILS_ENV=production reports:import REPORT_DIR=/var/lib/puppet/reports

5 FAQ

5.1 cannot load such file -- ftools

Si vous avez ce genre d'erreurs lors de l'importation du schema de base de données :

Command rake
> rake RAILS_ENV=production db:migrate
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from /usr/share/puppet-dashboard/vendor/rails/railties/lib/rails/gem_dependency.rb:21.
NOTE: Gem::SourceIndex#initialize is deprecated with no replacement. It will be removed on or after 2011-11-01.
Gem::SourceIndex#initialize called from /usr/share/puppet-dashboard/vendor/rails/railties/lib/rails/vendor_gem_source_index.rb:100.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:91.
rake aborted!
cannot load such file -- ftools
 
(See full trace by running task with --trace)

C'est que la version de Ruby que vous utilisez n'est pas en adéquation avec celle que Puppet Dashboard requiert. Sur Debian 7, vous êtes par défaut en 1.9.1 et il faut passer sur une 1.8 (vivement qu'ils mettent à jour le dashboard). Nous allons donc installer quelques prérequis :

Command aptitude
aptitude install -y build-essential irb libmysql-ruby libmysqlclient-dev libopenssl-ruby libreadline-ruby mysql-server rake rdoc ri ruby ruby-dev

Puis nous passons en ruby 1.8 :

Command
update-alternatives --install /usr/bin/gem gem /usr/bin/gem1.8 1
rm /etc/alternatives/ruby
ln -s /usr/bin/ruby1.8 /etc/alternatives/ruby

Maintenant nous allons compiler une version de rubygems :

Command
URL="http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz"
PACKAGE=$(echo $URL | sed "s/\.[^\.]*$//; s/^.*\///")
cd $(mktemp -d /tmp/install_rubygems.XXXXXXXXXX) && \
wget -c -t10 -T20 -q $URL && \
tar xfz $PACKAGE.tgz && \
cd $PACKAGE && \
sudo ruby setup.rb

Maintenant c'est bon, vous pouvez relancer un db::migrate.

5.2 Caught TERM; calling stop

Si vous rencontrez ce genre de message d'erreur dans Puppet Dashboard quant vous lancez depuis Mcollective des runs Puppet, il vous faut travailler sur le manifest de puppet, pour que cette ligne soit commentée :

Configuration File /etc/puppet/modules/puppet/manifests/redhat.pp
[...]
    service {
        'puppet-srv' :
            name => 'puppet',
            # Let this line commented if you're using Puppet Dashboard            #ensure => stopped,            enable => false
    }
[...]

6 Ressources

http://www.puppetlabs.com/blog/a-tour-of-puppet-dashboard-0-1-0/
http://bitcube.co.uk/content/puppet-dashboard-v101-install
http://www.mogilowski.net/lang/en-us/2011/01/20/puppet-dashboard-reports-ubuntu/
http://www.craigdunn.org/2010/08/part-3-installing-puppet-dashboard-on-centos-puppet-2-6-1/