I have one task in my playbook that I want to run on only one host at a time. The rest of the tasks I want to honor the --forks option. Is this possible?
Yes, this possible by using the throttle keyword:
Limit number of concurrent task runs on task, block and playbook level. This is independent of the forks and serial settings, but cannot be set higher than those limits. For example, if forks is set to 10 and the throttle is set to 15, at most 10 hosts will be operated on in parallel.
Example:
---
- hosts: all
tasks:
- name: wait in parallel
command: sleep 20
- name: wait in serial
command: sleep 30
throttle: 1
The throttle
keyword is available in Ansible since version 2.9.