Wednesday, September 26, 2012

Use Fabric more!

I have been really busy these days. I have many things I want to write about. Oh please good nature let me have some free times to write about things!

Anyway. I just happened to be on StackOverflow. There were two questions on sending files remotely. One was copying over to another machine, and another through FTP.

I am against using raw connection. Fabric is designed for deployment, so I am a strong advocate of using it.

How to automate the sending of files over the network using python?
Python Script Uploading files via FTP

I wrote the scripts very quickly.

    #!/usr/bin/python
    from fabric.api import run, env, sudo, put

    env.user = 'username'
    env.host = ['hostname,]
    #env.password = 'my_lovely_password'

    def copy():
        put('wong_8066.zip', '/home1/yeukhon/wong_8066.zip')

    def copy2():
        put('wong_8066.zip', '/www/public/wong_8066.zip')


You can save it as fabfile.py and run it via by calling fab task_name  or multiple task names all together.

If you need to automated it you should specify the path to the ssh key. Hardcoding the password (for FTP, for example) is OK if this is a personal thing.

Seriously... use Fabric more. Sadly, GLASSLAB needs a better automation system so we have to go with Chef.

No comments:

Post a Comment