为什么要在 Fabric 脚本中逐行重新实现 shell 命令?
Fabric 是一个“执行本地或远程 shell 命令”的工具。
为什么要在很长的 Fabric 脚本中逐行重新实现远程 shell 脚本?
也就是说,为什么不只编写一个简短的 Fabric 脚本来运行一个长的远程 shell 脚本呢?
Fabric is a tool for "executing local or remote shell commands."
Why would you re-implement a remote shell script line by line in a long Fabric script?
That is, why not just write a brief Fabric script that runs a long remote shell script instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
lobster1234 提出了一个很好的观点,即您不想在 10 台服务器上手动粘贴很长的远程 shell 脚本。但是,如果您仍然希望避免将长远程 shell 脚本重写为长 Fabric 脚本,则可以编写一个 Fabric 脚本,将该远程 shell 脚本复制到指定服务器,执行该脚本,然后删除该脚本。通过这种方式,您可以一起修订控制 fabfile 和 shell 脚本,但避免将 shell 脚本重写为 Fabric 脚本。
lobster1234 raises a good point that you don't want to have to manually stick a long, remote shell script on 10 servers. However, if you still want to avoid rewriting the long, remote shell script as a long Fabric script, you could write a Fabric script that copies that remote shell script to the designated server, executes that script, and then removes the script. This way you can revision control both the fabfile and shell script together but avoid rewriting the shell script into a Fabric script.
如果我必须在 10 台服务器上运行相同的脚本,这不是一个好主意。这意味着我不仅必须在 10 台服务器上粘贴相同的长脚本,而且还要确保如果我在 1 台服务器上更改它,则更改必须应用到所有服务器。我知道可以通过将该脚本保留在共享位置来避免这种情况,但将脚本放在 fabfile 中会更有组织性,它不仅可以进行版本控制,而且可以在所有角色之间保持统一。
It wont be a good idea if I have to run the same script on, lets say, 10 servers. This means I've to not only stick the same long script on 10 servers, but also make sure if I change it on 1 server, the change has to be applied to all servers. I know this can be averted by keeping that script on a shared location, but its much more organized to have the script in the fabfile, which can not only be version controlled but kept uniform across all the roles.
另外,我认为你选择的道路取决于你想要做什么。有些事情在 python 中更容易(将其写入您的 fabfile),而其他事情在 shell-land 中更容易(采用提到的 shell 方法之一)。
无论哪种方式,结构都是面向集中化和可移植性的,并且实际上是什么在进行提升并不重要。
Also, I think the path you'd choose would depend on what you're trying to do. Some things are easier in python (write it in your fabfile), while others are easier in shell-land (take one of the shell approaches mentioned).
Either way, fabric is geared towards centralization and portability, and it doesn't really matter what's actually doing the lifting.