Skip to content

Commit 852abc8

Browse files
authored
Update usage info in the docs (#116)
2 parents 6241ea2 + e1258e2 commit 852abc8

File tree

3 files changed

+55
-26
lines changed

3 files changed

+55
-26
lines changed

CHANGELOG.md

+14
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,26 @@ All notable changes to this project will be documented in this file.
88

99
- Show skipped and processed hosts in output - ([a5fdcbe](https://github.com/pythoninja/sshgen/commit/a5fdcbe810d246ac0e9af97ed901b50da95ace2f))
1010

11+
### Refactor
12+
13+
- Change create and writing methods - ([332c63c](https://github.com/pythoninja/sshgen/commit/332c63c547299e1db246b81a205d76fc3ee6f280))
14+
1115
### Development
1216

17+
- *(dev)* Ignore test files - ([9ac9b86](https://github.com/pythoninja/sshgen/commit/9ac9b8661e5e6956fdc97e01b34b106be71d7e6c))
18+
- *(dev)* Add justfile - ([6b5541e](https://github.com/pythoninja/sshgen/commit/6b5541ebb27bfaaa5b2d5130282358119bbcd35f))
19+
- *(dev)* Enable ruff-specific rules for linter - ([98b901c](https://github.com/pythoninja/sshgen/commit/98b901c837a130007f9c91ab4e0f1642559b728d))
20+
- *(dev)* Format the code on pre-commit - ([378e9c2](https://github.com/pythoninja/sshgen/commit/378e9c27cefd51677ab8636b69a0b0c10a7bf7ce))
1321
- *(dev)* Change ruff linter and formatter rules - ([783ba11](https://github.com/pythoninja/sshgen/commit/783ba115bce9c416f25c5b691e6d949e41173de5))
1422
- *(dev)* Update python to 3.12 - ([6c9166a](https://github.com/pythoninja/sshgen/commit/6c9166a25bea7ab82451a00be17333acd8b346fc))
1523
- *(dev)* Update to ruff 0.3.1 - ([f05ee2e](https://github.com/pythoninja/sshgen/commit/f05ee2e1ce926dd182106d1e1472160561ee3240))
1624

25+
### Documentation
26+
27+
- *(changelog)* Update release notes - ([f6d1323](https://github.com/pythoninja/sshgen/commit/f6d1323c767b93d1034bdea17a73e783fd7a50e8))
28+
- Update usage and output example - ([6a5dda4](https://github.com/pythoninja/sshgen/commit/6a5dda4b631b4830cc2e39db4132e3849e9d5a24))
29+
- Update example usage in cli - ([c20477a](https://github.com/pythoninja/sshgen/commit/c20477a55c9b67e42ede4085828a1288ee6aa777))
30+
1731
## [0.5.0](https://github.com/pythoninja/sshgen/compare/v0.4.0..v0.5.0) - 2023-12-19
1832

1933
### Features

README.md

+39-23
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Current version: v0.5.0
2323

2424
## Features
2525

26-
1. Generates a `config` file to merge with your existing SSH configuration.
26+
1. Generates a `config` file to merge with your existing SSH configuration or include as a separate `.conf` file (since v0.6.0).
2727
2. Custom configuration for ssh-agent.
2828
3. Custom SSH aliases for quick connections.
2929
4. Skip selected hosts from results file.
@@ -125,7 +125,8 @@ SSHGEN_DEBUG=1 sshgen generate
125125
After executing the command, you will see the following output:
126126

127127
```text
128-
[INFO] - Generated SSH config file was saved to /my_dir/config
128+
[2024-03-10 10:00:00] [INFO] - Generated SSH config file was saved to /my_dir/config
129+
[2024-03-10 10:00:00] [INFO] - Total processed hosts: 3, total skipped hosts: 1
129130
```
130131

131132
Check the file contents `cat /my_dir/config`:
@@ -151,37 +152,52 @@ Host host4 postgres-server # group2
151152
IdentityAgent ~/.1password/agent.sock
152153
```
153154

154-
If you ran using verbose mode, you should see additional information:
155+
If you run using verbose mode, you should see additional information:
155156

156157
<details><summary>Verbose output example</summary>
157158
<p>
158159

159160
```text
160-
[2023-10-21 17:53:31] [DEBUG] - Loading ansible hosts file: /home/user/code/python/sshgen/examples/hosts.yml
161-
[2023-10-21 17:53:31] [DEBUG] - Total hosts found (include skipped): 4
162-
[2023-10-21 17:53:31] [DEBUG] - Using template file /home/user/code/python/sshgen/sshgen/templates/ssh_config.template to generate ssh config
163-
[2023-10-21 17:53:31] [DEBUG] - Filtering hosts where _skip metafield was defined
164-
[2023-10-21 17:53:31] [DEBUG] - Host host1 should be skipped: False
165-
[2023-10-21 17:53:31] [DEBUG] - Host host2 should be skipped: True
166-
[2023-10-21 17:53:31] [DEBUG] - Host host3 should be skipped: False
167-
[2023-10-21 17:53:31] [DEBUG] - Host host4 should be skipped: False
168-
[2023-10-21 17:53:31] [DEBUG] - Processing host1 from group group1
169-
[2023-10-21 17:53:31] [DEBUG] - Adding SSH port 22 for host host1
170-
[2023-10-21 17:53:31] [DEBUG] - Adding aliases ['base', 'another-alias'] for host host1
171-
[2023-10-21 17:53:31] [DEBUG] - Adding custom auth methods for host host1
172-
[2023-10-21 17:53:31] [DEBUG] - Processing host3 from group group2
173-
[2023-10-21 17:53:31] [DEBUG] - Adding SSH port 19222 for host host3
174-
[2023-10-21 17:53:31] [DEBUG] - Processing host4 from group group2
175-
[2023-10-21 17:53:31] [DEBUG] - Adding SSH port 22 for host host4
176-
[2023-10-21 17:53:31] [DEBUG] - Adding aliases ['postgres-server'] for host host4
177-
[2023-10-21 17:53:31] [DEBUG] - Adding custom auth methods for host host4
178-
[2023-10-21 17:53:31] [INFO] - Generated SSH config file was saved to /home/user/code/python/sshgen/config
161+
[2024-03-10 10:00:00] [DEBUG] - Loading ansible hosts file: /home/user/code/python/sshgen/examples/hosts.yml
162+
[2024-03-10 10:00:00] [DEBUG] - Total hosts found (include skipped): 4
163+
[2024-03-10 10:00:00] [DEBUG] - Using template file /home/user/code/python/sshgen/sshgen/templates/ssh_config.template to generate ssh config
164+
[2024-03-10 10:00:00] [DEBUG] - Filtering hosts where _skip metafield was defined
165+
[2024-03-10 10:00:00] [DEBUG] - Host host1 should be skipped: False
166+
[2024-03-10 10:00:00] [DEBUG] - Host host2 should be skipped: True
167+
[2024-03-10 10:00:00] [DEBUG] - Host host3 should be skipped: False
168+
[2024-03-10 10:00:00] [DEBUG] - Host host4 should be skipped: False
169+
[2024-03-10 10:00:00] [DEBUG] - Processing host1 from group group1
170+
[2024-03-10 10:00:00] [DEBUG] - Adding SSH port 22 for host host1
171+
[2024-03-10 10:00:00] [DEBUG] - Adding aliases ['base', 'another-alias'] for host host1
172+
[2024-03-10 10:00:00] [DEBUG] - Adding custom auth methods for host host1
173+
[2024-03-10 10:00:00] [DEBUG] - Processing host3 from group group2
174+
[2024-03-10 10:00:00] [DEBUG] - Adding SSH port 19222 for host host3
175+
[2024-03-10 10:00:00] [DEBUG] - Processing host4 from group group2
176+
[2024-03-10 10:00:00] [DEBUG] - Adding SSH port 22 for host host4
177+
[2024-03-10 10:00:00] [DEBUG] - Adding aliases ['base', 'another-alias'] for host host4
178+
[2024-03-10 10:00:00] [DEBUG] - Adding custom auth methods for host host4
179+
[2024-03-10 10:00:00] [INFO] - Generated SSH config file was saved to /home/user/code/python/sshgen/config
180+
[2024-03-10 10:00:00] [DEBUG] - Skipped hosts list: 127.0.0.2
181+
[2024-03-10 10:00:00] [INFO] - Total processed hosts: 3, total skipped hosts: 1
179182
```
180183

181184
</p>
182185
</details>
183186

184-
Copy and insert the output into your `~/.ssh/config` file. After that, you can use any of the defined aliases to SSH
187+
There are two ways to use the generated file:
188+
1. Copy and insert the output into your `~/.ssh/config` file.
189+
2. Copy file to the conf directory, e.g. `~/.ssh/config.d/00-custom.conf` (if it's not exist, create one).
190+
Edit your `~/.ssh/config` and add `Include` directive **to the top**:
191+
192+
```
193+
#### Custom configuration
194+
195+
Include ~/.ssh/config.d/*.conf
196+
197+
#### End of custom configuration
198+
```
199+
200+
After that, you can use any of the defined aliases to SSH
185201
into the corresponding hosts. For example, running `ssh base` will connect you to the host with the IP address 127.0.0.1
186202
as the root user and utilizing 1password as your SSH agent.
187203

sshgen/cli.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ def generate_hosts_file(
1919
) -> None:
2020
"""
2121
Command to generate SSH configuration file.
22-
By default, it uses file hosts.yml placed in your working directory and outputs to the file named "config"
23-
24-
Example usage: sshconf generate -o my_ssh_config
22+
By default, it uses file hosts.yml placed in your working directory and outputs to the file named "config".
23+
Example usage: sshgen generate -o my_ssh_config
2524
"""
2625

2726
hosts_file = FileUtils.get_hosts_path(file_path=hosts_file)

0 commit comments

Comments
 (0)