Skip to content

Instantly share code, notes, and snippets.

@garethr

garethr/demos.md Secret

Last active October 5, 2016 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garethr/dd596989218ae8ef4b17a3ed93d1b3dd to your computer and use it in GitHub Desktop.
Save garethr/dd596989218ae8ef4b17a3ed93d1b3dd to your computer and use it in GitHub Desktop.
A collection of demos from my talk at PuppetConf 2016.

PuppetConf 2016 Demos

Puppet-in-Docker

Demonstrate running facter from inside the container:

docker run puppet/facter

Demonstrate running Puppet from the container:

docker run puppet/puppet-agent --help

Run a simple inline apply, and show it changed the container. Not useful in itself but demonstrates Puppet is present.

docker run --name apply-test puppet/puppet-agent apply -e 'file { "/tmp/adhoc": content => "Written from puppet on $hostname\n" }'
docker diff apply-test

Running a Puppet Master

Running a full Puppet stack using Docker Compose: https://github.com/puppetlabs/puppet-in-docker-examples/tree/master/compose

Running the same on Hyper_: https://github.com/puppetlabs/puppet-in-docker-examples/tree/master/hyper_

Running the same on Google Container Engine (GKE): https://github.com/puppetlabs/puppet-in-docker-examples/tree/master/kubernetes

Container-centric Operating Systems

As an example of running Puppet on a container-centric OS we'll look at running on VMware Phonton OS: https://github.com/puppetlabs/puppet-in-docker-examples/tree/master/photonos

Building Docker Images

Puppet Docker Build

docker build
puppet docker build
puppet docker dockerfile

Nginx example: https://github.com/puppetlabs/puppetlabs-image_build/tree/master/examples/nginx

Multi-image build example: https://github.com/puppetlabs/puppetlabs-image_build/tree/master/examples/multi

Pre-processors

Given the following Dockerfile:

FROM ubuntu:16.04
MAINTAINER Gareth Rushgrove "gareth@puppet.com"

ENV PUPPET_AGENT_VERSION="1.5.0" \
    R10K_VERSION="2.2.2" \
    UBUNTU_CODENAME="xenial"

PUPPET_INSTALL
PUPPET_COPY_PUPPETFILE
PUPPET_COPY_MANIFESTS
PUPPET_RUN

EXPOSE 80

CMD ["nginx"]

Pass it through the pre-processor to get a working Dockerfile.

cat Dockerfile | ./dockerfilepp-puppet

See https://github.com/garethr/dockerfilepp-puppet for the download and more examples.

Container Inventory

Run an inventory on an image which doesn't contain Puppet.

docker run --name puppet-inventory puppet/puppet-inventory
docker run --rm -it --volumes-from=puppet-inventory centos /opt/puppetlabs/bin/puppet inventory

Retrieve the underlying operating system in the container:

docker run puppet/puppet-inventory | jq '.facts.operatingsystem'

List all the users in the container:

docker run puppet/puppet-inventory | jq '.resources' | jq 'map(select(.resource == "user"))'
docker run puppet/puppet-inventory | jq '.resources' | jq 'map(select(.resource == "user"))' | jq '.[] .title'

List all resources with ssl in the title:

docker run puppet/puppet-inventory | jq '.resources' | jq 'map(select(.title | contains("ssl")))'

The version of OpenSSL installed:

docker run puppet/puppet-inventory | jq '.resources[] | select(.title == "openssl") .versions[0]'

Count the number of package resources:

docker run puppet/nginx cat /inventory.json | jq -c '.resources[] | select(.resource=="package")' | jq -s length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment