简体   繁体   English

如何迭代开发fabfile?

[英]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 . 我正在阅读结构,并针对测试VM运行脚本,但是在修复其中的错误后,由于它已经在使用addgroup成功创建了一个组,因此我无法再运行它,因为它在较早的一行失败了。 My question is 我的问题是

What is a good development strategy for writing a fabfile? 编写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? 是否存在使fabfile可重新运行或更健壮的最佳实践,以便您可以在编写fabfile时多次运行它,或者人们在每次运行后都快照其VM并回滚?

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. 就我个人而言(我一直在写fabfile大约2年),我倾向于这样做,以便在启动执行该操作的代码之前检查它是否存在。 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. 这样一来,当您运行它时,没有任何崩溃和跳动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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