Ansible - 任务序列 1 逆序 [英] Ansible - task serial 1 reverse order

查看:32
本文介绍了Ansible - 任务序列 1 逆序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建两个剧本,一个用于停止环境,另一个用于启动它.

I'd like to create two playbooks, one to stop an environment, another to start it.

部分环境是RabbitMQ集群,停止/启动顺序很重要,具体来说最后一个停止的节点需要是第一个启动的节点.

Part of the environment is a RabbitMQ cluster, for which stop/start order is quite important, specifically the last node stopped needs to be the first node started.

我想知道是否有办法指定针对组运行任务的相反顺序.这样我就可以用串行 1 应用停止,用串行 1 和反向组顺序应用开始.

I was wondering if there is a way to specify a reverse order for running a task against a group. That way I could apply the stop with serial 1, and the start with serial 1 and reverse group order.

我还没有找到一种方法来做到这一点,只能以相反的顺序定义rabbitmq主机组两次(以不同的名称),这似乎有点令人反感.

I haven't found a way to do that but to define the rabbitmq host group twice (under different names), in inverted order, which seems a bit distasteful.

还尝试了以下操作:

- hosts: "{ myhostsgroup | sort(reverse=False) }"
  serial: 1

- hosts: "{ myhostsgroup | reverse }"
  serial: 1

但无论尝试哪种情况及其变化(reverse=True, reverse|list),结果都保持不变

But result stays the same, whichever case and its variation (reverse=True, reverse|list) is attempted

任何帮助将不胜感激.

推荐答案

您可以在运行时创建动态组:

You can create dynamic groups in runtime:

---
- hosts: localhost
  gather_facts: no
  tasks:
    - add_host:
        name: "{{ item }}"
        group: forward
      with_items: "{{ groups['mygroup'] }}"

    - add_host:
        name: "{{ item }}"
        group: backward
      with_items: "{{ groups['mygroup'] | reverse | list }}"

- hosts: forward
  gather_facts: no
  serial: 1
  tasks:
    - debug:

- hosts: backward
  gather_facts: no
  serial: 1
  tasks:
    - debug:

这篇关于Ansible - 任务序列 1 逆序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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