Deploying Jenkins Master and Worker Nodes in AWS Behind an ALB Using Terraform and Ansible

1.75 hours
  • 4 Learning Objectives

About this Hands-on Lab

In this hands-on lab the students will be deploying Jenkins Master and worker nodes on EC2 instances(AWS) across regions through Terraform and managing the software and integration between the Jenkins nodes using Ansible.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Log in to the Terraform Controller Node EC2 Instance
  1. Find the details for logging in to the Terraform Controller node provided by the hands-on lab interface and log in to the node using SSH:

    ssh cloud_user@<IP-OF-TERRAFORM-CONTROLLER>

    Note: This instance already has an EC2 instance profile (role) attached to it and has all necessary AWS API permissions required for this lab. It also has the AWS CLI set up and configured with the AWS account attached to this lab, for which the console login credentials are also provided in the lab interface page once the lab spins up.

  2. After logging in, verify the version of Terraform installed (should be 12.29). Execute the following command to check:

    terraform version
Clone the GitHub Repo for Terraform Code

Use the git command to clone the GitHub repo which has the Terraform code for deploying the solution of this lab. GitHub repo URL.

  1. Execute the following command:

    git clone https://github.com/linuxacademy/content-deploying-to-aws-ansible-terraform.git
  2. Change to the directory for lab Terraform code:

    cd content-deploying-to-aws-ansible-terraform/lab_jenkins_master_worker
  3. Examine the contents of the directory you’re in:

    ls
Run the `gen_ssh_key.yaml` Ansible Playbook to Generate SSH Key Pair
  1. Run the Ansible Playbook:

    ansible-playbook ansible_templates/gen_ssh_key.yaml

    This Ansible Playbook will generate an SSH key pair for you user cloud_user which is required for deploying EC2 key pairs in our code.

    Note: Alternatively, you may also run the following Linux command to do the same:

    ssh-keygen -t rsa

    When this command prompts for input, keep pressing enter until you’re returned to the prompt. Do not enter a passphrase.

Deploy the Terraform Code
  1. Initialize the Terraform directory you changed into to download the required provider

    terraform init
  2. Ensure Terraform code is formatted properly:

    terraform fmt
  3. Ensure code has proper syntax and no errors:

    terraform validate
  4. See the execution plan and note the number of resources that will be created:

    terraform plan

    Enter yes when prompted.

  5. Deploy resources:

    terraform apply

    Enter yes when prompted.

    After terraform apply has run successfully, you can either use the AWS CLI on the Controller node to list and describe created resources or you can log in to the AWS Console to verify and investigate created resources.

  6. After a successful terraform apply, you will get the DNS URL of the ALB. Test it out to see if you can reach your Jenkins deployment.

    Jenkins credentials:

    • username: admin
    • password: password
  7. Finally, on the Terraform Controller node CLI, delete all resources which were created and ensure that it runs through successfully.

    terraform destroy

Additional Resources

Please ensure that only regions us-east-1 and us-west-2 are used to deploy resources.

You're an automation engineer at CloudWare Inc. and you have been tasked with deploying a CI/CD application across 2 AWS regions. You've been provided with the Git repo URL which hosts all the required code here:

https://github.com/linuxacademy/content-deploying-to-aws-ansible-terraform.git

The code that is relevant to this module of the project resides within this folder:

content-deploying-to-aws-ansible-terraform/lab_jenkins_master_worker

The system provided to you is a Terraform controller node that comes pre-configured with Terraform and Ansible. All you need to do is generate an SSH key pair on this controller node to be used by Ansible for bootstrapping and then deploy the Terraform code!

Hint: For generating the SSH key pair once you are within the correct folder in the code base, use the following command:

ansible-playbook ansible_templates/gen_ssh_key.yaml

The end result should be that you'll have an ALB DNS name that your Jenkins application will be accessible from.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?