Set up Puppet lab in docker


Just finished my first docker set up – building a puppet server and a puppet client in two separate containers.

1) My docker host is Fedora 20.

[root@1004521 ~]# cat /etc/system-release
Fedora release 20 (Heisenbug)

2) Install docker (https://docs.docker.com/installation/fedora/)

[root@1004521 ~]# yum -y install docker-io
[root@1004521 ~]# systemctl start docker
[root@1004521 ~]# systemctl enable docker

[root@1004521 ~]# docker version

Client version: 1.3.2
Client API version: 1.15
Go version (client): go1.3.3
Git commit (client): 39fa2fa/1.3.2
OS/Arch (client): linux/amd64
Server version: 1.3.2
Server API version: 1.15
Go version (server): go1.3.3
Git commit (server): 39fa2fa/1.3.2

3) Download the CentOS docker image from docker hub, register a user first by running ‘docker login ‘

[root@1004521 ~]# docker login

[root@1004521 ~]# docker pull centos:centos6

4) Start a container and install puppet-server package.

[root@1004521 ~]# docker run -t -i centos:centos6 /bin/bash
[root@18c6a52a4fdb /]# yum -y install wget
[root@18c6a52a4fdb /]# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@18c6a52a4fdb /]# rpm -ivh epel-release-6-8.noarch.rpm
[root@18c6a52a4fdb /]# yum -y install puppet-server puppet
[root@18c6a52a4fdb /]# service puppetmaster start
[root@18c6a52a4fdb /]# service puppet start
[root@18c6a52a4fdb /]# chkconfig puppetmaster on
[root@18c6a52a4fdb /]# chkconfig puppet on
[root@18c6a52a4fdb puppet]# exit

5) Commit the change to create a new image.

[root@1004521 ~]# docker commit -m=”installed puppet-server” -a=”Jackie Chen” 18c6a52a4fdb jc1518/centos:centos6-puppet-server

6) Start another container and install puppet client.

[root@1004521 ~]# docker run -t -i centos:centos6 /bin/bash
[root@94ea9cded0f8 /]# yum -y install wget
[root@94ea9cded0f8 /]# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@94ea9cded0f8 /]# rpm -ivh epel-release-6-8.noarch.rpm
[root@94ea9cded0f8 /]# yum -y install puppet
[root@94ea9cded0f8 /]# chkconfig puppet on
[root@94ea9cded0f8 /]# service puppet start
[root@94ea9cded0f8 /]# exit

7) Commit the change to create a new image.

[root@1004521 ~]# docker commit -m=”installed puppet client” -a=”Jackie Chen” 94ea9cded0f8 jc1518/centos:centos6-puppet-client

8) Check the two new images.

[root@1004521 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
jc1518/centos centos6-puppet-client 64c7ece9e8cd 17 seconds ago 295.4 MB
jc1518/centos centos6-puppet-server 6e50f549551f 18 minutes ago 295.4 MB

9) Create a new container from the new Puppet server image

[root@1004521 ~]# docker run -t -i –name puppet-server –dns-search=docker.lab jc1518/centos:centos6-puppet-server
[root@5166bdfb73ef /]#

10) Start a new terminal, create a new container from the new Puppet client image.

[root@1004521 ~]# docker run -t -i –name puppet-client –link puppet-server:5166bdfb73ef.docker.lab –dns-search=docker.lab jc1518/centos:centos6-puppet-client

[root@8060ab4125b2 /]# ping 5166bdfb73ef.docker.lab
PING 5166bdfb73ef.docker.lab (172.17.0.15) 56(84) bytes of data.
64 bytes from 5166bdfb73ef.docker.lab (172.17.0.15): icmp_seq=1 ttl=64 time=0.099 ms
^C
— 5166bdfb73ef.docker.lab ping statistics —
1 packets transmitted, 1 received, 0% packet loss, time 885ms
rtt min/avg/max/mdev = 0.099/0.099/0.099/0.000 ms

[root@8060ab4125b2 /]# vi /etc/puppet/puppet.conf
Add the ‘server = 5166bdfb73ef.docker.lab’ to the [main] section

[root@8060ab4125b2 /]# rm -rf /var/lib/puppet/ssl

[root@8060ab4125b2 /]# puppet agent –test
info: Creating a new SSL key for 8060ab4125b2.docker.lab
info: Caching certificate for ca
info: Creating a new SSL certificate request for 8060ab4125b2.docker.lab
info: Certificate Request fingerprint (md5): EF:08:45:66:B7:62:4C:F4:1B:77:3B:62:1B:27:50:4D
Exiting; no certificate found and waitforcert is disabled

11) Go back to the Puppet server container to sign the certificate request.

[root@5166bdfb73ef /]# puppet cert sign –all
notice: Signed certificate request for 8060ab4125b2.docker.lab
notice: Removing file Puppet::SSL::CertificateRequest 8060ab4125b2.docker.lab at ‘/var/lib/puppet/ssl/ca/requests/8060ab4125b2.docker.lab.pem’

12) Run the puppet again in the client. It works!!

[root@8060ab4125b2 /]# puppet agent –test
info: Caching catalog for 8060ab4125b2.docker.lab
info: Applying configuration version ‘1420696114’
info: Creating state file /var/lib/puppet/state/state.yaml
notice: Finished catalog run in 0.02 seconds

13) List the two new running containers.

[root@1004521 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8060ab4125b2 jc1518/centos:centos6-puppet-client “/bin/bash” 4 minutes ago Up 4 minutes puppet-client
5166bdfb73ef jc1518/centos:centos6-puppet-server “/bin/bash” 25 minutes ago Up 25 minutes puppet-server

Advertisement

One thought on “Set up Puppet lab in docker

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s