Ansible Interview Questions and Answers

DevOps

MOTOSHARE πŸš—πŸοΈ
Turning Idle Vehicles into Shared Rides & Earnings

From Idle to Income. From Parked to Purpose.
Earn by Sharing, Ride by Renting.
Where Owners Earn, Riders Move.
Owners Earn. Riders Move. Motoshare Connects.

With Motoshare, every parked vehicle finds a purpose. Owners earn. Renters ride.
πŸš€ Everyone wins.

Start Your Journey with Motoshare

Q1. Difference Between Terraform and Ansible?

Q2. What Kind of Work you did in Ansible?

Q3. What Kind of Playbook you have written in Ansible?

  • Playbook for Patching & Upgrading Linux APP Servers
  • Playbook for Patching & Upgrading Linux DB Servers
  • Playbook for Installing Applications in Linux VMS
  • Playbook for Installing Database in Linux VMS
  • Playbook for Installing Web Servers in Linux VMS

Q4. What is Architecture of Ansible or How it works?

Q5. Whats there in Playbooks? How you write playbook?

Q6. Example of Plybook of Ubuntu Servers

---
- name: Update web servers
  hosts: web

  tasks:
  - name: Install Apache in ubuntu
    ansible.builtin.apt:
      name: "apache2"
      state: latest
  - name: Copy index.html
    ansible.builtin.copy:
      src: index.html
      dest: /var/www/html/index.html
  - name: Starting a Apache Server
    ansible.builtin.service:
      name: "apache2"
      state: startedCode language: JavaScript (javascript)
---
- name: Update web servers
  hosts: web
  vars:
    myname: "Rajesh Kumar"
    httpport: 8090

  tasks:
  - name: Install Apache in ubuntu
    ansible.builtin.apt:
      name: apache2
      state: latest
  - name: Copy index.html
    ansible.builtin.copy:
      src: index.html
      dest: /var/www/html/index.html
  - name: Starting a Apache Server
    ansible.builtin.service:
      name: apache2
      state: started
  - name: Template for httpd.conf
    template:
      src: ports.conf.j2
      dest: /etc/apache2/ports.conf
    notify:
      - ReStarting a Apache Server

  handlers:
  - name: ReStarting a Apache Server
    ansible.builtin.service:
      name: apache2
      state: restartedCode language: JavaScript (javascript)

Q7. List of TOP Ansible modules you have used in Playbook

Certainly! Here is a list of commonly used Ansible modules in Playbook format, presented in a table without examples:

- name: Install a package
  apt:
    name: git
    state: present

- name: Ensure nginx is running
  service:
    name: nginx
    state: started
    enabled: true

- name: Copy a file to the remote server
  copy:
    src: /local/path/to/file
    dest: /remote/path/to/file

- name: Deploy a configuration file
  template:
    src: /local/path/to/template.j2
    dest: /remote/path/to/config.conf

- name: Ensure a directory exists
  file:
    path: /path/to/directory
    state: directory
    mode: '0755'

- name: Create a user
  user:
    name: johndoe
    state: present
    groups: sudo

- name: Run a custom shell command
  shell: echo "This is a test"

- name: Run a simple command
  command: /usr/bin/uptime

- name: Clone a Git repository
  git:
    repo: 'https://github.com/example/repo.git'
    dest: /path/to/destination

- name: Ensure a line is present in a file
  lineinfile:
    path: /path/to/file
    line: 'This is a line in the file'
Code language: JavaScript (javascript)

Q8. What is ROLE?

roles/
β”œβ”€β”€ common
β”‚   β”œβ”€β”€ defaults
β”‚   β”‚   └── main.yml                # Default variables for the role
β”‚   β”œβ”€β”€ files
β”‚   β”‚   └── ...                     # Files to be copied to remote hosts
β”‚   β”œβ”€β”€ handlers
β”‚   β”‚   └── main.yml                # Handlers, triggered by tasks
β”‚   β”œβ”€β”€ meta
β”‚   β”‚   └── main.yml                # Role dependencies and metadata
β”‚   β”œβ”€β”€ tasks
β”‚   β”‚   └── main.yml                # Main list of tasks to execute
β”‚   β”œβ”€β”€ templates
β”‚   β”‚   └── ...                     # Jinja2 templates to be deployed
β”‚   β”œβ”€β”€ tests
β”‚   β”‚   β”œβ”€β”€ inventory               # Test inventory file for Vagrant
β”‚   β”‚   └── test.yml                # Test playbook
β”‚   └── vars
β”‚       └── main.yml                # Variables for the role
β”œβ”€β”€ webserver
β”‚   β”œβ”€β”€ defaults
β”‚   β”‚   └── main.yml                # Default variables for the role
β”‚   β”œβ”€β”€ files
β”‚   β”‚   └── ...                     # Files to be copied to remote hosts
β”‚   β”œβ”€β”€ handlers
β”‚   β”‚   └── main.yml                # Handlers, triggered by tasks
β”‚   β”œβ”€β”€ meta
β”‚   β”‚   └── main.yml                # Role dependencies and metadata
β”‚   β”œβ”€β”€ tasks
β”‚   β”‚   └── main.yml                # Main list of tasks to execute
β”‚   β”œβ”€β”€ templates
β”‚   β”‚   └── ...                     # Jinja2 templates to be deployed
β”‚   β”œβ”€β”€ tests
β”‚   β”‚   β”œβ”€β”€ inventory               # Test inventory file for Vagrant
β”‚   β”‚   └── test.yml                # Test playbook
β”‚   └── vars
β”‚       └── main.yml                # Variables for the role
└── database
    β”œβ”€β”€ defaults
    β”‚   └── main.yml                # Default variables for the role
    β”œβ”€β”€ files
    β”‚   └── ...                     # Files to be copied to remote hosts
    β”œβ”€β”€ handlers
    β”‚   └── main.yml                # Handlers, triggered by tasks
    β”œβ”€β”€ meta
    β”‚   └── main.yml                # Role dependencies and metadata
    β”œβ”€β”€ tasks
    β”‚   └── main.yml                # Main list of tasks to execute
    β”œβ”€β”€ templates
    β”‚   └── ...                     # Jinja2 templates to be deployed
    β”œβ”€β”€ tests
    β”‚   β”œβ”€β”€ inventory               # Test inventory file for Vagrant
    β”‚   └── test.yml                # Test playbook
    └── vars
        └── main.yml                # Variables for the role
Code language: PHP (php)

Q9. What are top 10 Roles you have used in your work?

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
1
0
Would love your thoughts, please comment.x