将 Fabric env.host 字符串作为变量传递

发布于 2024-12-09 14:00:59 字数 867 浏览 0 评论 0原文

我希望能够以编程方式创建一个新的云服务器,然后传递新的 [email  protected] 到其他 Fabric 命令中以运行其他安装脚本。

我能够创建服务器,获取相关变量,并启动本地('ssh [ email protected]') 命令将新 IP 添加到我的已知主机文件中。但是,无论如何,我尝试传递字符串 '[email protected] ’对于 Fabric,它仍然向我展示:

未找到主机。请指定用于连接的(单个)主机字符串:

我尝试过各种字符串操作,例如:

env.host = '%s' % 主机

env.hosts = [主机]

env.host = str(主机)

但是,Fabric 总是向我显示“找不到主机”提示。如果我复制并粘贴“打印主机”的结果,效果很好。当然,这不是一个巨大的障碍,但确实破坏了我尝试采用的整个自动推出方法。

有没有人成功使用变量将 env.host/hosts 声明传递给 Fabric?

I want to be able to programmatically create a new cloud server, and then pass the new [email protected] into additional Fabric commands to run other setup scripts.

I am able to create the server, grab the relevant variables, and initiate a local('ssh [email protected]') command to add the new IP to my known hosts file. However, regardless of however I try to pass the string '[email protected]' to Fabric, it still presents me with:

No hosts found. Please specify (single) host string for connection:

I have tried all sorts of string manipulation, such as:

env.host = '%s' % host

env.hosts = [host]

env.host = str(host)

However, Fabric always presents me with the "No hosts found" prompt. If I copy and paste the result of 'print host', that works fine. Granted, not a huge hurdle but really breaks down the whole auto-rollout approach I am trying to take.

Has anyone been successful in passing a env.host/hosts declaration to Fabric using a variable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲜血染红嫁衣 2024-12-16 14:00:59

“找不到主机”错误有点欺骗性。如果您在 env.hosts 中放入的内容格式不正确,它会抛出异常。 env.hosts 应该类似于以下之一:

env.hosts = ['1.2.3.4']
env.hosts = ['1.2.3.4', 'hostname', '4.5.6.7']

它不应该包含用户([email protected]) 被传递到env.user

尝试这样的事情:

h = '1.2.3.4'
env.hosts = [h]

The "No hosts found" error is a bit deceptive. It throws if what you've put in env.hosts isn't well formed. env.hosts should look something like one of these:

env.hosts = ['1.2.3.4']
env.hosts = ['1.2.3.4', 'hostname', '4.5.6.7']

It should not include the user ([email protected]) that gets passed to env.user

Try something like this:

h = '1.2.3.4'
env.hosts = [h]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文