Skip to content

kavitha351/dvp-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS Infrastructure Automation & CI/CD Integration Project

Your organization is aiming at automating the Infrastructure creation and the deployment procedure. You are tasked with setting up and configuring the AWS environment to meet specific requirements.

Task:

The points from 1-2 are supposed to be done using a Terraform script.

  1. The script is supposed to create a VPC and a Subnet inside that particular VPC.
  2. Make sure that you create a security group for all the Instances that you will need to create. You need to create a total of 3 Instances with elastic IP for all of the Instances, use the same security group for all the Instances. The security group is supposed to enable ports 22, 80, 8080 for Inbound rules and enable All Traffic, i.e all ports for Outbound rules.

I would suggest you to please clone the repo first and then run the following commands.

terraform init
terraform plan
terraform apply --auto-approve

Install Ansible on one of these machines and Jenkins on the same machine manually. Set Ansible up and use the public ip (Elastic IP) in the default inventory file, i.e. /etc/ansible/hosts.

Here we will install ansible and jenkins in the "Master" Instance. Create a file install.sh. Copy the below commands.

#!/bin/bash

exec > /var/log/cloud-init-output.log 2>&1
set -x

# Update and install dependencies
sudo apt update -y
sudo apt install -y software-properties-common

# Add Ansible repository and install Ansible
sudo add-apt-repository --yes --update ppa:ansible/ansible
sudo apt install -y ansible

# Log installation success
echo "Ansible installation completed successfully" >> /var/log/ansible_install.log

# update
sudo apt update

# Install java and jenkins
sudo apt-get install openjdk-17-jdk -y

# Jenkins installation
sudo wget -O /etc/apt/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo "deb [signed-by=/etc/apt/keyrings/jenkins-keyring.asc]" \
  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins -y

Then edit the inventory file. In my case the inventory file is at /etc/ansible/hosts

[worker1]
<PUB-IP-WORKER1>
[worker2]
<PUB-IP-WORKER2>

Create a GitHub repository containing the Ansible script that will be run on the Slave machines. The Script is supposed to install Apache2 on one machine and nginx on the other machine.

The Ansible files can be found on this link: https://github.com/kavitha351/shYamlDockerFile_files/blob/main/playbook.yaml

On the above link the ansible file will install the Apache2 and nginx on the respective machines and will also replace the default page with my custom webpage.

You will then need to set up the Jenkins Dashboard and the Jenkins Agents for the other 2 Instances that will be created using Terraform. The Ansible script that will be available in the GitHub repository needs to be run via a Jenkins Job. A webhook also needs to be created for the same so that the Job can be triggered anytime a push is made to the GitHub repository

For the above issue will go the jenkins dashboard at http://:8080

First we will install the plugin ssh-agent and ansible

The go the globaltool configuration and then add ansible the path will be "/usr/bin/" then save and apply.

We can now run the pipeLine and put the below script.

pipeline {
    agent any

    stages {
        stage('Git') {
            steps {
                git branch: 'main',
                  url: 'https://github.com/Origamini/jenkins-test.git'
            }
        }
        stage('Ansible'){
            steps {
                ansiblePlaybook colorized: true, credentialsId: 'ssh', disableHostKeyChecking: true, installation: 'ansible', inventory: '/etc/ansible/hosts', playbook: 'playbook.yaml', vaultTmpPath: ''
            }
        }
    }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages