Here below are the Ansible Roles for installing Java, Jenkins, Maven on Ubuntu EC2 instance using Ansible. You need to installJava first (first link below) and then do the steps in the second link for installing Jenkins, third link for installing Maven.
Click here if you would like to create a new Ubuntu EC2 instance using Ansible Playbook.
You can watch this lab on YouTube:
Pre-requisites: Setup Ansible on your EC2 instance.
We will learn how to create Ansible Role for provisioning a new EC2 instance in AWS cloud. We will pick a playbook which has all the logic and we will refactor into reusable ansible role.
What is Ansible Role?
Ansible also lets you organize tasks in a directory structure called a Role. Using Ansible roles you can break down complex playbooks into smaller and manageable chunks. Ansible role enables reuse and share our Ansible code efficiently.
How to create Ansible Role?
Using ansible galaxy command, we can create Ansible role. This will create the below directory with all the files.
directory structure of Ansible role
aws-infra-role/
├── README.md
├── create.yml
├── defaults
│ └── main.yml
├── handlers
│ └── main.yml
├── meta
│ └── main.yml
├── tasks
│ ├── create-ec2.yml
│ └── create-sg.yml
├── tests
│ ├── inventory
│ └── test.yml
└── vars
└── main.yml
Directory structure explained
tasks - contains the main list of tasks to be executed by the role. handlers - handlers are typically used to start, reload, restart, and stop services. defaults - default variables for the role. vars - other variables for the role. Vars has the higher priority than defaults. meta - defines some data / information about this role (author, dependency, versions, examples, etc,.)
Ansible is #1 configuration management tool. It can also be used for infrastructureprovisioning as well. or You can use Ansible in combination of Terraform which can take care of infra automation and Ansible can do configuration management. We will be setting up Ansible on Red Hat VM in Azure cloud And create some resources in AWS Cloud by using Ansible playbooks.
Ansible Architecture:
The best way to install Ansible in Linux is to use PIP, a package manager for Python.
Pre-requisites:
Create new Red Hat EC2 in AWS Cloud for setting up Ansible, just open port 22 in firewall rule.
How to setup Ansible on Red Hat Linux VM?
Watch Steps in YouTube channel:
Change host name to AnsibleMgmtNode sudo hostnamectl set-hostname AnsibleMgmtNode
Jenkins is an open source continuous integration/continuous delivery and deployment (CI/CD) automation software DevOps tool written in the Java programming language. It is used to implement CI/CD workflows, called pipelines.
Please follow the steps to install Java, Jenkins, Maven on Ubuntu 22.0.4 instance. Jenkins, Maven are Java based applications, so we need to install Java first.
Pre-requisites:
port 8080 opened in firewall rule to access Jenkins
Connect to EC2 instance using git bash or iTerm
Change Host Name to Jenkins sudo hostnamectl set-hostname Jenkins
Perform update first sudo apt update
Install Java 17
sudo apt install openjdk-17-jdk -y
Verify Java Version
java -version
Maven Installation Maven is a popular build tool used for building Java applications. Please click here to learn more about Maven. You can install Maven by executing below command:
sudo apt install maven -y
you can type mvn --version you should see the below output.
Now lets start Jenkins installation
Jenkins Setup
Add Repository key to the system
curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
Update Ubuntu package
sudo apt update
Install Jenkins
sudo apt install jenkins -y
The above screenshot should confirm that Jenkins is successfully installed.
Access Jenkins in web browser
Now Go to AWS console. Click on EC2, click on running instances link. Select the checkbox of EC2 you are installing Java and Jenkins. Click on Action. Copy the value from step 4 that says --> Connect to your instance using its Public DNS:
Now go to browser. enter public dns name or public IP address with port no 8080.
How to Enable to use classic editor to create a pipeline without YAML in Azure DevOps ?
The "classic pipeline" is simply a term that refers to a simple way of creating pipelines in Azure DevOps using UI. The purpose of this web forms based assistant is basically to hide the complexity of the pipeline’s YAML based syntax. In other words, user can create pipelines without having to deal with “code”.
If classic editor option is disabled in Azure DevOps, you may see something like below in your Azure DevOps project. We can enable it by changing the settings at project or organizational level.
How to enable the classic build and release pipelines?
You can enable/disable it two ways
Organizational level
Project Level
In Azure DevOps, Go to Project Settings, Under Pipelines > Settings > General. Make sure 'Disable creation of classic build pipelines' and 'Disable creation of classic release pipelines' is turned off, to have classic editor shown after creating a project.
If those options are disabled, go to organizational level and do the same in 'Organization Settings'.
Select Pipelines --> Settings
Finally disable the options highlighted in the image below
when you go try creating a new pipeline, you should see the option now.
Scenario #1(post build) - How to trigger a Jenkins job from another Free style Job?
1. Login to Jenkins instance. 2. Open your any existing freestyle build job. 3. Click on Configure
4. Go to post build action
5. Add post-build action --> click on Build other projects
6. Select job name(projects) that you want to trigger by typing the name of the job and also check trigger only if build is stable
7. Save the job. 8. Build job now, once the current job is built, it will trigger the next job immediately. Check the console output of the current job, you will see id would trigger second job
9. Go to the secondJob Check console output. You will see the second job got triggered by first build job.
Scenario #2 (pre-build) - How to trigger a Jenkins job from another Free style Job?
1. Open your freestyle build job. 2. Click on Configure
3. Click on Build triggers
4. Check build other projects are built.
Select source job name which will be built first and then once the build is stable, it will be trigger this job. And also check trigger only if build is stable.
5. Save the job.
6. Run the first job. once that job is successful, and then it will trigger this job.
Scenario #3 - How to trigger any Jenkins job from a pipeline Job: