Managing Code with Code Manager
A newer version is available; see the version menu above for details.
Code Manager automates the management and deployment of your Puppet code. You push code updates to your source control repo, and then Puppet syncs the code to your masters, so that all your servers start running the new code at the same time, without interrupting agent runs.
How Code Manager Works
Under the hood, Code Manager uses r10k and the file sync service to stage, commit, and sync your code, automatically managing your directory environments and modules.
First, you’ll create a control repository with branches for each environment that you want to create (such as production, development, or testing). You’ll also create Puppetfiles for your environments, specifying exactly which modules to install in each environment. This allows r10k to create directory environments, based on the branches you’ve set up.
When you push code to your control repo, a webhook triggers Code Manager to pull that new code into a staging code directory (
/etc/puppetlabs/code-staging). File sync then picks up those changes, pauses Puppet Server to avoid conflicts, and then syncs the new code to the live code directories on your Puppet masters.
Code Manager is built into Puppet Enterprise. You can set up a default configuration of Code Manager , and then, if you require a more customized solution, you can customize your configuration by using Hiera.
Understanding File Sync and the Staging Directory
To sync your code across multiple masters and to make sure that code stays consistent, Code Manager relies on the Puppet file sync service. Without Code Manager or file sync, Puppet code lives in the codedir, or live code directory, at
/etc/puppetlabs/code. But the file sync service looks for code in a code staging directory (
/etc/puppetlabs/code-staging), and then syncs that to the live codedir. This means you can no longer write code to the codedir; instead, Code Manager moves new code from source control into the staging directory, and then file sync moves it into the live code directory.
Don’t modify code in the staging directory. Code Manager overwrites it with updates from the control repo. Similarly, don’t modify code in the live code directory, because file sync overwrites that with code from the staging directory.
For more information specific to file sync, see About file sync.
Moving from r10k to Code Manager
Code Manager uses r10k in the background to improve automation of your code management and deployment. However, switching to Code Manager means you can no longer use r10k manually. Because of this, some r10k users might not want to move to Code Manager yet. Specifically, be aware of the following restrictions:
- If you use Code Manager, you cannot deploy code manually with r10k. If you depend on the ability to deploy modules directly from r10k, using the
r10k deploy modulecommand, you should continue to use your current r10k workflow.
- Both r10k and Code Manager are capable of using multiple control repos in advanced configuration. However, Code Manager must deploy all control repos to the same directory. If you are using r10k to deploy control repos to different directories, you should continue to use your current r10k workflow.
- Code Manager does not support all r10k configurations. If you rely on an r10k configuration that Code Manager doesn’t yet support, you should continue to use your current r10k workflow.
If you are using a custom script to deploy code, you should carefully assess whether Code Manager meets your needs.
Getting Started with Code Manager
To get Code Manager ready:
- Set up your control repository.
- Create Puppetfiles for your environments.
- Configure Code Manager from fresh installation.
- If you are setting up Code Manager after an upgrade from a previous installation of PE, see Setting up Code Manager with a PE upgrade instead.
- Optional: Customize Code Manager’s configuration, if necessary.
- Set up Code Manager’s deployment trigger with either a webhook or a custom script.