Last couple of months I’ve been working closely with Puppet. I wrote some blogs about it, recorded a VMware vRA Expert Talk video and had two successful events in the Netherlands where I presented and demo’ed the Puppet Enterprise integration with VMware vRealize Automation. For the demo part, Kevin Reeuwijk and I created customPuppet code and stored it on the local code repository of the Puppet Master. Over time the code changed somewhat and because we were not using source control we had no history who made what changes to the code and also had no possibility for a rollback if something went horribly wrong. Luckily that was not the case, but now I know the best way to manage your Puppet code is to use a source control repository. This control repository is where code management stores code and data to deploy your environments.

Puppet Code management uses Git repository branches to create environments. Environments allow you to designate a node or node group to use a specific environment. As you update the code in your control repository, code management tracks the state of that repository to keep each environment updated.

This blog post will learn you how to setup Gitlab CE and configure Puppet Enterprise to use it as a control repository for your Puppet code.

Some items are assumed to be installed and are not part of this guide:

Step 1 – Setup Gitlab Community Edition

SSH into the CentOS7 machine and login with root. First install some dependencies.

Optional, stop the firewall and disable it.

Then install the latest version of Gitlab CE.

Edit /etc/gitlab.rb with nano or vim to change the external URL.

Change it in external_url ‘http://x.x.x.x or FQDN’

Configure and start Gitlab with the following command:

Check the status of Gitlab with:

Step 2 – Create a Puppet control repository in Gitlab

  1. Browse to the Gitlab CE server page and login with an account that has permissions to create groups and projects.
  2. Create a new group called ‘puppet’.
    1. Click the + icon on the top of the page.
    2. Click ‘New Group’.
    3. Set the group path to: http://<fqdn of your Gitlab server>/puppet
    4. Set the group name to: puppet
    5. Leave the visibility level at its default of ‘PrivateGitlab group
    6. Click ‘Create Group’.
  3. Create a new control-repo project in the puppet group.
    1. Click ‘New Project’.
    2. Set the project name to: control-repo
    3. Leave the visibility level at its default of ‘PrivateGitlab project
    4. Click ‘Create project’.Puppet repository

Step 3 – Setup SSH keys for Puppet Code Manager and Gitlab

  1. Login to the Puppet Enterprise server and create a set of SSH keys:
  2. Make the SSH keys available to Code Manager:
  3. Copy the SSH public key to your clipboard:
  4. Browse to the User Settings page in Gitlab for the account you used to create the control-repo project:
    1. Browse to the Gitlab CE server page and login with the same account used in Step 2.
    2. Click on the user’s avatar icon on the top right-hand side of the page and click ‘Settings’.
    3. Go to the ‘SSH Keys’ section.
    4. Paste the clipboard contents into the ‘Key’ field.
    5. Enter a description in the ‘Title’ field. For example ‘Name of your Puppet server‘.Gitlab SSH keys
    6. Click ‘Add key’.
  5. Check that you are now able to SSH from the Puppet Enterprise server into the Gitlab server with your SSH key:
  6. This should provide output similar to the following: SSH to Gitlab

Step 4 – Push Starter Content to the Gitlab Puppet control repository

  1. Login to the virtual machine with the git tools installed, or use the following command to install the git tools on a fresh virtual machine:
  2. Setup a git working folder:
  3. Clone the Puppet starter content and push it to your Gitlab server:
  4. You should see output similar to the following: Push content to Gitlab
  5. Browse to the Gitlab CE server page and login with the same account used in Step 2.
  6. Go to your Puppet control-repo, click on the + icon in the middle of the screen and select New branch to create an additional environment.Gitlab new branch
  7. Set the Branch name to: dev
  8. Select Create from production and click ‘Create Branch’.New Dev environment

Step 5 – Setup Puppet Code Manager

  1. Open the Puppet Enterprise webconsole (https://<fqdn of your puppet master>) and login with username ‘admin’.
  2. Browse to ‘Classification’ and click the + sign next to PE Infrastructure.
  3. Click on the ‘PE Master’ group, the click the ‘Configuration’ tab .Puppet classification
  4. Look for the section called ‘Class:puppet_enterprise::profile::master’.
  5. Click on the ‘Parameter name’ dropdown box and select ‘code_manager_auto_configure’. Set its value to: true Then click the ‘Add parameter’ button to lock in this parameter.
  6. Click on the ‘Parameter name’ dropdown box and select ‘r10k_private_key’. Set its value to: /etc/puppetlabs/puppetserver/ssh/id-control_repo.rsa Then click the ‘Add parameter’ button to lock in this parameter.
  7. Click on the ‘Parameter name’ dropdown box and select ‘r10k_remote’. Set its value to: git@<fqdn of your Gitlab server>:puppet/control-repo.git Then click the ‘Add parameter’ button to lock in this parameter.
  8. Finally, scroll down the page and click the button ‘Commit 3 changes’ to make the changes permanent.Puppet Code Manager classes
  9. Now you just need to run the Puppet agent on the server to have Code Manager set itself up. For this, login to the Puppet Master shell and execute the following command:
  10. When Code Manager is setup for the first time, some Puppet Master services will be restarted, this is normal.

Step 6 – Sync the control repository to the Puppet Master server

  1. We first need to create an access token to allow Code Manager to push content to the Puppet master:
  2. Now let’s perform a dry run to ensure Code Manager is working correctly:
  3. You should see output similar to the following: Puppet code deploy
  4. Next, let’s retrieve the actual access token so we can setup a webhook in Gitlab:
  5. Next, browse to your control-repo project in Gitlab and go to the ‘Settings’ section.
  6. Click on the ‘Integrations’ section.
  7. Enter the following URL in the ‘URL’ field:
    https://<fqdn of your master>:8170/code-manager/v1/webhook?type=gitlab&token=<paste access token here>
  8. Clear the ‘Enable SSL verification’ button, as we are using a self-signed certificate.
  9. Click the ‘Add webhook’ button to add the webhook.
  10. Logout and log back in your Gitlab server with the root account.
  11. Click on ‘Configure Gitlab’.Gitlab configure
  12. Under ‘Admin area’ go to the ‘Settings’ section and scroll all the way down to Outbound Requests. Make sure this option is enabled. Click the ‘Save’ button if you made any changes.Gitlab outbound requests
  13. Logout and log back in your Gitlab server with the account used in Step 2.
  14. Browse to your control-repo project in Gitlab and go to the ‘Settings’ section.
  15. Click on the ‘Integrations’ section.
  16. Next to the newly configured webhook, click the ‘Test’ button, then select ‘Push events’. You should get an HTTP 200 result to indicate success!Gitlab webhook for Puppet

Step 7 – Manage the Puppetfile for additional modules

  1. You now have your control-repo setup and Code Manager configured. You’re ready to start configuring your Puppetfile with modules from the Puppet Forge! As an example, use the following procedure to setup your Puppetfile.
  2. Browse to your control-repo project on your Gitlab server. Select the Production branch.
  3. Click the Puppetfile and click ‘Edit’.
  4. Configure your Puppetfile as follows:

    *ensure you change the FQDN of the Gitlab server in the example to your actual FQDN!
  5. Click ‘Commit changes’, this will kick off a code deployment to the Puppet Master and get the modules installed. You can view the progress of the deployment on the Puppet Master with this command:
  6. Finally, to confirm the modules have been deployed, run this command:
  7. You should see output similar to the following: Puppet modules installed
  8. Repeat the steps above for the ‘Dev‘ branch and off course you can use other modules in the Dev environment if you want.

 

That’s it! You are now ready to define profiles and roles in the /site section of your control-repo and store your Puppet code. Happy puppetizing!

Special thanks to Kevin Reeuwijk of Puppet who wrote the majority of this guide.