Ansible Execution Strategies

Ansible execution is versatile enough that we can modify how and when tasks are executed. The settings can be made globally or at the play level.

Execution StrategiesExplanationExample
linearThis is the default. The task is executed simultaneously against all the hosts using the forks, and then the next series of hosts until the batch is done before going to the next task At ansible.cfg
….
[defaults]
strategy = linear

Or at Play Level
– name: web servers
hosts: webservers
strategy: linear
debugTask execution is like the linear strategy, but controlled by an interactive debug sessionAt ansible.cfg
….
[defaults]
strategy = debug

Or at Play Level
– name: web servers
hosts: webservers
strategy: debug
freeAnsible will not wait for other hosts to finish before queueing for more tasks on other hosts. It prevents blocking new tasks for hosts that have already completed.At ansible.cfg
….
[defaults]
strategy = free

Or at Play Level
– name: web servers
hosts: webservers
strategy: free

References:

  • Red Hat Certified Engineer (RHCE) Ansible Automation Study Guide (Alexc Soto Bueno)

Ansible-Playbook Commonly Used Optional Arguments

These are commonly used Ansible-Playbook Optional Arguments

FlagDescription
-i, –inventorySpecify inventory host path or comma-seperated host list
-b, –becomeRun operations with become (not imply password prompting). Uses existing privilege escalation like sudo, dzdo, runas etc
-K –ask-become-passAsk for the privilege escalation password
–become-method <become-method>Privilege escalation method to use. Default is sudo.
–become-password-file <BECOME_PASSWORD_FILE>Privilege escalation password file
–become-user <BECOME_USER>Run the operation as this user. Default is root
-f <FORKS>, –fSpecify the number of parallel processes to use. Default is 5
-e, –extra-varsAdditional variables as key=value. When specifying a filecontaining a set of variables, prepend the file with @
-t <Tags> –tags <TAGS>Only run plays and tasks tagged with these values
–ask-vault-password, –ask-vault-passAsk foir vault password

References:

  • Red Hat Certified Engineer (RHCE) Ansible Automation Study Guide (Alexc Soto Bueno)