amnesh.soodar.soodar_l3_interfaces module – Resource module to configure L3 interfaces.

Note

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

It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

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.

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.

dhcp

dictionary

IP Address negotiated via DHCP.

enable

boolean

Enable dhcp.

Choices:

  • false

  • true

mtu

integer

Set IP Maximum Transmission Unit.

proxy_arp

boolean

Enable proxy_arp.

Choices:

  • false

  • true

ipv6

list / elements=dictionary

IPv6 address to be set for the Layer-3 interface mentioned in name option.

The address format is <ipv6 address>/<mask>, the mask is number in range 0-128 eg. fd5d:12c9:2201:1::1/64

address

string

Configures the IPv6 address for Interface.

enable

boolean

Enable IPv6 on interface

Choices:

  • false

  • true

eui

boolean

Use eui-64 interface identifier

Choices:

  • false

  • true

mac_address

string

Manually set interface MAC address.

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"

Notes

Note

  • Tested against Soodar Version 23.11

  • This module works with connection amnesh.soodar.network_cli.

  • The module examples uses callback plugin (stdout_callback = yaml) to generate task output in yaml format.

Examples

# Using merged

# Before state:
# -------------
#
# Router# show running-config | section ^interface
# interface loopback999
#  no ip address
#  shutdown
# interface ge1
#  description Management interface do not change
#  ip address dhcp
# interface ge2
#  ip address dhcp
#  shutdown
#  speed 1000
# interface ge3
#  description Configured and Overridden by Ansible Network
#  no ip address
#  shutdown
#  speed 1000
# interface ge4
#  no ip address
#  shutdown


- name: Merge provided configuration with device configuration
  amnesh.soodar.soodar_l3_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
    state: merged

# Task Output
# -----------
#
# before:
# - ipv4:
#   - dhcp:
#       enable: true
#   name: ge1
# - ipv4:
#   - dhcp:
#       enable: true
#   name: ge2
# - name: ge3
# - name: ge4
# - name: loopback999
# commands:
# - interface ge2
# - ip address 192.168.0.2/24
# - interface ge3
# - ipv6 address fd5d:12c9:2201:1::1/64
# - interface ge3.100
# - ip address 192.168.0.3/24
# after:
# - ipv4:
#   - dhcp:
#       enable: true
#   name: ge1
# - ipv4:
#   - address: 192.168.0.2/24
#   name: ge2
# - ipv6:
#   - address: FD5D:12C9:2201:1::1/64
#   name: ge3
# - name: ge3.100
#   ipv4:
#   - address: 192.168.0.3/24
# - name: ge4
# - name: loopback999

# After state:
# ------------
#
# Router# show running-config | section ^interface
# interface loopback999
#  no ip address
#  shutdown
# interface ge1
#  description Management interface do not change
#  ip address dhcp
# interface ge2
#  ip address 192.168.0.2/24
#  shutdown
#  speed 1000
# interface ge3
#  description Configured and Overridden by Ansible Network
#  no ip address
#  shutdown
#  speed 1000
#  ipv6 address FD5D:12C9:2201:1::1/64
# interface ge3.100
#  ip address 192.168.0.3/24
# interface ge4
#  no ip address
#  shutdown

# Using replaced

# Before state:
# -------------
#
# Router# show running-config | section ^interface
# interface loopback999
#  no ip address
#  shutdown
# interface ge1
#  description Management interface do not change
#  ip address dhcp
# interface ge2
#  ip address 192.168.0.2/24
#  shutdown
#  speed 1000
# interface ge3
#  description Configured and Overridden by Ansible Network
#  no ip address
#  shutdown
#  speed 1000
#  ipv6 address FD5D:12C9:2201:1::1/64
# interface ge3.100
# interface ge4
#  no ip address
#  shutdown

- name: Replaces device configuration of listed interfaces with provided configuration
  amnesh.soodar.soodar_l3_interfaces:
    config:
      - name: ge2
        ipv4:
          - address: 192.168.2.0/24
      - name: ge3
        ipv4:
          - dhcp:
              enable: true
    state: replaced

# Task Output
# -----------
#
# before:
# - ipv4:
#   - dhcp:
#       enable: true
#   name: ge1
# - ipv4:
#   - address: 192.168.0.2/24
#   name: ge2
# - ipv6:
#   - address: FD5D:12C9:2201:1::1/64
#   name: ge3
# - name: ge3.100
# - name: ge4
# - name: loopback999
# commands:
# - interface ge2
# - ip address 192.168.0.3/24
# - no ip address 192.168.0.2/24
# - interface ge3
# - ip address dhcp
# - no ipv6 address fd5d:12c9:2201:1::1/64
# after:
# - ipv4:
#   - dhcp:
#       enable: true
#   name: ge1
# - ipv4:
#   - address: 192.168.0.3/24
#   name: ge2
# - ipv4:
#   - dhcp:
#       enable: true
#   name: ge3
# - name: ge3.100
# - name: ge4
# - name: loopback999

# After state:
# ------------
#
# Router# show running-config | section ^interface
# interface loopback999
#  no ip address
#  shutdown
# interface ge1
#  description Management interface do not change
#  ip address dhcp
# interface ge2
#  ip address 192.168.0.3/24
#  shutdown
#  speed 1000
# interface ge3
#  description Configured and Overridden by Ansible Network
#  ip address dhcp
#  shutdown
#  speed 1000
# interface ge3.100
# interface ge4
#  no ip address
#  shutdown


# Using overridden

# Before state:
# -------------
#
# Router# show running-config | section ^interface
# interface loopback999
#  no ip address
#  shutdown
# interface ge1
#  description Management interface do not change
#  ip address dhcp
# interface ge2
#  ip address 192.168.0.3/24
#  shutdown
#  speed 1000
# interface ge3
#  description Configured and Overridden by Ansible Network
#  ip address dhcp
#  shutdown
#  speed 1000
# interface ge3.100
# interface ge4
#  no ip address
#  shutdown

- name: Override device configuration of all interfaces with provided configuration
  amnesh.soodar.soodar_l3_interfaces:
    config:
      - ipv4:
          - dhcp:
              enable: true
        name: ge1
      - name: ge2
        ipv4:
          - address: 192.168.0.1/24
      - name: ge3
    state: overridden

# Task Output
# -----------
# before:
# - ipv4:
#   - dhcp:
#       enable: true
#   name: ge1
# - ipv4:
#   - address: 192.168.0.3/24
#   name: ge2
# - ipv4:
#   - dhcp:
#       client_id: ge2
#       enable: true
#   name: ge3
# - name: ge3.100
# - name: ge4
# - name: loopback999
# commands:
# - interface ge2
# - ip address 192.168.0.1/24
# - no ip address 192.168.0.3/24
# - interface ge3
# - no ip address dhcp
# after:
# - ipv4:
#   - dhcp:
#       enable: true
#   name: ge1
# - ipv4:
#   - address: 192.168.0.1/24
#   name: ge2
# - name: ge3
# - name: ge3.100
# - name: ge4
# - name: loopback999

# After state:
# ------------
#
# Router# show running-config | section ^interface
# interface loopback999
#  no ip address
#  shutdown
# interface ge1
#  description Management interface do not change
#  ip address dhcp
# interface ge2
#  ip address 192.168.0.1/24
#  shutdown
#  speed 1000
# interface ge3
#  description Configured and Overridden by Ansible Network
#  no ip address
#  shutdown
#  speed 1000
# interface ge3.100
# interface ge4
#  no ip address
#  shutdown


# Using deleted

# Before state:
# -------------
#
# Router# show running-config | section ^interface
# interface loopback999
#  no ip address
#  shutdown
# interface ge1
#  description Management interface do not change
#  ip address dhcp
# interface ge2
#  ip address 192.168.0.1/24
#  shutdown
#  speed 1000
# interface ge3
#  description Configured and Overridden by Ansible Network
#  no ip address
#  shutdown
#  speed 1000
# interface ge3.100
# interface ge4
#  no ip address
#  shutdown

- name: "Delete attributes of given interfaces (NOTE: This won't delete the interfaces)"
  amnesh.soodar.soodar_l3_interfaces:
    config:
      - name: ge2
      - name: ge3.100
    state: deleted

# Task Output
# -----------
#
# before:
# - ipv4:
#   - dhcp:
#       enable: true
#   name: ge1
# - ipv4:
#   - address: 192.168.0.1/24
#   name: ge2
# - name: ge3
# - name: ge3.100
# - name: ge4
# - name: loopback999
# commands:
# - interface ge2
# - no ip address 192.168.0.1/24
# after:
# - ipv4:
#   - dhcp:
#       enable: true
#   name: ge1
# - name: ge2
# - name: ge3
# - name: ge3.100
# - name: ge4
# - name: loopback999

# After state:
# -------------
#
# Router# show running-config | section ^interface
# interface loopback999
#  no ip address
#  shutdown
# interface ge1
#  description Management interface do not change
#  ip address dhcp
# interface ge2
#  no ip address
#  shutdown
#  speed 1000
# interface ge3
#  description Configured and Overridden by Ansible Network
#  no ip address
#  shutdown
#  speed 1000
# interface ge3.100
# interface ge4
#  no ip address
#  shutdown

# Using deleted without config passed, only interface's configuration will be negated

# Before state:
# -------------

# Router# show running-config | section ^interface
# interface loopback999
#  no ip address
#  shutdown
# interface ge1
#  description Management interface do not change
#  ip address dhcp
# interface ge2
#  ip address 192.168.0.2/24
#  shutdown
#  speed 1000
# interface ge3
#  description Configured and Overridden by Ansible Network
#  no ip address
#  shutdown
#  speed 1000
#  ipv6 address FD5D:12C9:2201:1::1/64
# interface ge3.100
# interface ge4
#  no ip address
#  shutdown

- name: "Delete L3 config of all interfaces"
  amnesh.soodar.soodar_l3_interfaces:
    state: deleted

# Task Output
# -----------
#
# before:
# - ipv4:
#   - dhcp:
#       enable: true
#   name: ge1
# - ipv4:
#   - address: 192.168.0.2/24
#   name: ge2
# - ipv6:
#   - address: FD5D:12C9:2201:1::1/64
#   name: ge3
# - name: ge3.100
# - name: ge4
# - name: loopback999
# commands:
# - interface ge1
# - no ip address dhcp
# - interface ge2
# - no ip address 192.168.0.2/24
# - interface ge3
# - no ipv6 address fd5d:12c9:2201:1::1/64
# after:
# - name: ge1
# - name: ge2
# - name: ge3
# - name: ge3.100
# - name: ge4
# - name: loopback999

# After state:
# -------------
#
# interface loopback999
#  no ip address
#  shutdown
# interface ge1
#  description Management interface do not change
# interface ge2
#  shutdown
#  speed 1000
# interface ge3
#  description Configured and Overridden by Ansible Network
#  no ip address
#  shutdown
#  speed 1000
# interface ge3.100
# interface ge4
#  no ip address
#  shutdown


# Using gathered

# Before state:
# -------------
#
# Router# show running-config | section ^interface
# interface loopback999
#  no ip address
#  shutdown
# interface ge1
#  description Management interface do not change
#  ip address dhcp
# interface ge2
#  ip address 192.168.0.3/24
#  shutdown
#  speed 1000
# interface ge3
#  description Configured and Overridden by Ansible Network
#  ip address dhcp
#  shutdown
#  speed 1000
# interface ge3.100
# interface ge4
#  no ip address
#  shutdown

- name: Gather facts for l3 interfaces
  amnesh.soodar.soodar_l3_interfaces:
    state: gathered

# Task Output
# -----------
#
# gathered:
# - ipv4:
#   - dhcp:
#       enable: true
#   name: ge1
# - ipv4:
#   - address: 192.168.0.3/24
#   name: ge2
# - ipv4:
#   - dhcp:
#       enable: true
#   name: ge3
# - name: ge3.100
# - name: ge4
# - name: loopback999

# Using rendered

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

# Task Output
# -----------
#
# rendered:
# - interface ge1
# - ip address dhcp
# - interface ge2
# - ip address 198.51.100.1/24 secondary
# - ip address 198.51.100.2/24
# - ipv6 address 2001:db8:0:3::/64

# Using parsed

# File: parsed.cfg
# ----------------
#
# interface ge0
#  ip address dhcp
# interface ge1
#  ip address 198.51.100.1/24
#  ipv6 address 2001:db8:0:3::/64

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

# Task Output
# -----------
#
# parsed:
# - ipv4:
#   - dhcp:
#       enable: true
#   name: ge0
# - ipv4:
#   - address: 198.51.100.2/24
#   ipv6:
#   - address: 2001:db8:0:3::/64
#   name: ge1

Return Values

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

Key

Description

after

dictionary

The resulting configuration after module execution.

Returned: when changed

Sample: "This output will always be in the same format as the module argspec.\n"

before

dictionary

The configuration prior to the module execution.

Returned: when state is merged, replaced, overridden, deleted or purged

Sample: "This output will always be in the same format as the module argspec.\n"

commands

list / elements=string

The set of commands pushed to the remote device.

Returned: when state is merged, replaced, overridden, deleted or purged

Sample: ["sample command 1", "sample command 2", "sample command 3"]

gathered

list / elements=string

Facts about the network resource gathered from the remote device as structured data.

Returned: when state is gathered

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

parsed

list / elements=string

The device native config provided in running_config option parsed into structured data as per module argspec.

Returned: when state is parsed

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

rendered

list / elements=string

The provided configuration in the task rendered in device-native format (offline).

Returned: when state is rendered

Sample: ["sample command 1", "sample command 2", "sample command 3"]

Authors

  • Sagar Paul (@KB-perByte)

  • Sumit Jaiswal (@justjais)

  • Mahdi Varasteh (@m-varasteh)