Automated O & M tool Fabric-intelligent task execution (roles, execute)

Source: Internet
Author: User

Automated O & M tool Fabric-intelligent task execution (roles, execute)

This article is from the official Fabric document. The original Article is Intelligently executing tasks with execute.
Note: This function is only valid in Fabric 1.3 and mainly uses the execute function.

In Fabric 1.3, you can use roles to define a group of roles for the server and execute different operations based on the role.

Code 1
from fabric.api import run, rolesenv.roledefs = {    'db': ['db1', 'db2'],    'web': ['web1', 'web2', 'web3'],}@roles('db')def migrate():    # Database stuff here.    pass@roles('web')def update():    # Code updates here.    pass

In Fabric <= 1.2, this is the only way to make the migrate operation take effect on the db Group server. The update operation takes effect on the web group server as follows:

$ fab migrate update
Code 2

In Fabric 1.3, you can use execute to start a metatask. You can modify the Code as follows:

From fabric. api import run, roles, executeenv. roledefs = {'db': ['db1', 'db2 '], 'web': ['web1', 'web2', 'web3'],} @ roles ('db') def migrate (): # Database stuff here. pass @ roles ('web') def update (): # Code updates here. pass # New execute module def deploy (): execute (migrate) execute (update)

Run the following command:

fab deploy

In this way, the roles modifier will take effect as expected. The execution result is as follows:

migrate on db1migrate on db2update on web1update on web2update on web3
Note:

This technique allows tasks to run only once because they do not have a host list (including global host list settings). If a 'regular 'task is run on multiple hosts, execute is called multiple times, and the result is the increase in the number of sub-task calls multiplier-be careful

Note: The number of hosts is large, which may cause an "execution Storm "? Multiple repeated executions? Killing the machine? Or the client tasks will be repeated. You need to find a set of testing machines for testing, but not yet. Students who have passed the test can give a final answer.
Note: The reguar translation is normal? Regular? Qualified. Thank you for your attention.

If you want your exeute call to be executed only once, you can use the runs_once modifier.

This technique works because tasks that themselves have no host list (this includes des the global host list settings) only run one time. if used inside a "regular" task that is going to run on multiple hosts, callto execute will also run multiple times, resulting in multiplicative numbers of subtask cballs-be careful!

If you wowould like your execute callto only be called once, you may use the runs_once decorator.

Use Vagrant and Fabric for Integration Testing

Fabric: Python Remote Deployment Tool

This article permanently updates the link address:

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.