Managing environments with a control repository
To manage your Puppet code and data with either 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 repo) is the Git repository that code management uses to manage environments in your infrastructure. As you update code and data in your control repo, code management keeps each of your environments updated.
Code management creates and maintains your 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 with its own version of your Puppet code and data.
Environments are created in /etc/puppetlabs/code/environments
on the master. To learn more about
environments in Puppet, read the documentation about environments.
To create a control repo that includes the standard recommended structure, code examples, and configuration scripts, base your control repo on the Puppet control repo template. This template covers most customer situations. If you cannot access the internet or cannot use modules directly from the Forge because of your organization's security rules, create an empty control repo and add the files you need to it.
At minimum, a control repo comprises:
-
A Git remote repository. The remote is where your control repo is stored on your Git host.
-
A default branch named
production
, rather than the usual Git default ofmaster
. -
A Puppetfile to manage your environment content.
-
An
environment.conf
file that modifies the$modulepath
setting to allow environment-specific modules and settings.
Create a control repo from the Puppet template
To create a control repo that includes a standard recommended structure, code examples, and configuration scripts, base your control repo on the Puppet control repo template. This template covers most customer situations.
To base your control repo on the Puppet control repository template, you 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.
-
An
environment.conf
file to implement asite-modules/
directory for roles, profiles, and custom modules. -
config_version
scripts to notify you which control repo version was applied to the agents. -
Basic code examples for setting up roles and profiles.
-
An example
hieradata
directory that matches the default hierarchy . - A Puppetfile to manage content maintained in your environment.
Set up a private SSH key so that your master can identify itself to your Git host.
You now have a control repository based on the Puppet
control-repo
template. When you make changes to this
repo on your workstation and push those changes to the remote copy of the control
repo on your Git server, Code Manager deploys your infrastructure changes.
You also now have a Puppetfile available for you to start adding and managing content, like module code.
Create an empty control repo
If you can't use the control repo template because, for example, you cannot access the internet or use modules directly from the Forge because of your security rules, create an empty control repo and then add the files you need.
To start with an empty control repo, you create a new repo on your Git host and then copy it to your workstation. You make some changes to your repo, including adding a configuration file that allows code management tools to find modules in both your site and environment-specific module directories. When you're done making changes, push your changes to your repository on your Git host.
When you make changes to this repo on your workstation, push those changes to the remote copy of the control repo on your Git server, so that code management can deploy your infrastructure changes.
After you've set up your control repo, create a Puppetfile for managing your environment content with code management.
If you already have a Puppetfile, you can now configure code management. Code management configuration steps differ, depending on whether you're using Code Manager (recommended) or r10k. For important information about the function and limitations of each of these tools, along with configuration instructions, see the Code Manager and r10k pages.
Add an environment
Create new environments by creating branches based on the production branch of your control repository.
-
Configured either Code Manager or r10k.
-
Created a Puppetfile in the default (usually 'production') branch of your control repo.
-
Selected your code management deployment method (such as the
puppet-code
command or a webhook).
-
Create a new branch:
git branch <NAME-OF-NEW-BRANCH>
-
Check out the new branch:
git checkout <NAME-OF-NEW-BRANCH>
- Edit the Puppetfile to track the modules and data needed in your new environment, and save your changes.
-
Commit your changes:
git commit -m "a commit message summarizing your change"
-
Push your changes:
git push origin <NAME-OF-NEW-BRANCH>
- Deploy your environments as you normally would, either on the command line or with a Code Manager webhook.
Delete an environment with code management
To delete an environment with Code Manager or r10k, delete the corresponding branch from your control repository.
-
On the production branch of your control
repo directory, on the command line, delete the environment's
corresponding remote branch by running
git push origin --delete <BRANCH-TO-DELETE>
-
Delete the local branch by running
git branch -d <BRANCH-TO-DELETE>
- Deploy your environments as you normally would, either on the command line or with a Code Manager webhook.
puppet-code deploy --all --wait