Customizing Hosts, Runs, Handlers Flashcards

1
Q

What are possible host patterns?

A

all, union, intersection, exclusion, wildcard, range, regular expression

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

Explain intersection in host definition and give an example

A

Apply a task on the intersection of two groups.

hosts: database:&staging

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

Explain union in host definition and give an example

A

Apply a task on the union of two groups.

hosts: database:staging

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

Explain exclusion in host definition and give an example

A

Apply a task on the exclusion of a group from another groups.

hosts: database:!staging

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

Explain wildcard in host definition and give an example

A

Apply a task on set of hosts matching an expression defined with wildcard.

hosts: *.example.com

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

Explain range in host definition and give an example

A

Apply a task on set of hosts defined by range

hosts: web[1:20].example.com

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

Explain regex in host definition and give an example

A

Apply a task on set of hosts defined by regular expression

hosts: ~web\d+.example.(org|com)

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

Sketch a command that would run a playbook.yml against a group of hosts web as opposed to the whole invetory.

A

ansible-playbook -l web playbook.yml

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

Sketch a command that would run a playbook.yml against a group of hosts using filters.

A

ansible-playbook -l web:staging playbook.yml

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

What clause allows you to run a command on the control machine?

A

local_action

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

Give an example scenario where running a command on the control host makes sense and provide the correspdoning ansible task.

A

We restarted the managed host and we have to wait for it to be back before we do other configuraions. In this case, the wait will be on the control node.

-name: wait for managed host to be back
local_action: wait_for port=22 host=”{{ inventory_hostname}}” search_regex=OpenSSH

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

What are some use cases where you might want to run a command on a node other than the control and the managed node?

A

1) You have to add the managed node to a load balancer

2) You have to configure an alerting system to watch the managed node

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

What is the key clause that enables running a command on a node other than the control and the managed nodes?

A

delegate_to

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

Provide an example task of running a command on a node other than the control and the managed nodes?

A
  • name: enable alerts
    nagios: action=enable_alerts service=web host={{ inventory_hostname}}
    delegate_to: nagios.example.com
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the default execution mode: one node after anorher or all nodes in parallel?

A

all nodes in parallel.

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

Cite an example where running ansible on managed node in sequence would make sense as opposed to running in parallel.

A

Upgrading a production application where many nodes are behing a LB. Becase don’t need the service interruption, we would upgrade one node at a time.

17
Q

What clause do you use to run the playbook on one node at a time?

A

serial:1

18
Q

What clause do you use to run the playbook on 20% of node at a time?

A

serial: 20%

19
Q

I have 5000 nodes in my inventory. I want to try the playbook on one node first and then run it on 10% of nodes at a time. what is the right construct for this?

A

serial:

- 1
- 20%
20
Q

Explain max_fail_percentage

A

Allows you to specify the number of nodes that are allowed to fail when running the playbook. The value is in percentage. Beyond the specified percentage, Ansible will stop running the playbook.

21
Q

What is the clause for running a playbook only once?

A

run_once: true

22
Q

What scenario can it be useful to run the playbook only once?

A

database initialization or sometimes local actions

23
Q

What are example of ansible running strategies?

A

linear, free

24
Q

What is the default Ansible running strategy?

A

linear

25
Q

What is a running strategy?

A

Strategy is a mechanism that determines in which order Ansible will run the tasks across the nodes. For instance execute the same task on all nodes, wait for it to complete before proceeding to the next task, or do not wait for all tasks to complete and proceed to the next task once a node is node running the previous task.

26
Q

Explain ansible linear strategy.

A

Running strategy wherein ansible executes the same task on all nodes, wait for the task to complete on each of the nodes before proceeding to the next task.

27
Q

Explain ansible free strategy.

A

Running strategy wherein when executing a tasks on a node Ansible does not wait for other nodes to have completed this task. Any node that is done executing a task can proceed to the next task in the play.

28
Q

In what cases can it be useful to employ the free running strategy?

A

When nodes have different hardware specifications such that some may be faster than others. Network latency can also be a parameter.

29
Q

It is possible to execute a handler many times in one play. Explain how.

A

The same handler can be triggered from pre_tasks, tasks, or post_tasks sections. Each of these sections will trigger a separate execution of the handler.

30
Q

What is the scope of a handler?

A

The scope of a handler is the play. You cannot nofify a handler beyond a play.

31
Q

What problem do you see in listing the names of handlers in a notify clause?

A

hard coupling of handlers and tasks. This can get cumbersome if the notify includes many handlers.

32
Q

How can you solve the issue of hard coupling between tasks and handlers?

A

Make handlers to listen to changes as opposed to being notified.

handlers:

  • name: restart postfix
    service: name=postfix state=restarted
    listen: postfix config changed
33
Q

What is one of the fundamental benefits of handlers listen?

A

handlers across roles and solving role dependencies. In cases where a role has to notify the depending roles of any changes, this introduces unwanted strong coupling. E

34
Q

What is the default behavior if a notify is defined without handler?

A

Ansible will complain about notifying missing handler.

35
Q

Explain the error_on_missing_handler flag.

A

When set to true, Ansible will complain about notifying missing handler. When set to false, Ansible will not complain.