Greg B
Greg B

Reputation: 14898

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?

Upvotes: 0

Views: 63

Answers (1)

Javier Buzzi
Javier Buzzi

Reputation: 6828

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.

Upvotes: 2

Related Questions