Generate SSH config from Salt server lists
- Python 3.9+
It's your servers.sls file:
servers:
lab-1001:
main_ip: 1.2.3.4
...
...
lab-1002:
main_ip: 4.5.6.7
...
...
...
...
Note: Add/remove extra info from
main.pyfile. For exampleIdentityFile,IdentityAgent, etc
Run:
python main.py <servers.sls> <output> <ssh port> <ssh user> <mode>python main.py /Salt/pillar/dev/servers.sls out.txt 22 arash Staging#------- Staging Servers ------#
Host lab-1001
HostName 1.2.3.4
Port 22
User user
IdentitiesOnly yes
IdentityAgent ~/.gnupg/S.gpg-agent.ssh
IdentityFile ~/.ssh/id_rsa_yubikey.pub
Host lab-1002
HostName 4.5.6.7
Port 22
User user
IdentitiesOnly yes
IdentityAgent ~/.gnupg/S.gpg-agent.ssh
IdentityFile ~/.ssh/id_rsa_yubikey.pub
Also you will have two another files:
- A
ip-list.jsonfile containing all IPs will be generated for further use. - A
server-list.jsonfile containing all servers with their IP based onrole,zone,providerandcode. There is anotherkey for unknown servers. You can Change__create_list()function to fit your needs. - A
server-list.tomlfile to use with WireGuard-Config-Generator