Passing variable file name to grunt.file.read

1.3k views Asked by At

When trying to pass the users private key to grunt-ssh I want each developer to be able to setup their server keys in a Gruntsetting.json loaded in the Gruntfile like so:

    settings: grunt.file.readJSON('Gruntsettings.json'),

    sshexec: {
        test: {
            command: 'uptime',
            options: {
                privateKey: grunt.file.read('<%- settings.keyPath %>'),
                host: '<%= settings.host %>',
                username: '<%= settings.username %>'
            }
        },
    }

However when I use the keyPath setting in the grunt.file.read statement I get the error:

Error: Unable to read "<%- settings.keyPath %>" file (Error code: ENOENT).

Is it possible to pass variables from a read json file back to another read command?

1

There are 1 answers

0
max On BEST ANSWER

Expand the privateKey template to include the file-read method call:

settings: grunt.file.readJSON('Gruntsettings.json'),

sshexec: {
    test: {
        command: 'uptime',
        options: {
            privateKey: '<%= grunt.file.read(settings.keyPath) %>',
            host: '<%= settings.host %>',
            username: '<%= settings.username %>'
        }
    },
}