Introduction Flashcards

1
Q

In what file do you specify information about servers that have to be managed by Ansible?

A

inventory file

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

What is the command for running playbooks?

A

ansible-playbook

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

What is ansible command for ad-hoc execution of commands?

A

ansible -i hosts -m ping

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

In what order does ansible look for config file?

A

1) ANSIBLE_CONFIG env variable
2) ./ansible.cfg (current directory)
3) ~/.ansible.cfg (home folder)
4) /etc/ansible/ansible.cfg (Installation directory)

(ECHI)

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

What is the prefered location for ansible config file?

A

current directory alongside playbooks

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

Why put ansible config files alonside playbooks?

A

So they can be version controlled

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

Example of variables that can be defined in ansible config file

A

1) Location of inventory file
2) User to SSH
3) SSH private keys

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

What is the default location of ansible config?

A

/etc/ansible/ansible.cfg

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

Command module for check uptime on testserver

A

ansible testserver -m command -a uptime

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

Explain: ansible testserver -a uptime

A

Execute the command module to check uptime of remote server: testserver. -m command is ommitted because the command module is very often used.

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

When running the command module what is the -b flag used for?

A

become root and run the command in priviledged mode

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

What is a playbook?

A

An ansible configuration management script

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

What is the very first line of a playbook?

A

three dash: —

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

Strings in YAML?

A

1) “This is a string”

2) This is also a string

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

Comments in YAML

A

This is a comment

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

Booleans in YAML

A

true, True, TRUE, yes, Yes, YES, on, On, ON, y, Y

false, False, FALSE, no, No, NO, off, Off, OFF, n, N

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

List in Ansible

A
  • One
  • Two
  • Three

or

[One, Two, Three]

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

Dictrionary or Mapping in Ansible

A

address: 742 Evergreen Terrace
city: Vancouver
state: North Dakota

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

Define the structure of a playbook

A

A playbook is a list of plays, which themselves are dictionaries. So a playbook is a list of dictionaries.

20
Q

Define the structure of a play

A

A play is a dictionary that must include:

1) hosts to confiigure
2) A list of tasks, which themselves are dictionaries

The play connects hosts to tasks.

21
Q

Additional common settings of a play?

A

1) become
2) name
3) vars

22
Q

Sytructure of a task

A

1) Name

2) module : arguments (e.g. apt: name=nginx update_cache=yes)

23
Q

what are modules?

A

scripts that come with ansible and execute some sort of actions on the managed hosts

24
Q

Example of modules

A

apt, copy, file, template

25
How do you get documentation on a module such as "copy"?
ansible-doc copy
26
Sum up the structure of a playbook?
1) A playbook is a list of plays 2) A plays ties an unordered set of hosts to an ordered list of tasks 3) Each task is associated with exactly one module
27
How do you reference a variable "var" in a playbook?
{{ braces }}
28
When do you have to quote variable reference?
``` When it starts the argument part of a module declaration. For instance: command: {{ braces }} - a foo ``` Should be replaced with: command: "{{ braces }} - a foo"
29
What problems do you encounter if your command argument contain colon?
The colon makes ansible believe that your argument is a dictionary. This is solve by quoting the argument again. However, in the case of debug module double quote is needed. - name: show a debug message debug: "msg='This is a message: eh?'"
30
What is a handler?
A handler is a conditional structure similar to a task. It is triggered only if it has been notified by a task.
31
How does a task notify a handler?
It includes the notify instruction along with the name of the handler as argument. - name: Copy TLS certs copy: source dest notify: restart nginx
32
How many times can a handler run in the execution of a playbook and when?
A handler runs only once after all the tasks are run at the end of the play. Even if the handler is notified multiple times, it runs only once.
33
Many handlers are defined in a play. In which order will they be executed?
In the order in which they are defined in the play NOT in the order in which they are notified.
34
What are typical use cases for handlers?
1) restarting services (more frequent) | 2) reboot
35
Give two orchestration scenarios that are good for Ansible?
1) Upgrading web application behind a load balancer one after the other 2) Making sure DB is started and configured before web app starts
36
Write a task to install nginx on an Ubuntu node
- name: Install nginx | apt: name=nginx
37
Why is Ansible push model interesting?
You have full control on when the changes are applied and you do not need to wait for timers to expire.
38
What is the advantage of idempotency?
It's safe to run an Ansible playbook multiple times against a server
39
Write a task to create a user
- name: Create user deploy | user: name=deploy group=web
40
Example of activity that goes into a pre-handler
Update the apt cache on Ubuntu
41
What happens when a host is defined in many groups with different set of variables?
The variable set are merged and the precedence rule applies
42
How do you validate connectivity to a host?
ansible host -m ping
43
Give example of two modules that are not idempotent
command and shell
44
Is command module idempotent?
No, command and shell modules are not idempotemt
45
Is shell module idempotemt?
No, command and shell modules are not idempotemt
46
What is a module?
encapsulated procedure that is responsible for managing a specific component on a specific platform.
47
What is battery-included approach?
The fact that Ansible includes tones of modules built-in.