Tuesday, 18 June 2019

Install multiple python modules once from .txt file



pip install -r req.txt

Install Python 3.6.4 on CentOS 7 From a Repository


Install Python 3.6.4 on CentOS 7 From a Repository

This is the easier method of the two for installing Python on your machine. Here, we simply add a repository that has the pre-compiled version ready for us to install. In this case, we are adding the Inline with Upstream Stable repository, a community project whose goal is to bring new versions of software to RHEL-based systems.

Step 1: Open a Terminal and add the repository to your Yum install.

sudo yum install -y https://centos7.iuscommunity.org/ius-release.rpm

Step 2: Update Yum to finish adding the repository.

sudo yum update

Step 3: Download and install Python.

This will not only install Python – but it will also install pip to help you with installing add-ons.
sudo yum install -y python36u python36u-libs python36u-devel python36u-pip
Once these commands are executed, simply check if the correct version of Python has been installed by executing the following command:
python3.6 -V
You have now finished installing Python 3.6.4 on your CentOS 7 machine, as well as installing a native Python package management tool called pip.

Saturday, 15 June 2019

Ansible Ad-Hoc Commands




Syntax
# Command hostgroups module/arguements[options]


Examples
#ansible webserver reboot
#ansible all -a uptime
#ansible all -a "uname -a"
#ansible all -m 
# ansible-doc -l |more
#ansible-doc -l |more |wc -l
#ansible-doc -l | grep -i <modulename>
#ansible-doc <modulename>
#ansible-doc -s <modulename>
example
#ansible all -m ping
#ansible all -m ping -o
#ansible all -m user -a "name=john password=redhat"
#rpm -q httpd
#ansible all -a "yum -y install httpd"
rpm -q httpd
#ansible all -a "yum -y remove httpd"

#ansible all -m yum -a "name=httpd state=present"
#ansible all -m yum -a "name=httpd state=absent"

#ansible all -m shell -a "uname -a;df -h" -v


Friday, 14 June 2019

Installing Ansible on Ubuntu




Installing Ansible
Next, install Ansible. Here are the steps to make that happen:

Log into the Ubuntu Server that will host Ansible
Install the necessary repository with the command sudo apt-add-repository ppa:ansible/ansible.
Update apt with the command sudo apt-get update.
Install Ansible with the command sudo apt-get install ansible -y.
Because Ansible requires a Python interpreter (in order to run its modules), we need to install Python as well. For that, issue the command:

sudo apt-get install python -y
Note: You may find Python already installed.

At this point, Ansible is installed and ready to go.

Thursday, 2 May 2019

Top 15 Docker interview questions



Q1. What are the differences between Docker and Hypervisors?
Docker vs Hypervisors Features Hypervisors Docker Default Security Support
To a great degree
To a slightly less degree Memory on disk required
Complete OS plus apps
App requirement only Time Taken to start up
Substantially longer as it requires boot of OS plus app loading
Substantially shorter as apps only need to start as the kernel is already running Portability
Portable with proper preparation
Portable within image format; typically smaller Operating System
Supports multiple OS
It uses the host OS
Q2. What is Docker?
I will suggest you to start with a small definition of Docker.
• Docker is a containerization platform which packages your application and all its dependencies together in the form of containers so as to ensure that your application works seamlessly in any environment be it development or test or production.
• Docker containers, wrap a piece of software in a complete filesystem that contains everything needed to run: code, runtime, system tools, system libraries etc. anything that can be installed on a server.
• This guarantees that the software will always run the same, regardless of its environment.
You can refer the diagram shown below, as you can see that containers run on a single machine share the same operating system kernel, they start instantly as only apps need to start as the kernel is already running and uses less RAM.
Note: Unlike Virtual Machines which has its own OS Docker containers uses the host
OS
Q3. What is Docker image?
I will suggest you to go with the below mentioned flow:
Docker image is the source of Docker container. In other words, Docker images are used to create containers. Images are created with the build command, and they’ll produce a container when started with run. Images are stored in a Docker registry such as registry.hub.docker.com because they can become quite large, images are designed to be composed of layers of other images, allowing a minimal amount of data to be sent when transferring images over the network. Tip: Be aware of Dockerhub in order to answer questions on pre-available images.
Q4. What is Docker container?
This is a very important question so just make sure you don’t deviate from the topic and I will advise you to follow the below mentioned format:
Docker containers include the application and all of its dependencies, but share the kernel with other containers, running as isolated processes in user space on the host operating system. Docker containers are not tied to any specific infrastructure: they run on any computer, on any infrastructure, and in any cloud. Now explain how to create a Docker container, Docker containers can be created by either creating a Docker image and then running it or you can use Docker images that are present on the Dockerhub.
Docker containers are basically runtime instances of Docker images.
Q5 What is Docker hub?
Answer to this question is pretty direct.
Docker hub is a cloud-based registry service which allows you to link to code repositories, build your images and test them, stores manually pushed images, and links to Docker cloud so you can deploy images to your hosts. It provides a centralized resource for container image discovery, distribution and change management, user and team collaboration, and workflow automation throughout the development pipeline.
Q6. How is Docker different from other container technologies?
According to me, below, points should be there in your answer:
Docker containers are easy to deploy in a cloud. It can get more applications running on the same hardware than other technologies, it makes it easy for developers to quickly create, ready-to-run containerized applications and it makes managing and deploying applications much easier. You can even share containers with your applications. If you have some more points to add you can do that but make sure the above the above explanation is there in your answer.
Q7. What is Docker Swarm?
You should start this answer by explaining Docker Swarn.
Docker Swarm is native clustering for Docker. It turns a pool of Docker hosts into a single, virtual Docker host. Docker Swarm serves the standard Docker API, any tool that already
communicates with a Docker daemon can use Swarm to transparently scale to multiple hosts.
I will also suggest you to include some supported tools:
• Dokku
• Docker Compose
• Docker Machine
• Jenkins
Q8. What is Dockerfile used for?
This answer, according to me should begin by explaining the use of Dockerfile.
Docker can build images automatically by reading the instructions from a Dockerfile.
Now I will suggest you to give a small definition of Dockerfle.
A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession.
Q9. Can I use json instead of yaml for my compose file in Docker?
You can use json instead of yaml for your compose file, to use json file with compose, specify the filename to use for eg: docker-compose -f docker-compose.json up
Q10. Tell us how you have used Docker in your past position?
➢ Explain how you have used Docker to help rapid deployment. Explain how you have scripted Docker and used Docker with other tools like Puppet, Chef or Jenkins.
➢ If you have no past practical experience in Docker and have past experience with other tools in a similar space, be honest and explain the same. In this case, it makes sense if you can compare other tools to Docker in terms of functionality.
Q11. How to create Docker container?
I will suggest you to give a direct answer to this.
We can use Docker image to create Docker container by using the below command:
1
docker run -t -i command name
This command will create and start a container.
You should also add, If you want to check the list of all running container with the status on a host use the below command:
1
docker ps -a
Q12. How to stop and restart the Docker container?
In order to stop the Docker container you can use the below command:
1
docker stop container ID
Now to restart the Docker container you can use:
1
docker restart container ID
Q13 How far do Docker containers scale?
Large web deployments like Google and Twitter, and platform providers such as Heroku and dotCloud all run on container technology, at a scale of hundreds of thousands or even millions of containers running in parallel.
Q14. What platforms does Docker run on?
I will start this answer by saying Docker runs on only Linux and Cloud platforms and then I will mention the below vendors of Linux:
• Ubuntu 12.04, 13.04 et al
• Fedora 19/20+
• RHEL 6.5+
• CentOS 6+
• Gentoo
• ArchLinux
• openSUSE 12.3+
• CRUX 3.0+
Cloud:
• Amazon EC2
• Google Compute Engine
• Microsoft Azure
• Rackspace
Note that Docker does not run on Windows or Mac.
Q15. Do I lose my data when the Docker container exits?
You can answer this by saying, no I won’t lose my data when Docker container exits, any data that your application writes to disk gets preserved in its container until you explicitly delete the container. The file system for the container persists even after the container halts.
Q16. Mention some commonly used Docker command?
Below are some commonly used Docker commands:

Top 50 GIT interview questions



1) What is GIT?
GIT is a distributed version control system and source code management (SCM) system with an emphasis to handle small and large projects with speed and efficiency.
2) What is a repository in GIT?
A repository contains a directory named .git, where git keeps all of its metadata for the repository. The content of the .git directory are private to git.
3) What is the command you can use to write a commit message?
The command that is used to write a commit message is “git commit –a”. The –a on the command line instructs git to commit the new content of all tracked files that have been modified. You can use “git add<file>” before git commit –a if new files need to be committed for the first time.
4) What is the difference between GIT and SVN?
The difference between GIT and SVN is
a) Git is less preferred for handling extremely large files or frequently changing binary files while SVN can handle multiple projects stored in the same repository.
b) GIT does not support ‘commits’ across multiple branches or tags. Subversion allows the creation of folders at any location in the repository layout.
c) Gits are unchangeable, while Subversion allows committers to treat a tag as a branch and to create multiple revisions under a tag root.
5) What are the advantages of using GIT?
a) Data redundancy and replication
b) High availability
c) Only one.git directory per repository
d) Superior disk utilization and network performance
e) Collaboration friendly
f) Any sort of projects can use GIT
6) What language is used in GIT?
GIT is fast, and ‘C’ language makes this possible by reducing the overhead of runtimes associated with higher languages.
7) What is the function of ‘GIT PUSH’ in GIT?
‘GIT PUSH’ updates remote refs along with associated objects.
8) Why GIT better than Subversion?
GIT is an open source version control system; it will allow you to run ‘versions’ of a project, which show the changes that were made to the code overtime also it allows you keep the backtrack if necessary and undo those changes. Multiple developers can checkout, and upload changes and each change can then be attributed to a specific developer.
9) What is “Staging Area” or “Index” in GIT?
Before completing the commits, it can be formatted and reviewed in an intermediate area known as ‘Staging Area’ or ‘Index’.
10) What is GIT stash?
GIT stash takes the current state of the working directory and index and puts in on the stack for later and gives you back a clean working directory. So in case if you are in the middle of something and need to jump over to the other job, and at the same time you don’t want to lose your current edits then you can use GIT stash.
11) What is GIT stash drop?
When you are done with the stashed item or want to remove it from the list, run the git ‘stash drop’ command. It will remove the last added stash item by default, and it can also remove a specific item if you include as an argument.
12) How will you know in GIT if a branch has been already merged into master?
Git branch—merged lists the branches that have been merged into the current branch Git branch—-no merged lists the branches that have not been merged
13) What is the function of git clone?
The git clone command creates a copy of an existing Git repository. To get the copy of a central repository, ‘cloning’ is the most common way used by programmers.
14) What is the function of ‘git config’?
The ‘git config’ command is a convenient way to set configuration options for your Git installation. Behaviour of a repository, user info, preferences etc. can be defined through this command.
15) What does commit object contain?
a) A set of files, representing the state of a project at a given point of time
b) Reference to parent commit objects
c) An SHAI name, a 40 character string that uniquely identifies the commit object.
16) How can you create a repository in Git?
In Git, to create a repository, create a directory for the project if it does not exist, and then run command “git init”. By running this command .git directory will be created in the project directory, the directory does not need to be empty.
17) What is ‘head’ in git and how many heads can be created in a repository?
A ‘head’ is simply a reference to a commit object. In every repository, there is a default head referred as “Master”. A repository can contain any number of heads.
18) What is the purpose of branching in GIT?
The purpose of branching in GIT is that you can create your own branch and jump between those branches. It will allow you to go to your previous work keeping your recent work intact.
19) What is the common branching pattern in GIT?
The common way of creating branch in GIT is to maintain one as “Main“
branch and create another branch to implement new features. This pattern is particularly useful when there are multiple developers working on a single project.
20) How can you bring a new feature in the main branch?
To bring a new feature in the main branch, you can use a command “git merge” or “git pull command”.
21) What is a ‘conflict’ in git?
A ‘conflict’ arises when the commit that has to be merged has some change in one place, and the current commit also has a change at the same place. Git will not be able to predict which change should take precedence.
22) How can conflict in git resolved?
To resolve the conflict in git, edit the files to fix the conflicting changes and then add the resolved files by running “git add” after that to commit the repaired merge, run “git commit”. Git remembers that you are in the middle of a merger, so it sets the parents of the commit correctly.
23) To delete a branch what is the command that is used?
Once your development branch is merged into the main branch, you don’t need development branch. To delete a branch use, the command “git branch –d [head]”.
24) What is another option for merging in git?
“Rebasing” is an alternative to merging in git.
25) What is the syntax for “Rebasing” in Git?
The syntax used for rebase is “git rebase [new-commit] “
26) What is the difference between ‘git remote’ and ‘git clone’?
‘git remote add’ just creates an entry in your git config that specifies a name for a particular URL. While, ‘git clone’ creates a new git repository by copying and existing one located at the URI.
27) What is GIT version control?
With the help of GIT version control, you can track the history of a collection of files and includes the functionality to revert the collection of files to another version. Each version captures a snapshot of the file system at a certain point of time. A collection of files and their complete history are stored in a repository.
28) Mention some of the best graphical GIT client for LINUX?
Some of the best GIT client for LINUX is
a) Git Cola
b) Git-g
c) Smart git
d) Giggle
e) Git GUI
f) qGit
29) What is Subgit? Why to use Subgit?
‘Subgit’ is a tool for a smooth, stress-free SVN to Git migration. Subgit is a solution for a company - wide migration from SVN to Git that is:
a) It is much better than git-svn
b) No requirement to change the infrastructure that is already placed
c) Allows to use all git and all sub-version features
d) Provides genuine stress –free migration experience.
30) What is the function of ‘git diff ’ in git?
‘git diff ’ shows the changes between commits, commit and working tree etc.
31) What is ‘git status’ is used for?
As ‘Git Status’ shows you the difference between the working directory and the index, it is helpful in understanding a git more comprehensively.
32) What is the difference between the ‘git diff ’and ‘git status’?
‘git diff’ is similar to ‘git status’, but it shows the differences between various commits and also between the working directory and index.
33) What is the function of ‘git checkout’ in git?
A ‘git checkout’ command is used to update directories or specific files in your working tree with those from another branch without merging it in the whole branch.
34) What is the function of ‘git rm’?
To remove the file from the staging area and also off your disk ‘git rm’ is used.
35) What is the function of ‘git stash apply’?
When you want to continue working where you have left your work, ‘git stash apply’ command is used to bring back the saved changes onto the working directory.
36) What is the use of ‘git log’?
To find specific commits in your project history- by author, date, content or history ‘git log’ is used.
37) What is ‘git add’ is used for?
‘git add’ adds file changes in your existing directory to your index.
38) What is the function of ‘git reset’?
The function of ‘Git Reset’ is to reset your index as well as the working directory to the state of your last commit.
39) What is git Is-tree?
‘git Is-tree’ represents a tree object including the mode and the name of each item and the SHA-1 value of the blob or the tree.
40) How git instaweb is used?
‘Git Instaweb’ automatically directs a web browser and runs webserver with an interface into your local repository.
41) What does ‘hooks’ consist of in git?
This directory consists of Shell scripts which are activated after running the corresponding Git commands. For example, git will try to execute the post-commit script after you run a commit.
42) Explain what is commit message?
Commit message is a feature of git which appears when you commit a change. Git provides you a text editor where you can enter the modifications made in commits.
43) How can you fix a broken commit?
To fix any broken commit, you will use the command “git commit—amend”. By running this command, you can fix the broken commit message in the editor.
44) Why is it advisable to create an additional commit rather than amending an existing commit?
There are couple of reason
a) The amend operation will destroy the state that was previously saved in a commit. If it’s just the commit message being changed then that’s not an issue. But if the contents are being amended then chances of eliminating something important remains more.
b) Abusing “git commit- amend” can cause a small commit to grow and acquire unrelated changes.
45) What is ‘bare repository’ in GIT?
To co-ordinate with the distributed development and developers team, especially when you are working on a project from multiple computers ‘Bare Repository’ is used. A bare repository comprises of a version history of your code.
46) Name a few Git repository hosting services
Pikacode
Visual Studio Online GitHub GitEnterprise SourceForge.net

Git

1 git add ↳ It lets you add changes from the working directory into the staging area 2 git commit ↳ It lets you save a snapshot of currently...