I have a working setup of Puppet with Master and Agent. Now I'm trying to use r10k to manage Puppet code. My goal is that on each git push
of a code change the Puppet code below /etc/puppetlabs/code/environments
on the Puppet Master gets updated automatically.
While this seems to work for one monolithic control repository containing all modules, I'm not getting it to work if custom modules are in separate Git repositories.
My setup is as follows:
r10k configuration in /etc/puppetlabs/r10k/r10k.yaml
:
sources:
operations:
remote: '/srv/git/puppet.git'
basedir: '/etc/puppetlabs/code/environments'
Central control repository /srv/git/puppet.git
containing branches production
and testing
, each with:
- A
manifests/site.pp
with node configurations, e.g.node default { contain mymodule }
- A
Puppetfile
with external module references
The Puppetfile
for testing
would look like e.g.
mod 'mymodule',
:git => 'file:///srv/git/mymodule.git',
:ref => 'HEAD'
while for production
it would look like e.g.
mod 'mymodule',
:git => 'file:///srv/git/mymodule.git',
:ref => 'stable'
(Until this works I only have branch production
and reference to HEAD
.)
Another Git repository for each custom module, e.g. /srv/git/mymodule.git
Git Hooks to run r10k whenever git push
is executed:
/srv/git/puppet.git/hooks/post-receive
with content
r10k deploy environment -pv
/srv/git/mymodule.git/hooks/post-receive
with content
r10k deploy module mymodule -v
The hooks get executed, since upon git push
I get output like
remote: INFO -> Deploying environment /etc/puppetlabs/code/environments/production
remote: INFO -> Environment production is now at 991830eb1561cddd7970be4152748168df52ef79
remote: INFO -> Deploying Puppetfile content /etc/puppetlabs/code/environments/production/modules/mymodule
and
remote: INFO -> Deploying module /etc/puppetlabs/code/environments/production/modules/mymodule
My problem is that - despite this output - changes pushed to the module's repository are not reflected by the files below /etc/puppetlabs/code/environments
.
Edit
Elaborating a bit on my intended workflow:
- My control repo has two branches,
production
andtesting
, while the module repository has only one branchmaster
. I thought it would be easier that way, especially to avoid merge issues. But considering that in Git merges can be restricted to fast-forward, and r10k has active support for the tracking of branches, my workflow might actually be easier using the branchesproduction
andtesting
for the module repositories as well. I would then work (develop) ontesting
and only switch toproduction
to execute something likegit merge --ff-only testing
. - My first thought was to create a Git tag
stable
for the module repository which I move to the current commit every now and then, i.e. staying in themaster
branch all the time without any merging done at all. But a fast-forward-only merge between branches can also save me from merge conflicts, so there's probably no reason to avoid branches. Also I could get the same workflow on both the control repo and the module repos. - I'm only starting to learn about Puppet with two virtual machines, one Puppet master and one agent. I'll add another VM agent and then point one to the
production
environment and the other one totesting
so I can verify my workflow while building a usable Puppet configuration for the agents. For now I'll simply set the environment in each agent'spuppet.conf
. - Later I'll use real Linux boxes and map one agent to
testing
and all others toproduction
. The master will be on another box and set up manually.