New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support for "serial" on an individual task #12170
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Looks like there's a bounty for this here: https://www.bountysource.com/issues/26342862-support-for-serial-on-an-individual-task |
This comment has been minimized.
This comment has been minimized.
1 similar comment
+1 |
+1; however the serial needs not to fail the entire play for remaining hosts if all hosts in the current serial fail. I often have to do rolling restarts, one server at a time across 50+ servers. It sucks when the play fails on server 3 because server 3 had some strange unexpected condition that caused the restart to fail. Setting max_failpercent to something higher than 100% should force ansible to continue the play for remaining hosts. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
4 similar comments
+1 |
👍 |
+1 |
+1 |
+1 That's a good idea, but should not only go from playbooks to individual tasks but also to blocks, including all dependent options like max_fail_percentage and run_once. The update-reboot example could explain that easily:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
+1, rolling restarts are useful for distributed systems that are chained all together. For Ceph, we don't want to restart all the storage daemons at the same time because the configuration file changed. |
This comment has been minimized.
This comment has been minimized.
1 similar comment
+1 |
This comment has been minimized.
This comment has been minimized.
workaround: - name: service restart
# serial: 1 would be the proper solution here, but that can only be set on play level
# upstream issue: https://github.com/ansible/ansible/issues/12170
run_once: true
with_items: "[{% for h in play_hosts %}'{{ h }}'{% if not loop.last %} ,{% endif %}{% endfor %}]"
delegate_to: "{{ item }}"
command: "/bin/service restart" |
@alvaroaleman thanks for your suggestion however it seems to lead to this bug: #15103 Am I missing something? |
+1 |
@kami8607 I've faced the same issue with failures as rolling updates and restarts require the whole playbook to fail on any error. Solved with I also confirm that this solution works with - name: install and configure alive servers
include_tasks: "install_configure.yml"
with_items: "{{ healthy_servers }}"
when: "hostvars[host_item].inventory_hostname == inventory_hostname"
loop_control:
loop_var: host_item |
This comment has been minimized.
This comment has been minimized.
There's also a working solution in this thread. |
there is a workaround that works for most parts but no solution |
There is not a working solution in this thread. While it may work for some, its not a solution. |
@jonhatalla I don't have any issues with |
I would like to limit only an artifacts download task (due to some constrains) but to execute the rest of tasks in parallel. I have come with a proposal after reading comments which still is not working as desired for the download case. Notice that 2 is the maximum number of concurrent tasks executions desired. - name: Download at ratio three at most
win_get_url:
url: http://ipv4.download.thinkbroadband.com/100MB.zip
dest: c:/ansible/100MB.zip
force: yes
with_sequence: start=0 end={{ (( play_hosts | length ) / 2 ) | round (0, 'floor') | int }}
when: "(( ansible_play_batch.index(inventory_hostname) % (( play_hosts | length ) / 2 )) | round) == (item | int)" While this will match the Another way of testing it is with debug a message and a add a delay between iterations. This way is clear that only two are executed at each iterations. - debug:
msg: "Item {{ item }} with modulus {{ (( ansible_play_batch.index(inventory_hostname) % (( play_hosts | length ) / 2 )) | round) }}"
with_sequence: start=0 end={{ (( play_hosts | length ) / 2 ) | round (0, 'floor') | int }}
loop_control:
pause: 2
when: "(( ansible_play_batch.index(inventory_hostname) % (( play_hosts | length ) / 2 )) | round) == (item | int)" I discovered this issue thread thanks to this SO question Any idea why the download doesn't seem to work as the debug message does? |
As previous commenters said, I also see no workaround for handlers restarting services in a cluster where you don't want to restart all nodes at the same time. So there is at least one usecase where there doesn't seem to be a solution... This render handlers in this case totally useless, as handlers are used to restart the services WHEN this is needed only. And all other workarounds (handling concurrents write on a local hosts file for example) do work but they are so ugly... Finally, I concurr, closing an issue because it's too big a problem to solve is a bit depressing... |
@zwindler you can use tasks instead of handlers. I actually use rolling restarts with API checks. Implemented with |
Not really sure I understand what you suggest.
|
- name: install and configure alive servers
include_tasks: "install_configure.yml"
with_items: "{{ healthy_servers }}"
when: "hostvars[host_item].inventory_hostname == inventory_hostname"
loop_control:
loop_var: host_item in this case |
how has healthy_servers been defined? how is it used in the workaround? i dont see it being referenced. I want a serial task to apply to all hosts that the playbook is being ran against. |
@erpadmin why don't you use |
Hi all, it seems to point to this bug but would like to clarify:
thanks for your help and please keep us posted. best regards, Pablo. |
It seems to me that the Given two inventory hosts with the same |
There is a major problem with most of the proposed workarounds is CPU and memory usage, as well as massive deployment slowdowns. The method of checking that the With 200 hosts, I've seen ansible use 20GB of ram and 70 load avg just to serialize an |
This comment has been minimized.
This comment has been minimized.
Anyone is invited to test #42528 for their use-cases, and add a 👍 to the PR if you approve. |
(Feature Idea)
The natural way to handle configuration or other updates that require a rolling restart would be to perform updates in parallel, then notify a handler, which performs a restart with
serial
. But this is not possible, requiring either manual rolling restart or ugly hacks. See https://groups.google.com/forum/#!topic/ansible-project/rBcWzXjt-XcThe text was updated successfully, but these errors were encountered: