amnesh.soodar.soodar_l3_interfaces module – Manage Layer-3 interface on Amnesh Soodar 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_l3_interfaces.

New in amnesh.soodar 1.0

Synopsis

  • This module provides declarative management of Layer-3 interface on Amnesh Soodar devices.

Note

This module has a corresponding action plugin.

Parameters

Parameter

Comments

config

list / elements=dictionary

A dictionary of Layer-3 interface options

ipv4

list / elements=dictionary

IPv4 address to be set for the Layer-3 interface mentioned in name option. The address format is <ipv4 address>/<mask>, the mask is number in range 0-32 eg. 192.168.0.1/24

address

string

Configures the IPv4 address for Interface.

name

string / required

Full name of the interface e.g. ge0.

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 | section ^interface executed on device. For state parsed active connection to remote host is not required.

Choices:

  • "merged" ← (default)

  • "replaced"

  • "overridden"

  • "deleted"

  • "rendered"

  • "gathered"

  • "parsed"

Examples

# Using Deleted

# Before state:
# -------------
#
# soodar#show running-config | section ^interface
# interface ge1
#  ip address 192.0.2.10/24
#  shutdown
# interface ge2
#  description Configured by Ansible Network
#  ip address 192.168.1.1/24
#  no shutdown
# interface ge3
#  description Configured by Ansible Network
#  ip address 192.168.0.1/24
#  shutdown
#  ipv6 address fd5d:12c9:2201:1::1/64
# interface ge3.100
#  encapsulation dot1q 20
#  ip address 192.168.0.2/24
#  no shutdown

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

# After state:
# -------------
#
# soodar#show running-config | section ^interface
# interface ge1
#  no ip address
#  shutdown
# interface ge2
#  description Configured by Ansible Network
#  no ip address
#  no shutdown
# interface ge3
#  description Configured by Ansible Network
#  no ip address
#  shutdown
# interface ge3.100
#  encapsulation dot1q 20
#  no shutdown


# Using merged

# Before state:
# -------------
#
# soodar#show running-config | section ^interface
# interface ge1
#  description Configured by Ansible
#  ip address 10.1.1.1/24
# interface ge2
#  description This is test
#  no ip address
# interface ge3
#  description Configured by Ansible Network
#  no ip address
# interface ge3.100
#  encapsulation dot1q 20

- name: Merge provided configuration with device configuration
  soodar_interfaces:
    config:
      - name: ge1
        ipv4:
        - address: 192.168.0.1/24
      - name: ge2
        ipv4:
        - address: 192.168.0.2/24
      - name: ge3
        ipv6:
        - address: fd5d:12c9:2201:1::1/64
      - name: ge3.100
        ipv4:
        - address: 192.168.0.3/24
    operation: merged

# After state:
# ------------
#
# soodar#show running-config | section ^interface
# interface ge1
#  description Configured by Ansible
#  ip address 10.1.1.1/24
#  no shutdown
# interface ge2
#  description This is test
#  ip address 192.168.0.2/24
#  no shutdown
# interface ge3
#  description Configured by Ansible Network
#  ipv6 address fd5d:12c9:2201:1::1/64
# interface ge3.100
#  encapsulation dot1q 20
#  ip address 192.168.0.3/24
#  no shutdown


# Using overridden

# Before state:
# -------------
#
# soodar#show running-config | section ^interface
# interface ge1
#  description Configured by Ansible
#  ip address 10.1.1.1/24
#  no shutdown
# interface ge2
#  description This is test
#  ip address 192.168.2.1/24
#  no shutdown
# interface ge3
#  description Configured by Ansible Network
#  ipv6 address FD5D:12C9:2201:1::1/64
#  no shutdown
# interface ge3.100
#  encapsulation dot1q 20
#  ip address 192.168.0.2/24
#  no shutdown

- name: Override device configuration of all interfaces with provided configuration
  soodar_interfaces:
    config:
      - name: ge2
        ipv4:
        - address: 192.168.0.1/24
    operation: overridden

# After state:
# ------------
#
# soodar#show running-config | section ^interface
# interface ge1
#  description Configured by Ansible
#  no ip address
#  no shutdown
# interface ge2
#  description This is test
#  ip address 192.168.0.1/24
#  no shutdown
# interface ge3
#  description Configured by Ansible Network
#  ipv6 address FD5D:12C9:2201:1::1/64
#  no shutdown
# interface ge3.100
#  encapsulation dot1q 20
#  ip address 192.168.0.2/24
#  no shutdown


# Using replaced

# Before state:
# -------------
#
# soodar#show running-config | section ^interface
# interface ge1
#  description Configured by Ansible
#  ip address 10.1.1.1/24
#  no shutdown

# interface ge2
#  description This is test
#  no ip address
# interface ge3
#  description Configured by Ansible Network
#  ip address 192.168.2.0/24
#  no shutdown
# interface ge3.100
#  encapsulation dot1Q 20
#  ip address 192.168.0.2/24
#  no shutdown

- name: Replaces device configuration of listed interfaces with provided configuration
  soodar_interfaces:
    config:
      - name: ge2
        ipv4:
        - address: 192.168.2.0/24
      - name: ge3.100
        ipv4:
        - address: 192.168.0.3/24
    operation: replaced

# After state:
# ------------
#
# soodar#show running-config | section ^interface
# interface ge1
#  description Configured by Ansible
#  ip address 10.1.1.1/24
#  no shutdown
# interface ge2
#  description This is test
#  ip address 192.168.2.1/24
#  no shutdown
# interface ge3
#  description Configured by Ansible Network
#  ip address 192.168.2.0/24
#  no shutdown
# interface ge3.100
#  encapsulation dot1q 20
#  ip address 192.168.0.2/24
#  ip address 192.168.0.3/24


# Using Gathered

# Before state:
# -------------
#
# soodar# sh running-config | section ^interface
# interface ge1
#  ip address 203.0.113.27/24
# interface ge2
#  ip address 192.0.2.1/24
#  ip address 192.0.2.2/24
#  ipv6 address 2001:DB8:0:3::/64

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

# Module Execution Result:
# ------------------------
#
# "gathered": [
#         {
#             "ipv4": [
#                 {
#                     "address": "203.0.113.27/24"
#                 }
#             ],
#             "name": "ge1"
#         },
#         {
#             "ipv4": [
#                 {
#                     "address": "192.0.2.1/24",
#                 },
#                 {
#                     "address": "192.0.2.2/24"
#                 }
#             ],
#             "ipv6": [
#                 {
#                     "address": "2001:db8:0:3::/64"
#                 }
#             ],
#             "name": "ge2"
#         }
#     ]


# Using Rendered

- name: Render the commands for provided  configuration
  amnesh.soodar.soodar_l3_interfaces:
    config:
    - name: ge2
      ipv4:
      - address: 198.51.100.1/24
      - address: 198.51.100.2/24
      ipv6:
      - address: 2001:db8:0:3::/64
    state: rendered

# Module Execution Result:
# ------------------------
#
# "rendered": [
#         "interface ge2",
#         "ip address 198.51.100.1/24",
#         "ip address 198.51.100.2/24",
#         "ipv6 address 2001:db8:0:3::/64"
#     ]


# Using Parsed

# File: parsed.cfg
# ----------------
#
# interface ge2
# ip address 198.51.100.1/24
# secondary ip address 198.51.100.2/24
# ipv6 address 2001:db8:0:3::/64

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

# Module Execution Result:
# ------------------------
#
# "parsed": [
#         {
#             "ipv4": [
#                 {
#                     "address": "198.51.100.1/24",
#                     "secondary": true
#                 },
#                 {
#                     "address": "198.51.100.2/24"
#                 }
#             ],
#             "ipv6": [
#                 {
#                     "address": "2001:db8:0:3::/64"
#                 }
#             ],
#             "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 ge1", "ip address 192.168.0.2/24"]

Authors

  • Mahdi Varasteh (@m-varasteh)