Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm trying to put together a fabric script that creates a virtual instance via an API and then runs puppet on that instance. I've got a task that creates the VM, and a task that can 'bootstrap' the VM. However, I'm having difficulty linking these together, because I'm not sure how to pass the some data generated in the first task into the second task as the hostname. E.g.

def createVM():
    newhostname = local('/usr/bin/createVM')

def bootstrap(hostname):
    env.hosts = [hostname]
    run('puppet agent -t')

This doesn't appear to work, and I get prompted for the hostname to run the fabric script on, if I just execute fab createVM.

What's the best way of doing this?

share|improve this question

2 Answers 2

You can have a look at the execute() function. You can use it to override on which hosts you run a task and pass extra arguments.

You probably need something along the lines of

def createVM():
    newhostname = local('/usr/bin/createVM')
    execute(bootstrap, hosts=[newhostname])

def bootstrap():
    run('puppet agent -t')
share|improve this answer

You may want to set it on the environment dictionary (env), e.g:

env.newhostname = local('/usr/bin/createVM')

Or just set env.hosts:

env.hosts = [local('/usr/bin/createVM')]

Then execute fab createVM bootstrap

You can see more details here:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.