Ansible

Explain the Difference between Forks and Serial & Throttle.

Difficulty: unrated

Source: bregman-arie/devops-exercises by Arie Bregman

Answer

Serial is like running the playbook for each host in turn, waiting for completion of the complete playbook before moving on to the next host. forks=1 means run the first task in a play on one host before running the same task on the next host, so the first task will be run for each host before the next task is touched. Default fork is 5 in ansible.

[defaults]
forks = 30
- hosts: webservers
  serial: 1
  tasks:
    - name: ...

Ansible also supports throttle This keyword limits the number of workers up to the maximum set via the forks setting or serial. This can be useful in restricting tasks that may be CPU-intensive or interact with a rate-limiting API

tasks:
- command: /path/to/cpu_intensive_command
  throttle: 1