Skip to content

Commit

Permalink
feat: 🍻add variables to host file (#27)
Browse files Browse the repository at this point in the history
Allow adding variables to inventory(host file), available variables:

```text
host
port
user
password
keys
passphrase
```

Example host file:

```text
alias_name_node1 host=node1.sre.im
alias_name_node2 host=192.168.33.12 port=22 user=vagrant password=vagrant keys=~/.ssh/id_dsa,~/.ssh/id_rsa passphrase=xxx
node3.sre.im user=vagrant password=GOSSH-AES256:9cfe499133b69a6c7fc62b5b6ba72d3d8dfb4d0e7987170a40c5d50bb5d71e19
```
  • Loading branch information
windvalley committed Jan 25, 2022
1 parent 1d013b4 commit 87c52c2
Show file tree
Hide file tree
Showing 5 changed files with 369 additions and 196 deletions.
45 changes: 32 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.8.0]

### Added

- Allow adding variables to inventory(host file), available variables: `host port user password keys passphrase`.

Example host file:

```text
alias_name_node1 host=node1.sre.im
alias_name_node2 host=192.168.33.12 port=22 user=vagrant password=vagrant keys=~/.ssh/id_dsa,~/.ssh/id_rsa passphrase=xxx
node3.sre.im user=vagrant password=GOSSH-AES256:9cfe499133b69a6c7fc62b5b6ba72d3d8dfb4d0e7987170a40c5d50bb5d71e19
```

For details at ([#27](https://github.com/windvalley/gossh/issues/27)).

## [1.7.0]

### Added
Expand Down Expand Up @@ -77,20 +93,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
version Show gossh version information
```

After:
````
```text
Available Commands:
command Execute commands on target hosts
script Execute a local shell script on target hosts
push Copy local files/dirs to target hosts
fetch Copy files/dirs from target hosts to local
vault Encryption and decryption utility
config Generate gossh configuration file
version Show gossh version information
help Help about any command
completion Generate the autocompletion script for the specified shell
```
After:
```text
Available Commands:
command Execute commands on target hosts
script Execute a local shell script on target hosts
push Copy local files/dirs to target hosts
fetch Copy files/dirs from target hosts to local
vault Encryption and decryption utility
config Generate gossh configuration file
version Show gossh version information
help Help about any command
completion Generate the autocompletion script for the specified shell
```
- Optimize the order of flags to make them more friendly
([#23](https://github.com/windvalley/gossh/issues/23)).
Expand Down Expand Up @@ -441,3 +459,4 @@ If the dest directory given by flag `-d` does not exist or does not have permiss
### Fixed
### Security
````
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ Feel free to open a new issue if you have any issues, questions or suggestions a
foo[01-03,06,12-16].idc[1-3].[beijing,wuhan].bar.com
```

- Allow adding variables to host file. E.g.:

```text
alias_name_node1 host=node1.sre.im
alias_name_node2 host=192.168.33.12 port=8022 user=vagrant password=123456 keys=~/.ssh/id_dsa,~/.ssh/id_rsa passphrase=xxx
node3.sre.im user=vagrant password=GOSSH-AES256:9cfe499133b69a6c7fc62b5b6ba72d3d8dfb4d0e7987170a40c5d50bb5d71e19
```

- Use `sudo` to run as other user(default `root`) to execute the commands/shell-script or fetch files/dirs.

- Specify i18n environment variable value while executing commands or a shell script to help keep the language of the outputs consistent. For example: `zh_CN.UTF-8`, `en_US.UTF-8`.
Expand Down Expand Up @@ -158,7 +166,7 @@ Target servers: `hosts.list` contains `936` servers distributed in `86` differen
**Ansible:**

```sh
$ time ansible all -i hosts.list -m command -a "uptime" -k -f 100
$ time ansible all -i hosts.list -m command -a "uptime" -f 100 -k
```

Output:
Expand All @@ -174,7 +182,7 @@ sys 1m24.263s
**Gossh:**

```sh
$ time gossh command -H hosts.list -e "uptime" -c 100
$ time gossh command -H hosts.list -e "uptime" -c 100 -k
```

Output:
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func getVaultConfirmPassword() string {
util.CheckErr(fmt.Sprintf("get vault password from terminal prompt failed: %s", err))
}

log.Debugf("confirmed vault password that from terminal prompt")
log.Debugf("Vault: confirmed vault password that from terminal prompt")

return password
}
Expand All @@ -133,7 +133,7 @@ func GetVaultPassword() string {
fmt.Printf("password can not be null, retry\n")
}

log.Debugf("read vault password from terminal prompt '%s'", prompt)
log.Debugf("Vault: read vault password from terminal prompt '%s'", prompt)

return password
}
Expand All @@ -149,7 +149,7 @@ func getVaultPasswordFromFile() string {

password := strings.TrimSpace(string(passwordContent))

log.Debugf("read vault password from file '%s'", vaultPassFile)
log.Debugf("Vault: read vault password from file '%s'", vaultPassFile)

return password
}
Expand Down
Loading

0 comments on commit 87c52c2

Please sign in to comment.