Meet the Creator: Puppet Module for Mattermost

Huge thanks to Richard Grainger for not only his wonderful work creating the Puppet Module for Mattermost, but also for contributing this guest blog post. If you’re a user or contributor with thoughts to share, please mail info@mattermost.com. 

Richard Grainger applied his background managing high performance computing clusters to create an open source Puppet Module for Mattermost

When I worked for my previous employer I became frustrated with the limitations
of email and other collaboration tools, so I decided to try something new with
my small team of systems administrators.

We started using a popular SaaS messaging application (you may be able to guess
the name!) and it soon became intrinsic to the way we worked.

When I heard recently about Mattermost, an open-source alternative that runs
on-premise, I knew I had to give it a try. Duly impressed, it struck me that I
could make a modest contribution to the project.

I’ve been using Puppet for a few years to manage a diversity of systems, from workstations to high performance computing clusters. Writing a Puppet module for Mattermost was the perfect opportunity to improve my skills with Puppet further whilst supporting a worthwhile open-source project.

The module aims to make it easy as possible for Puppet users to get Mattermost
up and running in production on their preferred OS distribution. To this end,
the heart of the module uses Puppet’s Ruby templating support to create a
service definition file for Mattermost that will work with your operating
system’s native init system (System V, Upstart or systemd).

So far the module has been tested successfully on Enterprise Linux 6 and 7 (that is: RHEL, Scientific Linux, CentOS and Oracle Linux); Debian 6, 7 and 8; SLES 12; and Ubuntu 12.04 – 15.10.

Puppet Module for Mattermost deploys Mattermost to RHEL 6, 7; CentOS 6, 7; Oracle Linux 6, 7; Scientific Linux 6, 7; Debian 6, 7, 8; Ubuntu 12.04 to 15.10 and SLES 12

Getting down to business

Assuming you have another server running PostgreSQL, here’s some example Puppet
code for installing and configuring Mattermost:

class { 'mattermost':
 override_options => {
 'SqlSettings' => {
 'DriverName' => 'postgres',
 'DataSource' => "postgres://db_user:db_pass@db_host:db_port/mattermost?sslmode=disable&connect_timeout=10",
 },
 },
}

It will download and unzip the latest version of Mattermost into a sensible
default directory under `/opt`, create a mattermost user and group, create a
service definition, update Mattermost’s `config.json` file with the database
connection string and start the service. Not bad for eight lines of code!

If you wanted to host Mattermost on the same server as the database and the
reverse proxy, you could combine the module with NGINX and PostgreSQL modules
and write something like this:

class { 'postgresql::server':
 listen_addresses => '127.0.0.1',
 ipv4acls => ['host all all 127.0.0.1/32 md5'],
}
postgresql::server::db { 'mattermost':
 user => 'mattermost',
 password => postgresql_password('mattermost', 'mattermost'),
}
postgresql::server::database_grant { 'mattermost':
 privilege => 'ALL',
 db => 'mattermost',
 role => 'mattermost',
} ->
class { 'mattermost':
 override_options => {
 'SqlSettings' => {
 'DriverName' => 'postgres',
 'DataSource' => "postgres://mattermost:mattermost@127.0.0.1:5432/mattermost?sslmode=disable&connect_timeout=10",
 },
 },
}
class { 'nginx': }
nginx::resource::upstream { 'mattermost':
 members => [ 'localhost:8065' ],
}
nginx::resource::vhost { 'mattermost':
 server_name => [ 'myserver.mydomain' ],
 proxy => 'http://mattermost',
}

Do it your way

You will notice in both the above examples the use of the `override_options`
hash. This allows any option in Mattermost’s default `config.json` file to be
overwritten. You can override as few or as many defaults as you like, or
combine it with the `purge_conf` parameter to remove all default options and
supply your own in the hash. For those curious about such things, I used
Puppet’s excellent Augeas resource type with a Ruby template to
achieve this.

End of the road

That is probably enough to give you an idea of what you can achieve with the
module. If you want to learn more or give it a try you can find the module with
full documentation on Puppet Forge.
If you want to contribute you can find the code on GitHub (pull requests welcome!)

Happy Puppetting!

Biographical information, links, disclaimer

For his sins, Richard Grainger has been a systems administrator and technical
manager for 15 years. For most of that time he worked for the University of
Sussex and King’s College London trying to make computers work well despite
the unconventional things academics want to do with them. He recently started
working for a well-known IT security company outside London. In between work
shifts, he and his wife attempt to raise two small children… and get some
sleep.

The views expressed in this post are those of the author only and not of his
employer.

Stay updated

Want to know about the latest releases? Subscribe to our monthly mailing list

By | 2017-07-17T04:58:14+00:00 February 1st, 2016|Blog, Guest Posts|Comments Off on Meet the Creator: Puppet Module for Mattermost