DevOps Interview Questions

Write a script to install Java JDK on Linux as a non-root user from binary (zip, tar) and set JAVA_HOME


if [ -n “$2” ]

/bin/mkdir -pv $TAR_PATH

if [ -n “$TAR” ]
#mv -v $TAR $TAR_PATH
/bin/tar -xf “$TAR” –directory “$TAR_PATH”
VERSION=`echo $TAR | sed ‘s/jdk-\(.*\)-linux-.*$/\1/’`
MAJOR=`echo $VERSION | sed ‘s|\([0-9]\+\)u.*$|\1|’`
MINOR=`echo $VERSION | sed ‘s|^.*u\([0-9]\+\)|\1|’`

if grep -q JAVA_HOME $PROFILE; then
sed -i.bak
“s|\(JAVA_HOME=/usr/local/java/jdk1\.\)8\.0_60/|\1$MAJOR\.0_$MINOR|” $PROFILE

update-alternatives –install “/usr/bin/java” “java”
“$TAR_PATH/jdk1.$MAJOR.0_$MINOR/jre/bin/java” 1
update-alternatives –install “/usr/bin/javac” “javac”
“$TAR_PATH/jdk1.$MAJOR.0_$MINOR/bin/javac” 1
update-alternatives –set java $TAR_PATH/jdk1.$MAJOR.0_$MINOR/jre/bin/java
update-alternatives –set javac $TAR_PATH/jdk1.$MAJOR.0_$MINOR/bin/javac


java -version
Write a script to find files ending with .bak and archive them to a backup directory
find . -name “*.bak” -exec tar -cvf *.tar {} \;|mv * /archive directory path

Create a sample Hello World program and make it executable
java -jar helloworld.jar
Output: Hello World

Create program to read key-value pairs from a file called and echo to output when executing the application

java -jar helloworld.jar
Value of foo is bar

Build tool (ant/maven/gradle/)

Compile the program your choice of build tool. Provide skeleton of the build file (build.xml, pom.xml, build.gradle)


Given a sample demo java project that generates a jar how would you identify the dependency tree (direct and transitive dependencies)
——- format
mvn dependency:tree -Dverbose -Dincludes=java-projectname/modulename

Difference between maven goals package, install & deploy
mvn goals – The task (action) that executes. A plugin can have one or more goals. When configuring a plugin in a POM, goal needs to be specified.
Additionally, in case a plugin definition does not have a default build phase, the phase can be specified/bind with the plugin goal.

mvn package – take the compiled code and package it in its distributable format, such as a JAR.

mvn install
•install: installs the package into the local repository, for use as a dependency in other projects locally.

mvn deploy
This command invokes the deploy phase:
•deploy: copies the final package to the remote repository for sharing with other developers and projects.

mvn release
.will basically put your current code in a tag on your SCM, change your version in your projects.

What would you change if the the project needs to generate a “war” or “ear” as the output
————-in the pom.xml

war this will create bird.war
how does maven publish artifacts to a binary repository (nexus/artifactory)
————–A common use case for web applications

// create an Artifact for publishing the .war file
artifact in (Compile, packageWar) ~= { (art: Artifact) =>
art.copy(`type` = “war”, extension = “war”)

// add the .war file to what gets published
Configuration Mgmt (Ansible/Puppet/Chef/Salt)

Write a playbook/recipe/manifest for installing utilities say tree, net-utils, htop (as root – Debian/Redhat)

– hosts: webservers
remote_user: root
– name: install tree
name: tree
state: latest
– name: install net-utils
name: net-utils
state: latest
– name: install htop
name: htop
state: latest

Write a playbook/recipe/manifest for installing tomcat or jboss (non-root user)

———–1st playbook

– hosts: tomcat-servers
remote_user: interviewer

– tomcat

roles is a folder under which we will have tomcat folder , tomcat folder has anothe yml name install.yml
content of install.yml

– name: Install Java
yum: name=java state=present

– name: Download Tomcat

get_url: url= dest=/opt/apache-tomcat-7.0.61.tar.gz

– name: Extract archive

command: chdir=/usr/share /bin/tar xvf /opt/apache-tomcat-7.0.61.tar.gz -C /opt/ creates=/opt/apache-tomcat-7.0.61

– name: Symlink install directory

file: src=/opt/apache-tomcat path=/usr/share/tomcat state=link

– name: Change ownership of Tomcat installation

file: path=/usr/share/tomcat/ owner=tomcat group=tomcat state=directory recurse=yes

– name: Configure Tomcat server

template: src=server.xml dest=/usr/share/tomcat/conf/

notify: restart tomcat

– name: Configure Tomcat users

template: src=tomcat-users.xml dest=/usr/share/tomcat/conf/ (template is another dir under which you have config files)
notify: restart tomcat

– name: Install Tomcat init script

copy: dest=/etc/init.d/tomcat mode=0755

– name: Start Tomcat
service: name=tomcat state=started enabled=yes
– name: deploy iptables rules

template: src=iptables-save dest=/etc/sysconfig/iptables
notify: restart iptables

– name: wait for tomcat to start
wait_for: port={{http_port}}

Source control (Git/SVN)
Provide the commands for the following

Create a repository
— make a directory
example mkdir repository1
cd to the directory
cd repository
then run the git command
git init
Initializes empty Git repository in /repository1 directory . For verification you do a ls or check ofr hidden .git directory.

Add/Commit a sample java maven project into the repository
—– Create a local Maven repository directory, sit should be something like the below
+- pom.xml
+- src
Add a standard Maven repository directory called repo
+- pom.xml
+- src
+- repo
Deploy the Artifact Into the Repo
command syntax : mvn deploy:deploy-file
command : mvn deploy:deploy-file -Durl=file:///path/to/yourproject/repo/ -Dfile=mylib-1.0.jar -DgroupId
Update Pom file

Now add this jar as a dependency the way your normally would.

ADD/ commit to git

$ git add repo
$ git commit -m ‘adding project local maven repo, with mylib.jar 1.0’

how would you ignore target/build folders from being committed to the repo.
——–You can configure Git to ignore the generated folder/targets. for this purpose Create a .gitignore file in your Git repository
you can the files to and folder details in it to ignore.

CI tool (Jenkins, Bamboo, Teamcity )

No of jobs managed via the CI Tools
——— No restriction on the number of Job’s .

Process involved in getting a project through a CI/CD Pipeline
————-build automation and continuous integration; test automation; and deployment automation.
CI/CD pipeline usually consists of the following discrete steps:
1.Commit. When a developer finishes a change to an application, he or she commits it to a central source code repository.
2.Build. The change is checked out from the repository and the software is built so that it can be run by a computer. This steps depends a lot on what language is used and for interpreted languages this step can even be absent.
3.Automated tests. This is where the meat of the CI/CD pipeline is. The change is tested from multiple angles to ensure it works and that it doesn’t break anything else.
4.Deploy. The built version is deployed to production.

Binary Repository (Artifactory/Nexus/Archiva)
A binary repository is a software repository for packages, artifacts and their corresponding metadata. It can be used to store binaries produced by an organization itself,
such as releases and nightly builds, or for third party binaries which must be treated differently for both technical and legal reasons.
example: JFrog Artifactory


Leave a Reply

Your email address will not be published. Required fields are marked *