junipernetworks.junos.junos_l3_interfaces 模块 – 三层接口资源模块

注意

此模块是 junipernetworks.junos 集合 (版本 9.1.0) 的一部分。

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

要安装它,请使用:ansible-galaxy collection install junipernetworks.junos。您需要其他要求才能使用此模块,有关详细信息,请参阅 要求

要在剧本中使用它,请指定:junipernetworks.junos.junos_l3_interfaces

junipernetworks.junos 1.0.0 中的新增功能

摘要

  • 此模块提供对 Juniper JUNOS 设备上三层接口的声明式管理。

别名:l3_interfaces

要求

执行此模块的主机需要以下要求。

  • ncclient (>=v0.6.4)

参数

参数

注释

config

列表 / 元素=字典

三层接口选项的字典

ipv4

列表 / 元素=字典

为在 *name* 选项中提到的三层逻辑接口设置的 IPv4 地址。地址格式为 <ipv4 地址>/<掩码>。掩码是 0-32 范围内的数字,例如 192.0.2.1/24,或 dhcp 用于查询 DHCP 获取 IP 地址。

address

字符串

为特定接口设置的 IPv4 地址

ipv6

列表 / 元素=字典

为在 *name* 选项中提到的三层逻辑接口设置的 IPv6 地址。地址格式为 <ipv6 地址>/<掩码>,掩码是 0-128 范围内的数字,例如 2001:db8:2201:1::1/64 或 auto-config 用于使用 SLAAC。

address

字符串

为特定接口设置的 IPv6 地址

mtu

整数

协议族最大传输单元。

name

字符串 / 必需

接口的全名,例如 ge-0/0/1

unit

整数

逻辑接口编号。unit 的值应为整数类型。

默认值: 0

running_config

字符串

此选项仅与 state *parsed* 一起使用。

此选项的值应为通过执行命令 show interfaces 从 Junos 设备接收到的输出。

state *parsed* 从 running_config 选项读取配置并将其转换为 Ansible 结构化数据,符合资源模块的 argspec,然后该值将返回结果中的 *parsed* 键中。

state

字符串

模块完成后的配置状态

选项

  • "merged" ← (默认)

  • "replaced"

  • "overridden"

  • "deleted"

  • "gathered"

  • "rendered"

  • "parsed"

备注

注意

示例

# Using merged

# Before state
# ------------
#
# admin# show interfaces
# fxp0 {
#     enable;
#     unit 0 {
#         family inet {
#             dhcp;
#         }
#     }
# }

- name: Merge provided configuration with device configuration
  junipernetworks.junos.junos_l3_interfaces:
    config:
      - name: ge-0/0/1
        ipv4:
          - address: 192.168.1.10/24
        ipv6:
          - address: 8d8d:8d01::1/64
      - name: ge-0/0/2
        ipv4:
          - address: dhcp
    state: merged

# Task Output
# -----------
#
# before:
# - ipv4:
#   - address: dhcp
#   name: fxp0
#   unit: '0'
# commands:
# - <nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
#     <nc:interface>
#       <nc:name>ge-0/0/1</nc:name>
#       <nc:unit>
#         <nc:name>0</nc:name>
#         <nc:family>
#           <nc:inet>
#             <nc:address>
#               <nc:name>192.168.1.10/24</nc:name>
#             </nc:address>
#           </nc:inet>
#         </nc:family>
#         <nc:family>
#           <nc:inet6>
#             <nc:address>
#               <nc:name>8d8d:8d01::1/64</nc:name>
#             </nc:address>
#           </nc:inet6>
#         </nc:family>
#       </nc:unit>
#     </nc:interface>
#     <nc:interface>
#       <nc:name>ge-0/0/2</nc:name>
#       <nc:unit>
#         <nc:name>0</nc:name>
#         <nc:family>
#           <nc:inet>
#             <nc:dhcp/>
#           </nc:inet>
#         </nc:family>
#       </nc:unit>
#     </nc:interface>
#   </nc:interfaces>
# after:
# - ipv4:
#   - address: 192.168.1.10/24
#   ipv6:
#   - address: 8d8d:8d01::1/64
#   name: ge-0/0/1
#   unit: '0'
# - ipv4:
#   - address: dhcp
#   name: ge-0/0/2
#   unit: '0'
# - ipv4:
#   - address: dhcp
#   name: fxp0
#   unit: '0'

# After state:
# ------------
#
# admin# show interfaces
# ge-0/0/1 {
#     unit 0 {
#         family inet {
#             address 192.168.1.10/24;
#         }
#         family inet6 {
#             address 8d8d:8d01::1/64;
#         }
#     }
# }
# ge-0/0/2 {
#     unit 0 {
#         family inet {
#             dhcp;
#         }
#     }
# }
# fxp0 {
#     enable;
#     unit 0 {
#         family inet {
#             dhcp;
#         }
#     }
# }

# Using overridden

# Before state
# ------------
#
# admin# show interfaces
# ge-0/0/1 {
#     unit 0 {
#         family inet {
#             address 192.168.1.10/24;
#         }
#         family inet6 {
#             address 8d8d:8d01::1/64;
#         }
#     }
# }
# ge-0/0/2 {
#     unit 0 {
#         family inet {
#             dhcp;
#         }
#     }
# }
# fxp0 {
#     enable;
#     unit 0 {
#         family inet {
#             dhcp;
#         }
#     }
# }

- name: Override provided configuration with device configuration
  junipernetworks.junos.junos_l3_interfaces:
    config:
      - name: ge-0/0/1
        ipv4:
          - address: 192.168.1.10/24
      - ipv4:
          - address: dhcp
        name: fxp0
        unit: '0'
    state: overridden

# Task Output
# -----------
#
# before:
# - ipv4:
#   - address: 192.168.1.10/24
#   ipv6:
#   - address: 8d8d:8d01::1/64
#   name: ge-0/0/1
#   unit: '0'
# - ipv4:
#   - address: dhcp
#   name: ge-0/0/2
#   unit: '0'
# - ipv4:
#   - address: dhcp
#   name: fxp0
#   unit: '0'
# commands:
# - <nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
#   <nc:interface>
#     <nc:name>ge-0/0/1</nc:name>
#     <nc:unit>
#       <nc:name>0</nc:name>
#       <nc:family>
#         <nc:inet>
#           <nc:address delete="delete"/>
#         </nc:inet>
#         <nc:inet6>
#           <nc:address delete="delete"/>
#         </nc:inet6>
#       </nc:family>
#     </nc:unit>
#   </nc:interface>
#   <nc:interface>
#     <nc:name>ge-0/0/2</nc:name>
#     <nc:unit>
#       <nc:name>0</nc:name>
#       <nc:family>
#         <nc:inet>
#           <nc:dhcp delete="delete"/>
#         </nc:inet>
#         <nc:inet6>
#           <nc:address delete="delete"/>
#         </nc:inet6>
#       </nc:family>
#     </nc:unit>
#   </nc:interface>
#   <nc:interface>
#     <nc:name>fxp0</nc:name>
#     <nc:unit>
#       <nc:name>0</nc:name>
#       <nc:family>
#         <nc:inet>
#           <nc:dhcp delete="delete"/>
#         </nc:inet>
#         <nc:inet6>
#           <nc:address delete="delete"/>
#         </nc:inet6>
#       </nc:family>
#     </nc:unit>
#   </nc:interface>
#   <nc:interface>
#     <nc:name>ge-0/0/1</nc:name>
#     <nc:unit>
#       <nc:name>0</nc:name>
#       <nc:family>
#         <nc:inet>
#           <nc:address>
#             <nc:name>192.168.1.10/24</nc:name>
#           </nc:address>
#         </nc:inet>
#       </nc:family>
#     </nc:unit>
#   </nc:interface>
#   <nc:interface>
#     <nc:name>fxp0</nc:name>
#     <nc:unit>
#       <nc:name>0</nc:name>
#       <nc:family>
#         <nc:inet>
#           <nc:dhcp/>
#         </nc:inet>
#       </nc:family>
#     </nc:unit>
#   </nc:interface>
# </nc:interfaces>
# after:
# - ipv4:
#   - address: 192.168.1.10/24
#   name: ge-0/0/1
#   unit: '0'
# - name: ge-0/0/2
#   unit: '0'
# - ipv4:
#   - address: dhcp
#   name: fxp0
#   unit: '0'

# After state:
# ------------
#
# admin# show interfaces
# ge-0/0/1 {
#     unit 0 {
#         family inet {
#             address 192.168.1.10/24;
#         }
#         family inet6;
#     }
# }
# ge-0/0/2 {
#     unit 0 {
#         family inet;
#         family inet6;
#     }
# }
# fxp0 {
#     enable;
#     unit 0 {
#         family inet {
#             dhcp;
#         }
#         family inet6;
#     }
# }

# Using replaced

# Before state
# ------------
#
# admin# show interfaces
# ge-0/0/1 {
#     unit 0 {
#         family inet {
#             address 192.168.1.10/24;
#         }
#         family inet6;
#     }
# }
# ge-0/0/2 {
#     unit 0 {
#         family inet;
#         family inet6;
#     }
# }
# fxp0 {
#     enable;
#     unit 0 {
#         family inet {
#             dhcp;
#         }
#         family inet6;
#     }
# }

- name: Replace provided configuration with device configuration
  junipernetworks.junos.junos_l3_interfaces:
    config:
      - name: ge-0/0/1
        ipv4:
          - address: 192.168.1.10/24
        ipv6:
          - address: 8d8d:8d01::1/64
      - name: ge-0/0/2
        ipv4:
          - address: dhcp
    state: replaced

# Task Output
# -----------
#
# before:
# - ipv4:
#   - address: 192.168.1.10/24
#   name: ge-0/0/1
#   unit: '0'
# - name: ge-0/0/2
#   unit: '0'
# - ipv4:
#   - address: dhcp
#   name: fxp0
#   unit: '0'
# commands:
# - <nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
#   <nc:interface>
#     <nc:name>ge-0/0/1</nc:name>
#     <nc:unit>
#       <nc:name>0</nc:name>
#       <nc:family>
#         <nc:inet>
#           <nc:address delete="delete"/>
#         </nc:inet>
#         <nc:inet6>
#           <nc:address delete="delete"/>
#         </nc:inet6>
#       </nc:family>
#     </nc:unit>
#   </nc:interface>
#   <nc:interface>
#     <nc:name>ge-0/0/2</nc:name>
#     <nc:unit>
#       <nc:name>0</nc:name>
#       <nc:family>
#         <nc:inet/>
#         <nc:inet6>
#           <nc:address delete="delete"/>
#         </nc:inet6>
#       </nc:family>
#     </nc:unit>
#   </nc:interface>
#   <nc:interface>
#     <nc:name>ge-0/0/1</nc:name>
#     <nc:unit>
#       <nc:name>0</nc:name>
#       <nc:family>
#         <nc:inet>
#           <nc:address>
#             <nc:name>192.168.1.10/24</nc:name>
#           </nc:address>
#         </nc:inet>
#       </nc:family>
#       <nc:family>
#         <nc:inet6>
#           <nc:address>
#             <nc:name>8d8d:8d01::1/64</nc:name>
#           </nc:address>
#         </nc:inet6>
#       </nc:family>
#     </nc:unit>
#   </nc:interface>
#   <nc:interface>
#     <nc:name>ge-0/0/2</nc:name>
#     <nc:unit>
#       <nc:name>0</nc:name>
#       <nc:family>
#         <nc:inet>
#           <nc:dhcp/>
#         </nc:inet>
#       </nc:family>
#     </nc:unit>
#   </nc:interface>
# </nc:interfaces>
# after:
# - ipv4:
#   - address: 192.168.1.10/24
#   ipv6:
#   - address: 8d8d:8d01::1/64
#   name: ge-0/0/1
#   unit: '0'
# - ipv4:
#   - address: dhcp
#   name: ge-0/0/2
#   unit: '0'
# - ipv4:
#   - address: dhcp
#   name: fxp0
#   unit: '0'

# After state:
# ------------
#
# admin# show interfaces
# ge-0/0/1 {
#     unit 0 {
#         family inet {
#             address 192.168.1.10/24;
#         }
#         family inet6 {
#             address 8d8d:8d01::1/64;
#         }
#     }
# }
# ge-0/0/2 {
#     unit 0 {
#         family inet {
#             dhcp;
#         }
#         family inet6;
#     }
# }
# fxp0 {
#     enable;
#     unit 0 {
#         family inet {
#             dhcp;
#         }
#         family inet6;
#     }
# }

# Using deleted

# Before state:
# -------------
#
# admin# show interfaces
# ge-0/0/1 {
#     unit 0 {
#         family inet {
#             address 192.168.1.10/24;
#         }
#         family inet6 {
#             address 8d8d:8d01::1/64;
#         }
#     }
# }
# ge-0/0/2 {
#     unit 0 {
#         family inet {
#             dhcp;
#         }
#         family inet6;
#     }
# }
# fxp0 {
#     enable;
#     unit 0 {
#         family inet {
#             dhcp;
#         }
#         family inet6;
#     }
# }

- name: Delete L3 logical interface
  junipernetworks.junos.junos_l3_interfaces:
    config:
      - name: ge-0/0/1
      - name: ge-0/0/2
    state: deleted

# Task Output
# -----------
#
# before:
# - ipv4:
#   - address: 192.168.1.10/24
#   ipv6:
#   - address: 8d8d:8d01::1/64
#   name: ge-0/0/1
#   unit: '0'
# - ipv4:
#   - address: dhcp
#   name: ge-0/0/2
#   unit: '0'
# - ipv4:
#   - address: dhcp
#   name: fxp0
#   unit: '0'
# commands:
# - <nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
#     <nc:interface>
#       <nc:name>ge-0/0/1</nc:name>
#       <nc:unit>
#         <nc:name>0</nc:name>
#         <nc:family>
#           <nc:inet>
#             <nc:address delete="delete"/>
#           </nc:inet>
#           <nc:inet6>
#             <nc:address delete="delete"/>
#           </nc:inet6>
#         </nc:family>
#       </nc:unit>
#     </nc:interface>
#     <nc:interface>
#       <nc:name>ge-0/0/2</nc:name>
#       <nc:unit>
#         <nc:name>0</nc:name>
#         <nc:family>
#           <nc:inet>
#             <nc:dhcp delete="delete"/>
#           </nc:inet>
#           <nc:inet6>
#             <nc:address delete="delete"/>
#           </nc:inet6>
#         </nc:family>
#       </nc:unit>
#     </nc:interface>
#   </nc:interfaces>
# after:
# - name: ge-0/0/1
#   unit: '0'
# - name: ge-0/0/2
#   unit: '0'
# - ipv4:
#   - address: dhcp
#   name: fxp0
#   unit: '0'

# After state:
# ------------
#
# admin# show interfaces
# ge-0/0/1 {
#     unit 0 {
#         family inet;
#         family inet6;
#     }
# }
# ge-0/0/2 {
#     unit 0 {
#         family inet;
#         family inet6;
#     }
# }
# fxp0 {
#     enable;
#     unit 0 {
#         family inet {
#             dhcp;
#         }
#         family inet6;
#     }
# }

# Using gathered

# Before state:
# ------------
#
# user@junos01# show interfaces
# ge-0/0/1 {
#     description "Configured by Ansible";
#     disable;
#     speed 100m;
#     mtu 1024;
#     hold-time up 2000 down 2200;
#     link-mode full-duplex;
#     unit 0 {
#         family ethernet-switching {
#             interface-mode access;
#             vlan {
#                 members vlan100;
#             }
#         }
#     }
# }
# ge-0/0/2 {
#     description "Configured by Ansible";
#     native-vlan-id 400;
#     speed 10m;
#     mtu 2048;
#     hold-time up 3000 down 3200;
#     unit 0 {
#         family ethernet-switching {
#             interface-mode trunk;
#             vlan {
#                 members [ vlan200 vlan300 ];
#             }
#         }
#     }
# }
# ge-1/0/0 {
#     unit 0 {
#         family inet {
#             address 192.168.100.1/24;
#             address 10.200.16.20/24;
#         }
#         family inet6;
#     }
# }
# ge-2/0/0 {
#     unit 0 {
#         family inet {
#             address 192.168.100.2/24;
#             address 10.200.16.21/24;
#         }
#         family inet6;
#     }
# }
# ge-3/0/0 {
#     unit 0 {
#         family inet {
#             address 192.168.100.3/24;
#             address 10.200.16.22/24;
#         }
#         family inet6;
#     }
# }
# em1 {
#     description TEST;
# }
# fxp0 {
#     description ANSIBLE;
#     speed 1g;
#     link-mode automatic;
#     unit 0 {
#         family inet {
#             address 10.8.38.38/24;
#         }
#     }
# }

- name: Gather layer3 interfaces facts
  junipernetworks.junos.junos_l3_interfaces:
    state: gathered

# Task Output
# -----------
#
# gathered:
# - ipv4:
#   - address: 192.168.100.1/24
#   - address: 10.200.16.20/24
#   name: ge-1/0/0
#   unit: '0'
# - ipv4:
#   - address: 192.168.100.2/24
#   - address: 10.200.16.21/24
#   name: ge-2/0/0
#   unit: '0'
# - ipv4:
#   - address: 192.168.100.3/24
#   - address: 10.200.16.22/24
#   name: ge-3/0/0
#   unit: '0'
# - ipv4:
#   - address: 10.8.38.38/24
#   name: fxp0
#   unit: '0'

# Using parsed

# parsed.cfg
# ------------
#
# <?xml version="1.0" encoding="UTF-8"?>
# <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f">
#     <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC">
#         <interfaces>
#             <interface>
#                 <name>ge-1/0/0</name>
#                 <unit>
#                     <name>0</name>
#                     <family>
#                         <inet>
#                             <address>
#                                 <name>192.168.100.1/24</name>
#                             </address>
#                             <address>
#                                 <name>10.200.16.20/24</name>
#                             </address>
#                         </inet>
#                         <inet6></inet6>
#                     </family>
#                 </unit>
#             </interface>
#             <interface>
#                 <name>ge-2/0/0</name>
#                 <unit>
#                     <name>0</name>
#                     <family>
#                         <inet>
#                             <address>
#                                 <name>192.168.100.2/24</name>
#                             </address>
#                             <address>
#                                 <name>10.200.16.21/24</name>
#                             </address>
#                         </inet>
#                         <inet6></inet6>
#                     </family>
#                 </unit>
#             </interface>
#         </interfaces>
#     </configuration>
# </rpc-reply>

# - name: Convert interfaces config to argspec without connecting to the appliance
#   junipernetworks.junos.junos_l3_interfaces:
#     running_config: "{{ lookup('file', './parsed.cfg') }}"
#     state: parsed

# Task Output
# -----------
#
# parsed:
# - ipv4:
#   - address: 192.168.100.1/24
#   - address: 10.200.16.20/24
#   name: ge-1/0/0
#   unit: '0'
# - ipv4:
#   - address: 192.168.100.2/24
#   - address: 10.200.16.21/24
#   name: ge-2/0/0
#   unit: '0'

# Using rendered

- name: Render platform specific xml from task input using rendered state
  junipernetworks.junos.junos_l3_interfaces:
    config:
      - name: ge-1/0/0
        ipv4:
          - address: 192.168.100.1/24
          - address: 10.200.16.20/24
        unit: 0
      - name: ge-2/0/0
        ipv4:
          - address: 192.168.100.2/24
          - address: 10.200.16.21/24
        unit: 0
    state: rendered

# Task Output
# -----------
#
# "rendered": "<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
#     <nc:interface>
#         <nc:name>ge-1/0/0</nc:name>
#         <nc:unit>
#             <nc:name>0</nc:name>
#             <nc:family>
#                 <nc:inet>
#                     <nc:address>
#                         <nc:name>192.168.100.1/24</nc:name>
#                     </nc:address>
#                     <nc:address>
#                         <nc:name>10.200.16.20/24</nc:name>
#                     </nc:address>
#                 </nc:inet>
#             </nc:family>
#         </nc:unit>
#     </nc:interface>
#     <nc:interface>
#         <nc:name>ge-2/0/0</nc:name>
#         <nc:unit>
#             <nc:name>0</nc:name>
#             <nc:family>
#                 <nc:inet>
#                     <nc:address>
#                         <nc:name>192.168.100.2/24</nc:name>
#                     </nc:address>
#                     <nc:address>
#                         <nc:name>10.200.16.21/24</nc:name>
#                     </nc:address>
#                 </nc:inet>
#             </nc:family>
#         </nc:unit>
#     </nc:interface>
# </nc:interfaces>"

返回值

常见的返回值已在 此处 记录,以下是此模块特有的字段。

描述

after

列表 / 元素=字符串

模块完成后的结构化数据配置。

返回:发生更改时

示例: ["The configuration returned will always be in the same format\n of the parameters above.\n"]

before

列表 / 元素=字符串

模块调用前的结构化数据配置。

返回:始终返回

示例: ["The configuration returned will always be in the same format\n of the parameters above.\n"]

commands

列表 / 元素=字符串

推送到远程设备的命令集。

返回:始终返回

示例: ["<nc:interfaces xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\"> <nc:interface> <nc:name>ge-1/0/0</nc:name> <nc:unit> <nc:name>0</nc:name> <nc:family> <nc:inet> <nc:address> <nc:name>192.168.100.1/24</nc:name> </nc:address> <nc:address> <nc:name>10.200.16.20/24</nc:name> </nc:address> </nc:inet> </nc:family> </nc:unit> </nc:interfaces>", "xml 2", "xml 3"]

gathered

列表 / 元素=字符串

从远程设备收集的关于网络资源的事实,以结构化数据表示。

返回:stategathered

示例: ["This output will always be in the same format as the module argspec.\n"]

已解析

列表 / 元素=字符串

根据模块参数规范,将running_config选项中提供的设备原生配置解析为结构化数据。

返回:stateparsed

示例: ["This output will always be in the same format as the module argspec.\n"]

已渲染

列表 / 元素=字符串

任务中提供的配置以设备原生格式(离线)呈现。

返回:staterendered

示例: ["<nc:protocols xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"]

作者

  • Daniel Mellado (@dmellado)