Ansible-按我的意愿与主持人一起玩 [英] Ansible - Play with hosts in order I desire
问题描述
运行剧本时,Ansible会随机将一个节点设置为第一,第二和第三.
When running a playbook Ansible randomly sets a node as first, second and third.
TASK [setup] ********
ok: [node-p02]
ok: [node-p03]
ok: [node-p01]
如何配置Ansible以确保其发挥作用:
How can I configure Ansible to ensure it plays as:
TASK [setup] ********
ok: [node-p01]
ok: [node-p02]
ok: [node-p03]
Serial: 1
是不可选项,因为它会减慢播放速度,而我的剧本只能在一次播放中用于3个节点.
Serial: 1
is not an option, since it slows down the play, and my playbook is meant for 3 nodes in a single play.
推荐答案
适用于Ansible 2.4及更高版本:
这是默认的行为,ansible将按order
来控制它:
Applicable for Ansible 2.4 and higher:
This is now the default behaviour, ansible will play the hosts in the order they were mentioned in the inventory
file. Ansible also provides a few built in ways you can control it with order
:
- hosts: all
order: sorted
gather_facts: False
tasks:
- debug:
var: inventory_hostname
order
的可能值为:
- 库存:默认值.订单是按库存提供的"
- reverse_inventory:顾名思义,这将颠倒广告资源按提供的顺序"
- 已排序:主机按名称的字母顺序
- reverse_sorted:主机按名称以相反的字母顺序排序
- 随机播放:主机在每次运行时都是随机排序的
来源: https://docs.ansible. com/ansible/latest/user_guide/playbooks_intro.html#hosts-and-users
这篇关于Ansible-按我的意愿与主持人一起玩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!