Delegate concurrency and task timeouts for Ansible

Source: Internet
Author: User
Tags scalar

Asynchronous and polling

Ansible sometimes takes a long wait operation, which may take a long time and set the timeout beyond SSH. You can specify async and poll in step to implement asynchronous operations

Async represents the longest wait time for this step, and if set to 0, indicates that it waits until the action is complete.

Poll indicates the length of time between checking the result of the step operation.

Example 1:

----Name:test hosts:localhost tasks:-Name:wair for Shell:sleep async:10 poll:2 results: TASK: [Wair for] ************************************************************** OK: [localhost]<Job207388424975.101038>Polling, 8s Remainingok: [localhost]<Job207388424975.101038>polling, 6s Remainingok: [localhost]<Job207388424975.101038>polling, 4s remainingok: [localhost]<Job207388424975.101038>polling, 2s remainingok: [localhost]<Job207388424975.101038>polling, 0s remaining<Job207388424975.101038>FAILED on localhost

This step fails because the operation time exceeds the maximum waiting time

Example 2:

----name:test  hosts:localhost  tasks:    -Name:wair for      shell:sleep      async:10       <  621720484791.102116>  finished on Localhostplay RECAP ************************* poll is set to 0, which means that the step execution succeeds without waiting for execution results 

Example 3:

----Name:test  hosts:localhost  tasks:    -Name:wair for      shell:sleep      async:0 poll:10      results: # TI Me ansible-playbook xiama.yml TASK: [Wair for] ************************************************************** changed : [Localhost]play RECAP ******************************************************************** localhost                  : ok=2    changed=1    unreachable=0    failed=0   real    0m16.693sAsync is set to 0 and waits until the operation is complete.
Concurrency limits for play execution

Typically, Ansible performs user-defined actions on all servers at the same time, but users can define how many machines can be executed at the same time by serial parameters.

-  after 3 machines in the Name:test play Hosts:webservers serial:3webservers group complete Play, the other 3 machines will start to execute,

The serial parameter starts to support percentages after ansible-1.8.

Maximum failure percentage

By default, as long as there is no server failure in group, Ansible continues to perform tasks. In fact, the user can be defined by "max_fail_percentage", as long as the server exceeds the max_fail_percentage station fails, ansible can abort the execution of tasks.

-Hosts:webservers  max_fail_percentage:30
SerialTen
Note: Tasks will not be aborted until the actual failed machine must be larger than this percentage. The tasks are not aborted when they are equal.
Commissioned

With "Delegate_to", a user can place a task on a delegated machine.

-Hosts:webservers  serial:5  tasks:  -name:take out of load balancer Pool    command:/usr/bin/take_out_of _pool {{inventory_hostname}}    delegate_to:127.0.0.1

The above task will be executed on the machine running ansible, "delegate_to: 127.0.0.1" can be replaced by local_action.

  tasks:  -name:take out of load balancer pool    Local_action:command/usr/bin/take_out_of_pool {inventory_host Name}}
The facts of the entrusted person

By default, the facts of a delegated task is the facts of the host in Inventory_hostname , not the facts of the delegated machine. In Ansible 2.0, setting delegate_facts to True allows the task to collect the facts of the entrusted machine.

-Hosts:app_servers  tasks:    -Name:gather facts from DB servers      setup:      delegate_to: "{{item}}"      Delegate_facts:true      With_items: "{{groups[' dbservers '}}"

This example collects dbservers facts and assigns them to these machines instead of collecting app_servers facts

RUN ONCE

by Run_once: True to specify that the task can only be executed once on a single machine. Can be used in conjunction with the DELEGATE_TO

-command:/opt/application/upgrade_db.py  run_once:true  delegate_to:web01.example.org

Specifies to perform this on "web01.example.org"

If there is no delegate_to, then this task will be executed on the first machine.

Delegate concurrency and task timeouts for Ansible

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.