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)
ssh-keygen 

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

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
[My_Group]  
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

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

  - name: Install OpenJDK Java
    become: yes
    apt:
      name: "{{ item }}"
      state: present
    with_items:
     openjdk-8-jdk

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

Note:

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.

Pre-requistes:

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://0.0.0.0:4243

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:

{"Platform":{"Name":""},"Components":[{"Name":"Engine","Version":"17.12.0-ce","Details":{"ApiVersion":"1.35","Arch":"amd64","BuildTime":"2017-12-27T20:09:53.000000000+00:00","Experimental":"false","GitCommit":"c97c6d6","GoVersion":"go1.9.2","KernelVersion":"4.4.0-1049-aws","MinAPIVersion":"1.12","Os":"linux"}}],"Version":"17.12.0-ce","ApiVersion":"1.35","MinAPIVersion":"1.12","GitCommit":"c97c6d6","GoVersion":"go1.9.2","Os":"linux","Arch":"amd64","KernelVersion":"4.4.0-1049-aws","BuildTime":"2017-12-27T20:09:53.000000000+00:00"}

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 <!-- -->

  <server>
         <id>maven-snapshots</id>
         <username>admin</username>
         <password>admin123</password>
  </server>
  <server>
         <id>maven-releases</id>
         <username>admin</username>
         <password>admin123</password>
  </server>

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.




Pre-requisites:

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 - https://git-scm.com/downloads. 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" ubuntu@dns_name.compute.amazonaws.com

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: 
pwd
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" ubuntu@dns_name.compute.amazonaws.com
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


pwd
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" ubuntu@dns_name.compute.amazonaws.com
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.