将 Fabric env.host 字符串作为变量传递
我希望能够以编程方式创建一个新的云服务器,然后传递新的 [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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“找不到主机”错误有点欺骗性。如果您在
env.hosts
中放入的内容格式不正确,它会抛出异常。env.hosts
应该类似于以下之一:它不应该包含用户(
[email protected]
) 被传递到env.user
尝试这样的事情:
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:It should not include the user (
[email protected]
) that gets passed toenv.user
Try something like this: