ansible.utils.ipmath 过滤器 – 此过滤器旨在进行简单的 IP 数学/算术运算。
注意
此过滤器插件是 ansible.utils 集合 (版本 5.1.2) 的一部分。
如果您使用的是 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用: ansible-galaxy collection install ansible.utils。
要在 playbook 中使用它,请指定: ansible.utils.ipmath。
ansible.utils 2.5.0 中的新增功能
概要
- 此过滤器旨在进行简单的 IP 数学/算术运算。 
关键字参数
这描述了过滤器的关键字参数。这些是在以下示例中的值 key1=value1、key2=value2 等: input | ansible.utils.ipmath(key1=value1, key2=value2, ...)
| 参数 | 注释 | 
|---|---|
| 用于算术运算的整数。例如 -1,2,3 | |
| 子网列表或单个地址或任何其他用于 ipaddr 插件的输入值 | 
示例
#### examples
# Ipmath filter plugin with different arthmetic.
# Get the next fifth address based on an IP address
- debug:
    msg: "{{ '192.168.1.5' | ansible.netcommon.ipmath(5) }}"
# Get the tenth previous address based on an IP address
- debug:
    msg: "{{ '192.168.1.5' | ansible.netcommon.ipmath(-10) }}"
# Get the next fifth address using CIDR notation
- debug:
    msg: "{{ '192.168.1.1/24' | ansible.netcommon.ipmath(5) }}"
# Get the previous fifth address using CIDR notation
- debug:
    msg: "{{ '192.168.1.6/24' | ansible.netcommon.ipmath(-5) }}"
# Get the previous tenth address using cidr notation
# It returns a address of the previous network range
- debug:
    msg: "{{ '192.168.2.6/24' | ansible.netcommon.ipmath(-10) }}"
# Get the next tenth address in IPv6
- debug:
    msg: "{{ '2001::1' | ansible.netcommon.ipmath(10) }}"
# Get the previous tenth address in IPv6
- debug:
    msg: "{{ '2001::5' | ansible.netcommon.ipmath(-10) }}"
# TASK [debug] **********************************************************************************************************
# ok: [localhost] => {
#     "msg": "192.168.1.10"
# }
#
# TASK [debug] **********************************************************************************************************
# ok: [localhost] => {
#     "msg": "192.168.0.251"
# }
#
# TASK [debug] **********************************************************************************************************
# ok: [localhost] => {
#     "msg": "192.168.1.6"
# }
#
# TASK [debug] **********************************************************************************************************
# ok: [localhost] => {
#     "msg": "192.168.1.1"
# }
#
# TASK [debug] **********************************************************************************************************
# ok: [localhost] => {
#     "msg": "192.168.1.252"
# }
#
# TASK [debug] **********************************************************************************************************
# ok: [localhost] => {
#     "msg": "2001::b"
# }
#
# TASK [debug] **********************************************************************************************************
# ok: [localhost] => {
#     "msg": "2000:ffff:ffff:ffff:ffff:ffff:ffff:fffb"
# }
返回值
| 键 | 描述 | 
|---|---|
| 返回 IP 数学/算术运算的结果。 返回:成功 | 
