2 minute read

Concepts

Modules

Discrete units of code that can be used from the command line or in a playbook task. Ansible executes each module, usually on the remote managed node, and collects return values. In Ansible 2.10 and later, most modules are hosted in collections. Modules support taking arguments.

Collections

A distributed format for content that can include playbooks, roles, modules, and plugins. You can install and use collections through a distribution server, such as Ansible Galaxy.

Plugins

Pieces of code that augment Ansible’s core functionality. Ansible uses a plugin architecture to enable a rich, flexible and expandable feature set. Ansible ships with some plugins. You can write your own. Action plugins act in conjunction with modules to the execute actions required by playbook tasks.

Facts

Variables related to remote systems.

Magic Variables

Variables related to Ansible itself.


Command Lines

Gather facts from one host:

ansible <host-name-or-IP> -m ansible.builtin.setup

Run an ad-hoc command:

ansible <host-name-or-IP> -m command -a "getent hosts"


Managing Parallelism: Tune performance and control execution order.

Forks

The default number of forks is conservative. It can be optimized for the environment. The number of forks can be set in ansible.cfg, or by passing it on the command line with --forks. It can be set on a per project basis, with ansible.cfg in the project directory.

Serial

Limits the number of hosts affected by a play on a given run. This is a good option for updating only a portion of hosts at a time, as it allows for controlling the size of a rolling update window. Serial is set in the play header. You can set a number, a percentage, or a list of hosts.


Strategy plugins

Augment Ansible’s core functionality. They’re enabled by default. Strategy plugins handle the scheduling of tasks and hosts.

Strategy plugins:

  • Linear - The default. Runs each task on all hosts affected by a play, before starting the next task on any host. Fork and serial settings are important here. This strategy is only as fast as the slowest host, as every other host must wait until it’s done.
  • Free - All hosts run through tasks as quickly as possible, in parallel, without waiting for one another.
  • Host_Pinned - Enhancement of the ‘Free Strategy’. Uninterrupted execution per host. Number of hosts with an active play doesn’t exceed the forks limit. Workers stick to hosts until play completion. A new host starts only when another is done with the play.
  • Debug - Runs the same as the linear strategy, but when an error is encountered it invokes an interactive debug console. The debug console allows to modify the internal state to correct the problem. Debug can be run at the playbook or task level.
  • Throttling - Some tasks may suffer from parallel execution, such as CPU intensive tasks or tasks interacting with a rate limited API. Throttling limits the number of workers for a particular task or task block. The throttling setting must be lower than the serial or forks settings.

Only one strategy plugin can be used per play, but each play in a playbook can use a different one. To see the list of available strategy plugins: ansible-doc -t strategy -l

Categories:

Updated: