Setup puppet Storeconfigs with MySQL


Storeconfigs adalah sebuah opsi pada puppetmaster dimana kita bisa menyimpan konfigurasi(data) dari nodes ke dalam database. Berikut list database yang di support:
1. MySQL
2. SQLite
3. PostgreSQL.

Sebelum melangkah pada proses instalasi maupun setup konfigurasi, berikut adalah daftar task yang akan kita bahas:

1. Instalasi paket
2. konfigurasi database dan storeconfigs
3. Testing




1. Instalasi paket

Perlu di ketahui untuk proses instalasi yang melalui gem akan cukup lama, seperti activerecord dan rails. Berikut list paket data yang dibutuhkan untuk menjalankan Storeconfigs:
1. activerecord -v 2.3.5
2. rails -v 2.3.5
3. mysql-server
4. ruby-mysql

Pertama kita mengupdate gem dahulu, agar kedepannya pada saat instalasi rails tidak bermasalah dengan versi RubyGems lama.
[root@LAB01-01 manifests]# gem update --system
Updating RubyGems
Updating rubygems-update
Successfully installed rubygems-update-1.8.24
:0:Warning: Gem::SourceIndex#search support for String patterns is deprecated
Updating RubyGems to 1.8.24
Installing RubyGems 1.8.24
RubyGems 1.8.24 installed

== 1.8.24 / 2012-04-27

* 1 bug fix:

  * Install the .pem files properly. Fixes #320
  * Remove OpenSSL dependency from the http code path


---------------------------------------------------------------

RubyGems installed the following executables:
 /usr/bin/gem

Setelah RubyGems terupdate, yang akan kita lakukan selanjutnya adalah instalasi activerecord versi 2.3.5:
[root@LAB01-01 manifests]# gem install activerecord -v 2.3.5
Fetching: activesupport-2.3.5.gem (100%)
Fetching: activerecord-2.3.5.gem (100%)
Successfully installed activesupport-2.3.5
Successfully installed activerecord-2.3.5
2 gems installed
Installing ri documentation for activesupport-2.3.5...
Installing ri documentation for activerecord-2.3.5...
Installing RDoc documentation for activesupport-2.3.5...
Installing RDoc documentation for activerecord-2.3.5...

OK activerecord sudah terinstall, sekarang menginstall rails v 2.3.5
[root@LAB01-01 manifests]# gem install rails -v 2.3.5
Fetching: rake-0.9.2.2.gem (100%)
Fetching: rack-1.0.1.gem (100%)
Fetching: actionpack-2.3.5.gem (100%)
Fetching: actionmailer-2.3.5.gem (100%)
Fetching: activeresource-2.3.5.gem (100%)
Fetching: rails-2.3.5.gem (100%)
Successfully installed rake-0.9.2.2
Successfully installed rack-1.0.1
Successfully installed actionpack-2.3.5
Successfully installed actionmailer-2.3.5
Successfully installed activeresource-2.3.5
Successfully installed rails-2.3.5
6 gems installed
Installing ri documentation for rake-0.9.2.2...
Installing ri documentation for rack-1.0.1...
Installing ri documentation for actionpack-2.3.5...
Installing ri documentation for actionmailer-2.3.5...
Installing ri documentation for activeresource-2.3.5...
Installing ri documentation for rails-2.3.5...
Installing RDoc documentation for rake-0.9.2.2...
Installing RDoc documentation for rack-1.0.1...
Installing RDoc documentation for actionpack-2.3.5...
Installing RDoc documentation for actionmailer-2.3.5...
Installing RDoc documentation for activeresource-2.3.5...
Installing RDoc documentation for rails-2.3.5...
Cek keberadaan paket yang telah kita install tadi.
[root@LAB01-01 manifests]# gem list

*** LOCAL GEMS ***

actionmailer (2.3.5)
actionpack (2.3.5)
activerecord (2.3.5)
activeresource (2.3.5)
activesupport (2.3.5)
rack (1.0.1)
rails (2.3.5)
rake (0.9.2.2)

Jika kita tidak mau menginstall dokumentasi pada saat instal activerecord and rails kita bisa menggunakan opsi --no-ri --no-rdoc jadi bisa lebih mempercepat waktu instalasi:
[root@LAB01-01 manifests]# gem install activerecord -v 2.3.5 --no-ri --no-rdoc
[root@LAB01-01 manifests]# gem install rails -v 2.3.5 --no-ri --no-rdoc

Setelah activerecord dan rails terinstall, selanjutnya adalah kita lakukan instalasi database. Yang di gunakan oleh penulis adalah MySQL.
[root@LAB01-01 manifests]# yum install mysql-server ruby-mysql
Installing:
 mysql-server              x86_64            5.0.95-1.el5_7.1
 ruby-mysql                x86_64            2.7.3-2
Installing for dependencies:
 mysql                     x86_64            5.0.95-1.el5_7.1
 perl-DBD-MySQL            x86_64            3.0007-2.el5
 perl-DBI                  x86_64            1.52-2.el5

Hidupkan mysql daemon untuk pertama kalinya, perlu di perhatikan bahwa instalasi mysqld disini adalah untuk keperluan testing saja, pastikan untuk production server melalui serangkaian securing.
[root@LAB01-01 manifests]# /etc/init.d/mysqld start
Initializing MySQL database:  Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h LAB01-01.cloud.net password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
                                                           [  OK  ]
Starting MySQL:                                            [  OK  ]


Tahap instalasi sudah selesai saatnya kita melajutkan ke konfigurasi database MySQL dan Storeconfigs.

2. Konfigurasi database dan storeconfigs

Selanjutnya kita akan membuat sebuah database dengan nama puppet dan username puppet, untuk apa? disinilah kelak data yang digenerate oleh puppet akan disimpan. Berikut adalah prosesnya:
[root@LAB01-01 manifests]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.95 Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database puppet;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema | 
| mysql              | 
| puppet             | 
| test               | 
+--------------------+

mysql> grant all privileges on puppet.* to puppet@localhost identified by 'KunC!=PuPP3t';
Query OK, 0 rows affected (0.00 sec)

mysql>

Alhamdulillah database sudah berhasil kita setup, selanjutnya adalah men-setup puppetmaster, agar menggunakan storeconfigs, yang perlu dilakukan adalah tambahkan block config. Perlu di perhatikan versi MySQL yang kita gunakan, karena posisi file mysql.sock bisa berbeda. Tolong cek terlebih dahulu dimana posisi sock Mysqlnya sebelum melanjutkan. Dibawah ini kedalam file puppet.conf di puppetmaster:
[master]
storeconfigs = true dbadapter = mysql dbname = puppet dbuser = puppet dbpassword = KunC!=PuPP3t dbserver = localhost dbsocket = /var/lib/mysql/mysql.sock

Berikut adalah contoh lengkap dari file puppet.conf di puppetmaster,
[root@LAB01-01 manifests]# cat /etc/puppet/puppet.conf;
[main]
    # The Puppet log directory.
    # The default value is '$vardir/log'.
    logdir = /var/log/puppet

    # Where Puppet PID files are kept.
    # The default value is '$vardir/run'.
    rundir = /var/run/puppet

    # Where SSL certificates are kept.
    # The default value is '$confdir/ssl'.
    ssldir = $vardir/ssl

[agent]
    # The file in which puppetd stores a list of the classes
    # associated with the retrieved configuratiion.  Can be loaded in
    # the separate ``puppet`` executable using the ``--loadclasses``
    # option.
    # The default value is '$confdir/classes.txt'.
    classfile = $vardir/classes.txt

    # Where puppetd caches the local configuration.  An
    # extension indicating the cache format is added automatically.
    # The default value is '$confdir/localconfig'.
    localconfig = $vardir/localconfig

[master]
 storeconfigs = true
 dbadapter = mysql
 dbname = puppet
 dbuser = puppet
 dbpassword = KunC!=PuPP3t
 dbserver = localhost
 dbsocket = /var/lib/mysql/mysql.sock

Lengkap deh semua instalasi juga konfigurasi untuk puppet dan database.

3. Testing

Sekarang melakukan testing untuk melihat apakah benar storeconfigs kita bekerja, yaitu menyimpan data yang di generate oleh dari puppet kedalam database. Jalankan pada puppet agent:

[root@LAB01-02 ~]# puppet agent --test
Info: Retrieving plugin
Info: Caching catalog for lab01-02.cloud.net
Info: Applying configuration version '1350034295'
Finished catalog run in 0.16 seconds

Mari kita lihat pada database MySQL apakah benar puppetmaster telah menyimpannya kedalam database di puppetmaster.
[root@LAB01-01 ~]# mysql -u puppet -p -D puppet -e 'select name,last_compile from hosts;' --batch
Enter password:
name last_compile
lab01-02.cloud.net 2012-10-12 05:31:35

Terlihat outputnya, bahwa terekam puppet agent (lab01-02.cloud.net) meminta catalog ke puppetmaster.

Alhamdulillah selesai sudah artikel mengenai puppet Storeconfigs, semoga bisa berguna dan Alloh kasih penulis pahala. Amiin.