Managing environments with a control repository
To manage your Puppet code and data with Code Manager or r10k, you need a Git version control repository. This control repository is where code management stores code and data to deploy your environments.
How the control repository works
Code management relies on version control to track, maintain, and deploy your Puppet code and data. The control repository (or control repo) is a Git repository that code management uses to manage environments in your infrastructure. When you update code and data in your control repo, code management updates your environments accordingly.
Code management creates and maintains environments based on the branches in your control
repo. For example, if your control repo has a production
branch, a development
branch, and a testing
branch, code management creates a production environment, a
development environment, and a testing environment. Each environment has its own version of
your Puppet code and data based on the contents of the
corresponding branch.
/etc/puppetlabs/code/environments
. You can learn more About environments in the Puppet
documentation.- A Git remote repository. This is where your control repo is stored on your version control host.
- A default branch named
production
, rather than the usual Git default ofmaster
. You might have additional branches for other environments, such asdevelopment
ortesting
. - A Puppetfile to manage your environment content.
- An
environment.conf
file that modifies the$modulepath
setting to allow environment-specific modules and settings.
There are two ways to create control repos. To ensure your control repo has the recommended structure, code examples, and configuration scripts, Create a control repository from the Puppet template. This template covers most customer situations. If you cannot access the internet or cannot download modules directly from the Forge because of your organization's security rules, Create an empty control repo and add the necessary files to it.
- Configure the
repositories
setting in your code management tool's Git settings: - Map your sources.
Create a control repository from the Puppet template
To create a control repository (or control repo) that has the recommended structure, code examples, and configuration scripts, base your control repo on the Puppet control repo template. This template covers most customer situations.
- Basic code examples for setting up roles and profiles.
- A Puppetfile that references modules to manage content in your environments.
- An example Hiera configuration file and
hieradata
directory. - A
config_version
script that tells you which version of code from your control repo was applied to your agents. - An
environment.conf
file that implements theconfig_version
script and asite-modules
directory for roles, profiles, and custom modules.
In situations where you can't access the internet, or where organizational security policies prevent downloading modules from the Forge, you can Create an empty control repo and add the necessary files to it.
To use the template, you must set up a private SSH key, copy the control repo template to your development workstation, set your own remote Git repository as the default source, and then push the template contents to that source.
You now have a control repository based on the Puppet
control-repo
template. After configuring Code Manager, when you make changes to your control repo
on your workstation and push the changes to the remote control repo on your Git host, Code Manager
detects and deploys your infrastructure changes.
By using the control-repo
template, you now also have
a Puppetfile to which you can add and manage content,
like module code.
Create an empty control repo
In situations where you can't access the internet, or where organizational security policies prevent downloading modules from the Forge, you can create an empty control repo and add the necessary files to it.
After creating your control repo, you must create a Puppetfile to manage your environment content with code management. Then, you must configure either Code Manager (recommended) or r10k.
Add an environment
Create new environments by creating branches based on your control repo's production
branch.
- A control repository.
- A Puppetfile in your control repo's
production
branch. - Configured Code Manager or r10k.
- Selected a code management deployment method (either the
puppet-code
command or a webhook).
-
In your control repo, create a new branch based on the
production
branch:git branch <NEW_BRANCH_NAME>
-
Check out the new branch:
git checkout <NEW_BRANCH_NAME>
- Edit the Puppetfile to track the necessary modules and data for your new environment, and then save your changes.
-
Commit your changes:
git commit -m "prepare Puppetfile for new environment"
-
Push your changes:
git push origin <NEW_BRANCH_NAME>
- Deploy your environments as you normally would, either on the command line or with a webhook.
Delete an environment from code management
To delete an environment that is being managed by Code Manager or r10k, delete the corresponding branch from your control repository.