Ansible Flashcards

1
Q

What is ansible and how does it work?

A

Ansible is a tool that provides IT automation where you can write instructions that automate the IT set you would do in the past.
It can also do IT orchestration, where you have to run tasks I. Sequence and create a chain of events which must happen. Of several different servers or devices.

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.
    *create ansible playbooks for automation.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How would your convince your 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 (more on playbooks later).
    *powerful: ansible lets you model even in highly complex IT workflows.
  • flexible: you can orchestrate the entire application environment no matter where it’s deployed. You can also customize it based on your needs.
    *Agentlee: 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 don’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

Beside time saving what are other benefits by provisioning with Ansible?

A

*we can make configuration management.
*we can make manage services and user management at the same time.

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

How ansible control Node manages the managed nodes?

A

Through ssh

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

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

A

Ansible all –list-hosts

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

Can you describe idempotency?

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
8
Q

Are you familiar with Ansible Collection?

A

Yes I have worked ad-hoc commands, playbooks, roles, managed different modules and add different tasks.

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

What kind of playbook have you written?

A

I have written playbooks where I managed users, storage, web server management and patching, lineinfile,

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

Can you give me the names of modules you have 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
11
Q

Where are the modules located?

A

Default modules
/usr/lib/python2 7/site-packages/ansibles/modules
For local:
/usr/share/ansible/plugins/modules.

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

Do you know the difference between dynamic and static inventory?

A

*Dynamic host file is being updated right away in a shell script when the hosts are being decommissioned.
*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

How to manage your ansible hosts?

A

Create an inventory which is by default /etc/ansible/hosts.
Where we mention different groups for hosts and different group for managed nodes.
We cam 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
14
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
15
Q

How to check ansible version?

A

Ansible - - version

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

Do you know the 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
17
Q

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

A

*Is a way to run a single ansible task quickly on all you 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 pkg, shutdown set of hosts. Or to collect some info such as uptime on all of your servers.
*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
18
Q

Have you heard about tags in enviroment?

A

Tags in playbooks allow you to selectively target certain tasks at tun 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
19
Q

Are you familiar with concept of vars? How do 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
20
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
21
Q

How to create multiple users without the need to create multiple users?

A

*using for loop with a variable that is always {{ ‘item’ }}
*we define the list of user under the variables and then we use loop to call that variable .

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

Difference between shell and command module?

A

*both commands are used to excute linux command in ansible. However shell allows you to run commands on the remote host as if your were logged in.
*module it does not use shell and it can accomplish one task a time.

23
Q

Why we need command modules in the presence of shell module?

A

The command module it offers more security can work with the devices but shell module needs kernel it cannot work wit the devices like switch or route.

24
Q

How would you compare bash script and ansible?

A

Bash is written in bash to run multiple commands and ansible is written in different language YAML, used as management and orchestration tool and works with SSH.

25
Q

You got a playbook which you only have to run in specified conditions in ansible what you do to run on certain host?

A

We use conditionals where we use WHEN module.

26
Q

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

A

add -l ‘!nameserver’ at the end if the syntax.
Ansible-playbook playbook1.yml -limit !vm3 or ip

27
Q

You mentioned that you deploy webserver on ansible how can you do that?

A

Using a playbook with the yum module and httpd state present and then enabled httpd service .

28
Q

How can you limit the task on Ansible?

A

Using the - -l limit
Ansible -I myinventory all-m ping -l webservers

29
Q

What is handlers in ansible book?

A

Handler is a reaction to a completed task.
* a 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.

30
Q

What is a notify handler?

A

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

31
Q

How can you loop the variable in ansible book?

A

Loop: “{{ variable name }}”

32
Q

How can we define variable in a playbook?

A

Vars:
And under that we can give it a key and a value on the play level, task level or command line.
Vars:
Key:value
Pkg_name: name

33
Q

Can we define a variable on a play and how?

A

Yes by putting under tasks:
VARS:
and key value under it

34
Q

How can we call a variable in a playbook?

A

name: “{{variable_name}}”

35
Q

If we have same variable in play level and the very same under tasks, which one will take precedence?

A

The task will take precedence.

36
Q

How many tasks you have in a play?

A

Unlimited

37
Q

How many plays you can have in a playbook?

A

Unlimited

38
Q

Can we have a play in a task in a playbook?

A

No, play comes first

39
Q

Can we have task under the plays?

A

Yes

40
Q

What is the default inventory file for ansible?

A

/etc/ansible/hosts

41
Q

How can you use a custom inventory file?

A

Create a file name and use -I to call the inventory

42
Q

How can you use a custom configuration file?

A

Just have it as your pwd and run the playblook.

43
Q

What is the default configuration file for ansible?

A

/etc/ansible/ansible.cfg

44
Q

What flag would be used to call custom inventory?

A

-i

45
Q

How can you limit to run Ad-hoc command or playbook o. A certain group/hosts?

A

With -l to limit it to certain group or hosts. You can always put commas separated values to call multiple groups or hosts. It you want to exclude something you use “!” In quotes and put the name of the group or the hosts.

46
Q

How can you check the syntac error in a playbook?

A

Ansible-playbook (playbookname) –syntax-check

47
Q

How can you dry run playbook?

A

With -C.
Ansible-playbook (playbookname) -C

48
Q

What is dry run of a playbook?

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.

49
Q

Can you define a variable on command level?and will it take precedence on all other values defined?

A

-e, it will take precedence over other values defined.

50
Q

How do you define a default value in a task?

A

Whenever you call your variable just put a pipe there | write default and in the parenthesis with signal quotes define the value.
name: “{{package_name | default (‘httpd’) }}”

51
Q

What are competitors of Ansible?

A

Puppet , octopus deploy, azure pipeline, saltstack, chef

52
Q

How can we get list of modules?

A

ansible-doc -l

53
Q

How we can get the example or module?

A

Ansible-doc <module> then hit enter and write /EXAMPLE</module>