我如何在Ansibe的50%计算机上发布代码 [英] How can i release code on 50% machine in Ansibe
问题描述
我们在aws中使用标签Name = ad_server
运行了100台计算机,所以我如何只运行50%的发行代码。
示例:
we have running 100 Machines in aws with tag Name=ad_server so how can i run release code only 50% machines. Example:
- hosts: tag_Name_ad_server
sudo: yes
remote_user: ubuntu
tasks:
- name: whatever
那我该怎么办
推荐答案
选项1:序列+暂停
此将使用批处理的标准功能进行滚动更新,并且需要一些用户交互。
我们添加暂停
并带有提示作为第一个任务,等待ENTER输入
因此,在第一个50%的批次上按ENTER,然后在要求开始下一个后一半时中止执行。
Option 1: serial + pause
This will use standard feature of batches for rolling updates and require some user interaction.
We add pause
with prompt as a first task to wait for ENTER to be pressed at the start of every batch.
So press ENTER on the first 50%-batch and then abort execution when asked to start the second half.
- hosts: tag_Name_ad_server
user: ubuntu
serial: "50%"
tasks:
- pause: prompt="Press ENTER to run this batch"
- shell: echo task1
- shell: echo task2
每次运行剧本时,序列
始终会从清单中选择相同的服务器。在这种情况下,列表中的前50%。
With every playbook run serial
will always choose the same servers from inventory. In this case first 50% from the list.
通过主机位于tag_Name_ad_server组中,并形成一个新的50%组。
然后在此新组中执行实际任务。
不需要用户交互。
Loop through hosts in tag_Name_ad_server group and form a new 50_percent group.
Then execute your actual tasks within this new group.
No user interaction required.
- hosts: tag_Name_ad_server
gather_facts: no
tasks:
- group_by: key=50_percent
when: 100 | random > 50
- hosts: 50_percent
user: ubuntu
tasks:
- shell: echo task1
- shell: echo task2
如果运行了Playbook,则 random
将从列表中选择50%随机服务器。
With ever playbook run random
will choose 50% random servers from the list.
如果仅运行一项任务,则可以使用 max_fail_percentage:-1
在执行第一批任务后停止执行。
这将产生50%的批处理,在每个主机上执行第一个任务
If you have only one task to run, you can use max_fail_percentage: -1
to stop execution after first task of first batch.
This will make a 50%-batches, execute first task on every host of this batch and check failed servers count, as it always will be above -1 playbook will stop execution.
- hosts: tag_Name_ad_server
user: ubuntu
serial: "50%"
max_fail_percentage: -1
tasks:
- shell: echo task1
- shell: echo task2 # this task will never be executed with max_fail_percentage == -1
这篇关于我如何在Ansibe的50%计算机上发布代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!