Install Puppet Server on Docker

J.J. Attard
May 21, 2019 · 4 min read
Image for post
Image for post
Dockerizing a Puppet infrastructure

Getting Started

To get started, you will need an installation of Docker Compose on the host on which you will run your Puppet Infrastructure. We then continue to create the following docker-compose.yml file:

version: '3'

services:
puppet:
hostname: puppet.${DOMAIN:-internal}
image: puppet/puppetserver
ports:
- 8140:8140
environment:
# necessary to set certname and server in puppet.conf, required by
# puppetserver ca cli application
- PUPPETSERVER_HOSTNAME=puppet.${DOMAIN:-internal}
# DNS_ALT_NAMES must be set before starting the stack the first time,
# and must list all the names under which the puppetserver can be
# reached. 'puppet.${DOMAIN:-internal}' must be one of them, otherwise puppetdb won't be
# able to get a cert. Add other names as a comma-separated list
- DNS_ALT_NAMES=puppet,puppet.${DOMAIN:-internal},${DNS_ALT_NAMES:-}
- PUPPERWARE_ANALYTICS_ENABLED=${PUPPERWARE_ANALYTICS_ENABLED:-true}
- PUPPETDB_SERVER_URLS=https://puppetdb.${DOMAIN:-internal}:8081
volumes:
- ${VOLUME_ROOT:-.}/volumes/code:/etc/puppetlabs/code/
- ${VOLUME_ROOT:-.}/volumes/puppet:/etc/puppetlabs/puppet/
- ${VOLUME_ROOT:-.}/volumes/serverdata:/opt/puppetlabs/server/data/puppetserver/
dns_search: ${DOMAIN:-internal}
networks:
default:
aliases:
- puppet.${DOMAIN:-internal}

postgres:
image: postgres:9.6
environment:
- POSTGRES_PASSWORD=puppetdb
- POSTGRES_USER=puppetdb
- POSTGRES_DB=puppetdb
expose:
- 5432
volumes:
- ${VOLUME_ROOT:-.}/volumes/puppetdb-postgres/data:/var/lib/postgresql/data
- ./postgres-custom:/docker-entrypoint-initdb.d
dns_search: ${DOMAIN:-internal}
networks:
default:
aliases:
- postgres.${DOMAIN:-internal}

puppetdb:
hostname: puppetdb.${DOMAIN:-internal}
image: puppet/puppetdb
environment:
- PUPPERWARE_ANALYTICS_ENABLED=${PUPPERWARE_ANALYTICS_ENABLED:-true}
# This name is an FQDN so the short name puppet doesn't collide outside compose network
- PUPPETSERVER_HOSTNAME=puppet.${DOMAIN:-internal}
- PUPPETDB_POSTGRES_HOSTNAME=postgres.${DOMAIN:-internal}
- PUPPETDB_PASSWORD=puppetdb
- PUPPETDB_USER=puppetdb
ports:
- 8080
- 8081
depends_on:
- postgres
- puppet
volumes:
- ${VOLUME_ROOT:-.}/volumes/puppetdb/ssl:/etc/puppetlabs/puppet/ssl/
dns_search: ${DOMAIN:-internal}
networks:
default:
aliases:
- puppetdb.${DOMAIN:-internal}
  1. postgres: This is the PostgreSQL database server which will store the data for PuppetDB.
  2. puppetdb: This is the PuppetDB container that will store all the facts and configuration required to run the Puppet infrastructure. The actual data will be stored in the postgres container defined above. We therefore set a couple of dependencies to make sure that the previous two containers are up and running before spawning this one.

Running the Dockerized Puppet

You can start the Dockerized Puppet infrastructure by running the following command:

DNS_ALT_NAMES=host.exam docker-compose up -d
DOMAIN=foo docker-compose up -d
  • puppet/: Puppet configuration files, including puppet/ssl/ containing certificates for your infrastructure. This directory is populated with default configuration files if they are not present when the stack starts up. You can make configuration changes to your stack by editing files in this directory and restarting the stack.
  • puppetdb/ssl/: certificates in use by the PuppetDB instance in the stack.
  • puppetdb-postgres/: the data files for the PostgreSQL instance used by PuppetDB
  • serverdata/: persistent data for Puppet Server
  • Note: On OSX, you must add the volumes directory to "File Sharing" under Preferences>File Sharing in order for these directories to be created and volume-mounted automatically. There is no need to add each sub directory.

Adding your first manifest

As explained above, the Puppet code will be mounted on a Docker volume — code/. The hierarchical structure must be therefore created inside this directory as follows:

$ mkdir code/environments/production/manifests
node default {
file {'/tmp/example-ip':
ensure => present,
mode => '0644',
content => "Here is my Public IP Address: ${ipaddress_eth0}.\n",
}
}

Test your Dockerized Puppet setup

We can test the setup by running the puppet agent inside the Puppet master container:

# docker exec -it <Puppet Container ID> bash
root@puppet:/# puppet agent -t

Next steps

Now you are ready to take this setup a couple of steps further:

  1. Point your browser to the PuppetDB Docker container: http://puppetDB:8080 to view analytics pertaining to your Puppet infrastructure.

The Startup

Medium's largest active publication, followed by +683K people. Follow to join our community.

Sign up for Top Stories

By The Startup

A newsletter that delivers The Startup's most popular stories to your inbox once a month. Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

J.J. Attard

Written by

Tech Entrepreneur, Electrical Engineer, Founder of https://costansin.com.

The Startup

Medium's largest active publication, followed by +683K people. Follow to join our community.

J.J. Attard

Written by

Tech Entrepreneur, Electrical Engineer, Founder of https://costansin.com.

The Startup

Medium's largest active publication, followed by +683K people. Follow to join our community.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store