Ansible Interview Questions and Answers

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

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: started
---
- 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: restarted

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'

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

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
()
x