14-Day5-3-UnderstandingAndConfiguringExecutionStrategies
Day 5: Lab Series 3 - Understanding and Configuring Execution Strategies
Objective:
This lab introduces participants to execution strategies in Ansible. Participants will understand how forks, serial, and throttle settings affect task execution and learn to configure these strategies for optimal resource usage and control.
Lab 3.1: Configuring Forks
Scenario:
Optimize parallel task execution by increasing the number of forks.
Steps:
Default Forks Setting: Run a playbook with the default
forkssetting.--- - name: Test Default Forks hosts: all tasks: - name: Ping all hosts ping:Command to run:
ansible-playbook forks_example.yaml -i inventoryObserve the speed of execution for multiple hosts.
Increase Forks:
Set a higher
forksvalue in the playbook execution command:ansible-playbook forks_example.yaml -i inventory --forks 10Exercise:
Compare the execution time with different
forksvalues (e.g., 1, 5, 10).Test with a larger inventory file to see the impact.
Lab 3.2: Using Serial Execution
Scenario:
Control task execution by running tasks on a limited number of hosts at a time.
Steps:
Playbook with
serial:Save as
serial_example.yaml:Run the Playbook:
Exercise:
Modify the
serialvalue to1,2, or5, and observe the behavior.Identify scenarios where serial execution might be beneficial (e.g., rolling updates).
Lab 3.3: Using Throttle for Task Control
Scenario:
Limit concurrent execution of a specific task using the throttle keyword.
Steps:
Playbook with Throttling:
Save as
throttle_example.yaml:Run the Playbook:
Exercise:
Experiment with different throttle values (e.g., 1, 3, 5).
Compare how throttling differs from
serial.
Lab 3.4: Combining Strategies
Scenario:
Use serial, throttle, and forks together to configure complex execution strategies.
Steps:
Playbook with Multiple Strategies:
Save as
combined_example.yaml:Run the Playbook:
Exercise:
Analyze how
serial,throttle, andforksinteract.Test with a larger inventory file for deeper insights.
Optional Lab: Debugging Execution Strategies
Scenario:
Test execution strategies in failure scenarios.
Modify a playbook to deliberately fail on a few hosts (e.g., by using incorrect package names or unreachable hosts).
Run the playbook with different strategies:
serialthrottleforks
Observe the behavior and learn how each strategy handles errors.
Key Learning Points:
Forks: Determine how to optimize parallel execution for large inventories.
Serial Execution: Control rolling updates or phased deployments with
serial.Throttling: Limit resource-intensive tasks to a subset of hosts.
Combining Strategies: Mix execution strategies to balance speed and control in complex deployments.
These exercises empower participants to effectively manage execution flow in diverse scenarios.
Last updated