#Jenkins and #fabric script to execute commands remotely

tee /tmp/fabfile.py <<EOF
from fabric.api import *
import wget

env.hosts     = open('hostfile', 'r').readlines()
env.user      = open('userfile', 'r').readline().strip()
env.password  = open('passwordfile', 'r').readline().strip()


def vm_run_cmd(cmd, priv=True):
    if priv is True:
        sudo(cmd)
    else:
        run(cmd)


def vm_exec_remote_script(uri, privt=False):
        temp_f = wget.download(uri)
        inf = open(temp_f)
        vm_run_cmd(inf.read().replace('\n', ' '), privt)
        inf.close()
EOF

tee /tmp/hostfile <<EOF
localhost
EOF

tee /tmp/userfile <<EOF
xxxxxx
EOF

tee /tmp/passwordfile <<EOF
xxxxxx
EOF

cd /tmp/
virtualenv venv
source venv/bin/activate
fab vm_exec_remote_script:'https://raw.githubusercontent.com/Flukas88/CodeUtils/master/hello.bash',privt=$sa
fab vm_run_cmd:"$cmdline",priv=$sa
deactivate
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 )

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s