November 21, 2016

Installing docker with a Puppet Forge module

Installing docker with a Puppet Forge module

In this blog I'm going to install docker with a predefined module available on puppet forge, these modules are created by community members. I will also create the user and group docpuppet, with this user you can use docker. This blog requires internet connection.

Module 'garethr-docker', is the module which we use in this blog. Change it if you want to use another module.

# puppet module install garethr-docker --version 5.3.0
Notice: Preparing to install into 
/etc/puppetlabs/code/environments/production/modules ...
Notice: Downloading from ...
Notice: Installing -- do not interrupt ...
└─┬ garethr-docker (v5.3.0)
  ├── puppetlabs-apt (v2.3.0)
  ├── puppetlabs-stdlib (v4.13.1)
  └── stahnma-epel (v1.2.2)

This module will be installed in: ==/etc/puppetlabs/code/environments/production/modules/==docker/

No we can use this module to install docker on puppetclient, our manisfest looks like this:

node 'puppetclient' { # Applies only to mentioned node; if nothing mentioned, applies to all.
file { '/tmp/puppettestfile': # Resource type file
ensure => 'present', # Make sure it exists
owner => 'root', # Ownership
group => 'root', # Group Name
mode => '0644', # File permissions
content => "This File is created by Puppet Server\n"
# Here we install prerequisites packeges for vmware
package { 'perl': ensure => 'installed'}
package { 'gcc': ensure => 'installed'}
package { 'make': ensure => 'installed'}
package { 'kernel-headers': ensure => 'installed'}
package { 'kernel-devel': ensure => 'installed'}
package { 'net-tools': ensure => 'installed'}
# Here we are going to install docker, used by the garethr-docker module
include 'docker'
# Create group for user docpuppet
group { 'docpuppet':
ensure                  => 'present',
gid                     => '1000',
# Here we going create a user which may use docker
user { 'docpuppet':
ensure                  => 'present',
managehome              => 'true',
home                    => '/home/docpuppet',
comment                 => 'Docker Puppet',
groups                  => [docpuppet, docker],
password                => '$1$HARN7hAh$YEcGufMWg4jtVncEmfkDe/',
password_max_age        => '99999',
password_min_age        => '0',
shell                   => '/bin/bash',
uid                     => '1000',
# Create home dir for user docpuppet
file { '/home/docpuppet/':
ensure                  => 'directory',
owner                   => 'docpuppet',
group                   => 'docpuppet',
mode                    => '0750',

For creating the passwd hash we can use the following command: openssl passwd -1

Before we use this new manifest we can test it on the puppermaster.
So copy this file in /root and give it a name like test-site.pp
Check if the syntax is okay by typing:

puppet parser validate test-site.pp

When it gives no output the manifest file is okay, replace the /etc/puppetlabs/code/environments/production/manifests/site.pp file with test-site.pp.
Check on puppetclient if you can use docker with user docpuppet:

[root@puppetclient ~]# sudo su - docpuppet
Last login: Wed Nov 16 12:15:03 CET 2016 on pts/0
[docpuppet@puppetclient ~]$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

In this blog we have installed a docker environement which can be used by user docpuppet. In my next job I will tell you about puppetdb and facts.
Puppet will collect system information with Facter. Puppet receives this information as facts, which are pre-set variables you can use anywhere in your manifests.