Ansible Flashcards

1
Q

What is Ansible and how it works?

A

Ansible is an open-source software platform for automating and configuring computer systems. It is designed to help administrators and developers automate system administration tasks, such as configuration management, application deployment, and provisioning.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What have you done with Ansible?

A

Installed ansible on control node.
Added host in inventory
Configured ansible.cfg (custom inventory and playbook)
Ran ad-hoc commands
Created ansible playbooks for automation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How would you convince you manager that provisioning with Ansible is beneficial for the company?

A

Free: ansible is an open source tool.
Very simple to set up and use: no special coding skills are necessary to use ansible’s playbooks.
Powerful: ansible lets you model even in highly complex IT workflows.
Fexible: you can orchestrate the entire application environment no matter where its deployed. You can also customize it based on your needs.
Agentless: you don’t need to install any other software or firewall ports on the client’s systems you want to automate. You also don’t have to set up a separate management structure.
Efficient because you do’t need to install any extra software. There’s more room for applications resources on your server.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How Ansible control node manages the manage nodes?

A

through ssh

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How we can list all the hosts that ansible is managing?

A

ansible all - -list-host

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Can you describe idempotancy?

A

Is the ability to execute an operation several times which provides same results. Meaning if its run once or multiple times.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Can you give me name of modules you worked with?

A

Package management , service, copy, debug, lineinfile, users.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to manage your Ansible hosts?

A

Create an inventory with is by default /etc/ansible/hosts where we mention different group for managed nodes. We can create our customized inventory file anywhere and we call that inventory file. Ansible uses ssh to communicate with the mentioned inventory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the path to the Ansible configuration file?

A

/etc/ansible/ansible.cfg

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to check Ansible version?

A

ansible - -version

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you maintain Ansible inventory?

A

The inventory can be specified in a variety of formats, including a simple list of host names or IP addresses, a group of host names or IP addresses, or a more complex configuration that specifies multiple groups of hosts and their associated variables.
Static inventory or dynamic inventory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is static inventory?

A

static inventory file is a plain text file containing a list of managed hosts or remote nodes whose numbers and IP addresses fairly constant.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is dynamic inventory?

A

Dynamic host file is being updated right away in a shell script when the hosts are being decommissioned

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Do you know difference between notify and register?

A

Notify tells the handlers that the tasks has been changed and the handlers will perform the task.
The register is a way to capture the output from the task execution and stores it into a variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the difference between job templates and projects in tower?

A

job templates are used to define and execute specific tasks, while projects are used to organize and manage the files and artifacts that are required to execute those tasks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are things you automated through Ansible?

A

configuration of systems, such as installing and configuring software, setting up users and groups, and modifying system settings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is dry run?

A

A dry run is when all of the tasks defined in the playbook will be checked against all of the hosts but none of them will actually ran

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is ansible galaxy?

A

Is a way to run a single ansible task quickly on all your managed notes.
You may want to run the ad-hoc command to edit some configuration files, stop/start service on your remote machines update particular package, shutdown set of hosts or to collect some info such as uptime on all your servers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Can you define roles in ansible?

A

Roles are really just a way to split up your playbook into smaller reusable parts. It also simplifies playbooks since you only have to create minimal playbooks.
By default, Ansible looks for roles in the roles subdirectory relative to the playbook file or the system directory /etc/ansible/roles . You can also use the Ansible configuration roles_path to define alternative role locations. You can also include the role in the playbook using the module include_role.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Can you tell me how to use inventory file in Ansible?

A

-i
Ansible - I ansible all -m ping

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is Ad-hoc command why it is really needed?

A

Is a way to run a single ansible task quickly on all your managed notes.
You may want to run the ad-hoc command to edit some configuration files, stop/start service on your remote machines update particular package, shutdown set of hosts or to collect some info such as uptime on all your servers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Why we don’t go with play book and we use Ad-hoc commands preferably?

A

Ad-hoc command is useful to perform quickly task but it has limited usage.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Have you heard about tags in environment?

A

Tags in playbooks allow you to selectively target certain tasks at run time. For example:
Tag:users it will run only that.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Can you go over little bit about Ansible tower?

A

Ansible by itself is a command line tool.

Ansible Tower is a framework for Ansible.

It is a web-based solution that provides a Graphical User Interface (GUI). It reduces the dependency on the command line prompt window.

It is easy to use and makes it easy for non developers to create the environment they want.

Tasks can now be performed in a single click instead of typing long commands.

Ansible Tower dashboard shows hosts, inventory, and projects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What have you done with Ansible tower?

A

Managing credentials, managing job templates and job workflows. Simple task adding users, resetting users passwords.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Are you familiar with the concept of vars? How we use them?

A

Vars are variables, we define most of the time on the play level. we can use these variables later in our playbook. We call it in different tasks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

If you want to register the output of a task in your playbook. How do you do that?

A

Register is the way to capture the output of a task execution and store it in a variable.
Register: (register name)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

If I want to push list of packages, which are not segregated and want to run on all machines as RHEL 6, RHEL 7 & RHEL 8 packages get install on respective machines?

A

Use WHEN module and use the following ansible_distribution= “” and ansible_distribution_major_version=”” variables defined in gather facts .
defined to reel 6, rhel7, rhel8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

When do you use notify in Ansible playbook?

A

Notify is a supporting module for a handler, you must notify a handler for it to be executed.

30
Q

Do you know the use of delegate_to module when writing a playbook?

A

Ansible Delegate_to module helps us to execute a specific task in our playbook to run in other host or machine.
If you want to run any task on any particular machine you can use ansible delegate_to module.

31
Q

Difference between shell and command module?

A

Both commands are used to execute linux commands in ansible. However shell allows you to run commands on the remote host and if you were logged in.
Module it doesn’t not use shell and it can accomplish one task at a time.

32
Q

You got a playbook which you only have to run in specified condition?

A

Use the when clause to specify a condition that must be met for a task to be run.

33
Q

How we can manage to run a task out of the whole playbook on a certain host?

A

To run a specific task out of a playbook on a specific host, you can use the ansible-playbook command with the –limit option and the name of the host

34
Q

If you don’t want to run the playbook on specific host how can you do that?

A

Ansible -I my inventory all -m ping -l webserver

35
Q

How can you limit the task on Ansible?

A

using –l
ansible –l myinventory all-m ping -l webserver

36
Q

If you want to add a line on multiple server. How can you do that?

A

Line in file module

37
Q

What is handlers in Ansible playbook?

A

Handler is a reaction to a completed task.
Handler is a special type of task that is run at the end of a group of a task. They are only run when notified.

38
Q

How can you loop the variable in Ansible playbook?

A

loop: “{{variable name}}”

39
Q

If you want to keep everything encrypted how would you do that?

A

Ansible vault is a mechanism that allows you encrypt content (variables, keys, passwords, files, etc..), which can be incorporated into ansible workflow. The tasks ansible vault can perform are encrypt a file, decrypt a file, view an encrypted file without breaking the encryption, edit an encrypted file, create an encrypted file, generate or reset the encrypted key. This is important with files that contain sensitive and important data like usernames and passwords and this feature prevents this type of data from being exposed.
– example –
creating an encrypted file using the command “ansible-vault create secure.yml” after which u set a password.
Editing the encrypted file using command “ansible-vault edit secure.yml” and give password and edit the sensitive data file.

40
Q

What is difference between diff and check mode in Ansible?

A

shows the difference between the current state of a file on the remote server and the state the file should be in, according to the Ansible task. The “check” mode, on the other hand, performs a dry-run of the task and reports any changes that would be made, without actually making those changes. T

41
Q

When you use copy module what it do in backend? And why Ansible is better than SCP?

A

The copy module in Ansible uses the remote_src option to determine if the file should be transferred from the local machine to the remote machine or if it should be transferred between remote machines. Ansible uses an agentless architecture, whereas SCP requires an SSH server to be installed and configured on the remote machine.
Ansible allows for more fine-grained control over the state of the remote machine, whereas SCP is limited to file transfer.
Ansible allows for more complex automation and orchestration tasks, such as rolling
With Ansible, you can automate and configure multiple machines at the same time, whereas with SCP you would have to manually transfer files to each machine.

42
Q

Why Ansible is better than pssh (Parallel SSH)?

A

With Ansible, you can automate and configure multiple machines at the same time, whereas with pssh you would have to manually run commands and transfer files to each machine.
Ansible uses an agentless architecture, whereas pssh requires that SSH clients be installed and configured on the remote machines.

43
Q

Do you know main differences between static and dynamic inventory in Ansible Tower?

A

a static inventory is a pre-defined list of hosts that you can manage with Ansible Tower. This list of hosts is defined in the Tower interface and does not change unless you manually update it.
A dynamic inventory, on the other hand, is an inventory that is generated on the fly by a script or an external system. This allows for the inventory to be updated automatically without manual intervention.

44
Q

what are ansible plugins?

A

Ansible plugins are scripts or modules that extend Ansible’s functionality.

45
Q

Any time you build a server you have to update it manually this inventory or it is set up its own?

A

You have set it up manually regardless if its dynamic or static.

46
Q

What type of application support did you extended through Ansible?

A

Containers: Ansible can be used to automate the deployment and management of container-based applications, including the orchestration of containers using tools such as Docker and Kubernetes.

47
Q

Did you have a situation when Ansible can’t do what you want to do? And how you can do it?

A
48
Q

What is the difference between job templates and projects in tower?

A

a job template is a reusable configuration that defines the parameters for a job, including the playbook that will be executed, the inventory that will be used, and the credentials that will be required to connect to the hosts.
A project is a container for Ansible playbooks and related files. It includes the source code repository, the inventory file, and the credentials that are required to run the playbooks.

49
Q

Are there different output beside -v?

A

t (tags): This option allows you to run only specific parts of a playbook, by specifying one or more tags that identify the tasks you want to run.
-l (limit): This option allows you to run a playbook on a specific subset of hosts.

50
Q

How we can differentiate a playbook for development and production environment?

A

Use different inventories
Use environment variables
Use tags
Use different playbooks
Use different roles
Use conditionals

51
Q

What are different type of variables in Ansible?

A

Facts
Variables
Registered variables
Special variables
Magic Variables

52
Q

How do you target different servers?

A

The “hosts” keyword specifies the group of servers. Example:
- hosts: web_servers
tasks:

53
Q

Do you know about tasks and vars, and how do we use them in roles?

A

Tasks are defined in playbooks and are executed in the order they are listed.
Variables, as mentioned earlier, are values that can be used in tasks and playbooks.
A role is a collection of tasks, files, templates, and variables that can be reused across different playbooks.

54
Q

Difference between module and roles in Ansible?

A

Modules are pre-defined units of code that perform specific tasks and can be used in playbooks to perform tasks on remote servers.
Roles are a way to organize and group tasks and variables in Ansible, and are used to make playbooks more organized and reusable. They encapsulate tasks and variables in a specific functionality that can be reused across different playbooks.

55
Q

How do you get more details on command line when running playbook?

A

-vvvv .
can be used to display even more detailed output, including all of the tasks that are run and their output.
ansible-playbook -vvv -C web_server.yml

56
Q

Can you give a example where you have writing any playbook or configured application?

A
  • name: Configure web server
    hosts: web_servers
    become: true
    vars:
    apache_version: 2.4
    tasks:
    • name: Install Apache web server
      package:
      name: apache2
      state: present
      version: “{{ apache_version }}
    • name: Restart Apache
      service:
      name: apache2
      state: restarted
57
Q

You are trying to build a server 6th time with same kind of application. Do you think that you can optimize this process by using Ansible template?

A

Yes of course because you can use a template where you have variables, connection for the network or any configurations, use loops or and conditionals to customize the configuration of the application.

58
Q

When you are going to edit a code like playbook. What tool you use to edit the code?

A

I will use vim editor

59
Q

If you have a collection of webservers and database servers, and you have to install apps on different servers what would you do? What are some different things you would consider?

A

Ansible, puppet or chef. Consider different inventory database server, web server , prod etc..

60
Q

If you want to add one string before and after that line on Ansible. How can you do that?

A

you can use the lineinfile module to add a string before or after a specific line in a file

61
Q

How you check the code change (in feature branch) is going to work or not using Ansible playbooks?

A

dry run

62
Q

Can we automate the application deployment and configuration by using Ansible template?

A

Yes, you can use Ansible templates to automate the deployment and configuration of applications.

63
Q

Does the Ansible template help us to deploy or take care of all the configuration?

A

Yes to deploy but not all types of configuration for example kernel configuration that will be modules or user commands.

64
Q

Did you create and custom logical-volume in playbooks?

A

Yes using playbooks using the lvcreate and lvm modules.

65
Q

Difference between playbook and roles?

A

Ansible playbooks are a collection of tasks written in . A role is a collection of files and directories that are organized in a specific structure, and it can be used to perform a specific task or set of tasks. format that describe the desired state of the servers.

66
Q

How to create multiple users without the need to creating the script multiple times?

A

You can use Ansible loops to create multiple users without the need to create the script multiple times. Ansible loops allow you to iterate over a list of items and perform the same task on each item.
- name: Create multiple users
user:
name: “{{ item }}”
state: present
loop:
- user1
- user2
- user3

67
Q

How would you manage the servers and put them in different groups?

A

The inventory file is a simple text file that lists the servers that Ansible will manage, along with their IP addresses or hostnames, and any groups or variables that are associated with them.

68
Q

If you want to keep everything encrypted how would you do that?

A

ansible-vault encrypt secrets.yml –vault-password-file vault_pass.txt

69
Q

If you want to run playbook on 15,000 servers already mention in inventory. How would you accelerate that?

A

It can take a significant amount of time, depending on the complexity of the tasks and the resources of the servers. You can enter -f for fork.
ansible-playbook -f 100 playbook.yml

70
Q

If you want to manage these server from the single server. How can you make it fault tolerant?

A

Managing a large number of servers from a single server can be challenging, especially when it comes to fault tolerance so we can use ansible tower.