简体   繁体   中英

How do I iteratively develop a fabfile?

I'm reading up on fabric and running my script against a test VM but after an fixing an error in it I can no longer run it as it fails at an earlier line because it already successfully created a group with addgroup . My question is

What is a good development strategy for writing a fabfile?

Are there best practices that can make fabfiles re-runnable or more robust so that you can run it several times as you're writing it, or do people snapshot their VM and roll back after every run?

Personally speaking (ive been writing fabfiles for about 2 years) i tend to make it so that i check if it exist before launching the code that does it. Example:

@task
def provision():
    sudo('apt-get update')
    sudo('apt-get install -y {}'.format(' '.join(SERVER_PACKAGES)))

    # always do this so it never crashes
    sudo('mkdir -p {}'.format(ROOT_PATH)) 

    if files.exists(os.path.join(path, 'nginx')):
        print 'NGINX {} installed. Skipping.'.format(version)
        return

    do_instalation_here()

That way when you run it nothing crashes and jigs you out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM