diff options
| author | Shulhan <m.shulhan@gmail.com> | 2020-06-26 07:21:58 +0700 |
|---|---|---|
| committer | Shulhan <m.shulhan@gmail.com> | 2020-06-26 07:21:58 +0700 |
| commit | 5dfcef1eaba4b8563a7eb2865d28bf45be282f23 (patch) | |
| tree | 9ea3346fde7bfb79468719665bf4f2a1a77b867b | |
| parent | f370c2a598d3b4482e2d391458fc6878fada49af (diff) | |
| download | awwan-5dfcef1eaba4b8563a7eb2865d28bf45be282f23.tar.xz | |
environment: set the SSH key, user, host, and port
By knowing this values, user can use it to invoke other SSH related
command, for example to copy file using `scp`
scp -i {{.SSHKey}} src {{.SSHUser}}@{{.SSHHost}}:{{.SSHPort}}/dst
| -rw-r--r-- | CHANGELOG.adoc | 7 | ||||
| -rw-r--r-- | README.adoc | 12 | ||||
| -rw-r--r-- | command.go | 5 | ||||
| -rw-r--r-- | environment.go | 5 |
4 files changed, 26 insertions, 3 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index e3e49c7..b4be2a0 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -4,6 +4,13 @@ === New features +* environment: export the SSH key, user, host, and port + +By knowing this values, user can use it to invoke other SSH related +command, for example to copy file using `scp` + + scp -i {{.SSHKey}} src {{.SSHUser}}@{{.SSHHost}}:{{.SSHPort}}/dst + * all: add magic command "#require:" Magic word `#require:` will ensure that the next statement will always diff --git a/README.adoc b/README.adoc index 8a740ab..5ff7b18 100644 --- a/README.adoc +++ b/README.adoc @@ -173,16 +173,22 @@ We will explain how to use and get the environment variables below. Template file is any text or script files that dynamically generated using values from variables defined in environment files. -There are two global variables that shared to all template or script files, +There are six global variables that shared to all template or script files, -* `.BaseDir` contains the absolute path of current directory, and -* `.ScriptDir` contains the relative path to script directory. +* `.BaseDir` contains the absolute path of current directory +* `.ScriptDir` contains the relative path to script directory +* `.SSHKey` contains the value of "IdentityFile" in SSH configuration +* `.SSHUser` contains the value of "User" in SSH configuration +* `.SSHHost` contains the value of "Host" in SSH configuration +* `.SSHPort` contains the value of "Port" in SSH configuration To get the value wrap the variable using '{{}}' for example, ---- #put! {{.BaseDir}}/templates/etc/hosts /etc/ #put! {{.ScriptDir}}/etc/hosts /etc/ + +scp -i {{.SSHKey}} src {{.SSHUser}}@{{.SSHHost}}:{{.SSHPort}}/dst ---- To get the value of variable in environment file you put the string ".Val" @@ -401,4 +401,9 @@ func (cmd *Command) initSSHClient() { if err != nil { log.Fatal("cmd: cannot create new SSH client: " + err.Error()) } + + cmd.env.SSHKey = sshSection.IdentityFile[0] + cmd.env.SSHUser = sshSection.User + cmd.env.SSHHost = sshSection.Hostname + cmd.env.SSHPort = strconv.Itoa(sshSection.Port) } diff --git a/environment.go b/environment.go index 5f31f74..af9662b 100644 --- a/environment.go +++ b/environment.go @@ -28,6 +28,11 @@ type Environment struct { BaseDir string // The current working directory. ScriptDir string // The base directory of the script. + SSHKey string // The value of "IdentityFile" in SSH config. + SSHUser string // The value of "User" in SSH config. + SSHHost string // The value of "Hostname" in configuration. + SSHPort string // The value of "Port" in configuration. + mode string // One of the mode to execute the script. hostname string // The hostname where script will be executed. scriptPath string // Location of the script in file system. |
