amnesh.soodar.soodar_interfaces module – Manages interface attributes of Amnesh Soodar network devices

Note

This module is part of the amnesh.soodar collection (version 1.0.0).

To install it, use: ansible-galaxy collection install https://soodar.ir/ansible/amnesh.soodar.tar.gz.

To use it in a playbook, specify: amnesh.soodar.soodar_interfaces.

New in amnesh.soodar 1.0

Synopsis

  • This module manages the interface attributes of Amnesh Soodar network devices.

Note

This module has a corresponding action plugin.

Parameters

Parameter

Comments

config

list / elements=dictionary

A dictionary of interface options

description

string

Interface description.

enabled

boolean

Administrative state of the interface.

Set the value to true to administratively enable the interface or false to disable it.

Choices:

  • false

  • true ← (default)

mtu

string

MTU for a specific interface. Must be a number between 64 and 9600. Applicable for Ethernet interfaces only.

name

string / required

Full name of interface, e.g. ge0, tunnel20.

running_config

string

This option is used only with state parsed.

The value of this option should be the output received from the Soodar device by executing the command show running-config | section ^interface.

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

The state the configuration should be left in

The states rendered, gathered and parsed does not perform any change on the device.

The state rendered will transform the configuration in config option to platform specific CLI commands which will be returned in the rendered key within the result. For state rendered active connection to remote host is not required.

The state gathered will fetch the running configuration from device and transform it into structured data in the format as per the resource module argspec and the value is returned in the gathered key within the result.

The state parsed reads the configuration from running_config option and transforms it into JSON format as per the resource module parameters and the value is returned in the parsed key within the result. The value of running_config option should be the same format as the output of command show running-config | include ip route|ipv6 route executed on device. For state parsed active connection to remote host is not required.

Choices:

  • "merged" ← (default)

  • "replaced"

  • "overridden"

  • "deleted"

  • "rendered"

  • "gathered"

  • "parsed"

Notes

Note

  • Tested against Soodar Version 21.04

Examples

# Using Deleted

# Before state:
# -------------
#
# soodar# show running-config | section ^interface
# interface ge1
#  no ip address
# interface ge2
#  description Configured and Overridden by Ansible Network
#  no ip address
# interface ge3
#  description Configured and Replaced by Ansible Network
#  mtu 2500
#  no ip address
#  shutdown

- name: Delete attributes of given interfaces (Note: This won't delete the interface itself)
  soodar_interfaces:
    config:
      - name: ge2
      - name: ge3
    operation: deleted

# After state:
# -------------
#
# soodar# show running-config | section ^interface
# interface ge1
#  no ip address
# interface ge2
#  no ip address
# interface ge3
#  no ip address


# Using merged

# Before state:
# -------------
#
# soodar#show running-config | section ^interface
# interface ge1
#  description Configured by Ansible
#  no ip address
# interface ge2
#  description This is test
#  no ip address
# interface ge3
#  no ip address

- name: Merge provided configuration with device configuration
  soodar_interfaces:
    config:
      - name: ge2
        description: 'Configured and Merged by Ansible Network'
        enabled: True
      - name: ge3
        description: 'Configured and Merged by Ansible Network'
        mtu: 2800
        enabled: False
    operation: merged

# After state:
# ------------
#
# soodar#show running-config | section ^interface
# interface ge1
#  description Configured by Ansible
#  no ip address
# interface ge2
#  description Configured and Merged by Ansible Network
#  no ip address
#  no shutdown
# interface ge3
#  description Configured and Merged by Ansible Network
#  mtu 2800
#  no ip address
#  shutdown


# Using overridden

# Before state:
# -------------
#
# soodar#show running-config | section ^interface#
# interface ge1
#  description Configured by Ansible
#  no ip address
# interface ge2
#  description This is test
#  no ip address
# interface ge3
#  description Configured by Ansible
#  mtu 2800
#  no ip address
#  shutdown

- name: Override device configuration of all interfaces with provided configuration
  soodar_interfaces:
    config:
      - name: ge2
        description: 'Configured and Overridden by Ansible Network'
        mtu: 3000
      - name: ge3
        description: 'Configured and Overridden by Ansible Network'
        enabled: False
        mtu: 2000
    operation: overridden

# After state:
# -------------
#
# soodar#show running-config | section ^interface
# interface ge1
#  no ip address
# interface ge2
#  description Configured and Overridden by Ansible Network
#  no ip address
#  mtu 3000
# interface ge3
#  description Configured and Overridden by Ansible Network
#  mtu 2000
#  no ip address
#  shutdown


# Using replaced

# Before state:
# -------------
#
# soodar#show running-config | section ^interface
# interface ge1
#  no ip address
# interface ge2
#  description Configured by Ansible Network
#  no ip address
# interface ge3
#  mtu 2000
#  no ip address
#  shutdown

- name: Replaces device configuration of listed interfaces with provided configuration
  soodar_interfaces:
    config:
      - name: ge3
        description: 'Configured and Replaced by Ansible Network'
        enabled: False
        mtu: 2500
    operation: replaced

# After state:
# -------------
#
# soodar#show running-config | section ^interface
# interface ge1
#  no ip address
# interface ge2
#  description Configured by Ansible Network
#  no ip address
# interface ge3
#  description Configured and Replaced by Ansible Network
#  mtu 2500
#  no ip address
#  shutdown


# Using Gathered

# Before state:
# -------------
#
# soodar# sh running-config | section ^interface
# interface ge1
#  no shutdown
#  description this is interface1
#  mtu 65
# interface ge2
#  description this is interface2
#  mtu 110
#  shutdown

- name: Gather listed interfaces with provided configurations
  amnesh.soodar.soodar_interfaces:
    config:
    state: gathered

# Module Execution Result:
# ------------------------
#
# "gathered": [
#         {
#             "description": "this is interface1",
#             "enabled": true,
#             "mtu": 65,
#             "name": "ge1",
#         },
#         {
#             "description": "this is interface2",
#             "duplex": "auto",
#             "enabled": false,
#             "mtu": 110,
#         }
#     ]

# After state:
# ------------
#
# soodar# sh running-config | section ^interface
# interface ge1
#  no shutdown
#  description this is interface1
#  mtu 65
# interface ge2
#  description this is interface2
#  mtu 110
#  shutdown


# Using Rendered

- name: Render the commands for provided  configuration
  amnesh.soodar.soodar_interfaces:
    config:
    - name: ge1
      description: Configured by Ansible-Network
      mtu: 110
      enabled: true
    - name: ge2
      description: Configured by Ansible-Network
      mtu: 2800
      enabled: false
    state: rendered

# Module Execution Result:
# ------------------------
#
# "rendered": [
#         "interface ge1",
#         "description Configured by Ansible-Network",
#         "mtu 110",
#         "no shutdown",
#         "interface ge2",
#         "description Configured by Ansible-Network",
#         "mtu 2800",
#         "shutdown"


# Using Parsed

# File: parsed.cfg
# ----------------
#
# interface ge1
# description interfaces 0/1
# mtu 110
# no shutdown
# interface ge2
# description interfaces 0/2
# mtu 2800
# shutdown

- name: Parse the commands for provided configuration
  amnesh.soodar.soodar_interfaces:
    running_config: "{{ lookup('file', 'parsed.cfg') }}"
    state: parsed

# Module Execution Result:
# ------------------------
#
# "parsed": [
#         {
#             "description": "interfaces 0/1",
#             "enabled": true,
#             "mtu": 110,
#             "name": "ge1"
#         },
#         {
#             "description": "interfaces 0/2",
#             "enabled": true,
#             "mtu": 2800,
#             "name": "ge2",
#         }
#     ]

Return Values

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

Key

Description

after

list / elements=string

The configuration as structured data after module completion.

Returned: when changed

Sample: ["The configuration returned will always be in the same format of the parameters above."]

before

list / elements=string

The configuration as structured data prior to module invocation.

Returned: always

Sample: ["The configuration returned will always be in the same format of the parameters above."]

commands

list / elements=string

The set of commands pushed to the remote device

Returned: always

Sample: ["interface ge0", "description This is test", "mtu 1500"]

Authors

  • Mahdi Varasteh (@m-varasteh)