Accelerate Ansible Flashcards

1
Q

What is SSH multiplexing

A

Reuse of TCP connections to execute many SSH sessions. Traditionally, each SSH session establishes a separate TCP connections, which incures negotiation penalty.

By using SSH multiplexing, playbooks are able to reuse the TCP connection

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

What is ControlPersist?

A

Same as SSH multiplexing

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

How do you check if ssh multiplexing is enabled for a site myserver.example.com?

A

ssh -o check ubuntu@myserver.example.com

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

How do you termine the master connection for a site myserver.example.com

A

ssh -o exit ubuntu@myserver.example.com

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

What are the three parameters that can be configured for customizing multiplexing behavior?

A
  • ControlMaster: tell if ssh multiplexing should be enabled
  • ControlPath: tells where tos tore the socket file for esach node
  • ControlPersist: how long the master connection should be kept idle
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When talking about ssh multiplexing, explain what is a master connection.

A

Master connection is the reusable connection that TCP creates to talk to a host when SSH multiplexing is enabled.

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

Despite enabling SSH multiplexing, TCP might sometimes not setup a master connection. Explain why?

A

SSH multiplexing opens a file to represent each master connection. It uses the hostname as the name of the file. If this filename is too long, the operating system might reject its creation; causing TCP to error in the creation of the master connection and therefore falling back to creating a new socket each time.

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

In what situations can it make sense to disable fact gathering and why?

A

if my playbook doesn’t use facts, I can disable fact gathering to speed up the playbook execution.

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

How do you disable fact gathering for one playbook?

A

gather_facts: false

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

How do I disable fact gathering for all my playbooks?

A

In ansible.cfg default section:

[defaults]
gathering=explicit

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

How can I speed up my playbook fact gathering process?

A

Use fact caching

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

How do you enable fact caching?

A

in ansible.cfg

[defaults]
gathering=smart
fact_caching=jsonfile

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

How do you specify fact caching timeout?

A

In ansible.cg (in seconds)
[defaults]
fact_caching_timeout= 300

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

What are the fact caching implementations supported by ansible?

A

redis
memcached
json

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

How do I specify which fact caching implementation Ansible should use?

A

In ansible.cfg,

[defaults]
fact_caching=jsonfile (or redis or memcached)

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

What is the default ansible fact caching implementation?

A

There is no default fact caching implementation. if you do not specify one, Ansible will not cache facts.

17
Q

I want to use json for caching facts. How do I specify where these files should be stored?

A

in ansible.cfg

[defaults]
fact_aching_connection=/tmp/ansible_fact?cache

18
Q

I want to use memcached for fact caching, how do I specify the address and port of the memcached instance to be used by ansible?

A

memcahed instance should be installed locally to the control node.

19
Q

I want to use redis for fact caching, how do I specify the address and port of the memcached instance to be used by ansible?

A

redis instance should be installed locally to the control node.

20
Q

If I have an inventory of 500 nodes, will Ansible connect to all of them in parallel to execute my playbook?

A

The short answer is no. While Ansible connects to node in parallel, the number of nodes ansible connects to simultaneously is limited. This limit can be defined in ansible.cfg

[defaults]
forks=20

21
Q

Explain:

[defaults]
forks=20

A

This is a configuration that goes into ansible.cfg to define how many managed nodes ansible.cfg should connect to in paralle.

22
Q

What is the use of async in Ansible?

A

Asynchronous tasks are useful in following scenarios:

  • task that would take so long that the tcp connection would timeout before the task is completed
  • ## start a second task before the the previous one is completed
23
Q

What happens when the socket timeout is shorter than the time it takes to execute a task?

A

The socket may timeout causing ansible to report the task as failed. This can be avoided by making the task async.

24
Q

How does Ansible know that an async task is completed?

A

it periodically polls the node to check whether the tsk is complete, sleeping between checks

25
Q

If I use async, how do I capture the result of the task execution?

A

Use register clause to capture the async result

26
Q

Explain pipelining

A

Instead of copying files, running them on the remote server, then removing them, pipelining sends and executes commands directly over the SSH connection