Wednesday, February 28, 2018

Ansible playbook for Java Installation on Ubuntu | Install Java using Ansible Playbook

1. Login to Ansible management server/machine. Create SSH keys in Ansible host machine by executing the below command: (if you already have keys created, please skip this step)

enter three you will see keys successfully created.
2.  Execute the below command on Ansible management node and copy the public key content:
 sudo cat ~/.ssh/

copy the above output.
3. Now login to target node, execute the below command to open the file
 sudo vi /home/ubuntu/.ssh/authorized_keys
type shift A and then enter now 
    and paste the key in the above file. please do not delete any existing values in this file.

4. go back to ansible mgmt node, make sure you are able to ssh from ansible mgmt node after copying the keys above:
  ssh private_ip_of_target_node
now type exit to come out of the target node.
5. Now in ansible mgmt node, now make changes in /etc/ansible/hosts file to include the node you will be installing software. Make sure you add public IP address as highlighted below in red color:
   sudo vi /etc/ansible/hosts
xx.xx.xx.xx ansible_ssh_user=ubuntu ansible_ssh_private_key_file=~/.ssh/id_rsa  ansible_python_interpreter=/usr/bin/python3

6. make changes in playbooks as given below,
cd ~/playbooks

sudo vi installJava.yml

- hosts: My_Group

  - name: Update APT package manager repositories cache
    become: true
      update_cache: yes

  - name: Install OpenJDK Java
    become: yes
      name: "{{ item }}"
      state: present

7. Execute Ansible playbook
ansible-playbook installJava.yml

now after successfully executing, enter below command to make sure Java is installed in target node:

java -version


If you have issues in installing Java on target node, please do the following on target node to install python modules:

sudo apt-get update
sudo apt-get install python-software-properties

No package matching “python-software-properties” Error in Ansible provisioning

Do the below on target node..

sudo apt-get update
sudo apt-get install python-software-properties

Sunday, February 25, 2018

How to change default interval time in Puppet agent?

Let's say you would like to change to 2 minutes instead of 30 minutes which is default time.
sudo vi /etc/puppetlabs/puppet/puppet.conf

runinterval = 120

Wednesday, February 21, 2018

How to Enable Docker Remote API on Ubuntu 16.04?

Please find below steps for enabling Docker Remote API on Ubuntu 16.0.4. You would need Docker API in order to access Docker containers running on the Docker Host. You can enable by modifying the /lib/systemd/system/docker.service.


port 4243 opened in security firewall

1. sudo vi /lib/systemd/system/docker.service
Look for the text that says

ExecStart=/usr/bin/dockerd -H fd:// 

Now append like below:

ExecStart=/usr/bin/dockerd -H fd:// -H tcp://

save the file and exit.

Now update the configuration in order for Docker daemon to take the changes effect.
systemctl daemon-reload

Restart Docker service
sudo service docker restart

Now test whether Docker API is accessible

curl http://localhost:4243/version

You will see below output:


Tuesday, February 20, 2018

Return code is: 401, ReasonPhrase: Unauthorized. Nexus Error

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project MyWebApp: Failed to deploy artifacts: Could not transfer artifact com.mkyong:MyWebApp:war from/to maven-snapshots (http://1ip_address:8081/repository/maven-snapshots/): Failed to transfer file: http://address:8081/repository/maven-snapshots/com/mkyong/MyWebApp/1.0-SNAPSHOT/MyWebApp-1.0-20180220.175544-1.war. Return code is: 401, ReasonPhrase: Unauthorized.

you may have this issue when you try to upload artifacts into Nexus from using Maven.

Here is possible fix:

Make sure you have the below entry outside comment, it should not be in between <!-- -->


Monday, February 19, 2018

How to connect to an EC2 instance from your local machine after creating EC2 in AWS? | Connect to AWS EC2 instance from your local machine

Let's learn how to connect to an EC2 instance running in AWS from your local machine. Your local machine can be Windows laptop or MacBook laptop.


1. Keys(for e.g., yourkey.pem) already downloaded in your local machine, preferably in Downloads folder.
2. EC2 instance is up and running
3. For windows laptop, you need to install Git by downloading from this URL - For Apple laptop you need to download iTerm from here.

Steps to connect to your EC2 instance:

1. Go to AWS console.
2. Click on EC2, click on running instances link

3. Select the checkbox of EC2 you would like to connect to.
4. Click on Connect or Action, Connect. Under SSH client.
Copy the url from SSH which looks like below:
For e.g.
ssh -i "mykey.pem"

Watch steps in YouTube channel:

Windows Laptop instructions
5. Go to your local machine, Open Git Bash in Windows

make sure you are in downloads directory where your keys got downloaded. Type the below commands:

type below commands: 
this should tell you which directory you are and then navigate to downloads dir.

cd  ~/downloads 

Now copy the value from Example in the above screen

ssh -i "mykey.pem"
and then type enter, say yes and enter

Mac Book Laptop or iMac Instructions

Open iTerm window, type the below command to go to downloads directory.
cd downloads

For few Mac laptops, it may add .txt in the end of pem file. in that case you need to remove .txt in the end

and then execute below command to make sure the keys have only read permissions.

chmod 400 *.pem

6. Paste the url from example highlighted above in step # 4.
ssh -i "mykey.pem"
7. type yes when it is asking to connect.
8. now you should be in AWS cloud, screen should show something like this, It means you are successfully connected to EC2 instance running on AWS cloud. It will also show private IP address of your EC2 instance.


Wednesday, February 14, 2018

How to enable SonarQube Scanner for PL/SQL files? - Code quality check for SQL files using SonarQube - Scan sql code using Sonar

If you would like to enable scanning for PL/SQL files in SonarQube, there are both commercial and open source plug-ins available. Lets see how to enable open source plug-in for SonarQube. Useful information is below:

SonarQube is already set up and running.

Steps: (Execute this step on SonarQube instance)

1. navigate to folder where you installed SonarQube:
cd /opt/sonarqube/lib/extensions
2. Download the plsql opensource plug-in from the above websites by executing below command:
sudo wget
3. Stop the Sonarqube scanner.
sudo systemctl stop sonar
4. Start the Sonarqube scanner.
 sudo systemctl start sonar
5. Make sure Sonarqube is up and running
sudo systemctl status sonar

once started, you should see below message
sonar.service - SonarQube service
Loaded: loaded (/etc/systemd/system/sonar.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2018-02-15 01:36:23 UTC;
6. If you don't see server is not starting, you might want to check the logs by executing:
cat /opt/sonarqube/logs/web.log 
7. Now login to SonarQube, Navigate to Quality Profiles section, you should see PL/SQL rules added.
You can watch the above steps in my TouYube video as well:

Tuesday, February 6, 2018

How to connect to Bitbucket or Github using SSH url/private keys from Jenkins?

It is a good practice to use SSH url in Jenkins jobs when configuring free style jobs. See below for the steps:

1. Go Jenkins. Click on your freestyle job, click on configure
2. Go to source code management, click on Git
3. Enter SSH url of your repository as repo url. you can get SSH url by going into bitbucket.
4. Under credentials, Click on Add, Jenkins.
5. Choose SSH username with private key
6. Enter username as ubuntu for Ubuntu. otherwise enter correct username.
7. check the enter directly under private key option
8. Copy and paste private key(not public key) of your from Jenkins instance. command is below:
sudo cat ~/.ssh/id_rsa

copy the content of whole output from above command.
9. now choose the username(ubuntu) from the drop down.
10. run the build in Jenkins. Make sure there is no error.

That's it. This is how you use SSH url and private keys to checkout code from bitbucket or Github without entering username/password in Jenkins.

Friday, February 2, 2018

How to create CICD pipelines or build definitions in VSTS - Create CICD Pipelines using Azure DevOps

How to configure CI/build pipeline in VSTS?
Lets us see the steps for creating CICD pipeline using VSTS or Azure DevOps.
Login to VSTS, choose project dashboard.
Go to Pipelines
Click on builds.

Click on new Build pipelines

Choose Bitbucket as a source

Click on  Change, New service connection. Click on username and password.
enter bitbucket user name and password. Click on Authorize.

Choose the repository. Click Continue.

Now choose a template by entering Java in the search textbook.

Select “Azure Web App for Java” template, Click Apply.
Now click on Agent queue, select Hosted.
Click on get sources. Select Git repo, branch as master. 
Click on Maven pom.xml task and select the maven pom.xml by clicking on three dots …make sure you change to MyWebApp/pom.xml
goal should be clean install
Leave the default value in copy files to staging folder
Leave the default value in publish artifact :drop
Click on Stop azure web app
Enter Azure subscription.

Select Free trial subscription from the drop down.
Click on authorize

Create App service on Azure portal
Now to login
click on App services

Click on + Add
Click on Web App.
Enter App service name(it should be unique)
Create a new resource group(for first time if you create an app service, otherwise you can use existing group name)

Select azure free subscription

Leave the rest default click save/create

Save and try to access the app service url by going to overview section of app service.

After you see the app service home page, come back to VSTS
Choose the app service name from the drop down.
Do the same thing Deploy Azure WebApp and Start Azure Web App task.
Now click on Triggers to enable Continuous integration enabled so it builds for every check-in.

Click on Save & Queue to kick start the build.

How to set up SSH keys in Azure Repos | Setup SSH keys and Java Web App in Repos in Azure DevOps

How to set up SSH keys in Azure Repos and Setup WebApp in Azure Repo

Go to your visual studio home page. You should be able to go by clicking on the below URL.

Create a new project by clicking on New project and enter project details like below. This will create a project dashboard.

Once project is created, Click on Repos.

 Click on initialize link to add README.

Click on clone link on the top right hand side.
Click on SSH link
Click Manage SSH keys

Click Add

Go to any virtual machine you had setup that has both Java and Maven installed. If you would like to know how to create a Virtual Machine in Azure Cloud, click here to do so.

Create the SSH keys by executing the below command:
(If you already have keys generated, you can overwrite it or skip to next step to copy keys)

execute the below command to copy the keys:

cat ~/.ssh/

Add the public keys.
Once keys added into Azure DevOps, go to Repos, copy the SSH clone url

Go to your machine where you have installed Java, Maven, preferably your EC2. Execute this command:
git clone <ssh_url>

This should download the empty repo from Azure DevOps to local machine(or ec2).
now after cloning, it will create a folder with repo name..


ls -al to see the folder name after you cloned.

go inside that folder by
cd reponame

Now create the maven project executing the below command:
mvn archetype:generate -DartifactId=MyAwesomeApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

type git status --> to see the newly created project
git add *
git status

git commit -m "my first project check-in to Azure Repos"
git push

Now go to Azure DevOps, Select the Repos —> Files —> you should see the project uploaded here.

Thursday, February 1, 2018

Region does not seem to be available error for AWS module boto.ec2

When you have this error, there is a good chance that your boto version is outdated. You will have to update the boto version by executing the below command:

pip install boto

This will install latest version of Boto framework which is 2.48.0. 

you can confirm by executing the below command:
pip list boto | grep boto

boto (2.48.0)
boto3 (1.5.22)
botocore (1.8.36)