Watch out for fabric pitfalls

Standard

Fabric has been a very useful tool. It helps a lot in simplifying and documenting server deployments.

Recently I am tasked to convert a bash script web server setup file to a fabric deployment file. Of course due to some unfamiliarity with fabric, I thought by converting every single line of the bash script to fabric run(‘<command line from bash>’) it would work. Man, I was proven wrong again and again.

So I am blogging some of the pitfalls I have fallen into so that you don’t repeat my mistakes:

Bash Script: cd /opt/mongodb

Fabric: run('cd /opt/mono') WRONG

run don’t accept cd. It does not tell the server to go to the folder. You need to use another library fabric.context_manager.cd. The correct way is

with cd('/opt/mono'):

git clone http://github.com/mono.git


Bash Script: export CONFIG_PATH='/usr/lib/config'

Fabric: run("export CONFIG_PATH='/usr/lib/config'") WRONG

You cannot use run command in fabric to set environment variables. You need to use shell_env function, also under fabric context_manger library

with shell_env(CONFIG_PATH='/usr/lib/config')

    sudo('./configure')

Finally when you put files, it is advisable that you put(local filename, remote filename/folder). I experience that if you put both parameters as folders, the files that you transferred end up becomes 0 bytes

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s