Skip to content

Commit 87c52c2

Browse files
committed
feat: 🍻add variables to host file (#27)
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 ```
1 parent 1d013b4 commit 87c52c2

File tree

5 files changed

+369
-196
lines changed

5 files changed

+369
-196
lines changed

CHANGELOG.md

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.8.0]
11+
12+
### Added
13+
14+
- Allow adding variables to inventory(host file), available variables: `host port user password keys passphrase`.
15+
16+
Example host file:
17+
18+
```text
19+
alias_name_node1 host=node1.sre.im
20+
alias_name_node2 host=192.168.33.12 port=22 user=vagrant password=vagrant keys=~/.ssh/id_dsa,~/.ssh/id_rsa passphrase=xxx
21+
node3.sre.im user=vagrant password=GOSSH-AES256:9cfe499133b69a6c7fc62b5b6ba72d3d8dfb4d0e7987170a40c5d50bb5d71e19
22+
```
23+
24+
For details at ([#27](https://github.com/windvalley/gossh/issues/27)).
25+
1026
## [1.7.0]
1127

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

80-
After:
96+
````
8197
82-
```text
83-
Available Commands:
84-
command Execute commands on target hosts
85-
script Execute a local shell script on target hosts
86-
push Copy local files/dirs to target hosts
87-
fetch Copy files/dirs from target hosts to local
88-
vault Encryption and decryption utility
89-
config Generate gossh configuration file
90-
version Show gossh version information
91-
help Help about any command
92-
completion Generate the autocompletion script for the specified shell
93-
```
98+
After:
99+
100+
```text
101+
Available Commands:
102+
command Execute commands on target hosts
103+
script Execute a local shell script on target hosts
104+
push Copy local files/dirs to target hosts
105+
fetch Copy files/dirs from target hosts to local
106+
vault Encryption and decryption utility
107+
config Generate gossh configuration file
108+
version Show gossh version information
109+
help Help about any command
110+
completion Generate the autocompletion script for the specified shell
111+
```
94112
95113
- Optimize the order of flags to make them more friendly
96114
([#23](https://github.com/windvalley/gossh/issues/23)).
@@ -441,3 +459,4 @@ If the dest directory given by flag `-d` does not exist or does not have permiss
441459
### Fixed
442460
443461
### Security
462+
````

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ Feel free to open a new issue if you have any issues, questions or suggestions a
4646
foo[01-03,06,12-16].idc[1-3].[beijing,wuhan].bar.com
4747
```
4848

49+
- Allow adding variables to host file. E.g.:
50+
51+
```text
52+
alias_name_node1 host=node1.sre.im
53+
alias_name_node2 host=192.168.33.12 port=8022 user=vagrant password=123456 keys=~/.ssh/id_dsa,~/.ssh/id_rsa passphrase=xxx
54+
node3.sre.im user=vagrant password=GOSSH-AES256:9cfe499133b69a6c7fc62b5b6ba72d3d8dfb4d0e7987170a40c5d50bb5d71e19
55+
```
56+
4957
- Use `sudo` to run as other user(default `root`) to execute the commands/shell-script or fetch files/dirs.
5058

5159
- 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`.
@@ -158,7 +166,7 @@ Target servers: `hosts.list` contains `936` servers distributed in `86` differen
158166
**Ansible:**
159167

160168
```sh
161-
$ time ansible all -i hosts.list -m command -a "uptime" -k -f 100
169+
$ time ansible all -i hosts.list -m command -a "uptime" -f 100 -k
162170
```
163171

164172
Output:
@@ -174,7 +182,7 @@ sys 1m24.263s
174182
**Gossh:**
175183

176184
```sh
177-
$ time gossh command -H hosts.list -e "uptime" -c 100
185+
$ time gossh command -H hosts.list -e "uptime" -c 100 -k
178186
```
179187

180188
Output:

internal/cmd/vault/vault.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func getVaultConfirmPassword() string {
106106
util.CheckErr(fmt.Sprintf("get vault password from terminal prompt failed: %s", err))
107107
}
108108

109-
log.Debugf("confirmed vault password that from terminal prompt")
109+
log.Debugf("Vault: confirmed vault password that from terminal prompt")
110110

111111
return password
112112
}
@@ -133,7 +133,7 @@ func GetVaultPassword() string {
133133
fmt.Printf("password can not be null, retry\n")
134134
}
135135

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

138138
return password
139139
}
@@ -149,7 +149,7 @@ func getVaultPasswordFromFile() string {
149149

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

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

154154
return password
155155
}

0 commit comments

Comments
 (0)