Ansible-按我的意愿与主持人一起玩 [英] Ansible - Play with hosts in order I desire

查看:88
本文介绍了Ansible-按我的意愿与主持人一起玩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行剧本时,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将按文件中提到的顺序播放主机. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆