Accelerate Ansible Flashcards
What is SSH multiplexing
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
What is ControlPersist?
Same as SSH multiplexing
How do you check if ssh multiplexing is enabled for a site myserver.example.com?
ssh -o check ubuntu@myserver.example.com
How do you termine the master connection for a site myserver.example.com
ssh -o exit ubuntu@myserver.example.com
What are the three parameters that can be configured for customizing multiplexing behavior?
- 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
When talking about ssh multiplexing, explain what is a master connection.
Master connection is the reusable connection that TCP creates to talk to a host when SSH multiplexing is enabled.
Despite enabling SSH multiplexing, TCP might sometimes not setup a master connection. Explain why?
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.
In what situations can it make sense to disable fact gathering and why?
if my playbook doesn’t use facts, I can disable fact gathering to speed up the playbook execution.
How do you disable fact gathering for one playbook?
gather_facts: false
How do I disable fact gathering for all my playbooks?
In ansible.cfg default section:
[defaults]
gathering=explicit
How can I speed up my playbook fact gathering process?
Use fact caching
How do you enable fact caching?
in ansible.cfg
[defaults]
gathering=smart
fact_caching=jsonfile
How do you specify fact caching timeout?
In ansible.cg (in seconds)
[defaults]
fact_caching_timeout= 300
What are the fact caching implementations supported by ansible?
redis
memcached
json
How do I specify which fact caching implementation Ansible should use?
In ansible.cfg,
[defaults]
fact_caching=jsonfile (or redis or memcached)
What is the default ansible fact caching implementation?
There is no default fact caching implementation. if you do not specify one, Ansible will not cache facts.
I want to use json for caching facts. How do I specify where these files should be stored?
in ansible.cfg
[defaults]
fact_aching_connection=/tmp/ansible_fact?cache
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?
memcahed instance should be installed locally to the control node.
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?
redis instance should be installed locally to the control node.
If I have an inventory of 500 nodes, will Ansible connect to all of them in parallel to execute my playbook?
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
Explain:
[defaults]
forks=20
This is a configuration that goes into ansible.cfg to define how many managed nodes ansible.cfg should connect to in paralle.
What is the use of async in Ansible?
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
What happens when the socket timeout is shorter than the time it takes to execute a task?
The socket may timeout causing ansible to report the task as failed. This can be avoided by making the task async.
How does Ansible know that an async task is completed?
it periodically polls the node to check whether the tsk is complete, sleeping between checks
If I use async, how do I capture the result of the task execution?
Use register clause to capture the async result
Explain pipelining
Instead of copying files, running them on the remote server, then removing them, pipelining sends and executes commands directly over the SSH connection