EzDev.org

fabric

Simple, Pythonic remote execution and deployment. Welcome to Fabric! — Fabric documentation


How to ForwardAgent yes using fabric?

I am successfully run()ning commands on remote server with my private key pair.

However, I'd like to do git clone ssh://private/repo on remote server using my local key (or using local ssh agent I'm in).

How to do it using fabric?


Source: (StackOverflow)

fabric appears to start apache2 but doesn't

I'm using fabric to remotely start a micro aws server, install git and a git repository, adjust apache config and then restart the server.

If at any point, from the fabfile I issue either

sudo('service apache2 restart') or run('sudo service apache2 restart') or a stop and then a start, the command apparently runs, I get the response indicating apache has started, for example

[ec2-184-73-1-113.compute-1.amazonaws.com] sudo: service apache2 start
[ec2-184-73-1-113.compute-1.amazonaws.com] out:  * Starting web server apache2
[ec2-184-73-1-113.compute-1.amazonaws.com] out:    ...done.
[ec2-184-73-1-113.compute-1.amazonaws.com] out: 

However, if I try to connect, the connection is refused and if I ssh into the server and run sudo service apache2 status it says that "Apache is NOT running"

Whilst sshed in, if run sudo service apache start, the server is started and I can connect. Has anyone else experienced this? Or does anyone have any tips as to where I could look, in log files etc to work out what has happened. There is nothing in apache2/error.log, syslog or auth.log.

It's not that big a deal, I can work round it. I just don't like such silent failures.


Source: (StackOverflow)

Get the current value of env.hosts list with Python Fabric Library

I've got this code (foo and bar are local servers):

env.hosts = ['foo', 'bar']

def mytask():
    print(env.hosts[0])

Which, of course prints foo every iteration.

As you probably know, Fabric iterates through the env.hosts list and executes mytask() on each of them this way:

fab mytask

does

task is executed on foo
task is executed on bar

I'm looking for a way to get the current host in every iteration.

Thanks,


Source: (StackOverflow)

Install Python Fabric on Windows [closed]

How to get a working Python Fabric installation on Windows?


Source: (StackOverflow)

Fabric's cd context manager does not work

I have set up my development environment on a new PC and seems I am having strange error with Fabric. Its 'cd' context manager seems does not change the current directory, and thus a lot of my commands don't work. I have written the test and it showed me results I have not expected to get:

from __future__ import with_statement
from fabric.api import local, run, cd

def xxx():
    with cd("src"):
        local("pwd")

Here are the results after running fab xxx:

[localhost] local: pwd
/home/pioneer/workspace/myproject

But instead of /home/pioneer/workspace/myproject there should be /home/pioneer/workspace/myproject/src, I think.


Source: (StackOverflow)

Python 3 support for fabric

Does fabric (http://docs.fabfile.org/en/1.7/) support Python 3 yet. As per Python 3 Wall of Superpowers it does not yet. If not what is the best alternative if using Django 1.5 with Python 3.


Source: (StackOverflow)

Best way to add an environment variable in fabric?

I would like to pass a few values from fabric into the remote environment, and I'm not seeing a great way to do it. The best I've come up with so far is:

with prefix('export FOO=BAR'):
    run('env | grep BAR')

This does seem to work, but it seems like a bit of a hack.

I looked in the GIT repository and it looks like this is issue #263.


Source: (StackOverflow)

Is there a deployment tool similar to Fabric written in JavaScript?

I put together a mobile development stack that is almost entirely using Javascript on node.js. With the only exception of SASS (prefer it to LESS) and Fabric. I prefer not to pollute my development directory and as I have to combine and minify JS and CSS anyway, I thought I could also use node.js to serve my code.

I would like to reduce my dependence on Ruby and/or Python. I don't really use all features of Fabric so I have the hope of replacing it. But I couldn't find any similar tool written in Javascript.

All I need is to:

  • Pull from git repository.
  • Install depencies locally.
  • Minify and combine JS/CSS invoking require.js/SASS.
  • Run testsuite.
  • Serve the code via node.js for hands-on or testing with Ripple.

Fabric might already be overkill, I only use it for my Python web projects because the necessary servers don't run on my machine, but that wouldn't be the case here. What would be the best way to handle this without Fabric?


Source: (StackOverflow)

Can a Python Fabric task invoke other tasks and respect their hosts lists?

I have a fabfile like the following:

@hosts('host1')
def host1_deploy():
    """Some logic that is specific to deploying to host1"""

@hosts('host2')
def host2_deploy():
    """Some logic that is specific to deploying to host2"""

def deploy():
    """"Deploy to both hosts, each using its own logic"""
    host1_deploy()
    host2_deploy()

I would like to do

fab deploy

and have it be equivalent to

fab host1_deploy host2_deploy

In other words, run each of the subtasks and for each one use the list of hosts that it specifies. However, this does not work. Instead, the deploy() task wants its own list of hosts that it will propogate to all of its subtasks.

Is there a way to update the deploy() task here so it will do what I want while leaving the subtasks alone so they can be run individually?


Source: (StackOverflow)

How to git commit nothing without an error?

I'm trying to write a fabric script that does a git commit; however, if there is nothing to commit, git exits with a status of 1. The deploy script takes that as unsuccessful, and quits. I do want to detect actual failures-to-commit, so I can't just give fabric a blanket ignore for git commit failures. How can I allow empty-commit failures to be ignored so that deploy can continue, but still catch errors caused when a real commit fails?

def commit():
    local("git add -p && git commit")

Source: (StackOverflow)

Best Fabric scripts for Django

What are the best stock Fabric scripts for deploying a typical Django project? Fabric looks very good, but seems to require you to start from scratch and write your own deployment script. Coming from Capistrano, I'd like to start with something that works more out-of-the-box that others have tested rather than writing one from scratch.

Ideally I'd like one that syncs the database, performs migrations using South, backs up the site and database, and can roll back previous deploys.


Source: (StackOverflow)

running fabric script locally

I have a django app and I wrote a fabric script that installs my app on deployment server (Cent OS 5).

Now I want to run the same fabric script locally on the deployment server.

Is there a way to do it without supplying ssh user and password?

I mean just with "-H localhost"?

Thanks, Alex A.


Source: (StackOverflow)

Can I catch error codes when using Fabric to run() calls in a remote shell?

Normally Fabric quits as soon as a run() call returns a non-zero exit code. For some calls, however, this is expected. For example, PNGOut returns an error code of 2 when it is unable to compress a file.

Currently I can only circumvent this limitation by either using shell logic (do_something_that_fails || true or do_something_that_fails || do_something_else), but I'd rather be able to keep my logic in plain Python (as is the Fabric promise).

Is there a way to check for an error code and react to it rather than having Fabric panic and die? I still want the default behaviours for other calls, so changing its behaviour by modifying the environment doesn't seem like a good option (and as far as I recall, you can only use that to tell it to warn instead of dying anyway).


Source: (StackOverflow)

Can I prevent fabric from prompting me for a sudo password?

I am using Fabric to run commands on a remote server. The user with which I connect on that server has some sudo privileges, and does not require a password to use these privileges. When SSH'ing into the server, I can run sudo blah and the command executes without prompting for a password. When I try to run the same command via Fabric's sudo function, I get prompted for a password. This is because Fabric builds a command in the following manner when using sudo:

sudo -S -p <sudo_prompt> /bin/bash -l -c "<command>"

Obviously, my user does not have permission to execute /bin/bash without a password.

I've worked around the problem by using run("sudo blah") instead of sudo("blah"), but I wondered if there is a better solution. Is there a workaround for this issue?


Source: (StackOverflow)

Connecting to a host listed in ~/.ssh/config when using Fabric

I'm having trouble with Fabric not recognizing hosts that I have in ~/.ssh/config.

My fabfile.py is as follows:

from fabric.api import run, env

env.hosts = ['lulu']

def whoami():
    run('whoami')

Running $ fab whoami gives:

[lulu] run: whoami

Fatal error: Name lookup failed for lulu

The name lulu is in my ~/.ssh/config, like this:

Host lulu
     hostname 192.168.100.100
     port 2100
     IdentityFile ~/.ssh/lulu-key

My first thought to solving this is adding something like lulu.lulu to /etc/hosts (I'm on a Mac), but then I have to also pass in the identity file to Fabric - and I'd rather keep my authentication (i.e. ~/.ssh/config) separate from my deployment (i.e. fabfile.py).

As well, incidentally, if you try to connect to a host in the hosts file, fabric.contrib.projects.rsync_project doesn't seem to acknowledge 'ports' in the hosts.env (i.e. if you use hosts.env = [lulu:2100] a call to rsync_project seems to try connecting to lulu:21).

Is there a reason Fabric doesn't recognize this lulu name?


Source: (StackOverflow)