Terraform: Provision AWS EC2 (Jenkins server), user_data: Install Git and Ansible, run Ansible playbook to install Jenkins in the EC2.
Pre-requisites (Locally):
- Terraform
- AWS credentials - AWS cli
- Files to be created:
- main.tf
- provider.tf
- data-provider.tf
- ec2_setup.sh
- jenkins-playbook.yml
-
Once created the files, push them to the repository
-
Locally execute terraform init, plan, apply
-
Terraform files will create an EC2 instance which, using the userdata template file (ec2_setup.sh), will install:
- Ansible
- Git
- And clone this repository () to execute the playbook (jenkins-playbook.yml)
ansible --version
cd /user/ubuntu
- java -version
- sudo systemctl status jenkins
Check tasks playbook-installations in /var/log/ cat user-data.log --> To watch the tasks playbook-installations
Access Jenkins by the browser: [ec2-ip]:8080 to setup Jenkins
Copy the path to get the administrator password and unlock Jenkins
At the end, destroy the AWS resources terraform destroy --auto-approve