I'm updating several hosts with ansible at the same time, however I have a limitation...
I have to download artifacts from a common repository with no more than 3 simultaneous downloads!
The current solution I have is to limit the whole playbook to max three concurrent tasks
strategy: linear
serial: 3
Is it possible to limit concurrency only for particular task step rather than the whole playbook?
For long running asynchronous tasks, it's good to set poll=0 so that Ansible can immediately jump to the next task after starting the current one without waiting for the result. Register: It is basically used to register the results on a task in a variable.
The easiest way to run only one task in Ansible Playbook is using the tags statement parameter of the “ansible-playbook” command. The default behavior is to execute all the tags in your Playbook with --tags all .
Interact with multiple hosts simultaneously, on a per-playbook basis with Ansible's serial keyword. Parallelism describes a software's ability to spawn multiple processes to execute tasks in tandem. It also applies to Ansible's default ability to interact with numerous hosts simultaneously.
There's no direct way. Only workarounds like run_once
loop with delegate_to
or multiplying the task with loop and executing only one item per host.
See issue #12170, which is closed with "won't fix" status for details.
delegate_to
loop:
- mytask: ..
delegate_to: "{{item}}"
run_once: true
# many diff ways to make the loop
with_inventory_hostnames: all
multiplied task:
- name: target task
debug: msg="Performing task on {{ inventory_hostname }}, item is {{ item }}"
with_items: "{{ play_hosts }}"
when: "hostvars[item].inventory_hostname == inventory_hostname"
Yes, it's possible to only limit the concurrency of a certain task.
You just need to add the throttle
keyword to your download task.
Example:
- name: Download payload.tar.gz
get_url:
url: https://example.com/path/payload.tar.gz
dest: /mnt/scratch/payload.tar.gz
mode: '0640'
throttle: 3
Note that throttle
was introduced in Ansible 2.9.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With