Take the 2-minute tour ×
Server Fault is a question and answer site for professional 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')
    bootstrap(newhostname)

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

1 Answer 1

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

Your Answer

 
discard

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.