Sunday 27 March 2022

Install Java with Apt on Ubuntu 20.04


sudo apt update

java -version

Command 'java' not found, but can be installed with:

sudo apt install default-jre              # version 2:1.11-72, or

sudo apt install openjdk-11-jre-headless  # version 11.0.14+9-0ubuntu2~20.04

sudo apt install openjdk-16-jre-headless  # version 16.0.1+9-1~20.04

sudo apt install openjdk-17-jre-headless  # version 17.0.2+8-1~20.04

sudo apt install openjdk-8-jre-headless   # version 8u312-b07-0ubuntu1~20.04

sudo apt install openjdk-13-jre-headless  # version 13.0.7+5-0ubuntu1~20.04


sudo apt install default-jre

<...>

java -version

openjdk version "11.0.14" 2022-01-18

OpenJDK Runtime Environment (build 11.0.14+9-Ubuntu-0ubuntu2.20.04)

OpenJDK 64-Bit Server VM (build 11.0.14+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)


sudo apt install default-jdk

<...>

javac -version

javac 11.0.14


Tuesday 22 March 2022

Install Docker on Ubuntu 20.04


sudo apt update

sudo apt-get install ca-certificates curl gnupg lsb-release


sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg


 sudo echo  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

sudo docker --version

Docker version 20.10.13, build a224086


sudo systemctl status docker

● docker.service - Docker Application Container Engine

     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)

     Active: active (running) since Tue 2022-03-22 16:21:57 PDT; 2min 37s ago

...


#check Docker is working correctly

sudo docker run hello-world

#list complete list of available subcommands

docker

#for more information on a command

docker COMMAND --help


#view system-wide information

sudo docker info

#crawl Docker Hub and return a listing of all images 

sudo docker search ubuntu

#see the images that have been downloaded

sudo docker images


#view the active containers

sudo docker ps

#view all containers — active and inactive

sudo docker ps -a

#view the latest container

sudo docker ps -l


#start container with the ID/NAME

sudo docker start container_ID/container_NAME

#stop container with the ID/NAME

sudo docker stop container_ID/container_NAME

#delete container

sudo docker rm container_ID/container_NAME

Ref: docs.docker.com


Thursday 17 March 2022

Ansible Vault Simple Examples


#encrypt a file

ansible-vault encrypt file_name

New Vault password:

Confirm New Vault password:

Encryption successful


#view encrypted files

ansible-vault view file_name

Vault password:


#edit encrypted files

ansible-vault edit file_name

Vault password:


#change password of encrypted files

ansible-vault rekey --ask-vault-pass file_name

Vault password:

New Vault password:

Confirm New Vault password:

Rekey successful


#decrypt files

ansible-vault decrypt --ask-vault-pass file_name

Vault password:

Decryption successful


#use vault password file

echo "password" > password_file

ansible-vault encrypt file_name --vault-password-file=password_file

Encryption successful


TASK [Deploy tomcat config] fatal: [localhost]: FAILED! => {"msg": "an error occurred while trying to read the file '/path/to/file_name': [Errno 13] Permission denied: b'/path/to/file_name'.

 

Issue

TASK [Deploy tomcat config] *****************************************************************************************************************************************************************

fatal: [localhost]: FAILED! => {"msg": "an error occurred while trying to read the file '/path/to/file_name': [Errno 13] Permission denied: b'/path/to/file_name'. [Errno 13] Permission denied: b'/path/to/file_name'"}


Troubleshoot

809755 -rw-r-----  1 root   root   7598 Mar 16 18:33 file_name

sudo chown -R user:user file_name

809755 -rw-r-----  1 user user 7598 Mar 16 18:33 file_name


Wednesday 16 March 2022

Ansible ping: Check connectivity status of target remote hosts


mkdir ansible

cd ansible


vim inventory.ini

[webservers]

IP


[all:vars]

ansible_connection=ssh

ansible_user=user_name

ansible_ssh_pass=password

ansible_port=42006

ansible_ssh_common_args='-o StrictHostKeyChecking=no'


#ansible -m ping -i inventory.ini all

ansible -m ping -i inventory.ini webservers

localhost | SUCCESS => {

    "ansible_facts": {

        "discovered_interpreter_python": "/usr/bin/python3"

    },

    "changed": false,

    "ping": "pong"

}


Check connectivity between ansible and the target.

ping module checks connectivity using inventory file.

the group can be specified in the inventory file.


ansible all -m ping -v

#Using /etc/ansible/ansible.cfg as config file

localhost | SUCCESS => {

    "ansible_facts": {

        "discovered_interpreter_python": "/usr/bin/python3"

    },

    "changed": false,

    "ping": "pong"

}


ansible webservers -m ping


#to check connectivity manually

ssh -p 42006 username@IP


#check ssh port

sudo netstat -tnlup | grep ssh

tcp        0      0 0.0.0.0:42006           0.0.0.0:*               LISTEN      1006/sshd: /usr/sbi 

tcp6       0      0 :::42006                :::*                    LISTEN      1006/sshd: /usr/sbi


| UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host localhost port 22: Connection refused",


 Issue


ansible -m ping -i inventory.ini webservers

localhost | UNREACHABLE! => {

    "changed": false,

    "msg": "Failed to connect to the host via ssh: ssh: connect to host localhost port 22: Connection refused",

    "unreachable": true

}


Troubleshoot


#specify port number

ansible_port=42006


| UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: Invalid multiplex command.", "unreachable": true


Issue


ansible -m ping -i inventory.ini webservers

localhost | UNREACHABLE! => {

    "changed": false,

    "msg": "Failed to connect to the host via ssh: Invalid multiplex command.",

    "unreachable": true

}


Troubleshoot


vim devops.ini

ansible_ssh_common_args='-O StrictHostKeyChecking=no'

#change to

ansible_ssh_common_args='-o StrictHostKeyChecking=no'


Result


ansible -m ping -i devops.ini webservers

localhost | SUCCESS => {

    "ansible_facts": {

        "discovered_interpreter_python": "/usr/bin/python3"

    },

    "changed": false,

    "ping": "pong"

}


Monday 14 March 2022

ansible-playbook fatal: [localhost]: FAILED! => {"changed": false, "msg": "Unable to start service nginx: Job for nginx.service failed because the control process exited with error code.

 

Issue


ansible-playbook demo_playbook.yml -i demo_ansible.ini --user=user-name --extra-vars "ansible_sudo_pass=password"


PLAY [This demo playbook] *******************************************************************************************************************************************************************


TASK [Gathering Facts] **********************************************************************************************************************************************************************

ok: [localhost]


TASK [This is to install nginx software] ****************************************************************************************************************************************************

changed: [localhost]


TASK [This is restart the nginx service] ****************************************************************************************************************************************************

fatal: [localhost]: FAILED! => {"changed": false, "msg": "Unable to start service nginx: Job for nginx.service failed because the control process exited with error code.\nSee \"systemctl status nginx.service\" and \"journalctl -xe\" for details.\n"}


PLAY RECAP **********************************************************************************************************************************************************************************

localhost                  : ok=2    changed=1    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0


systemctl status nginx.service

● nginx.service - A high performance web server and a reverse proxy server

     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)

     Active: failed (Result: exit-code) since Sun 2022-03-13 05:03:15 PDT; 2min 13s ago

       Docs: man:nginx(8)

    Process: 9296 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)

    Process: 9297 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)


Mar 13 05:03:13 ubuntu nginx[9297]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

Mar 13 05:03:13 ubuntu nginx[9297]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)

Mar 13 05:03:14 ubuntu nginx[9297]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

Mar 13 05:03:14 ubuntu nginx[9297]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)

Mar 13 05:03:14 ubuntu nginx[9297]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

Mar 13 05:03:14 ubuntu nginx[9297]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)

Mar 13 05:03:15 ubuntu nginx[9297]: nginx: [emerg] still could not bind()

Mar 13 05:03:15 ubuntu systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE

Mar 13 05:03:15 ubuntu systemd[1]: nginx.service: Failed with result 'exit-code'.

Mar 13 05:03:15 ubuntu systemd[1]: Failed to start A high performance web server and a reverse proxy server.


cat /var/log/nginx/error.log

2022/03/13 05:03:12 [emerg] 9297#9297: bind() to 0.0.0.0:80 failed (98: Address already in use)

2022/03/13 05:03:12 [emerg] 9297#9297: bind() to [::]:80 failed (98: Address already in use)

2022/03/13 05:03:12 [emerg] 9297#9297: bind() to 0.0.0.0:80 failed (98: Address already in use)

2022/03/13 05:03:12 [emerg] 9297#9297: bind() to [::]:80 failed (98: Address already in use)

2022/03/13 05:03:12 [emerg] 9297#9297: bind() to 0.0.0.0:80 failed (98: Address already in use)

2022/03/13 05:03:12 [emerg] 9297#9297: bind() to [::]:80 failed (98: Address already in use)

2022/03/13 05:03:12 [emerg] 9297#9297: bind() to 0.0.0.0:80 failed (98: Address already in use)

2022/03/13 05:03:12 [emerg] 9297#9297: bind() to [::]:80 failed (98: Address already in use)

2022/03/13 05:03:12 [emerg] 9297#9297: bind() to 0.0.0.0:80 failed (98: Address already in use)

2022/03/13 05:03:12 [emerg] 9297#9297: bind() to [::]:80 failed (98: Address already in use)

2022/03/13 05:03:12 [emerg] 9297#9297: still could not bind()


Troubleshoot


vim /etc/nginx/sites-enabled/default

server {

        listen 80 default_server;

        listen [::]:80 default_server;

#change to

server {

        listen 5601 default_server;

        listen [::]:5601 default_server;


ansible-playbook fatal: [localhost]: FAILED! => {"msg": "Missing sudo password"}


 Issue

ansible-playbook demo_playbook.yml -i inventory.ini

PLAY [This demo playbook] *******************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************

fatal: [localhost]: FAILED! => {"msg": "Missing sudo password"}

PLAY RECAP **********************************************************************************************************************************************************************************

localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0


Troubleshoot 

#execute from command line
ansible-playbook demo_playbook.yml -i demo.ini --user=user_name --extra-vars "ansible_sudo_pass=password"

OR

#add the following line in inventory.ini
[all:vars]
ansible_sudo_pass="password"

ansible-playbook RequestsDependencyWarning: urllib3 (1.26.8) or chardet (3.0.4) doesn't match a supported version


Issue


ubuntu@ubuntu:~/ansible-work$ ansible-playbook demo_playbook.yml -i ansible.ini

/usr/lib/python3/dist-packages/requests/__init__.py:89: RequestsDependencyWarning: urllib3 (1.26.8) or chardet (3.0.4) doesn't match a supported version!

  warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "


PLAY [This demo playbook] *******************************************************************************************************************************************************************


Troubleshoot

pip3 install --upgrade requests


Installation of Terraform using zip file on Ubuntu 20.04


wget https://releases.hashicorp.com/terraform/1.1.7/terraform_1.1.7_linux_amd64.zip

unzip terraform_1.1.7_linux_amd64.zip

mv terraform /usr/local/bin/


which terraform

/usr/local/bin/terraform


terraform -version

Terraform v1.1.7

on linux_amd64

+ provider registry.terraform.io/hashicorp/aws v4.5.0


Friday 11 March 2022

Downloading ChromeDriver, Selenium TestNG Installation and Integration in Eclipse


Tools required: Selenium, ChromeDriver

Pre-requisites: Ubuntu, Java, Eclipse


Downloading ChromeDriver


Chrome ➡ Settings ➡ about chrome ➡ version

Version 99.0.4844.51 (Official Build) (64-bit)

chromedriver.chromium.org

OR

wget https://chromedriver.storage.googleapis.com/99.0.4844.51/chromedriver_linux64.zip

unzip chromedriver_linux64.zip


Selenium Installation


locate selenium

# for locate, sudo apt install mlocate

sudo pip install selenium

OR

Download the Latest stable version from selenium.dev


Integrating Selenium to Eclipse


Open the Eclipse. Create a new Java project. 

Right-click on the project and create a package. 

Create a new class inside the package.

Configure the build path by right-clicking on the created project.

Java  Build Path ➡ Libraries(select class) ➡ Add External JARs(Add Selenium JAR) ➡ 

Apply and Close

See the referenced .jar files in the project to confirm.


Install TestNG


wget http://www.java2s.com/Code/JarDownload/testng/testng-6.8.7.jar.zip

unzip testng-6.8.7.jar.zip


Setting up TestNG in Eclipse


Configure the build path by right-clicking on the created project.

Java  Build Path ➡ Libraries(select class) ➡ Add External JARs(Add Selenium JAR) ➡ 

Apply and Close

See the referenced .jar files in the project to confirm.

Eclipse ➡ Help ➡ Eclipse Marketplace… ➡ Search(testng) ➡ Go ➡ TestNG for Eclipse ➡ Install ➡ TestNG (required) ➡ confirm ➡ I accept the terms of the license agreement ➡ Finish.


Tuesday 8 March 2022

Jenkins: Remote Triggering of a Parameterized Build


Configure a parameterized build in Jenkins


#Install Plugin - Build With parameters

Jenkins ➡ Manage Jenkins ➡ Manage Plugins ➡ Available ➡ Build With Parameters

Jenkins ➡ New Item ➡ Enter an item name ➡ [ParameterizedDemo] ➡ Freestyle project ➡ OK

General ➡ This project is parameterized ➡ String parameter

Name

my_param

Default Value

Hello


Build Triggers ➡ Trigger builds remotely ➡ 

Authentication Token

Token_987


Build ➡ dd build step ➡ Execute shell

Command

echo $my_param

Apply-Save


Triggering a parameterized build remotely


#Open the terminal

#curl -X GET <YourJenkinsJobUrl>/buildWithParameters?token=TOKEN_NAME

curl -X GET http://localhost:8080/job/ParameterizedDemo/buildWithParameters?token=Token_987


#Open the job in the Jenkins UI

Build with Parameters ➡ Build ➡ Build history ➡ Console Output


Console Output


Started by user admin

Running as SYSTEM

Building in workspace /var/lib/jenkins/workspace/ParameterizedDemo

[ParameterizedDemo] $ /bin/sh -xe /tmp/jenkins17901601731840577267.sh

+ echo Hello

Hello

Finished: SUCCESS


Install Ant plugin and integrate it with Jenkins


Tools: Git, GitHub, and Jenkins


1. Create a GitHub repository 

Create a new repository ➡ Repository Name ➡ Public ➡ Add a README file ➡ create repository

Code ➡ HTTPS ➡ https://<url> ➡ copy


2. Add build.xml file to the repository

#open terminal

git clone https://<url>

cd Demo-Ant/

vim build.xml

<?xml version="1.0"?>

<project name="Hello World Project" default="info">

<target name="info">

<echo> Hello World - Demo Ant</echo>

</target>

</project>


git init

git add build.xml

git commit -m "Add build file"

git remote -v

git push -u origin main


3. Set the Global Tool Configuration


Jenkins ➡ Manage Jenkins ➡ Global Tool Configuration


Ant-

Ant installations  

Add Ant

Ant

Name

[FirstAnt]

Install automatically

Install from Apache

Version

List of Ant installations on this system

Apply ➡ Save


4. Integrate Ant with Jenkins

Jenkins ➡ New Item ➡ Enter an item name ➡ Freestyle project ➡ OK

Source Code Management ➡ Git ➡ Repository URL[https://<url>] ➡ Branch Specifier[*/main]

Build ➡ Add build step ➡ Invoke Ant ➡ Ant Version[FirstAnt]

Apply ➡ Save


Build Now ➡ Build History ➡ Console Output


Monday 7 March 2022

How To Install Ansible on Ubuntu 20.04

 

sudo apt install -f

#find dependencies


sudo apt install software-properties-common

#update package repositories and get the latest package information


sudo apt-add-repository ppa:ansible/ansible

#list of available software and install ansible

#It also pulls down Ansible PPA's signing key and adds it to the system


sudo apt update

sudo apt install ansible

ansible --version

ansible [core 2.12.2]

  config file = /etc/ansible/ansible.cfg

  configured module search path = ['/home/ubuntu/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']

  ansible python module location = /usr/lib/python3/dist-packages/ansible

  ansible collection location = /home/ubuntu/.ansible/collections:/usr/share/ansible/collections

  executable location = /usr/bin/ansible

  python version = 3.8.10 (default, Nov 26 2021, 20:14:08) [GCC 9.3.0]

  jinja version = 2.10.1

  libyaml = True



Sunday 6 March 2022

Get Absolute Path of a File in Linux


readlink -f filename

realpath filename

ls "`pwd`/filename"


echo $(pwd)/filename

echo $(pwd)$/$(ls filename)

find $PWD -type f -name filename


locate filename

find $PWD -type f | grep "filename"


Friday 4 March 2022

Reset Jenkins Admin Password


 sudo vi /var/lib/jenkins/config.xml


 <useSecurity>true</useSecurity>

#modify to

 <useSecurity>false</useSecurity>


 sudo systemctl restart jenkins


Navigate to the web console

Notice that you were not prompted for a username or password


do the following.


Click on People on the left-hand navigation menu.

Click on the Admin

Delete the user account


Navigate to Manage Jenkins

Click on Configure Global Security

Under Security Realm, select Jenkins’ own user database


In the Authorization section, select Logged-in users can do anything

Unselect Allow anonymous read access

Save changes


It will redirect to a page where a new Admin user can be created


#try by specifying the right path

http://localhost:8080/securityRealm/firstUser


#not working? repeat the above steps after the following

sudo mv /var/lib/jenkins/users/* /tmp/jenkins


Ref: - serverlab.ca


Thursday 3 March 2022

Install Eclipse IDE on Ubuntu 20.04

 

sudo apt update

sudo apt install default-jre

java --version

wget https://mirrors.ustc.edu.cn/eclipse/oomph/epp/2021-12/R/eclipse-inst-linux64.tar.gz

sudo tar -xf eclipse-inst-linux64.tar.gz -C /opt

ls /opt/eclipse-installer/ -1

cd /opt/eclipse-installer/

./eclipse-inst

choose your favorite package IDE.


Eclipse can be downloaded via eclipse.org

Ref:- inoxide.com


install Google Chrome in Ubuntu 20.04 LTS


sudo apt update

sudo apt upgrade

wget --version

#if not get wget

sudo apt install wget


#download and install

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

ls google-chrome-stable_current_amd64.deb

sudo dpkg -i google-chrome-stable_current_amd64.deb


#launch chrome in terminal

google-chrome


Ref:- linuxways.net