ansible.utils.subnet_of 测试 – 测试一个网络是否是另一个网络的子网

注意

这个测试插件是 ansible.utils 集合(版本 5.1.2)的一部分。

如果您正在使用 ansible 包,您可能已经安装了这个集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install ansible.utils

要在 Playbook 中使用它,请指定:ansible.utils.subnet_of

ansible.utils 2.2.0 中的新功能

概要

  • 此插件检查提供的网络地址中,第一个网络是否是第二个网络的子网

关键字参数

这描述了测试的关键字参数。这些值是在以下示例中 key1=value1key2=value2 等:input is ansible.utils.subnet_of(key1=value1, key2=value2, ...)input is not ansible.utils.subnet_of(key1=value1, key2=value2, ...)

参数

注释

network_a

字符串 / 必需

一个表示第一个网络地址的字符串

例如:10.1.1.0/24

network_b

字符串 / 必需

一个表示第二个网络地址的字符串

例如:10.0.0.0/8

示例

- name: Check if 10.1.1.0/24 is a subnet of 10.0.0.0/8
  ansible.builtin.set_fact:
    data: "{{ '10.1.1.0/24' is ansible.utils.subnet_of '10.0.0.0/8' }}"

# TASK [Check if 10.1.1.0/24 is a subnet of 10.0.0.0/8] **************************
# ok: [localhost] => {
#     "ansible_facts": {
#         "data": true
#     },
#     "changed": false
# }

- name: Check if 192.168.1.0/24 is not a subnet of 10.0.0.0/8
  ansible.builtin.set_fact:
    data: "{{ '192.168.1.0/24' is not ansible.utils.subnet_of '10.0.0.0/8' }}"

# TASK [Check if 192.168.1.0/24 is not a subnet of 10.0.0.0/8] *******************
# ok: [localhost] => {
#     "ansible_facts": {
#         "data": true
#     },
#     "changed": false
# }

返回值

描述

数据

字符串

如果 Jinja 测试满足插件表达式 true

如果 Jinja 测试不满足插件表达式 false

返回:成功

作者

  • Priyam Sahoo (@priyamsahoo)

提示

每个条目类型的配置条目都具有从低到高的优先级顺序。例如,列表中较低的变量将覆盖较高的变量。