Using HashiCorp Packer, Terraform, and Ansible to Set Up Jenkins

Sam Gabrail
HashiCorp Solutions Engineering Blog
12 min readDec 18, 2020

--

This post first appeared on TeKanAid’s blog.

Overview

Welcome to our second post in the blog post series called End-to-End Infrastructure and Application Deployment. In part 1, we discussed the HashiCorp Vault Azure Secrets Engine. That was the first step in securely automating our CI/CD pipeline. The purpose was to deliver Azure credentials dynamically for provisioning resources in Azure.

Our focus for this blog post is on the second step and that is to set up our CI/CD pipeline with Jenkins. This is done by following the steps below:

  1. Use Packer to build an Azure image that has Docker installed.
  2. Create a Docker container image that contains Jenkins, Vault, Terraform, and Ansible.
  3. Use HashiCorp Vault to retrieve Azure credentials to use with Terraform
  4. Run Terraform to build a Jenkins VM in Azure based on the Packer image.
  5. Use Ansible to configure the Jenkins VM by running the Docker container.

As a reminder, the goal of this series is to learn best practices around the automation of infrastructure provisioning and application deployment. We cover the concepts of Infrastructure as Code, CI/CD, secrets management, dynamic secrets, the secret zero problem, service mesh, and more.

tl;dr you can find the code for the blog series in this GitHub repo. Moreover, below is a…

--

--