Wednesday, January 24, 2024

Install Tomcat 9 on Ubuntu 22.0.4 | Setup Tomcat 9 on Ubuntu 22.0.4 in AWS EC2 | Setup Tomcat on Ubuntu

Tomcat is one of the popular web containers for deploying Java applications. Tomcat is an open source web container. Click here to learn more about Tomcat. Let's see how to install Tomcat on Ubuntu 22.0.4.



Tomcat is both Web server and web container


Please follow below steps to install Tomcat 9 on Ubuntu 22.0.4.

Pre-requisites:
  • Create new EC2 instance first for setting up Tomcat. 
  • Also open port 8080 in security firewall rules for EC2 instance in AWS.
Tomcat Installation
Tomcat is a web server or web container where java web application can be deployed by developers. You can learn more about by clicking this URL.  Tomcat can be installed by executing below commands:

Change Host Name to Tomcat
sudo hostnamectl set-hostname Tomcat

Update to Latest packages
sudo apt update

Install Tomcat9
sudo apt install tomcat9 tomcat9-docs tomcat9-admin -y

Perform below command for setting up tomcat admin app
sudo cp -r /usr/share/tomcat9-admin/* /var/lib/tomcat9/webapps/ -v

Setup an user in tomcat 
Open the tomcat-users.xml file by executing below command
sudo nano /var/lib/tomcat9/conf/tomcat-users.xml

We need to edit this file.
We need to add tomcat user and assign to manager-script role.
Scroll down all the way to the end of the file,
Add the below lines in second last line above (above </tomcat-users>)

<role rolename="manager-script"/>
<user username="tomcat" password="password" roles="manager-script"/>


Press Control O and enter for saving the file. 
Press Control + X for exiting the file after saving.

Now restart tomcat to take the changes in effect
sudo systemctl restart tomcat9

Verify if tomcat9 is working fine
sudo systemctl status tomcat9

Now press q for quitting from that window. Now open the browser to access Tomcat, enter
You should see a page that says.

That's it. You have setup Tomcat successfully!!

Watch steps in YouTube channel:
 

Tuesday, January 23, 2024

Create Ansible Role to create a new EC2 instance | Ansible Role for provisioning infrastructure in AWS | Refactor Ansible playbook into Ansible Role

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,.)

tests - test cases if you have any.

Pre-requisites:
Steps to create EC2 instance using Ansible Role:

Login to EC2 instance using Git bash or ITerm/putty where you installed Ansible. Execute the below command:

Create an Inventory file first

sudo mkdir /etc/ansible

Edit Ansible hosts or inventory file
sudo vi /etc/ansible/hosts

Add the below two lines in the end of the file:
[localhost]
local


cd ~
mkdir roles  
cd roles

Create Ansible Role

ansible-galaxy role init aws-infra-role


We will convert this playbook into ansible role.
So all the variables will go inside vars folder.

vars
    └── main.yml

sudo vi aws-infra-role/vars/main.yml
(copy below content)
keypair: myNov2023Key
instance_type: t2.small
image: ami-007855ac798b5175e
wait: yes
group: webserver
region: us-east-1
security_group: my-jenkins-security-grp1

Save the file and come out of it.

So all the tasks will go inside tasks folder. let's create security group first.

sudo vi aws-infra-role/tasks/create-sg.yml
---
  - include_vars: "vars/main.yml"
    tags: create

# tasks file for security group
  - name: configuring security group for the instance
    ec2_group:
        name: "{{ security_group }}"
        description: my-ajenkin-security_groAup
        region: "{{ region }}"
        rules:
            - proto: tcp
              from_port: 22
              to_port: 22
              cidr_ip: 0.0.0.0/0
            - proto: tcp
              from_port: 80
              to_port: 80
              cidr_ip: 0.0.0.0/0
            - proto: tcp
              from_port: 8080
              to_port: 8080
              cidr_ip: 0.0.0.0/0
        rules_egress:
            - proto: all
              cidr_ip: 0.0.0.0/0

Let's create a task for ec2 instance creation.

sudo vi aws-infra-role/tasks/create-ec2.yml

---
  - include_vars: "vars/main.yml"
    tags: create
  - name: creating ec2 instance
    ec2_instance:
        security_group: "{{ security_group }}"
        name: test-stan
        key_name: "{{ keypair }}"
        instance_type: "{{ instance_type}}"
        image_id: "{{ image }}"
        region: "{{ region }}"
        wait_timeout: 2   


Let's create a task for creating s3 bucket.

sudo vi aws-infra-role/tasks/create-s3.yml                                                                                                     
---
  - include_vars: "vars/main.yml"
    tags: create
  - name: creating s3

    s3_bucket:
      name: myansibles3bucket1234
      state: present
      region: "{{ region }}"
      versioning: yes
      tags:
        name: myansiblebucket
        type: example
    register: s3_url

  - name: Display s3 url
    debug: var=s3_url       

Let's create Ansible main playbook.
sudo vi aws-infra-role/main.yml
---
# This Playbook creates infra in aws cloud

- hosts: local
  connection: local
  gather_facts: False
  tags: ec2_create

  tasks:
  - include: tasks/create-sg.yml
  - include: tasks/create-ec2.yml
  - include: tasks/create-s3.yml 

now execute the ansible playbook by
ansible-playbook aws-infra-role/main.yml


If everything is good, you should see the new instance, S3 bucket created on AWS console. make sure you are able to connect to that instance.

That's it!! That is how you create a new EC2 instance using Ansible role in AWS cloud. 
Please watch steps in YouTube channel:

Monday, January 22, 2024

Errors during EC2 instance creating using Ansible playbook | Ansible playbook Execution Error during EC2 creation

No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV4Handler'] Check your credentials" 

If you are running into above issue when provisioning EC2 instance using Ansible playbook, please refer the fix below:


Fix:

Please refer the below page for the resolution with playbook.

https://www.coachdevops.com/2024/01/ansible-playbook-for-provisioning-new.html


Thursday, January 18, 2024

Ansible Playbook for provisioning a new EC2 in AWS | Create new EC2 instance in AWS cloud using Ansible Playbook

We will learn how to create a simple Ansible Playbook for provisioning a new EC2 instance in AWS cloud. Please follow the below steps in the machine where you have installed Ansible.

Pre-requisites:
Steps to create EC2 instance using Ansible:

Login to EC2 instance using Git bash or iTerm/putty where you installed Ansible. Execute the below command:

Create an Inventory file first

sudo mkdir /etc/ansible

Edit Ansible hosts or inventory file
sudo vi /etc/ansible/hosts

Add the below two lines in the end of the file:
[localhost]
local


cd ~
mkdir playbooks  
cd playbooks

Create Ansible playbook
sudo vi create-ec2.yml 
(copy the below content in green color)
edit the create-ec2.yml to make sure you update the key, AMI and region code which is red marked below:

- name: Ansible ec2 launch
  hosts: localhost
  connection: local
  gather_facts: False
  tags: provisioning

  vars:
    keypair: myNov2023Key
    instance_type: t2.small
    instance_name: test-ec2-instance
    image: ami-007855ac798b5175e
    wait: yes
    group: webserver
    region: us-east-1
    security_group: my-jenkins-security-grp1

  tasks:
  - name: configuring security group for the instance
    ec2_group:
        name: "{{ security_group }}"
        description: my-jenkins-security_group
        region: "{{ region }}"
        rules:
            - proto: tcp
              from_port: 22
              to_port: 22
              cidr_ip: 0.0.0.0/0
            - proto: tcp
              from_port: 80
              to_port: 80
              cidr_ip: 0.0.0.0/0
            - proto: tcp
              from_port: 8080
              to_port: 8080
              cidr_ip: 0.0.0.0/0
        rules_egress:
            - proto: all
              cidr_ip: 0.0.0.0/0
  - name: creating ec2 instance
    ec2_instance:
        security_group: "{{ security_group }}"
        name: "{{ instance_name }}"
        key_name: "{{ keypair }}"
        instance_type: "{{ instance_type}}"
        image_id: "{{ image }}"
        region: "{{ region }}"
        wait_timeout: 3

now execute the ansible playbook by
ansible-playbook create_ec2.yml




If everything is good, you should see the new instance created on AWS console. make sure you are able to connect to that instance.

That's it!! That is how you create a new EC2 instance using Ansible. 

Watch steps in YouTube channel:

How to Enable to use the classic editor to create a pipeline without YAML in Azure DevOps | Enable Classic Pipeline Option in Azure DevOps

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.


Watch Steps in YouTube channel:

Wednesday, January 17, 2024

Install Jenkins on Ubuntu 22.0.4 | Setup Jenkins on Linux instance | How to setup Jenkins in Ubuntu EC2 instance using Java 17?

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:
  •  at least memory should be t2.medium (4 GB RAM)
  • 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 \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null

Append debian package repo address to the system
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.

Unlock Jenkins
You may get screen, enter the below command in Git bash( Ubuntu console)
Get the initial password from the below file
sudo cat /var/lib/jenkins/secrets/initialAdminPassword


Copy the password and paste in the browser.
Then click on install suggested plug-ins. 
Also create user name and password.
enter everything as admin. at least user name as admin password as admin
Click on Save and Finish. Click on start using Jenkins. Now you should see a screen like below:


That's it. You have setup Jenkins successfully 😊Please watch the steps in our YouTube channel:

Monday, January 1, 2024

How to learn and master DevOps skills in five effective ways in 2024? | Five effective ways to learn and master DevOps skills in 2024

Learning DevOps involves a combination of theoretical knowledge and hands-on experience. Here are five effective ways to learn DevOps:


Sign up for DevOps Courses and Tutorials:

    • Platforms like www.coachdevops.com, Udemy, Pluralsight offer comprehensive DevOps courses. Look for courses that cover version control, CI/CD, containerization, infrastructure as code, and other key DevOps concepts. Many of these platforms provide hands-on labs and projects to reinforce your learning.

  1. Books and Documentation:

    • Read authoritative books on DevOps, such as "The Phoenix Project" by Gene Kim, Kevin Behr, and George Spafford or "Site Reliability Engineering" by Niall Richard Murphy and others. Additionally, explore documentation for popular DevOps tools like Jenkins, Docker, Kubernetes, and Terraform. These resources provide in-depth insights into best practices and real-world implementations.

  2. Hands-On Projects:

    • Learning by doing is crucial in DevOps. Work on real projects that involve setting up CI/CD pipelines, automating infrastructure, and deploying applications. GitHub is a valuable resource for finding open-source projects and contributing to them. Create your own projects to apply and reinforce your knowledge. You can also join the course offered by Coach AK.

  3. Networking and Community Involvement:

    • Join DevOps communities, forums, and social media groups. Participate in discussions, ask questions, and share your experiences. Attend local meetups, conferences, and webinars to connect with professionals in the field. Networking with others in the DevOps community can provide valuable insights, tips, and opportunities for collaboration.

  4. Certifications:

    • Consider pursuing certifications that validate your DevOps skills. Certifications such as AWS Certified DevOps Engineer, Docker Certified Associate, Terraform and Kubernetes certifications are widely recognized in the industry. While certifications alone may not make you an expert, they can provide a structured learning path and help you showcase your skills to employers.

How to configure Self-Hosted GitHub Actions Runner | How to install Self-Hosted GitHub Actions Runner | Configure EC2 instance as self-hosted runner in GitHub Actions

A self-hosted GitHub runner is a machine (physical or virtual) that you set up and manage to run GitHub Actions workflows.  A self-hosted ru...