Tag Archives: error handling

Fabric – Wrappers and more error handling

I wrote about Fabric’s error handling in this post and there task execution errors were handled like this:


def cmd(cmd):
    if run(cmd).failed:

What if the task is a bit more complex and has multilple parts that can go wrong? You might want to abort the execution and do some kind of rollback action.

The task could be aborted by just using env.warn_only=False but then then the task would be aborted before we can do any rollback actions.

Without a wrapper it could be done like this:

Read more of this post

Fabric tutorial 2 – File transfer & error handling

On the first turorial we learned to run commands on remote hosts with Fabric. Now we move on to
transfering files. Transfering new configuration files is usually quite important part of system administration.
Also retrieving log files from the remote machines might be useful.

Sending files

Let’s assume we’ve made a new ssh_config file with important changes and we want to send it to our
remote hosts. Here’s a task for sending files.

def file_send(localpath,remotepath):

Run it with:
fab file_send:path/to/edited/ssh_config,/etc/ssh/ssh_config
or if the modified ssh_config is in the directory where you’re running Fabric:
fab file_send:ssh_config,/etc/ssh/ssh_config

If we’re sending the file to a location that doesn’t need sudo eg. /tmp/, we don’t need the use_sudo=True.

Another example: Read more of this post