基于Ansible组中ip范围的动态组 [英] Dynamic groups based on ip range in Ansible groups

查看:159
本文介绍了基于Ansible组中ip范围的动态组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在无库存清单组中基于IP地址范围创建变量组?我在不同位置有两组服务器.我想在每次使用剧本时都创建组,以便在更新的服务器列表上运行剧本.我已经根据主机清单中的分布,产品,开发,测试,质量保证,博士进行了分组.

How to create variable group based on ip address-range in ansible inventory groups ? I have two groups of servers in different location. I want to create the groups every time the playbook so that the playbook is run on a updated list of servers. I already groups based on distribution, prod, dev, test, qa ,dr in my host inventory.

预先感谢

推荐答案

您可以在开始时扫描所有主机,并根据需要将它们分组,例如通过网络:

You can scan all hosts at the beginning and group them how you want, e.g. by network:

- hosts: all
  tasks:
    - group_by: key=network_{{ ansible_default_ipv4.network }}

这将创建与您拥有的许多不同网络一样多的名称为network_<network>的组.但是请记住,它需要从所有主机收集事实,因此根据主机数量和连接速度,它可能需要大量时间.事实缓存可以加快速度,但是无论如何...

This will create as many groups with names network_<network> as many different networks you have. But keep in mind that it need to gather facts from all hosts, so depending on count of hosts and speed of connections it can require significant time. Facts caching will speed up things, but anyway...

如果您手动管理库存文件,请考虑也手动指定区域组.

If you manage your inventory file by hand, consider manually specifying regional groups as well.

这篇关于基于Ansible组中ip范围的动态组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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