Saturday, May 4, 2019

Ansible: Installation and Configuration

Ansible is an open-source software provisioning, configuration management, and application deployment tool. It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows. Before proceeding for the installation, it is necessary to get yourself comfortable with basic knowledge.

Ansible Wikipedia: https://en.wikipedia.org/wiki/Ansible_(software)
Official Documentation: https://docs.ansible.com/ 

1. Ansible installation

1.1.  Through pip

The easy way to install ansible is through pip, which is a python package manager.
Prerequisite:
> For before installing ansible, make sure that python3 is already installed.  
> Once Python3 is installed go ahead to install pip
    Sudo easy-install pip3
> Now install ansible through pip3
    pip3 install ansible

1.2.  Through apt (ubuntu)

$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo apt-add-repository --yes --update ppa:ansible/ansible
$ sudo apt-get install ansible

2.  Basic Configuration:

If ansible is installed manually through pip, the ansible_host inventory file needs to be created manually. Following this you also need to check the reachability of remote servers.

2.1. Adding host file if NOT present

If the ansible is installed using pip3, you will not find any host inventory in the directory /etc/ansible/hosts

if you execute the command ansible webservers --list-hosts this will give an error something like "unable to parse the inventory file in /etc/ansible/hosts". This means that no directory named ansible in /etc/ directory is present. For this follow steps below:

1: cd /etc/
2: sudo mkdir -p ansible/hosts/
3: vim ansible_host
[localhost]
127.0.0.1
[webservers]
[dbservers]
[myhomepage]
[testservers]

4: now enter the command ansible testservers --list-hosts
This will list the webservers that are listed in the group called [testservers]

2.2. Connecting to remote host using ssh


1: open the ansible_host inventory file
vim /etc/ansible/hosts/ansible_host
2: add the following host group or host
[myhomepage]
160.153.137.40 ansible_port=<sshport#> ansible_user=username1 ansible_ssh_pass=user1password

It is assumed that you are able to login to that remote using ssh and using above credentials.
3: now save the ansible_host file
4: enter following command
ansible myhomepage -m ping

2.3. Disabling ssh key host checking

Open the config file in /etc/ansible/ansible.config
Find for #host_key_checking = false. Uncomment the line to make it enable.
[src]: https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#latest-releases-via-pip

-Thats all for now.

Tuesday, April 16, 2019

Ansible Playbook: Generate multiple files at specific time interval

In the previous post, we have seen how to generate multiple files using with_sequence and loop features.

Here, we will introduce the delay functionality in the loop feature. This will give a pause after every iteration. So, each file will be created at specific time interval. Let's say, we will create 20 files at 10sec time interval.
Download the yml file [generateFiles_pattern_withDelay.yml]

--- 
- hosts: localhost
  gather_facts: no
  become: no
  tasks:
    - name: create 20 empty file in each 10 sec
      file:
        path: "/tmp/playing_opera/loopdemo/file{{ item }}"
        state: touch
      with_sequence: start=1 end=20
      loop_control:
        pause: 10
...



Next: ..?? Not yet decided :)





Ansible Playbook: Generating multiple files with loop and with_sequence

Let's write a playbook which would create multiple empty files. All the filenames must follow a pattern. Lets say file1, file2, file3, ...

For this we will use with_sequence and loop features. with_sequence would allow us to generate a list of numbers and loop feature would allow us to iterate of the lists.

Generate empty file from a list

Job is to create a list of filenames and use that list to create multiple empty file.
Download yml file [generateFiles1.yml]
--- 
- hosts: localhost
  gather_facts: no
  become: no
  tasks:
    - name: create the location/directory
      file:
        path: /tmp/playing_opera/loopdemo
        state: directory

    - name: generate empty file from a list of file names
      file:
        path: "/tmp/playing_opera/loopdemo/{{ item }}"
        state: touch
      with_items:
        - fruitsList
        - censusReport
        - countryList
…

The first task would first make sure that the directory is present. If not this would create one.
The second task is to create three files with name "fruitsList", "censusReport", and "countryList".

The above playbook can also written in following way.
Download yml file [generateFiles2.yml]

--- 
- hosts: localhost
  gather_facts: no
  become: no
  tasks:
    - name: create the location/directory
      file:
        path: /tmp/playing_opera/loopdemo
        state: directory

    - name: generate empty file from a list of file names
      file:
        path: "/tmp/playing_opera/loopdemo/{{ item }}"
        state: touch
      loop: [ fruitsList, censusReport, countryList ]
…


Generate empty files with pattern

It is sometimes necessary to create a list of files following some patterns. For example file1, file2, file3, ...
This can be achieved using with_sequence feature of ansible.
Following is an example.

Download yml file [generateFiles_pattern.yml]

--- 
- hosts: localhost
  gather_facts: no
  become: no
  tasks:
    - name: generate 10 empty files
      file:
        path: "/tmp/playing_opera/loopdemo/file{{ item }}"
        state: touch
      with_sequence: start=1 end=10
…

This playbook would create 10 files with the names file1, file2, ..., file10.
Explorer the official documentation for more info.









Manually adding ansible_host inventory file, if NOT present.

In computing, Ansible is an open-source software provisioning, configuration management, and application deployment tool. It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows. 

If you are installing ansible using pip or any other manual process, first check if "ansible" directory is present inside "/etc" 

if not, here is the steps you can follow to add ansible_host inventory file. This inventory file mainly keeps the inventory of detail information regarding all the host machines. 

Steps: 

1>  Open Terminal in the linux system and enter following commands
2>  cd /etc
3>  mkdir -p ansible/host/
4>  cd ansible/host/
5>  vim ansible_host
6> Add host details in following format
 [host group name]
<host IP> [ansible_port=<port number>] [ansible_user=<username>] [ansible_ssh_pass=<password>]
e.g.
[localvms]
172.17.12.65 ansible_user=guestuser1 ansible_ssh_pass=123
172.17.12.80 ansible_port=808 ansible_user=
guestuser1 ansible_ssh_pass=123

Click here for more information from official source.


Ansible Playbook: ping remote server(s)

ping command is basically used to test the reachability of a server. Ansible allows you to ping multiple servers or a group of servers at once. It is assumed that, Ansible tool is already installed in your linux system.

Steps:
1>   Create empty yml file with the name pingserver.yml

vim pingserver.yml

2>   Add following contents:

---
- hosts: myservers
  tasks:
   - name: check the ping
     ping:
...

3>   Save and execute the pingserver.yml file using followng command
ansible-playbook pingserver.yml


make sure following content is present in ansible_host inventory file
[myservers]
192.168.15.34 ansible_user=chinmaya ansible_ssh_pass=mypassword
www.chinmayadehury.in ansible_user=chinmaya ansible_ssh_pass=mypassword
192.168.15.37 ansible_user=chinmaya ansible_ssh_pass=mypassword  

[Alternative]
In this method no playbook file is needed to create.
Pass the following command to the terminal

ansible myservers -m ping


If ansible_host file is not present, click here for the steps to add ansible_host file.
-Thanks

Wednesday, February 27, 2019

JSAC Submission Error: "Upload failed: One or more fonts are not embedded."

This is a very common problem that JSAC needs to fix.
Understanding the problem: 
Lets say we generate the PDF by using some Latex editor such as TeXstudio. 
By default the all the font are not embedded to the PDF itself. This is to keep the PDF size small. Embedding all fonts is not necessary because some fonts are common to all modern OS. So it does not make sense to embed all the fonts in the PDF itself.

You can check the list of fonts embedded by following steps:
1. Open the PDF
2. Right click on any place
3. Click on "document properties."
4. Click on "Font" tab.

 
But, the EDAS system, through which we usually submit the manuscript, expect all the fonts to be embedded into the PDF.

How to solve (Windows OS)?
    1> After generating the PDF using any Latex Editor, find the corresponding .ps file, probably in the same directory
    2> Open the Windows command prompt 
    change the current directory to the directory of PS file. 
Now enter following command 


    ps2pdf -dPDFSETTINGS#/prepress -dEmbedAllFonts#true -dMaxSubsetPct#100 -dCompatibilityLevel#1.3 file_name.ps file_name.pdf

  3> Give the ps file name and the output pdf file name. 
Now in the new pdf file, you can see the embedded fonts.





EDIT (23 Jan 2020):
How to Solve (Mac OS)?
- Open the PDF with Preview app (I am using MacOS Catalina)
- Under "File" menu select "Export as PDF..."
- Give different filename and click on "Save" button.
Be default this should embed all the fonts.



Tuesday, February 12, 2019

Working with Cloudify and ARIA TOSCA - Beginner

Before you start reading this post, it is recommended to have the knowledge of cloud computing concept: how the cloud specific applications are developed and deployed, how those are tested, scaled according to users requirements etc. In this post we will see what is Cloudify and the brief of TOSCA standard.

 

Cloudify 



> This is an open source cloud orchestration framework. This allows to manage the entire life cycle of the cloud application, which ranges from: application modelling, life cycle automation, cloud deployment, monitoring, detecting issues and failures, handling on going maintenance tasks etc. 
> This entire software tool comprises of other different open-source components, such as Nginx, Elasticsearch, Logstash, RabbitMQ, Riemann, InfluxDB, Grafana, Flask, Gunicorn, Celery, Fabric, diamond, Jinja2 etc. This means, the installation of Cloudify includes the installation of all above-mentioned open-source components. 
> This open-source tool is written in Python programming language
> Its Domain Specific Language is based on TOSCA standard. 
> Each application is describe in a YMAL file called blueprint. Application description represents the logical representation called topology, dependencies of the applications etc.



TOSCA



> TOSCA: Topology and Orchestration Specification of Cloud Applications
> It is a standard created by group of industrial experts.
> The first version (version 1.0) of this standard came on 16 January 2014.
> It is used to describe the topology of cloud based web services, the components of the web services and their relationships and the processes that manage them. 
> Cloudify is an open source cloud service orchestration frame based on TOSCA
> Similarly, Alien4Cloud is an open source cloud application lifecycle management platform based on TOSCA
> Ubicity provides tooling and orchestration  cloud environment which is base on TOSCA
> SeaCloud and DICE are some of the related research projects that are based on this standard.

Monday, February 11, 2019

Service Deployement on local machine using Cloudify CLI

Prerequisite: It is assumed that Docker and Cloudify CLI is already installed on the local machine.
Basic knowledge of Docker commands.

If Cloudify is NOT yet install follow the previous post HERE.
If Docker is NOT yet install follow the previous post HERE.


In this post we will see how to deploy a web service on the local machine using Cloudify CLI. We will follow the TOSCA standard of blueprint file.


The deployment can be done in two ways: (a) using command line console and (b) using Cloudify web interface. We will deploy a simple web service or the blueprint available in 
or 

Deploy the Hello World Example on your local machine using console 
 
Step - 1 : Open terminal byAlt+Ctrl+t
pressing the key combination
Step - 2 : Run the following command to start 

sudo docker run --name cfy_manager_local \
    -d --restart unless-stopped \
    -v /sys/fs/cgroup:/sys/fs/cgroup:ro \
    --tmpfs /run \
    --tmpfs /run/lock \
    --security-opt seccomp:unconfined \
    --cap-add SYS_ADMIN \
    -p 80:80 \
    -p 8000:8000 \
    cloudifyplatform/community:18.10.4

Step - 3 : Run following command the install the Hello World web service

sudo docker exec -it cfy_manager_local sh -c "cfy install https://github.com/chinmaya-dehury/local-simple-python-webserver-blueprint/archive/master.zip"
The entire Git directory will be copied to /opt/manager/resource directory

Step - 4 : Open the web browser and goto localhost:8000. You can see the output.


Deploy the Hello World Example on your local machine using web interface 
Step - 1: Open web Browser:
Step - 2: Goto localhost or enter the IP of the local computer
Step - 3: Enter admin as username and password


Step - 4: After login, the interface would look like below.


Step - 5: Click on "upload Blueprint" option 
Step - 6: Enter the URL  https://github.com/chinmaya-dehury/local-simple-python-webserver-blueprint/archive/master.zip
Change the Blueprint name to "local-simple-python-webserver-blueprint"
Click On "Upload" button




Step - 7: Click on "Deployments" Page. Then Click on "Create Deployment" option



Step - 8: Enter "MyfirstDeploymentUI" as the deployment name
    From the dropdown list of blueprints, select the newly created blueprint.
    Click on "Deploy"  button.


Step - 9: Click on "Install" option.


Step - 10: Now click on "Execute" button.

Step -11:  Enter localhost:8000 in your browser.
The web server application is deployed. The output should look like below.




Installation of Cloudify CLI on Ubuntu 14.04 for service deployment using TOSCA standard

In this post we will see how to install Cloudify CLI, through which we can deploy, scale and monitor the different cloud service. For better understanding lets install this in local machine. The basic steps can be refereed and extended for actual cloud environment.

The steps are as follows:
Environment: we will be using Ubuntu 14.04, Python 2.6/2.7
Cloudify  does NOT support Python 3

Step 1: Install Docker on local machine. [ How to install Docker on Ubuntu 14.04? ]
Step 2: Open ubuntu terminal
Step 3: Run the following command

sudo docker run --name cfy_manager_local \
    -d --restart unless-stopped \
    -v /sys/fs/cgroup:/sys/fs/cgroup:ro \
    --tmpfs /run \
    --tmpfs /run/lock \
    --security-opt seccomp:unconfined \
    --cap-add SYS_ADMIN \
    -p 80:80 \
    -p 8000:8000 \
    cloudifyplatform/community:18.10.4


Step 4: Now go to web browser and enter localhost or enter your own IP
             You can see the web interface of the Cloudify Console
Step 5: Enter admin as both username and password.


NEXT: Service Deployement on local machine using Cloudify CLI