grunt-ssh icon indicating copy to clipboard operation
grunt-ssh copied to clipboard

Could support multiple remote servers connection?

Open yuezheng opened this issue 10 years ago • 2 comments

If I have multiple servers, I want execute same commands for all servers. How can I do? I think convenient in following way:

  1. Define the secret file like: { "server_1": {"username": "root"}, "server_2": {"username": "root"}
    }
  2. Config task at Gruntfile.js like:
sshconfig: {
    "server_1": grunt.file.readJSON('secret.json')['server_1'],
    "server_2":grunt.file.readJSON('secret.json')['server_2']
}
sshexec: {
    task: {
        command: ['ls -la'],
        options: {'config': ['server_1', 'server_2']}
     }
}

yuezheng avatar Jun 17 '15 06:06 yuezheng

:+1:

nbonamy avatar Sep 16 '15 05:09 nbonamy

You could probably do something like this:

// grunt.initConfig
sshconfig: {
    "server_1": grunt.file.readJSON('secret.json')['server_1'],
    "server_2": grunt.file.readJSON('secret.json')['server_2']
}
sshexec: {
    task: {
        command: ['ls -la']
     }
}
grunt.registerTask('list_multiple', function() {
    var servers = ['server_1', 'server_2'];
    for (var i in servers) {
        grunt.option('config', servers[i]);
        grunt.task.run(['sshexec:task']);
    }
});

I haven't tested this so please feel free to reply back if it works for you or not.

chrislondon avatar Nov 24 '15 16:11 chrislondon