Puppet – Configuring Storeconfigs for MySQL


Exported resource allow node to share information with each other. This is useful when one node has information that another node needs in order to manage a resource. The common cases are monitoring and backups.

To use exported resource in Puppet, the storeconfigs has to be enabled. This will allow puppet to save data (resources, facts etc) to a database. The database can be Mysql, PostgreSQL, sqlite and PuppetDB. My lab environment (CentOS 6.5 32bits, Puppet 2.7.25) does not support PuppetDB, so I decided to use MySQL. If you use newer version (3.5.1 or later ), you can install PuppetDB via module (puppet module install puppetlabs-puppetdb).

Here is my how to:

1) Ensure the environment meets the installing prerequisites.

2) Install mysql and associated packages

yum -y install mysql mysql-devel mysql-server

3) Create puppet database and grant privileges to user puppet.

# mysql -u root -p
mysql> create database puppet;
mysql> grant all privileges on puppet.* to ‘puppet’@’localhost’ identified by ‘password’;

4) Refer step 1 to install the right rails version

gem install rails -v 2.2.2

5) Install mysql connector for rail.

gem install mysql — –with-mysql-config=/usr/bin/mysql_config

6) Add the following entries in to puppet.conf

storeconfigs = true
dbadapter = mysql
dbuser = puppet
dbpassword = password
dbserver = localhost
dbsocket = /var/lib/mysql/mysql.sock

7) Verify the tables have been created

# mysql -u root -p
mysql> use puppet;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+——————+
| Tables_in_puppet |
+——————+
| fact_names |
| fact_values |
| hosts |
| inventory_facts |
| inventory_nodes |
| param_names |
| param_values |
| puppet_tags |
| resource_tags |
| resources |
| source_files |
+——————+
11 rows in set (0.00 sec)

mysql> select * from hosts;
+—-+——————–+———–+————-+———————+—————–+————-+———————+—————-+———————+
| id | name | ip | environment | last_compile | last_freshcheck | last_report | updated_at | source_file_id | created_at |
+—-+——————–+———–+————-+———————+—————–+————-+———————+—————-+———————+
| 1 | puppet.mylab.local | 10.0.2.12 | production | 2014-10-01 09:31:25 | NULL | NULL | 2014-10-01 09:31:25 | NULL | 2014-09-29 17:03:34 |
| 2 | dev01.mylab.local | 10.0.2.13 | development | 2014-10-01 09:28:53 | NULL | NULL | 2014-10-01 09:28:53 | NULL | 2014-09-30 08:58:07 |
| 3 | admin.mylab.local | 10.0.2.11 | production | 2014-10-01 09:28:46 | NULL | NULL | 2014-10-01 09:28:46 | NULL | 2014-09-30 09:15:29 |
+—-+——————–+———–+————-+———————+—————–+————-+———————+—————-+———————+
3 rows in set (0.00 sec)

Reference: http://projects.puppetlabs.com/projects/1/wiki/using_stored_configuration#Installing-Prerequisites

Advertisements

4 thoughts on “Puppet – Configuring Storeconfigs for MySQL

  1. Hi,
    Really nice information, thanks a lot.
    I am also using same setup, I could see the same output in DB too which you mentioned here. But I am unable to export IP address from one node to another.
    It would be great, if you help me on this issue as I am struggling for this long back.
    Thanks in advance. Please find the below class.
    ———————————————-
    class admin::file{
    @@file {“/tmp/ip.txt/${::ipaddress}”:
    path => ‘/tmp/ip.txt/’,
    content => “\ndefine(‘DB_HOST’,\t${::ipaddress});”,
    tag => “ip”
    }
    }
    node ‘dbserver.garuda.com’
    {
    include admin::file
    }
    ——————————————-
    class admin
    {
    File <>
    }

    node ‘webserver.garuda.com’
    {
    include admin
    }
    ————————————————-

  2. Below class is not showing properly again adding.
    class admin {
    File <>
    }

    node ‘webserver.garuda.com’
    {
    include admin
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s