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.
Successfully complete this lab by achieving the following learning objectives:
- Log in to the Terraform Controller Node EC2 Instance
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:
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.
After logging in, verify the version of Terraform installed (should be 12.29). Execute the following command to check:
- Clone the GitHub Repo for Terraform Code
gitcommand to clone the GitHub repo which has the Terraform code for deploying the solution of this lab. GitHub repo URL.
Execute the following command:
git clone https://github.com/linuxacademy/content-deploying-to-aws-ansible-terraform.git
Change to the directory for lab Terraform code:
Examine the contents of the directory you’re in:
- Run the `gen_ssh_key.yaml` Ansible Playbook to Generate SSH Key Pair
Run the Ansible Playbook:
This Ansible Playbook will generate an SSH key pair for you user
cloud_userwhich 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
Initialize the Terraform directory you changed into to download the required provider
Ensure Terraform code is formatted properly:
Ensure code has proper syntax and no errors:
See the execution plan and note the number of resources that will be created:
terraform applyhas 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.
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.
- username: admin
- password: password
Finally, on the Terraform Controller node CLI, delete all resources which were created and ensure that it runs through successfully.