Thursday, January 31, 2019

How to install Terraform on Ubuntu 16.0.4 - TerraForm Installation Steps on Ubuntu 16.0.4

Please find steps for installing Terraform for the session. You can install this on any of your existing Ubuntu EC2 instance.

Terraform is used for provisioning infrastructure on Cloud. you don't need to create manually any resource in AWS.

Create a working directory
sudo mkdir -p /opt/terraform
cd /opt/terraform

Download Terraform from Hasicorp website
sudo wget https://releases.hashicorp.com/terraform/0.12.23/terraform_0.12.23_linux_amd64.zip

sudo apt-get install unzip -y

Unzip Terraform Zip file

sudo unzip terraform_0.12.23_linux_amd64.zip

Add terraform to PATH

sudo vi ~/.bashrc
   add below entry in the last line 
   export PATH="/opt/terraform:$PATH"

source ~/.bashrc

terraform -version

    this should show version of Terraform.

    Terraform v0.12.23

Tuesday, January 29, 2019

How to Install GitLab on Ubuntu? Setup GitLab on Ubuntu 16.0.4

GitLab is open source, simple version control system. GitLab also have new CICD capabilities to automate your workflow. You can easily setup GitLab on Ubuntu. Please find below steps for installing GitLab on Ubuntu.

Install and configure the necessary dependencies

sudo apt-get update
sudo apt-get install -y curl openssh-server ca-certificates

Add the GitLab package repository and install the package

sudo apt-get install -y postfix
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash
sudo EXTERNAL_URL="http://your_public_dns_Ec2" apt-get install gitlab-ee

Browse the host name login
http://your_public_dns_Ec2

This should show GitLab home page

Thursday, January 24, 2019

Install Maven using Ansible playbook on Ubuntu - Install Maven on Ubuntu using Ansible playbook

Playbook for installing Maven on Ubuntu using Ansible Playbook

sudo vi installMaven.yml
---
- hosts: My_Group
  tasks:
    - name: Install Maven using Ansible
      become: yes
      apt:
        name: "{{ packages }}"
        state: present
      vars:
        packages:
           - maven

sudo ansible-playbook installMaven.yml


This is the execution result of Ansible playbook.

Sunday, January 20, 2019

Puppet code to provision an EC2 instance on AWS cloud - How to provision EC2 instance on AWS cloud using Puppet


Here below is the puppet code to provision an EC2 instance on AWS cloud.

create-ec2-instance.pp
 ec2_instance { 'My EC2 instance':
    ensure              => present,
    region              => 'us-east-2',
    image_id            => 'ami-916f59f4',
    instance_type       => 't2.micro',
    security_groups     => ['mySecurityGroup'],
    subnet              => 'subnet-aff937d5',
    key_name            => 'my2019EC2Key',

  }

ec2_securitygroup { 'mySecurityGroup':
  region      => 'us-east-2',
  ensure      => present,
  description => 'Security group for aws advent',
ingress     => [{
    protocol => 'tcp',
    port     => 8080,
    cidr     => '0.0.0.0/0',
  },{
    protocol => 'tcp',
    port     => 80,
    cidr     => '0.0.0.0/0',
  },{
    protocol => 'tcp',
    port     => 22,
    cidr     => '0.0.0.0/0',
 }],
  tags        => {
    tag_name  => 'mySecurityGroup',
},
}

And then execute the below command to create EC2 instance.
  sudo /opt/puppetlabs/bin/puppet apply create-ec2.pp

Make sure you have access keys and secret keys downloaded from AWS.

sudo vi ~/.aws/credentials
[default]
aws_access_key_id = ?
aws_secret_access_key = ?

How to add SSH keys into Bitbucket from your machine? - Create SSH keys and upload into BitBucket

Let us see how to create SSH keys in your machine and upload into Bitbucket so that you can start checking code into Bitbucket.

Pre-requistes: 

Git installed on your machine by downloading from the below URL:
https://git-scm.com/downloads

Steps:
1. First create SSH keys by entering the below command.
ssh-keygen 
(and then simply enter four times, do not give any password)

2. the above command should create two keys - public keys and private keys.
copy the content of public key executing below command in Gitbash.
 
sudo cat ~/.ssh/id_rsa.pub

3. Now go to bitbuket.org
4. now click on your avatar (left bottom of the screen, and BitBucket settings-> security--> ssh keys
5. go to click on Add key,  and paste the content of public key. give some name as mySSH key. click on Add key.
6. Now click on repo you would like to check in or make code changes. Click on Clone and copy the SSH url. Do not select HTTPS Url. The url will be from your repo you created under Clone link.  

git clone <ssh_url_from_bitbucket_repo_you_created>  

7. That should create a folder in your machine. type ls -al
8. cd into repo name
9. Make code changes now

 

Wednesday, January 16, 2019

How to destroy a specific resource using Terraform - Destroy specific resource using Terraform

If you would like to destroy all the resources you had created using Terraform, all you have to do is perform the below command:
 
terraform destroy
 
The above command will destroy all the resources. 
 
But let's say you would like to destroy only a specific resource you have created using Terraform. You can do it by passing a an argument in terraform destroy command. if you would like to delete EC2 instance, you can mention like below:

Destroy specific resources
terraform destroy -target aws_instance.myInstanceName

if you would like to delete a security group, you can mention like below:
terraform destroy -target aws_security_group.security_group_name
 
Please watch in YouTube on how to do the above steps:


Friday, January 11, 2019

Ansible Playbook to install Java 8 on Ubuntu - How to install Java 8 using Ansible Playbook


Find below Ansible playbook to install Java 8 on Ubuntu

Step 1: Create the playbook first with name. for e.g, installJava.xml

---
- hosts: Java_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

2. sudo vi /etc/ansible/hosts
make sure you add below entry with target node IP changed (in red color).
[Java_Group]  
xx.xx.xx.xx ansible_ssh_user=ubuntu ansible_ssh_private_key_file=~
/.ssh/id_rsa  ansible_python_interpreter=/usr/bin/python3

3. sudo ansible-playbook installJava.xml

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

java -version

Click here to learn how to create more playbooks in Ansible for installing Maven and Jenkins.