junipernetworks.junos.junos_interfaces – Junos Interfaces resource module

Note

This plugin is part of the junipernetworks.junos collection.

To install it use: ansible-galaxy collection install junipernetworks.junos.

To use it in a playbook, specify: junipernetworks.junos.junos_interfaces.

New in version 1.0.0: of junipernetworks.junos

Synopsis

  • This module manages the interfaces on Juniper Junos OS network devices.

Requirements

The below requirements are needed on the host that executes this module.

  • ncclient (>=v0.6.4)

Parameters

Parameter Choices/Defaults Comments
config
list / elements=dictionary
The provided configuration
description
string
Interface description.
duplex
string
    Choices:
  • automatic
  • full-duplex
  • half-duplex
Interface link status. Applicable for Ethernet interfaces only, either in half duplex, full duplex or in automatic state which negotiates the duplex automatically.
enabled
boolean
    Choices:
  • no
  • yes ←
Administrative state of the interface.
Set the value to true to administratively enabled the interface or false to disable it.
hold_time
dictionary
The hold time for given interface name.
down
integer
The link down hold time in milliseconds.
up
integer
The link up hold time in milliseconds.
mtu
integer
MTU for a specific interface.
Applicable for Ethernet interfaces only.
name
string / required
Full name of interface, e.g. ge-0/0/0.
speed
string
Interface link speed. Applicable for Ethernet interfaces only.
running_config
string
This option is used only with state parsed.
The value of this option should be the output received from the Junos device by executing the command show interfaces.
The state parsed reads the configuration from running_config option and transforms it into Ansible structured data as per the resource module's argspec and the value is then returned in the parsed key within the result.
state
string
    Choices:
  • merged ←
  • replaced
  • overridden
  • deleted
  • gathered
  • parsed
  • rendered
The state of the configuration after module completion

Notes

Note

  • This module requires the netconf system service be enabled on the remote device being managed.

  • Tested against vSRX JUNOS version 18.4R1.

  • This module works with connection netconf. See the Junos OS Platform Options.

Examples

# Using deleted

# Before state:
# -------------
# [email protected]# show interfaces
# ge-0/0/1 {
#    description "Configured by Ansible-1";
#    speed 1g;
#    mtu 1800
# }
# ge-0/0/2 {
#    description "Configured by Ansible-2";
#    ether-options {
#        auto-negotiation;
#    }
# }

- name: "Delete given options for the interface (Note: This won't delete the interface itself if any other values are configured for interface)"
  junipernetworks.junos.junos_interfaces:
    config:
    - name: ge-0/0/1
      description: Configured by Ansible-1
      speed: 1g
      mtu: 1800
    - name: ge-0/0/2
      description: Configured by Ansible -2
    state: deleted

# After state:
# ------------
# [email protected]# show interfaces
# ge-0/0/2 {
#    ether-options {
#        auto-negotiation;
#    }
# }


# Using merged

# Before state:
# -------------
# [email protected]# show interfaces
# ge-0/0/1 {
#    description "test interface";
#    speed 1g;
# }

- name: Merge provided configuration with device configuration (default operation
    is merge)
  junipernetworks.junos.junos_interfaces:
    config:
    - name: ge-0/0/1
      description: Configured by Ansible-1
      enabled: true
      mtu: 1800
    - name: ge-0/0/2
      description: Configured by Ansible-2
      enabled: false
    state: merged

# After state:
# ------------
# [email protected]# show interfaces
# ge-0/0/1 {
#    description "Configured by Ansible-1";
#    speed 1g;
#    mtu 1800
# }
# ge-0/0/2 {
#    disable;
#    description "Configured by Ansible-2";
# }


# Using overridden

# Before state:
# -------------
# [email protected]# show interfaces
# ge-0/0/1 {
#    description "Configured by Ansible-1";
#    speed 1g;
#    mtu 1800
# }
# ge-0/0/2 {
#    disable;
#    description "Configured by Ansible-2";
#    ether-options {
#        auto-negotiation;
#    }
# }
# ge-0/0/11 {
#    description "Configured by Ansible-11";
# }

- name: Override device configuration of all interfaces with provided configuration
  junipernetworks.junos.junos_interfaces:
    config:
    - name: ge-0/0/2
      description: Configured by Ansible-2
      enabled: false
      mtu: 2800
    - name: ge-0/0/3
      description: Configured by Ansible-3
    state: overridden

# After state:
# ------------
# [email protected]# show interfaces
# ge-0/0/2 {
#    disable;
#    description "Configured by Ansible-2";
#    mtu 2800
# }
# ge-0/0/3 {
#    description "Configured by Ansible-3";
# }


# Using replaced

# Before state:
# -------------
# [email protected]# show interfaces
# ge-0/0/1 {
#    description "Configured by Ansible-1";
#    speed 1g;
#    mtu 1800
# }
# ge-0/0/2 {
#    disable;
#    mtu 1800;
#    speed 1g;
#    description "Configured by Ansible-2";
#    ether-options {
#        auto-negotiation;
#    }
# }
# ge-0/0/11 {
#    description "Configured by Ansible-11";
# }

- name: Replaces device configuration of listed interfaces with provided configuration
  junipernetworks.junos.junos_interfaces:
    config:
    - name: ge-0/0/2
      description: Configured by Ansible-2
      enabled: false
      mtu: 2800
    - name: ge-0/0/3
      description: Configured by Ansible-3
    state: replaced

# After state:
# ------------
# [email protected]# show interfaces
# ge-0/0/1 {
#    description "Configured by Ansible-1";
#    speed 1g;
#    mtu 1800
# }
# ge-0/0/2 {
#    disable;
#    description "Configured by Ansible-2";
#    mtu 2800
# }
# ge-0/0/3 {
#    description "Configured by Ansible-3";
# }
# ge-0/0/11 {
#    description "Configured by Ansible-11";
# }
# Using gathered
# Before state:
# ------------
#
# [email protected]# show interfaces
# gr-0/0/0 {
#     description "test gre interface";
# }
# fxp0 {
#     unit 0 {
#         family inet {
#             dhcp;
#         }
#     }
# }
# pp0 {
#     unit 0 {
#         pppoe-options {
#             idle-timeout 100;
#             access-concentrator ispl.com;
#             service-name "[email protected]";
#             auto-reconnect 100;
#             client;
#             ## Warning: missing mandatory statement(s): 'underlying-interface'
#         }
#     }
# }
#
- name: Gather junos interfaces as in given arguments
  junipernetworks.junos.junos_interfaces:
    state: gathered
# Task Output (redacted)
# -----------------------
#
# "gathered": [
#         {
#             "description": "test gre interface",
#             "enabled": true,
#             "name": "gr-0/0/0"
#         },
#         {
#             "enabled": true,
#             "name": "fxp0"
#         },
#         {
#             "enabled": true,
#             "name": "pp0"
#         }
#     ]
# After state:
# ------------
#
# [email protected]# show interfaces
# gr-0/0/0 {
#     description "test gre interface";
# }
# fxp0 {
#     unit 0 {
#         family inet {
#             dhcp;
#         }
#     }
# }
# pp0 {
#     unit 0 {
#         pppoe-options {
#             idle-timeout 100;
#             access-concentrator ispl.com;
#             service-name "[email protected]";
#             auto-reconnect 100;
#             client;
#             ## Warning: missing mandatory statement(s): 'underlying-interface'
#         }
#     }
# }
# 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-0/0/1</name>
#                 <description>Configured by Ansible</description>
#                 <disable/>
#                 <speed>100m</speed>
#                 <mtu>1024</mtu>
#                 <hold-time>
#                     <up>2000</up>
#                     <down>2200</down>
#                 </hold-time>
#                 <link-mode>full-duplex</link-mode>
#                 <unit>
#                     <name>0</name>
#                     <family>
#                         <ethernet-switching>
#                             <interface-mode>access</interface-mode>
#                             <vlan>
#                                 <members>vlan100</members>
#                             </vlan>
#                         </ethernet-switching>
#                     </family>
#                 </unit>
#             </interface>
#         </interfaces>
#     </configuration>
# </rpc-reply>
# - name: Convert interfaces config to argspec without connecting to the appliance
#   junipernetworks.junos.junos_interfaces:
#     running_config: "{{ lookup('file', './parsed.cfg') }}"
#     state: parsed
# Task Output (redacted)
# -----------------------
# "parsed": [
#         {
#             "description": "Configured by Ansible",
#             "duplex": "full-duplex",
#             "enabled": false,
#             "hold_time": {
#                 "down": 2200,
#                 "up": 2000
#             },
#             "mtu": 1024,
#             "name": "ge-0/0/1",
#             "speed": "100m"
#         }
#     ]
#
# Using rendered
- name: Render platform specific xml from task input using rendered state
  junipernetworks.junos.junos_interfaces:
    config:
    - name: ge-0/0/2
      description: Configured by Ansibull
      mtu: 2048
      speed: 20m
      hold_time:
        up: 3200
        down: 3200
    state: rendered
# Task Output (redacted)
# -----------------------
# "rendered": <nc:interfaces
#     xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
#     <nc:interface>
#         <nc:name>ge-0/0/2</nc:name>
#         <nc:description>Configured by Ansibull</nc:description>
#         <nc:speed>20m</nc:speed>
#         <nc:mtu>2048</nc:mtu>
#         <nc:hold-time>
#             <nc:up>3200</nc:up>
#             <nc:down>3200</nc:down>
#         </nc:hold-time>
#     </nc:interface>
# </nc:interfaces>"

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
after
list / elements=string
when changed
The configuration as structured data after module completion.

Sample:
The configuration returned will always be in the same format of the parameters above.
before
list / elements=string
always
The configuration as structured data prior to module invocation.

Sample:
The configuration returned will always be in the same format of the parameters above.
xml
list / elements=string
always
The set of xml rpc payload pushed to the remote device.

Sample:
['<?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-0/0/1</name> <description>Configured by Ansible</description> <disable/> <speed>100m</speed> <mtu>1024</mtu> <hold-time> <up>2000</up> <down>2200</down> </hold-time> <link-mode>full-duplex</link-mode> <unit> <name>0</name> <family> <ethernet-switching> <interface-mode>access</interface-mode> <vlan> <members>vlan100</members> </vlan> </ethernet-switching> </family> </unit> </interface> </interfaces> </configuration> </rpc-reply>', 'xml 2', 'xml 3']


Authors

  • Ganesh Nalawade (@ganeshrn)