0% found this document useful (0 votes)
13 views5 pages

Devops Interview

The document provides answers to various questions related to Terraform, Ansible, and Docker. Key topics include Terraform commands like 'terraform graph' and 'terraform taint', S3 bucket encryption, installing Nginx on EC2 instances, and CI/CD concepts. It also covers Dockerfile components, network types, and managing resources with Terraform and Ansible Tower.

Uploaded by

poojanandish1993
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views5 pages

Devops Interview

The document provides answers to various questions related to Terraform, Ansible, and Docker. Key topics include Terraform commands like 'terraform graph' and 'terraform taint', S3 bucket encryption, installing Nginx on EC2 instances, and CI/CD concepts. It also covers Dockerfile components, network types, and managing resources with Terraform and Ansible Tower.

Uploaded by

poojanandish1993
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Here are answers to the next set of questions:

1. What is .file in Terraform? Have you used terraform graph?


 .file: In Terraform, there is no specific .file extension, but files that
contain Terraform code usually have the .tf extension. It's possible
that the question is referring to .tf files or the file extension used for
Terraform configurations.

 terraform graph: This command generates a visual representation of


the Terraform resources, showing how they depend on each other in a
directed acyclic graph (DAG). It helps in understanding the
relationships between resources and can be used to generate a graph
in DOT format, which can be visualized using tools like Graphviz.

2. S3 bucket needs to enable encryption; if you forget to write it,


should it not create?
If you forget to enable encryption in the Terraform configuration for an S3
bucket, the bucket will still be created, but it won't have encryption enabled
by default. To ensure encryption is always enabled, you can make the
encryption a required part of the configuration by setting it explicitly, like
this:
hclCopyEditresource "aws_s3_bucket" "example" {
bucket = "my-example-bucket"

server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
}

To prevent it from being created without encryption, you can use terraform
validate to check the configuration.

3. I need to install nginx on the resource created by Terraform.


You can use the user_data field to install Nginx when an EC2 instance is
created. Here's an example:
hclCopyEditresource "aws_instance" "nginx_instance" {
ami = "ami-0c55b159cbfafe1f0" # Specify your preferred
AMI
instance_type = "t2.micro"

user_data = <<-EOF
#!/bin/bash
apt-get update
apt-get install -y nginx
systemctl start nginx
systemctl enable nginx
EOF
}

This script runs when the EC2 instance is launched.

4. What does terraform taint do?


terraform taint marks a resource as "tainted," which forces Terraform to
destroy and recreate the resource on the next terraform apply. It is typically
used when you need to manually trigger a resource to be replaced due to
issues or changes that can't be handled by Terraform automatically.

5. I need to update older plugins in Terraform.


To update Terraform providers or plugins, you can use the terraform init
command, which will download the latest versions of the provider plugins
specified in your configuration. If you want to upgrade the providers, you can
run:
bashCopyEditterraform init -upgrade

This will update all the provider plugins to their latest compatible versions.

6. Write a shell script to print from 1 to 10.


Here’s a simple shell script to print numbers from 1 to 10:
bashCopyEdit#!/bin/bash
for i in {1..10}
do
echo $i
done

7. What is $*, $@, $?. Have you used shift? What is CI/CD?
 $*: Represents all the arguments passed to the script as a single
string.

 $@: Similar to $*, but treats each argument as a separate word. This is
useful if you want to handle arguments individually in the script.
 $?: Represents the exit status of the last executed command. A value
of 0 indicates success, and any non-zero value indicates an error.

 shift: The shift command is used to move the positional parameters


(arguments) left, so $1 becomes $2, $2 becomes $3, and so on. This is
useful when you want to process arguments in a loop and discard the
first argument after processing it.

 CI/CD: Continuous Integration (CI) is the practice of merging all


developer working copies to a shared repository several times a day.
Continuous Delivery (CD) ensures that code changes are automatically
built, tested, and deployed to production.

8. Do you know Ansible Tower? How to execute a playbook?


Yes, Ansible Tower is a web-based interface for managing Ansible
automation. To execute a playbook:
 Create an inventory and configure your project in the Tower UI.

 Under the "Templates" section, create a new job template and specify
the playbook.

 You can then run the job from the UI or use the API.

Alternatively, to execute the playbook directly from the command line:


bashCopyEditansible-playbook playbook.yml

9. Tell me how to write the pipeline, including the deployment


stage.
Here’s an example of a basic CI/CD pipeline written in a YAML format for
Jenkins:
yamlCopyEditpipeline {
agent any
stages {
stage('Build') {
steps {
// Build steps here, e.g., compiling code
sh 'mvn clean install'
}
}
stage('Test') {
steps {
// Testing steps here, e.g., running unit tests
sh 'mvn test'
}
}
stage('Deploy') {
steps {
// Deployment steps, e.g., deploying to AWS
sh './deploy.sh'
}
}
}
}

10. What is ansible_host and inventory_host?


 ansible_host: It’s a variable that defines the actual IP or DNS name of
the target machine if you need to override the default hostname in
your Ansible inventory.

 inventory_host: Refers to the specific host or machine in the Ansible


inventory file that you want to manage.

11. How to create your own base image? How to build it?
To create a custom base image, you can start with a minimal operating
system (like Ubuntu or Alpine) and install only the necessary packages.
Here’s an example of building a custom Docker image:
1. Create a Dockerfile:

dockerfileCopyEditFROM ubuntu:20.04
RUN apt-get update && apt-get install -y nginx
COPY ./index.html /usr/share/nginx/html/
CMD ["nginx", "-g", "daemon off;"]

2. Build the image:

bashCopyEditdocker build -t my-custom-image .

12. Components of a Dockerfile? Suppose I have not named the


Dockerfile as Dockerfile, how to build?
Key components of a Dockerfile include:
 FROM: Specifies the base image.

 RUN: Executes commands in the image.

 COPY: Copies files from the host machine into the image.

 CMD: Specifies the command to run when a container starts.


If you name your file something other than Dockerfile, use the -f option:

bashCopyEditdocker build -f MyCustomDockerfile .

13. Types of network? Uses of overlay. What is Docker Compose


and Docker Swarm? Components of a Dockerfile.
 Docker Networks:

o Bridge Network: Default network for containers on a single


host.

o Host Network: Shares the host network stack.

o Overlay Network: Allows containers to communicate across


multiple Docker hosts. Used in Docker Swarm or Kubernetes
clusters.

 Docker Compose: A tool for defining and running multi-container


Docker applications using a docker-compose.yml file.

 Docker Swarm: A native clustering tool for Docker that turns a group
of Docker engines into a single, virtual Docker engine.

14. How to save persistent data?


To save persistent data, use Docker volumes or bind mounts:
 Volume: Managed by Docker, suitable for long-term storage.

 Bind mount: Links a host directory to a container directory.

15. You have created 3 resources in AWS using Terraform, 1


resource is deleted through UI. What happens when you run
terraform apply?

When you run terraform apply, Terraform will detect that one of the
resources has been deleted (because the state file no longer matches the
actual cloud state) and will recreate the resource to match the configuration.

16. I have multiple resources in the cwd, I need to destroy a


specific resource.
To destroy a specific resource, use the -target flag:

bashCopyEditterraform destroy -target=aws_instance.example

This will only destroy the specified resource while leaving others intact.
Let me know if you need further details!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy