将do dropts与ssh配置结合起来
do-to-ssh-config的Python项目详细描述
数字海洋->;ssh配置
取决于https://github.com/koalalorenzo/python digitalocean,可以使用 这个python 3脚本将帮助您保持ssh配置与数字海洋水滴同步 保存在 注意:这是最简单的配置文件,对每个液滴和液滴名称使用与 上面的json配置包含 在这两个标记之间,脚本将删除所有内容并添加新条目。注意不要在这两个标记之间添加自己的主机。 现在您的ssh配置如下: 如果您自动生成了从液滴名称派生的难看的主机名,则可以改为使用液滴标记;请继续阅读。 最后的配置如下: 重要信息:一个液滴可以有多个标签,这就是为什么这里有一个名为"优先级"的字段。在上面的示例中,如果液滴同时具有 对于与特定标记匹配的液滴,现在ssh配置中的 这对于自动生成液滴名称的大型环境非常方便 注意:水滴名称在每个条目的第一行中仍显示为注释 注意:如上例所示,如果两个或多个液滴共享同一个标记,则会在 现在,您可以使用ssh的tab completion轻松查看所有内容,并连接到任何位置: 只需在 另外,在ssh配置文件中添加不同的标记,例如: 现在如果您运行 它将继续从 它将继续从 是的,前提是您在配置中指定的标记之间没有包含任何条目。每次运行脚本时,标记之间的所有内容都会被删除。pip3 install-u python digitalocean安装
$ python3 do_to_ssh_config.py production
· Reading /home/alex/.config/do_to_ssh_config/production.json
· Parsing /home/alex/.ssh/config
· Fetching droplets from DO
· Writing into your ssh config file
✓ Done, 11 droplets synced
功能
如何
步骤1:创建json配置文件
~/.config/do_to_ssh_config/<;name>;.json
,其中<;name>;
是您要如何调用它的,例如生产
或测试
或其他任何位置。在这个例子中,我将使用production
{"token":"DIGITAL_OCEAN_READ_ONLY_TOKEN_HERE","keys":{"tagToKey":{},"default":{"key":"common","priority":0}},"startMark":"# DO production","endMark":"# /DO production","hostPrefix":"do-prod-"}
主机相同的键,有关更多选项,请继续阅读。
host prefix
是要在ssh配置中的host
键中为通过此配置加载的每个水滴添加的前缀,可以是您想要的任何内容第2步:在ssh配置中添加2个标记
startmark
和endmark
。这些应该在ssh配置中的某个地方,可以是您想要的任何东西(不过,对于ssh配置注释,可以从开始):
# DO production
# /DO production
第3步:运行脚本
$ python3 do_to_ssh_config.py production
· Reading /home/alex/.config/do_to_ssh_config/production.json
· Parsing /home/alex/.ssh/config
· Fetching droplets from DO
· Writing into your ssh config file
✓ Done, 11 droplets synced
# DO production
Host do-prod-control-center1517024146
# control-center1517024146
Hostname X.X.X.X
IdentityFile ~/.ssh/common
User user
Host do-prod-control-center1517027030
# control-center1517027030
Hostname X.X.X.X
IdentityFile ~/.ssh/common
User user
... 9 more entries
# /DO production
我想使用不同的ssh密钥,而不是
common
!键。默认值。键
设置我想使用不同的ssh密钥每滴标签!
键.tagtokey
设置并添加如下条目:"control-center":{"key":"cc_prv","priority":7},"consul-server":{"key":"cs_prv","priority":6},"postgres-master":{"key":"common","priority":5}
{"token":"DIGITAL_OCEAN_READ_ONLY_TOKEN_HERE","keys":{"tagToKey":{"control-center":{"key":"cc_prv","priority":7},"consul-server":{"key":"cs_prv","priority":6},"postgres-master":{"key":"common","priority":5}},"default":{"key":"common","priority":0}},"startMark":"# DO production","endMark":"# /DO production","hostPrefix":"do-prod-"}
控制中心
和领事服务器
标记,则它将使用具有更高优先级的键(此处为控制中心
)。如果液滴没有标记或其标记未出现在标记中,则使用默认键。
host
将具有标记的名称,而不是液滴名称:# DO production
Host do-prod-control-center
# control-center1517024146
Hostname X.X.X.X
IdentityFile ~/.ssh/cc_prv
User user
Host do-prod-control-center2
# control-center1517027030
Hostname X.X.X.X
IdentityFile ~/.ssh/cc_prv
User user
... more entries
# /DO production
主机
值后面附加一个升序数字。$ ssh do-prod- <hit TAB key twice>
do-prod-control-center do-prod-mongodb do-prod-load-balancer do-prod-nodejs2 do-prod-postgres-slave do-prod-blog
do-prod-control-center2 do-prod-landing-page do-prod-nodejs do-prod-postgres-master do-prod-redis
我有生产和测试,我在10家不同的公司工作!
~/.config/do下创建不同的配置文件_要使用ssh_config/
,每个用例一个,比如production.json
和testing.json
。对于每个用例,使用不同的主机前缀将非常有用。$ python3 do_to_ssh_config.py production
· Reading /home/alex/.config/do_to_ssh_config/production.json
· Parsing /home/alex/.ssh/config
· Fetching droplets from DO
· Writing into your ssh config file
✓ Done, 11 droplets synced
0
$ python3 do_to_ssh_config.py production
· Reading /home/alex/.config/do_to_ssh_config/production.json
· Parsing /home/alex/.ssh/config
· Fetching droplets from DO
· Writing into your ssh config file
✓ Done, 11 droplets synced
1
production.json
读取并在ssh配置中写入相应的标记。如果您运行$ python3 do_to_ssh_config.py production
· Reading /home/alex/.config/do_to_ssh_config/production.json
· Parsing /home/alex/.ssh/config
· Fetching droplets from DO
· Writing into your ssh config file
✓ Done, 11 droplets synced
2
testing.json中读取并写入相应的标记。
我可以随时安全地重新运行脚本吗?
推荐PyPI第三方库