Friday, April 17, 2020

Install Ant in Ubuntu 16.04/18.04/20.04 Machine

APACHE ANT
  • ANT stands for another neat tools
  • It is java based build tool from Apache Software Fundation
  • Ant uses build.xml file 
  • Ant was created by james duncan davidson
Ant- Build Files:
  • Ants build file is called build.xml should reside in base directory(base directory means where the source code will maintained) of the project
  • In build.xml or any xml file it start with an xml tag project name and target a single project can have multiple targets
  • There should be no blank lines or white spaces before the xml declaration

Installation: 

    We can install ANT in different ways, those are 1. Using "apt" command module
                                                                                 2. Using "distribution method"

Here, we will see both the ways how to install ANT.

Prerequisites: 

Java should be install in the server.

Step 1: Update the Server 

$ sudo apt update -y 
Step 2: Install Java latest version, basically this command will install JAVA Runtime Environment
$ sudo apt install default-jre
Install Apache ANT in Ubuntu using "apt" command module
Step 3:  Update the Server Install Ant
$ sudo apt update 
$ sudo apt install ant -y
To verify the Ant installation
$ ant -version
Install Apache Ant Using "Distribution Method"
Step 1: Enter into the "opt" directory
cd /opt/
Step 2:  Download the tar or zap source file from http://ant.apache.org/bindownload.cgi
$ sudo wget http://mirrors.estointernet.in/apache//ant/binaries/apache-ant-1.10.5-bin.zip
Step 3:  Exatract the zip file or tar file
unzip apache-ant-1.10.5-bin.zip
Step 4: Add the ANT_HOME path.
$ sudo ANT_HOME=/opt/apache-ant-1.10.5
Step 5:  Now export the PATH
$ sudo PATH=$PATH:${ANT_HOME}/bin
Step 6: Now enter into the apache-ant-1.10.5
cd apache-ant-1.10.5
Step 7:  Now, Run the below command to start the "Build"
$ sudo ant -f fetch.xml -Ddest=system


Sunday, April 12, 2020

NFS Server Installation


Important files for NFS Configration

  • /etc/exports: Its a main configuration file of NFS, all exported files and directories are defined in this file at the NFS Server end.
  • /etc/fstab: To mount a NFS directory on your system across the reboots, we need to make an entry in /etc/fstab.
  • /etc/sysconfig/nfs: Configuration file of NFS to control on which port rpc and other services are listening.

To setup NFS mounts, we’ll be needing at least two Linux/Unix machines. Here in this tutorial, I’ll be using two servers.

             NFS Server: nfs.example.com with IP-192.168.0.63

             NFS Client : nfs-client.example.com with IP-192.168.0.64

At NFS Server End

Step 1: As the first step, we will install these packages on the CentOS server with yum
#      sudo yum install nfs-utils -y
Step 2:  Now create the directory that will be shared by NFS
#  sudo mkdir /var/nfsshare
Step 3: Change the permissions of the folder as follows:
# chmod -R 755 /var/nfsshare
# chown nobody:nobody /var/nfshare

NOTE: We use /var/nfsshare as shared folder, if we use another drive such as the /home directory, then the permission chnges will cause a massive permissions problem and ruin the whole hierarchy. So in case we want to share the /home directory then permissions must not be changed.

Step 4: 
#      PATH=$PATH:${ANT_HOME}/bin







How to Install ANT(Build Tool) in CentOS machine

APACHE ANT
  • ANT stands for another neat tools
  • It is java based build tool from Apache Software Fundation
  • Ant uses build.xml file 
  • Ant was created by james duncan davidson
Ant- Build Files:
  • Ants build file is called build.xml should reside in base directory(base directory means where the source code will maintained) of the project
  • In build.xml or any xml file it start with an xml tag project name and target a single project can have multiple targets
  • There should be no blank lines or white spaces before the xml declaration
Ant Installation In CentOS Machine

Step 1: Update the Virtual machine
$ sudo yum update -y 
Step 2: Enter into the "opt" directory
cd /opt/

Step 3:  Download the tar or zap source file from http://ant.apache.org/bindownload.cgi
Step 4:  Exatract the zip file or tar file
$ sudo unzip apache-ant-1.10.5-bin.zip

Step 5: Add the ANT_HOME path.
$ sudo ANT_HOME=/opt/apache-ant-1.10.5
Step 6:  Now export the PATH
$ sudo PATH=$PATH:${ANT_HOME}/bin
Step 7: Now enter into the apache-ant-1.10.5
$ sudo cd apache-ant-1.10.5
Step 8:  Now, Run the below command to start the "Build"
$ sudo ant -f fetch.xml -Ddest=system

Saturday, April 11, 2020

Ansible templates

Ansible templates:
  • Templates will copy the source file to the target host destination.
  • While the template module gets executed it will read the template file and change all the variables to its value and copy the file to the target host.
  • Template file ends with .j2 extension which stands for Jinja2 templates.
Example-1:
—–
Create a directory.
#mkdir templates
Sample template file.
#vi templates/file.j2

<html>

<h1> Hello! Venkat </h1>

<h1> GoodDay {{username}} </h1>

</html>
Ansible Templates in Playbooks:
——————————————-
#vi playbooks/pb1.yml

- hosts: dev
vars:
- username: Venkat
- file_path: /var/www/html
tasks:
- name: Copy site files
template:
src= templates/file.j2
dest= {{file_path}}/index.html mode=0777
–> Use template module to copy the template file and the variables used in the template.

Ex-2: To change Tomcat port
#vi templates/demo.j2

.......

<Connector port= "{{myport}}"
protocol= "HTTP/1.1"
.......

(server.xml content)
After changing the Port edit the playbook.
#vi playbooks/pb2.yml
---
- hosts: web
become: true
vars:
- myport: 9090
- file_path: /etc/tomcat7/
tasks:
- name: to update packages
apt: update_cache=yes

- name: to install java
apt:
name=openjdk-7-jdk
state: latest

- name: to install tomcat
apt: 
name: tomcat7 
state: latest
- name: to change tomcat port
template:
src: templates/demo.j2
dest: {{file_path}}/server.xml
notify:
- restart tomcat

handlers:
- name: restart tomcat
service: 
name: tomcat7
state: restarted

Ansible Roles

<Ansible Playbooks                                                                                                                      Ansible Templates>
ANSIBLE ROLES:
  • Ansible roles are the organized way to perform the tasks in different playbooks according to their functionality in a directory structure way.
  • Roles allow you to call a set of variables, tasks, and handlers by simply specifying a defined role.
  • In the role file inside every directory, there is a main.yml file.
  • By default, the execution starts from the main.yml file.
Ansible Role Directory Structure:
Mainly ansible roles contain below the directories below.
  • Tasks (a series of tasks are defined here)
  • Handlers (All handlers are defined here)
  • vars (all the variables are defined here)
  • files (all the files will be placed inside this directory)
  • meta (It is used to declare role dependences and information about a role)

Example:
#vi playbooks/pb1.yml
 ---
 - hosts: dev 
   remote_user: root 
   roles: 
     - myrole
Create the directories in the role directory.
#cd playbooks
#mkdir -p roles/myrole/{files,handlers,tasks,vars,meta}
Create task files.
#vi roles/myroles/tasks/main.yml

- include: pack_install.yml
- include: deploy_app.yml
Create the installation files.
#vi roles/myrole/tasks/pack_install.yml

- name: install {{pack1}}
  apt:
  name: {{pack1}}
  state: latest
  when: ansible_distribution=='Ubuntu'
  notify:
   - start apache2

- name: install {{pack2}}
  apt: 
  name: {{pack2}}
  state: latest
  when: ansible_distribution=='Ubuntu'
  notify:
  - start tomcat

- name: install {{pack3}}
  apt:
  name: {{pack3}}
  state: latest
  when: ansible_distribution=='Ubuntu'
  notify:
  - start mysql

Create deploy file.
#cd /playbooks/roles/myrole/tasks

#vi deploy_app.yml

- name: to deploy index.html
  copy: 
    src: index.html
    dest: /var/www/html/index.html

- name: to deploy sample.war
  copy: 
    src: sample.war
    dest: /var/lib/tomcat7/webapps/sample.war
Create handlers file.
#vi roles/myrole/handlers/main.yml

- name: start apache
  service:
  name: apache2
  state: started

- name: start tomcat
  service:
  name: tomcat7
  state: started

- name: start mysql
  service:
  name: mysql
  state: started
Create variables file.
#vi roles/myrole/vars/main.yml

pack1: apache2
pack2: tomcat7
pack3: mysql-server
Create sample files.
#vi roles/myrole/files/index.html

<h1> Hello from ansible role</h1>
See the files in the files directory
#vi playbooks/roles/myrole/files# ls

index.html  sample.war
Check the syntax
#ansible-playbook playbooks/myrole.yml --syntax-check
Execute the Roles
#ansible-playbook playbooks/myrole.yml

Role tree Structure:
After creating the roles directories and all files, the tree view will display like the example below.
Common role directory tree structure
                                                                                          
<Ansible Playbooks                                                                                                                     Ansible Templates> 





Featured Post

Ansible Tool Introduction

                                                                                                                                    Next ...