Skip to content

Would be nice to be able to execute code in target plans. #82

Open
@ribalba

Description

@ribalba

It would be useful if it would be possible to execute local code in target plans as you might want to run some shell commands to figure out what hosts you have to connect to. For example to connect to a vagrant machine you need to write code like

plan.target('vagrant', function(done) {

    var hosts = [];

    var sys = require('sys')
    var exec = require('child_process').spawnSync;

    //Run vagrant in the shell to get the ssh config info
    var vagrantOutputString = exec('vagrant', ['ssh-config']).stdout.toString();

    var re = /IdentityFile (.*)/gm;

    //Match the IdentityFile
    var keyFile = re.exec(vagrantOutputString)[1];

    hosts.push({
        host: '127.0.0.1',
        port:2222,
        username: 'vagrant',
        privateKey: keyFile,
        agent: process.env.SSH_AUTH_SOCK

    });
    done(hosts);
});

which is not the nicest way. In fabric it can look like :) Just a feature request.

@task
def vagrant():
    env.user = 'vagrant'
    env.hosts = ['127.0.0.1:2222']
    result = local('vagrant ssh-config | grep IdentityFile', capture=True)
    env.key_filename = result.split()[1]

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions