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 pushof 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.ppwith node configurations, e.g.node default { contain mymodule } - A
Puppetfilewith 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-receivewith content
r10k deploy environment -pv/srv/git/mymodule.git/hooks/post-receivewith 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,
productionandtesting, 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 branchesproductionandtestingfor the module repositories as well. I would then work (develop) ontestingand only switch toproductionto execute something likegit merge --ff-only testing. - My first thought was to create a Git tag
stablefor the module repository which I move to the current commit every now and then, i.e. staying in themasterbranch 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
productionenvironment and the other one totestingso 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
testingand all others toproduction. The master will be on another box and set up manually.