有没有办法在fabric文件中进行滚动部署?
给出以下 fabfile:
from fabric.api import env, run
env.user = 'implicit_user'
env.hosts = ['host1', 'explicit_user@host2', 'host3']
def print_user():
with hide('running'):
run('echo "%(user)s"' % env)
当我们运行 fab print_user 时,我们得到:
[host1] out: implicit_user
[explicit_user@host2] out: explicit_user
[host3] out: implicit_user
Done.
Disconnecting from host1... done.
Disconnecting from host2... done.
Disconnecting from host3... done.
但是,我非常愿意按顺序执行整个 fab print_user ,中间间隔 10 秒确保前一个主机在下一个主机开始操作之前完成其操作:
[host1] out: implicit_user
<10 seconds here...>
[explicit_user@host2] out: explicit_user
<10 seconds here...>
[host3] out: implicit_user
<10 seconds here...>
Done.
Disconnecting from host1... done.
Disconnecting from host2... done.
Disconnecting from host3... done.
有办法做到这一点吗?我应该如何调整我的 fabfile 来实现它?
Giving the following fabfile:
from fabric.api import env, run
env.user = 'implicit_user'
env.hosts = ['host1', 'explicit_user@host2', 'host3']
def print_user():
with hide('running'):
run('echo "%(user)s"' % env)
When we run fab print_user
, we get:
[host1] out: implicit_user
[explicit_user@host2] out: explicit_user
[host3] out: implicit_user
Done.
Disconnecting from host1... done.
Disconnecting from host2... done.
Disconnecting from host3... done.
However, I would very much to conduct the entire fab print_user
sequentially, with 10 second interval in between to make sure that the previous host is finished with its actions before the next host kicks the actions off:
[host1] out: implicit_user
<10 seconds here...>
[explicit_user@host2] out: explicit_user
<10 seconds here...>
[host3] out: implicit_user
<10 seconds here...>
Done.
Disconnecting from host1... done.
Disconnecting from host2... done.
Disconnecting from host3... done.
Is there a way to do it? How should I tweak my fabfile to achieve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非您通过命令行指定并行,否则您的文件已经按顺序执行。要明确此顺序执行,请使用 @serial装饰器。
您希望通过延迟来处理失败吗?
warn_only=False
将导致您的顺序任务之一失败而终止该任务(其他主机不会运行该任务)。这也可以在下面的示例中看到,其中一旦运行 false(它具有失败退出状态),其余主机就不会运行该任务。如果你真的想要这 10 秒的延迟,我想你可以制作一个休眠 10 秒的装饰器,或者只是在任务结束时休眠。
Your file already executes sequentially unless you are specifying parallel via the command line. To be explicit about this sequential execution use the @serial decorator .
Do you want this delay to deal with a failure?
warn_only=False
will cause a failure in one of your sequential tasks to terminate the task (other hosts will not run the task). This is also seen in the example below where as soon as false is run (it has failure exit status) the remaining host do not run the task.If you really want this 10 second delay I guess you could make a decorator that sleeps for 10 or just sleep at the end of your tasks.