Skip to content

Instantly share code, notes, and snippets.

@maju6406

maju6406/blog.md Secret

Created April 3, 2018 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maju6406/2ff1e6e8b1a5f438798d1c75d1f7ac37 to your computer and use it in GitHub Desktop.
Save maju6406/2ff1e6e8b1a5f438798d1c75d1f7ac37 to your computer and use it in GitHub Desktop.

Connecting Visual Studio Team Services to Code Manager in Puppet Enterprise

As a Sales Engineer, I hear about large scale Microsoft Windows-centric environments all the time. Many of these teams use Microsoft Team Foundation Server (TFS) for their source control. There is a hosted version of TFS called Microsoft Visual Studio Team Services (VSTS) that is a great alternative to Github or Gitlab. Luckily, Puppet Enterprise (PE) will work with either.

While these tools operate just like Github & Gitlab, their user interface can seem a little unfamiliar. The following is a guide for setting VSTS with an existing Puppet Control repo, and then connecting it to freshly installed Puppet Enterprise that doesn't have Code Manager configured. While the guide is explictly for VSTS the steps should be very similar in TFS.

Create a VSTS account

  1. Create a free account on visualstudio.com.
  2. Create a New project.
  3. For Version Control choose 'git'.
    Create New Project
  4. Select "Import a repository" on the dashboard.
    Import Repo
  5. Enter https://github.com/puppetlabs/control-repo. Leave "Requires Authorization" turned off.
    Import Repo
  6. (Optional) Click Clone in the upper right corner and select "Create Git Credentials". Create an username and password. These credentials will be used if you choose HTTPS authentication in PE below.
    Generate Git Creds

Install Code Manager in Puppet Enterprise

The easiest way to set up Code Manager is via the verbosely named "pe_code_manager_easy_setup" task. It automates all the steps required to connect your VSTS repo with PE.

  1. From the command line, run the following command as a root user:
    https://gist.github.com/7f5dfd537dcc54331b2bc482180c786b

  2. Open the Tasks view and select the 'pe_code_manager_easy_setup'task. The task has 1 parameter: "r10k_remote_url". You have 2 options for this parameter. 2a. If you specify the HTTPS url you will need to put the username and password in the URL from step 6 above (ex. https://username:password@abirpuppet.visualstudio.com/MyFirstProject/_git/control-repo). 2b. Alternatively, you can use the ssh url (ssh://abirpuppet@vs-ssh.visualstudio.com:22/MyFirstProject/_ssh/control-repo).

  3. Run the task on the master node. It can take 3-5 minutes to complete. If the task is successful, you will see output like the following: Task Output

  4. If you chose 2b. above, there's one last step. In VSTS, click Clone in the upper right corner and select the SSH tab.
    SSH Tab
    Then click on the "Manage SSH keys". Click Add, and then put "code manager" for Description, and copy and past the Public SSH Key shown in the above output (ssh-rsa...) to the Key Data.
    7AddKey
    You should all set up now!

Do a manual code deploy

Finally to test if things work you need to do a manual code deploy. Before doing the code deploy you will need to log into the PE master as the root user and create an "access token". To do so, you must execute the following from the command line:
puppet access login --lifetime <timeframe>
<timeframe> is the length of time you want the token to last. For example "1y" would make the token valid for a year. It will then ask you for your PE console username and password.
Now you're ready! You can this one of 2 ways: from the terminal or the PE console...

1. From the terminal:

Execute the following from the command line:
puppet code deploy <environment> --wait
<environment> is the Puppet environment you want to deploy. The --wait parameter tells the command to return after the deploy has completed (instead of right away).

2. From the PE Console via the code_deploy task:

Execute the following from the command line:
puppet module install tspy-code_deploy
Then open the Tasks view in the PE Console and select the 'code_deploy'task. The task has 1 parameter: "production". Run the task on the master node. It can take a minute to complete. If the task is successful, you will see output like the following:
8Deploy

Congratulations! You've set up your PE instance. If you're having issues, check out [Troubleshooting Code Manager] in the Puppet Documentation.(https://puppet.com/docs/pe/2017.3/code_management/code_mgr_troubleshoot.html).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment