Chapter 11. Other Things To Do With Puppet
There's way more you can do with puppet. Actually there's so much you can do with puppet it does not fit in a workshop type of course.
11.1. Store Configurations In A Database
A database can be configured to store the configuration distributed by the puppetmaster, and applied by the puppet. This is optional, and creates some overhead to the original purpose of configuring the puppets, but provides the opportunity to create overviews of applied classes to nodes, and a complete inventory of facts for all nodes. similarities / exemptions.
Regardless of which of the following methods is chosen, they have one thing in common and that is that only the database has to be created. Puppet will create the tables with the correct schema's for you. Only the postgresql example is shown, for the other databases, please consult the respective manual on how to create a database.
SQLite(3) is a file based, light SQL database which is suitable for small databases. Depending on the size of the organization or priority you give to storing configs, generally speaking using SQLite(3) is not very suitable. In addition, SQLite3 isn't easily queried either manually or automatically. To setup SQLite3, provide the following settings in /etc/puppet/puppet.conf:
[puppetmasterd]
reports = store[,tagmail,rrdgraph]
storeconfigs = true
dbadapter = sqlite3
dblocation = /var/lib/puppet/storeconfigs.sqlite
MySQL of course is much more scalable, and you can query it manually or automatically. A simple query can give you all webservers in the organization:
$ mysql -p puppet -e 'SELECT hosts.name
FROM resources INNER JOIN hosts
ON resources.host_id = hosts.id
WHERE resources.title = "webserver"
GROUP BY name;'
+---------------------------+
| name |
+---------------------------+
| app1.genomicscenter.nl |
| elwood.kanarip.com |
| master.puppetmanaged.org |
| open.the-cave-of-steef.nl |
| pinky.kanarip.com |
| server.ogd.nl |
| vito.kanarip.com |
+---------------------------+
7 rows in set (0.02 sec)
To configure storing the configurations, use the following settings in /etc/puppet/puppet.conf:
[puppetmasterd]
storeconfigs = true
dbadapter = mysql
dbserver = 127.0.0.1
dbuser = puppetuser
dbpassword = password
[dbsocket = /var/lib/mysql/mysql.sock]
And create the database:
# mysql -p -e "CREATE DATABASE puppetdb;"
# mysql -p -e "GRANT ALL PRIVILEGES on puppetdb.* to puppetuser@localhost identified by 'password';"
PostgreSQL is even more scalable then MySQL as it's multi-master, but most importantly you may already have PostgreSQL running in your organization, and may just want to add puppet's configuration store to that infrastructure.
To add the configuration store to PostgreSQL, use the following settings in /etc/puppet/puppet.conf:
[puppetmasterd]
storeconfigs = true
dbadapter = postgresql
dbuser = puppetuser
dbpassword = password
dbserver = localhost
dbname = puppetdb
And create the database:
# su - postgres
$ psql
postgres=# create database puppetdb;
CREATE DATABASE
postgres=# create user puppetuser with unencrypted password 'password';
CREATE ROLE
postgres=# grant create on database puppetdb to puppetuser;