summaryrefslogtreecommitdiff
path: root/plugins/modules
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/modules')
-rw-r--r--plugins/modules/vyos_banner.py5
-rw-r--r--plugins/modules/vyos_command.py5
-rw-r--r--plugins/modules/vyos_config.py3
-rw-r--r--plugins/modules/vyos_facts.py4
-rw-r--r--plugins/modules/vyos_interface.py554
-rw-r--r--plugins/modules/vyos_l3_interface.py357
-rw-r--r--plugins/modules/vyos_linkagg.py363
-rw-r--r--plugins/modules/vyos_lldp.py143
-rw-r--r--plugins/modules/vyos_lldp_interface.py280
-rw-r--r--plugins/modules/vyos_logging.py4
-rw-r--r--plugins/modules/vyos_ping.py5
-rw-r--r--plugins/modules/vyos_static_route.py335
-rw-r--r--plugins/modules/vyos_system.py5
-rw-r--r--plugins/modules/vyos_user.py20
-rw-r--r--plugins/modules/vyos_vlan.py4
15 files changed, 6 insertions, 2081 deletions
diff --git a/plugins/modules/vyos_banner.py b/plugins/modules/vyos_banner.py
index 07b5a28..a5f3fb9 100644
--- a/plugins/modules/vyos_banner.py
+++ b/plugins/modules/vyos_banner.py
@@ -95,9 +95,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import
get_config,
load_config,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- vyos_argument_spec,
-)
def spec_to_commands(updates, module):
@@ -164,8 +161,6 @@ def main():
state=dict(default="present", choices=["present", "absent"]),
)
- argument_spec.update(vyos_argument_spec)
-
required_if = [("state", "present", ("text",))]
module = AnsibleModule(
diff --git a/plugins/modules/vyos_command.py b/plugins/modules/vyos_command.py
index c0df9ce..d5ab918 100644
--- a/plugins/modules/vyos_command.py
+++ b/plugins/modules/vyos_command.py
@@ -154,9 +154,6 @@ from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.u
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
run_commands,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- vyos_argument_spec,
-)
def parse_commands(module, warnings):
@@ -183,8 +180,6 @@ def main():
interval=dict(default=1, type="int"),
)
- spec.update(vyos_argument_spec)
-
module = AnsibleModule(argument_spec=spec, supports_check_mode=True)
warnings = list()
diff --git a/plugins/modules/vyos_config.py b/plugins/modules/vyos_config.py
index 0142b8c..4b2b31d 100644
--- a/plugins/modules/vyos_config.py
+++ b/plugins/modules/vyos_config.py
@@ -203,7 +203,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import
run_commands,
)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- vyos_argument_spec,
get_connection,
)
@@ -340,8 +339,6 @@ def main():
save=dict(type="bool", default=False),
)
- argument_spec.update(vyos_argument_spec)
-
mutually_exclusive = [("lines", "src")]
module = AnsibleModule(
diff --git a/plugins/modules/vyos_facts.py b/plugins/modules/vyos_facts.py
index 9effee6..5e57821 100644
--- a/plugins/modules/vyos_facts.py
+++ b/plugins/modules/vyos_facts.py
@@ -146,9 +146,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts
Facts,
FACT_RESOURCE_SUBSETS,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- vyos_argument_spec,
-)
def main():
@@ -158,7 +155,6 @@ def main():
:returns: ansible_facts
"""
argument_spec = FactsArgs.argument_spec
- argument_spec.update(vyos_argument_spec)
module = AnsibleModule(
argument_spec=argument_spec, supports_check_mode=True
diff --git a/plugins/modules/vyos_interface.py b/plugins/modules/vyos_interface.py
deleted file mode 100644
index 04fd85d..0000000
--- a/plugins/modules/vyos_interface.py
+++ /dev/null
@@ -1,554 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-
-# (c) 2017, Ansible by Red Hat, inc
-#
-# This file is part of Ansible by Red Hat
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-
-from __future__ import absolute_import, division, print_function
-
-__metaclass__ = type
-
-DOCUMENTATION = """
-module: vyos_interface
-author: Ganesh Nalawade (@ganeshrn)
-short_description: (deprecated, removed after 2022-06-01) Manage Interface on VyOS
- network devices
-description:
-- This module provides declarative management of Interfaces on VyOS network devices.
-version_added: 1.0.0
-deprecated:
- alternative: vyos_interfaces
- why: Updated modules released with more functionality.
- removed_at_date: '2022-06-01'
-notes:
-- Tested against VYOS 1.1.7
-options:
- name:
- description:
- - Name of the Interface.
- type: str
- description:
- description:
- - Description of Interface.
- type: str
- enabled:
- description:
- - Interface link status.
- type: bool
- default: True
- speed:
- description:
- - Interface link speed.
- type: str
- mtu:
- description:
- - Maximum size of transmit packet.
- type: int
- duplex:
- description:
- - Interface link status.
- type: str
- choices:
- - full
- - half
- - auto
- delay:
- description:
- - Time in seconds to wait before checking for the operational state on remote
- device. This wait is applicable for operational state argument which are I(state)
- with values C(up)/C(down) and I(neighbors).
- default: 10
- type: int
- neighbors:
- description:
- - Check the operational state of given interface C(name) for LLDP neighbor.
- - The following suboptions are available.
- type: list
- elements: dict
- suboptions:
- host:
- description:
- - LLDP neighbor host for given interface C(name).
- type: str
- port:
- description:
- - LLDP neighbor port to which given interface C(name) is connected.
- type: str
- aggregate:
- description: List of Interfaces definitions.
- type: list
- elements: dict
- suboptions:
- name:
- description:
- - Name of the Interface.
- required: true
- type: str
- description:
- description:
- - Description of Interface.
- type: str
- enabled:
- description:
- - Interface link status.
- type: bool
- speed:
- description:
- - Interface link speed.
- type: str
- mtu:
- description:
- - Maximum size of transmit packet.
- type: int
- duplex:
- description:
- - Interface link status.
- type: str
- choices:
- - full
- - half
- - auto
- delay:
- description:
- - Time in seconds to wait before checking for the operational state on remote
- device. This wait is applicable for operational state argument which are I(state)
- with values C(up)/C(down) and I(neighbors).
- type: int
- neighbors:
- description:
- - Check the operational state of given interface C(name) for LLDP neighbor.
- - The following suboptions are available.
- type: list
- elements: dict
- suboptions:
- host:
- description:
- - LLDP neighbor host for given interface C(name).
- type: str
- port:
- description:
- - LLDP neighbor port to which given interface C(name) is connected.
- type: str
- state:
- description:
- - State of the Interface configuration, C(up) means present and operationally
- up and C(down) means present and operationally C(down)
- type: str
- choices:
- - present
- - absent
- - up
- - down
- state:
- description:
- - State of the Interface configuration, C(up) means present and operationally
- up and C(down) means present and operationally C(down)
- default: present
- type: str
- choices:
- - present
- - absent
- - up
- - down
-extends_documentation_fragment:
-- vyos.vyos.vyos
-
-
-"""
-
-EXAMPLES = """
-- name: configure interface
- vyos.vyos.vyos_interface:
- name: eth0
- description: test-interface
-
-- name: remove interface
- vyos.vyos.vyos_interface:
- name: eth0
- state: absent
-
-- name: make interface down
- vyos.vyos.vyos_interface:
- name: eth0
- enabled: false
-
-- name: make interface up
- vyos.vyos.vyos_interface:
- name: eth0
- enabled: true
-
-- name: Configure interface speed, mtu, duplex
- vyos.vyos.vyos_interface:
- name: eth5
- state: present
- speed: 100
- mtu: 256
- duplex: full
-
-- name: Set interface using aggregate
- vyos.vyos.vyos_interface:
- aggregate:
- - {name: eth1, description: test-interface-1, speed: 100, duplex: half, mtu: 512}
- - {name: eth2, description: test-interface-2, speed: 1000, duplex: full, mtu: 256}
-
-- name: Disable interface on aggregate
- net_interface:
- aggregate:
- - name: eth1
- - name: eth2
- enabled: false
-
-- name: Delete interface using aggregate
- net_interface:
- aggregate:
- - name: eth1
- - name: eth2
- state: absent
-
-- name: Check lldp neighbors intent arguments
- vyos.vyos.vyos_interface:
- name: eth0
- neighbors:
- - port: eth0
- host: netdev
-
-- name: Config + intent
- vyos.vyos.vyos_interface:
- name: eth1
- enabled: false
- state: down
-"""
-
-RETURN = """
-commands:
- description: The list of configuration mode commands to send to the device
- returned: always, except for the platforms that use Netconf transport to manage the device.
- type: list
- sample:
- - set interfaces ethernet eth0 description "test-interface"
- - set interfaces ethernet eth0 speed 100
- - set interfaces ethernet eth0 mtu 256
- - set interfaces ethernet eth0 duplex full
-"""
-import re
-
-from copy import deepcopy
-from time import sleep
-
-from ansible.module_utils._text import to_text
-from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.connection import exec_command
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
- conditional,
- remove_default_spec,
-)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- load_config,
- get_config,
-)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- vyos_argument_spec,
-)
-
-
-def search_obj_in_list(name, lst):
- for o in lst:
- if o["name"] == name:
- return o
-
- return None
-
-
-def map_obj_to_commands(updates):
- commands = list()
- want, have = updates
- params = ("speed", "description", "duplex", "mtu")
- for w in want:
- name = w["name"]
- disable = w["disable"]
- state = w["state"]
-
- obj_in_have = search_obj_in_list(name, have)
- set_interface = "set interfaces ethernet " + name
- delete_interface = "delete interfaces ethernet " + name
-
- if state == "absent" and obj_in_have:
- commands.append(delete_interface)
- elif state in ("present", "up", "down"):
- if obj_in_have:
- for item in params:
- value = w.get(item)
-
- if value and value != obj_in_have.get(item):
- if item == "description":
- value = "'" + str(value) + "'"
- commands.append(
- set_interface + " " + item + " " + str(value)
- )
-
- if disable and not obj_in_have.get("disable", False):
- commands.append(set_interface + " disable")
- elif not disable and obj_in_have.get("disable", False):
- commands.append(delete_interface + " disable")
- else:
- commands.append(set_interface)
- for item in params:
- value = w.get(item)
- if value:
- if item == "description":
- value = "'" + str(value) + "'"
- commands.append(
- set_interface + " " + item + " " + str(value)
- )
-
- if disable:
- commands.append(set_interface + " disable")
- return commands
-
-
-def map_config_to_obj(module):
- data = get_config(module, flags=["| grep interface"])
- obj = []
- for line in data.split("\n"):
- if line.startswith("set interfaces ethernet"):
- match = re.search(r"set interfaces ethernet (\S+)", line, re.M)
- name = match.group(1)
- if name:
- interface = {}
- for item in obj:
- if item["name"] == name:
- interface = item
- break
-
- if not interface:
- interface = {"name": name}
- obj.append(interface)
-
- match = re.search(r"%s (\S+)" % name, line, re.M)
- if match:
- param = match.group(1)
- if param == "description":
- match = re.search(r"description (.+)", line, re.M)
- description = match.group(1).strip("'")
- interface["description"] = description
- elif param == "speed":
- match = re.search(r"speed (\S+)", line, re.M)
- speed = match.group(1).strip("'")
- interface["speed"] = speed
- elif param == "mtu":
- match = re.search(r"mtu (\S+)", line, re.M)
- mtu = match.group(1).strip("'")
- interface["mtu"] = int(mtu)
- elif param == "duplex":
- match = re.search(r"duplex (\S+)", line, re.M)
- duplex = match.group(1).strip("'")
- interface["duplex"] = duplex
- elif param.strip("'") == "disable":
- interface["disable"] = True
-
- return obj
-
-
-def map_params_to_obj(module):
- obj = []
- aggregate = module.params.get("aggregate")
- if aggregate:
- for item in aggregate:
- for key in item:
- if item.get(key) is None:
- item[key] = module.params[key]
-
- d = item.copy()
- if d["enabled"]:
- d["disable"] = False
- else:
- d["disable"] = True
-
- obj.append(d)
- else:
- params = {
- "name": module.params["name"],
- "description": module.params["description"],
- "speed": module.params["speed"],
- "mtu": module.params["mtu"],
- "duplex": module.params["duplex"],
- "delay": module.params["delay"],
- "state": module.params["state"],
- "neighbors": module.params["neighbors"],
- }
-
- if module.params["enabled"]:
- params.update({"disable": False})
- else:
- params.update({"disable": True})
-
- obj.append(params)
- return obj
-
-
-def get_interfaces_data(module, name):
- command = "show interfaces ethernet %s" % name
- rc, out, err = exec_command(module, command)
- return [rc, out, err]
-
-
-def get_lldp_neighbor(module):
- command = "show lldp neighbors detail"
- rc, out, err = exec_command(module, command)
- return [rc, out, err]
-
-
-def check_declarative_intent_params(module, want, result):
- failed_conditions = []
- have_neighbors = None
- for w in want:
- want_state = w.get("state")
- want_neighbors = w.get("neighbors")
-
- if want_state not in ("up", "down") and not want_neighbors:
- continue
-
- if result["changed"]:
- sleep(w["delay"])
-
- command = "show interfaces ethernet %s" % w["name"]
- rc, out, err = get_interfaces_data(w["name"], module)
- if rc != 0:
- module.fail_json(
- msg=to_text(err, errors="surrogate_then_replace"),
- command=command,
- rc=rc,
- )
-
- if want_state in ("up", "down"):
- match = re.search(r"%s (\w+)" % "state", out, re.M)
- have_state = None
- if match:
- have_state = match.group(1)
- if have_state is None or not conditional(
- want_state, have_state.strip().lower()
- ):
- failed_conditions.append("state " + "eq(%s)" % want_state)
-
- if want_neighbors:
- have_host = []
- have_port = []
- if have_neighbors is None:
- rc, have_neighbors, err = get_lldp_neighbor(module)
- if rc != 0:
- module.fail_json(
- msg=to_text(err, errors="surrogate_then_replace"),
- command=command,
- rc=rc,
- )
-
- if have_neighbors:
- lines = have_neighbors.strip().split("Interface: ")
- for line in lines:
- field = line.split("\n")
- if field[0].split(",")[0].strip() == w["name"]:
- for item in field:
- if item.strip().startswith("SysName:"):
- have_host.append(item.split(":")[1].strip())
- if item.strip().startswith("PortDescr:"):
- have_port.append(item.split(":")[1].strip())
- for item in want_neighbors:
- host = item.get("host")
- port = item.get("port")
- if host and host not in have_host:
- failed_conditions.append("host " + host)
- if port and port not in have_port:
- failed_conditions.append("port " + port)
-
- return failed_conditions
-
-
-def main():
- """main entry point for module execution"""
- neighbors_spec = dict(host=dict(), port=dict())
-
- element_spec = dict(
- name=dict(),
- description=dict(),
- speed=dict(),
- mtu=dict(type="int"),
- duplex=dict(choices=["full", "half", "auto"]),
- enabled=dict(default=True, type="bool"),
- neighbors=dict(type="list", elements="dict", options=neighbors_spec),
- delay=dict(default=10, type="int"),
- state=dict(
- default="present", choices=["present", "absent", "up", "down"]
- ),
- )
-
- aggregate_spec = deepcopy(element_spec)
- aggregate_spec["name"] = dict(required=True)
-
- # remove default in aggregate spec, to handle common arguments
- remove_default_spec(aggregate_spec)
-
- argument_spec = dict(
- aggregate=dict(type="list", elements="dict", options=aggregate_spec),
- )
-
- argument_spec.update(element_spec)
- argument_spec.update(vyos_argument_spec)
-
- required_one_of = [["name", "aggregate"]]
- mutually_exclusive = [["name", "aggregate"]]
-
- required_together = [["speed", "duplex"]]
- module = AnsibleModule(
- argument_spec=argument_spec,
- required_one_of=required_one_of,
- mutually_exclusive=mutually_exclusive,
- required_together=required_together,
- supports_check_mode=True,
- )
-
- warnings = list()
-
- result = {"changed": False}
-
- if warnings:
- result["warnings"] = warnings
-
- want = map_params_to_obj(module)
- have = map_config_to_obj(module)
-
- commands = map_obj_to_commands((want, have))
- result["commands"] = commands
-
- if commands:
- commit = not module.check_mode
- diff = load_config(module, commands, commit=commit)
- if diff:
- if module._diff:
- result["diff"] = {"prepared": diff}
- result["changed"] = True
-
- failed_conditions = check_declarative_intent_params(module, want, result)
-
- if failed_conditions:
- msg = "One or more conditional statements have not been satisfied"
- module.fail_json(msg=msg, failed_conditions=failed_conditions)
- module.exit_json(**result)
-
-
-if __name__ == "__main__":
- main()
diff --git a/plugins/modules/vyos_l3_interface.py b/plugins/modules/vyos_l3_interface.py
deleted file mode 100644
index 214022a..0000000
--- a/plugins/modules/vyos_l3_interface.py
+++ /dev/null
@@ -1,357 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-
-# (c) 2017, Ansible by Red Hat, inc
-#
-# This file is part of Ansible by Red Hat
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-
-from __future__ import absolute_import, division, print_function
-
-__metaclass__ = type
-
-DOCUMENTATION = """
-module: vyos_l3_interface
-author: Ricardo Carrillo Cruz (@rcarrillocruz)
-short_description: (deprecated, removed after 2022-06-01) Manage L3 interfaces on
- VyOS network devices
-description:
-- This module provides declarative management of L3 interfaces on VyOS network devices.
-version_added: 1.0.0
-deprecated:
- alternative: vyos_l3_interfaces
- why: Updated modules released with more functionality.
- removed_at_date: '2022-06-01'
-notes:
-- Tested against VYOS 1.1.7
-options:
- name:
- description:
- - Name of the L3 interface.
- type: str
- ipv4:
- description:
- - IPv4 of the L3 interface.
- type: str
- ipv6:
- description:
- - IPv6 of the L3 interface.
- type: str
- aggregate:
- description: List of L3 interfaces definitions
- type: list
- elements: dict
- suboptions:
- name:
- description:
- - Name of the L3 interface.
- type: str
- required: True
- ipv4:
- description:
- - IPv4 of the L3 interface.
- type: str
- ipv6:
- description:
- - IPv6 of the L3 interface.
- type: str
- state:
- description:
- - State of the L3 interface configuration.
- type: str
- choices:
- - present
- - absent
- state:
- description:
- - State of the L3 interface configuration.
- default: present
- type: str
- choices:
- - present
- - absent
-extends_documentation_fragment:
-- vyos.vyos.vyos
-
-
-"""
-
-EXAMPLES = """
-- name: Set eth0 IPv4 address
- vyos.vyos.vyos_l3_interface:
- name: eth0
- ipv4: 192.168.0.1/24
-
-- name: Remove eth0 IPv4 address
- vyos.vyos.vyos_l3_interface:
- name: eth0
- state: absent
-
-- name: Set IP addresses on aggregate
- vyos.vyos.vyos_l3_interface:
- aggregate:
- - {name: eth1, ipv4: 192.168.2.10/24}
- - {name: eth2, ipv4: 192.168.3.10/24, ipv6: "fd5d:12c9:2201:1::1/64"}
-
-- name: Remove IP addresses on aggregate
- vyos.vyos.vyos_l3_interface:
- aggregate:
- - {name: eth1, ipv4: 192.168.2.10/24}
- - {name: eth2, ipv4: 192.168.3.10/24, ipv6: "fd5d:12c9:2201:1::1/64"}
- state: absent
-"""
-
-RETURN = """
-commands:
- description: The list of configuration mode commands to send to the device
- returned: always, except for the platforms that use Netconf transport to manage the device.
- type: list
- sample:
- - set interfaces ethernet eth0 address '192.168.0.1/24'
-"""
-
-import socket
-import re
-
-from copy import deepcopy
-
-from ansible.module_utils.basic import AnsibleModule
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
- is_masklen,
- validate_ip_address,
-)
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
- remove_default_spec,
-)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- load_config,
- run_commands,
-)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- vyos_argument_spec,
-)
-
-
-def is_ipv4(value):
- if value:
- address = value.split("/")
- if is_masklen(address[1]) and validate_ip_address(address[0]):
- return True
- return False
-
-
-def is_ipv6(value):
- if value:
- address = value.split("/")
- if 0 <= int(address[1]) <= 128:
- try:
- socket.inet_pton(socket.AF_INET6, address[0])
- except socket.error:
- return False
- return True
- return False
-
-
-def search_obj_in_list(name, lst):
- for o in lst:
- if o["name"] == name:
- return o
-
- return None
-
-
-def map_obj_to_commands(updates, module):
- commands = list()
- want, have = updates
-
- for w in want:
- name = w["name"]
- ipv4 = w["ipv4"]
- ipv6 = w["ipv6"]
- state = w["state"]
-
- obj_in_have = search_obj_in_list(name, have)
-
- if state == "absent" and obj_in_have:
- if (
- not ipv4
- and not ipv6
- and (obj_in_have["ipv4"] or obj_in_have["ipv6"])
- ):
- if name == "lo":
- commands.append("delete interfaces loopback lo address")
- else:
- commands.append(
- "delete interfaces ethernet " + name + " address"
- )
- else:
- if ipv4 and ipv4 in obj_in_have["ipv4"]:
- if name == "lo":
- commands.append(
- "delete interfaces loopback lo address " + ipv4
- )
- else:
- commands.append(
- "delete interfaces ethernet "
- + name
- + " address "
- + ipv4
- )
- if ipv6 and ipv6 in obj_in_have["ipv6"]:
- if name == "lo":
- commands.append(
- "delete interfaces loopback lo address " + ipv6
- )
- else:
- commands.append(
- "delete interfaces ethernet "
- + name
- + " address "
- + ipv6
- )
- elif state == "present" and obj_in_have:
- if ipv4 and ipv4 not in obj_in_have["ipv4"]:
- if name == "lo":
- commands.append(
- "set interfaces loopback lo address " + ipv4
- )
- else:
- commands.append(
- "set interfaces ethernet " + name + " address " + ipv4
- )
-
- if ipv6 and ipv6 not in obj_in_have["ipv6"]:
- if name == "lo":
- commands.append(
- "set interfaces loopback lo address " + ipv6
- )
- else:
- commands.append(
- "set interfaces ethernet " + name + " address " + ipv6
- )
-
- return commands
-
-
-def map_config_to_obj(module):
- obj = []
- output = run_commands(module, ["show interfaces"])
- lines = re.split(r"\n[e|l]", output[0])[1:]
-
- if len(lines) > 0:
- for line in lines:
- splitted_line = line.split()
-
- if len(splitted_line) > 0:
- ipv4 = []
- ipv6 = []
-
- if splitted_line[0].lower().startswith("th"):
- name = "e" + splitted_line[0].lower()
- elif splitted_line[0].lower().startswith("o"):
- name = "l" + splitted_line[0].lower()
-
- for i in splitted_line[1:]:
- if ("." in i or ":" in i) and "/" in i:
- value = i.split(r"\n")[0]
- if is_ipv4(value):
- ipv4.append(value)
- elif is_ipv6(value):
- ipv6.append(value)
-
- obj.append({"name": name, "ipv4": ipv4, "ipv6": ipv6})
-
- return obj
-
-
-def map_params_to_obj(module):
- obj = []
-
- aggregate = module.params.get("aggregate")
- if aggregate:
- for item in aggregate:
- for key in item:
- if item.get(key) is None:
- item[key] = module.params[key]
-
- obj.append(item.copy())
- else:
- obj.append(
- {
- "name": module.params["name"],
- "ipv4": module.params["ipv4"],
- "ipv6": module.params["ipv6"],
- "state": module.params["state"],
- }
- )
-
- return obj
-
-
-def main():
- """main entry point for module execution"""
- element_spec = dict(
- name=dict(),
- ipv4=dict(),
- ipv6=dict(),
- state=dict(default="present", choices=["present", "absent"]),
- )
-
- aggregate_spec = deepcopy(element_spec)
- aggregate_spec["name"] = dict(required=True)
-
- # remove default in aggregate spec, to handle common arguments
- remove_default_spec(aggregate_spec)
-
- argument_spec = dict(
- aggregate=dict(type="list", elements="dict", options=aggregate_spec),
- )
-
- argument_spec.update(element_spec)
- argument_spec.update(vyos_argument_spec)
-
- required_one_of = [["name", "aggregate"]]
- mutually_exclusive = [["name", "aggregate"]]
- module = AnsibleModule(
- argument_spec=argument_spec,
- required_one_of=required_one_of,
- mutually_exclusive=mutually_exclusive,
- supports_check_mode=True,
- )
-
- warnings = list()
-
- result = {"changed": False}
-
- if warnings:
- result["warnings"] = warnings
-
- want = map_params_to_obj(module)
- have = map_config_to_obj(module)
-
- commands = map_obj_to_commands((want, have), module)
- result["commands"] = commands
-
- if commands:
- commit = not module.check_mode
- load_config(module, commands, commit=commit)
- result["changed"] = True
-
- module.exit_json(**result)
-
-
-if __name__ == "__main__":
- main()
diff --git a/plugins/modules/vyos_linkagg.py b/plugins/modules/vyos_linkagg.py
deleted file mode 100644
index 4320dd3..0000000
--- a/plugins/modules/vyos_linkagg.py
+++ /dev/null
@@ -1,363 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-
-# (c) 2017, Ansible by Red Hat, inc
-#
-# This file is part of Ansible by Red Hat
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-
-from __future__ import absolute_import, division, print_function
-
-__metaclass__ = type
-
-DOCUMENTATION = """
-module: vyos_linkagg
-author: Ricardo Carrillo Cruz (@rcarrillocruz)
-short_description: (deprecated, removed after 2022-06-01) Manage link aggregation
- groups on VyOS network devices
-description:
-- This module provides declarative management of link aggregation groups on VyOS network
- devices.
-version_added: 1.0.0
-deprecated:
- alternative: vyos_lag_interfaces
- why: Updated modules released with more functionality.
- removed_at_date: '2022-06-01'
-notes:
-- Tested against VYOS 1.1.7
-options:
- name:
- description:
- - Name of the link aggregation group.
- type: str
- mode:
- description:
- - Mode of the link aggregation group.
- default: "802.3ad"
- choices:
- - 802.3ad
- - active-backup
- - broadcast
- - round-robin
- - transmit-load-balance
- - adaptive-load-balance
- - xor-hash
- - "on"
- type: str
- members:
- description:
- - List of members of the link aggregation group.
- type: list
- elements: str
- aggregate:
- description: List of link aggregation definitions.
- type: list
- elements: dict
- suboptions:
- name:
- description:
- - Name of the link aggregation group.
- required: true
- type: str
- mode:
- description:
- - Mode of the link aggregation group.
- choices:
- - 802.3ad
- - active-backup
- - broadcast
- - round-robin
- - transmit-load-balance
- - adaptive-load-balance
- - xor-hash
- - "on"
- type: str
- members:
- description:
- - List of members of the link aggregation group.
- type: list
- elements: str
- state:
- description:
- - State of the link aggregation group.
- choices:
- - present
- - absent
- - up
- - down
- type: str
- state:
- description:
- - State of the link aggregation group.
- default: present
- choices:
- - present
- - absent
- - up
- - down
- type: str
-extends_documentation_fragment:
-- vyos.vyos.vyos
-
-
-"""
-
-EXAMPLES = """
-- name: configure link aggregation group
- vyos.vyos.vyos_linkagg:
- name: bond0
- members:
- - eth0
- - eth1
-
-- name: remove configuration
- vyos.vyos.vyos_linkagg:
- name: bond0
- state: absent
-
-- name: Create aggregate of linkagg definitions
- vyos.vyos.vyos_linkagg:
- aggregate:
- - {name: bond0, members: [eth1]}
- - {name: bond1, members: [eth2]}
-
-- name: Remove aggregate of linkagg definitions
- vyos.vyos.vyos_linkagg:
- aggregate:
- - name: bond0
- - name: bond1
- state: absent
-"""
-
-RETURN = """
-commands:
- description: The list of configuration mode commands to send to the device
- returned: always, except for the platforms that use Netconf transport to manage the device.
- type: list
- sample:
- - set interfaces bonding bond0
- - set interfaces ethernet eth0 bond-group 'bond0'
- - set interfaces ethernet eth1 bond-group 'bond0'
-"""
-from copy import deepcopy
-
-from ansible.module_utils.basic import AnsibleModule
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
- remove_default_spec,
-)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- load_config,
- run_commands,
-)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- vyos_argument_spec,
-)
-
-
-def search_obj_in_list(name, lst):
- for o in lst:
- if o["name"] == name:
- return o
-
- return None
-
-
-def map_obj_to_commands(updates, module):
- commands = list()
- want, have = updates
-
- for w in want:
- name = w["name"]
- members = w.get("members") or []
- mode = w["mode"]
-
- if mode == "on":
- mode = "802.3ad"
-
- state = w["state"]
-
- obj_in_have = search_obj_in_list(name, have)
-
- if state == "absent":
- if obj_in_have:
- for m in obj_in_have["members"]:
- commands.append(
- "delete interfaces ethernet " + m + " bond-group"
- )
-
- commands.append("delete interfaces bonding " + name)
- else:
- if not obj_in_have:
- commands.append(
- "set interfaces bonding " + name + " mode " + mode
- )
-
- for m in members:
- commands.append(
- "set interfaces ethernet " + m + " bond-group " + name
- )
-
- if state == "down":
- commands.append(
- "set interfaces bonding " + name + " disable"
- )
- else:
- if mode != obj_in_have["mode"]:
- commands.append(
- "set interfaces bonding " + name + " mode " + mode
- )
-
- missing_members = list(
- set(members) - set(obj_in_have["members"])
- )
- for m in missing_members:
- commands.append(
- "set interfaces ethernet " + m + " bond-group " + name
- )
-
- if state == "down" and obj_in_have["state"] == "up":
- commands.append(
- "set interfaces bonding " + name + " disable"
- )
- elif state == "up" and obj_in_have["state"] == "down":
- commands.append(
- "delete interfaces bonding " + name + " disable"
- )
-
- return commands
-
-
-def map_config_to_obj(module):
- obj = []
- output = run_commands(module, ["show interfaces bonding slaves"])
- lines = output[0].splitlines()
-
- if len(lines) > 1:
- for line in lines[1:]:
- splitted_line = line.split()
-
- name = splitted_line[0]
- mode = splitted_line[1]
- state = splitted_line[2]
-
- if len(splitted_line) > 4:
- members = splitted_line[4:]
- else:
- members = []
-
- obj.append(
- {
- "name": name,
- "mode": mode,
- "members": members,
- "state": state,
- }
- )
-
- return obj
-
-
-def map_params_to_obj(module):
- obj = []
- aggregate = module.params.get("aggregate")
- if aggregate:
- for item in aggregate:
- for key in item:
- if item.get(key) is None:
- item[key] = module.params[key]
-
- obj.append(item.copy())
- else:
- obj.append(
- {
- "name": module.params["name"],
- "mode": module.params["mode"],
- "members": module.params["members"],
- "state": module.params["state"],
- }
- )
-
- return obj
-
-
-def main():
- """main entry point for module execution"""
- element_spec = dict(
- name=dict(),
- mode=dict(
- choices=[
- "802.3ad",
- "active-backup",
- "broadcast",
- "round-robin",
- "transmit-load-balance",
- "adaptive-load-balance",
- "xor-hash",
- "on",
- ],
- default="802.3ad",
- ),
- members=dict(type="list", elements="str"),
- state=dict(
- default="present", choices=["present", "absent", "up", "down"]
- ),
- )
-
- aggregate_spec = deepcopy(element_spec)
- aggregate_spec["name"] = dict(required=True)
-
- # remove default in aggregate spec, to handle common arguments
- remove_default_spec(aggregate_spec)
-
- argument_spec = dict(
- aggregate=dict(type="list", elements="dict", options=aggregate_spec),
- )
-
- argument_spec.update(element_spec)
- argument_spec.update(vyos_argument_spec)
-
- required_one_of = [["name", "aggregate"]]
- mutually_exclusive = [["name", "aggregate"]]
- module = AnsibleModule(
- argument_spec=argument_spec,
- required_one_of=required_one_of,
- mutually_exclusive=mutually_exclusive,
- supports_check_mode=True,
- )
-
- warnings = list()
-
- result = {"changed": False}
-
- if warnings:
- result["warnings"] = warnings
-
- want = map_params_to_obj(module)
- have = map_config_to_obj(module)
-
- commands = map_obj_to_commands((want, have), module)
- result["commands"] = commands
-
- if commands:
- commit = not module.check_mode
- load_config(module, commands, commit=commit)
- result["changed"] = True
-
- module.exit_json(**result)
-
-
-if __name__ == "__main__":
- main()
diff --git a/plugins/modules/vyos_lldp.py b/plugins/modules/vyos_lldp.py
deleted file mode 100644
index c1aaf5d..0000000
--- a/plugins/modules/vyos_lldp.py
+++ /dev/null
@@ -1,143 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-
-# (c) 2017, Ansible by Red Hat, inc
-#
-# This file is part of Ansible by Red Hat
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-
-from __future__ import absolute_import, division, print_function
-
-__metaclass__ = type
-
-
-DOCUMENTATION = """
-module: vyos_lldp
-author: Ricardo Carrillo Cruz (@rcarrillocruz)
-short_description: (deprecated, removed after 2022-06-01) Manage LLDP configuration
- on VyOS network devices
-description:
-- This module provides declarative management of LLDP service on VyOS network devices.
-version_added: 1.0.0
-deprecated:
- alternative: vyos_lldp_global
- why: Updated modules released with more functionality.
- removed_at_date: '2022-06-01'
-notes:
-- Tested against VYOS 1.1.7
-options:
- interfaces:
- description:
- - Name of the interfaces.
- type: list
- elements: str
- state:
- description:
- - State of the link aggregation group.
- default: present
- choices:
- - present
- - absent
- - enabled
- - disabled
- type: str
-extends_documentation_fragment:
-- vyos.vyos.vyos
-
-
-"""
-
-EXAMPLES = """
-- name: Enable LLDP service
- vyos.vyos.vyos_lldp:
- state: present
-
-- name: Disable LLDP service
- vyos.vyos.vyos_lldp:
- state: absent
-"""
-
-RETURN = """
-commands:
- description: The list of configuration mode commands to send to the device
- returned: always, except for the platforms that use Netconf transport to manage the device.
- type: list
- sample:
- - set service lldp
-"""
-from ansible.module_utils.basic import AnsibleModule
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- get_config,
- load_config,
-)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- vyos_argument_spec,
-)
-
-
-def has_lldp(module):
- config = get_config(module).splitlines()
-
- if "set service 'lldp'" in config or "set service lldp" in config:
- return True
- else:
- return False
-
-
-def main():
- """main entry point for module execution"""
- argument_spec = dict(
- interfaces=dict(type="list", elements="str"),
- state=dict(
- default="present",
- choices=["present", "absent", "enabled", "disabled"],
- ),
- )
-
- argument_spec.update(vyos_argument_spec)
-
- module = AnsibleModule(
- argument_spec=argument_spec, supports_check_mode=True
- )
-
- warnings = list()
-
- result = {"changed": False}
-
- if warnings:
- result["warnings"] = warnings
-
- HAS_LLDP = has_lldp(module)
-
- commands = []
-
- if module.params["state"] == "absent" and HAS_LLDP:
- commands.append("delete service lldp")
- elif module.params["state"] == "present" and not HAS_LLDP:
- commands.append("set service lldp")
-
- result["commands"] = commands
-
- if commands:
- commit = not module.check_mode
- load_config(module, commands, commit=commit)
- result["changed"] = True
-
- module.exit_json(**result)
-
-
-if __name__ == "__main__":
- main()
diff --git a/plugins/modules/vyos_lldp_interface.py b/plugins/modules/vyos_lldp_interface.py
deleted file mode 100644
index b8bf91c..0000000
--- a/plugins/modules/vyos_lldp_interface.py
+++ /dev/null
@@ -1,280 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-
-# (c) 2017, Ansible by Red Hat, inc
-#
-# This file is part of Ansible by Red Hat
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-
-from __future__ import absolute_import, division, print_function
-
-__metaclass__ = type
-
-DOCUMENTATION = """
-module: vyos_lldp_interface
-author: Ricardo Carrillo Cruz (@rcarrillocruz)
-short_description: (deprecated, removed after 2022-06-01) Manage LLDP interfaces configuration
- on VyOS network devices
-description:
-- This module provides declarative management of LLDP interfaces configuration on
- VyOS network devices.
-version_added: 1.0.0
-deprecated:
- alternative: vyos_lldp_interfaces
- why: Updated modules released with more functionality.
- removed_at_date: '2022-06-01'
-notes:
-- Tested against VYOS 1.1.7
-options:
- name:
- description:
- - Name of the interface LLDP should be configured on.
- type: str
- aggregate:
- description: List of interfaces LLDP should be configured on.
- type: list
- elements: dict
- suboptions:
- name:
- description:
- - Name of the interface LLDP should be configured on.
- required: True
- type: str
- state:
- description:
- - State of the LLDP configuration.
- choices:
- - present
- - absent
- - enabled
- - disabled
- type: str
- state:
- description:
- - State of the LLDP configuration.
- default: present
- choices:
- - present
- - absent
- - enabled
- - disabled
- type: str
-extends_documentation_fragment:
-- vyos.vyos.vyos
-
-
-"""
-
-EXAMPLES = """
-- name: Enable LLDP on eth1
- net_lldp_interface:
- state: present
-
-- name: Enable LLDP on specific interfaces
- net_lldp_interface:
- interfaces:
- - eth1
- - eth2
- state: present
-
-- name: Disable LLDP globally
- net_lldp_interface:
- state: disabled
-
-- name: Create aggregate of LLDP interface configurations
- vyos.vyos.vyos_lldp_interface:
- aggregate:
- - name: eth1
- - name: eth2
- state: present
-
-- name: Delete aggregate of LLDP interface configurations
- vyos.vyos.vyos_lldp_interface:
- aggregate:
- - name: eth1
- - name: eth2
- state: absent
-"""
-
-RETURN = """
-commands:
- description: The list of configuration mode commands to send to the device
- returned: always, except for the platforms that use Netconf transport to manage the device.
- type: list
- sample:
- - set service lldp eth1
- - set service lldp eth2 disable
-"""
-
-
-from copy import deepcopy
-
-from ansible.module_utils.basic import AnsibleModule
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
- remove_default_spec,
-)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- get_config,
- load_config,
-)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- vyos_argument_spec,
-)
-
-
-def search_obj_in_list(name, lst):
- for o in lst:
- if o["name"] == name:
- return o
-
- return None
-
-
-def map_obj_to_commands(updates, module):
- commands = list()
- want, have = updates
-
- for w in want:
- name = w["name"]
- state = w["state"]
-
- obj_in_have = search_obj_in_list(name, have)
-
- if state == "absent" and obj_in_have:
- commands.append("delete service lldp interface " + name)
- elif state in ("present", "enabled"):
- if not obj_in_have:
- commands.append("set service lldp interface " + name)
- elif (
- obj_in_have
- and obj_in_have["state"] == "disabled"
- and state == "enabled"
- ):
- commands.append(
- "delete service lldp interface " + name + " disable"
- )
- elif state == "disabled":
- if not obj_in_have:
- commands.append("set service lldp interface " + name)
- commands.append(
- "set service lldp interface " + name + " disable"
- )
- elif obj_in_have and obj_in_have["state"] != "disabled":
- commands.append(
- "set service lldp interface " + name + " disable"
- )
-
- return commands
-
-
-def map_config_to_obj(module):
- obj = []
- config = get_config(module).splitlines()
-
- output = [c for c in config if c.startswith("set service lldp interface")]
-
- for i in output:
- splitted_line = i.split()
-
- if len(splitted_line) > 5:
- new_obj = {"name": splitted_line[4]}
-
- if splitted_line[5] == "'disable'":
- new_obj["state"] = "disabled"
- else:
- new_obj = {"name": splitted_line[4][1:-1]}
- new_obj["state"] = "present"
-
- obj.append(new_obj)
-
- return obj
-
-
-def map_params_to_obj(module):
- obj = []
-
- aggregate = module.params.get("aggregate")
- if aggregate:
- for item in aggregate:
- for key in item:
- if item.get(key) is None:
- item[key] = module.params[key]
-
- obj.append(item.copy())
- else:
- obj.append(
- {"name": module.params["name"], "state": module.params["state"]}
- )
-
- return obj
-
-
-def main():
- """main entry point for module execution"""
- element_spec = dict(
- name=dict(),
- state=dict(
- default="present",
- choices=["present", "absent", "enabled", "disabled"],
- ),
- )
-
- aggregate_spec = deepcopy(element_spec)
- aggregate_spec["name"] = dict(required=True)
-
- # remove default in aggregate spec, to handle common arguments
- remove_default_spec(aggregate_spec)
-
- argument_spec = dict(
- aggregate=dict(type="list", elements="dict", options=aggregate_spec),
- )
-
- argument_spec.update(element_spec)
- argument_spec.update(vyos_argument_spec)
-
- required_one_of = [["name", "aggregate"]]
- mutually_exclusive = [["name", "aggregate"]]
-
- module = AnsibleModule(
- argument_spec=argument_spec,
- required_one_of=required_one_of,
- mutually_exclusive=mutually_exclusive,
- supports_check_mode=True,
- )
-
- warnings = list()
-
- result = {"changed": False}
-
- if warnings:
- result["warnings"] = warnings
-
- want = map_params_to_obj(module)
- have = map_config_to_obj(module)
-
- commands = map_obj_to_commands((want, have), module)
- result["commands"] = commands
-
- if commands:
- commit = not module.check_mode
- load_config(module, commands, commit=commit)
- result["changed"] = True
-
- module.exit_json(**result)
-
-
-if __name__ == "__main__":
- main()
diff --git a/plugins/modules/vyos_logging.py b/plugins/modules/vyos_logging.py
index 2c160c3..4b3eaaf 100644
--- a/plugins/modules/vyos_logging.py
+++ b/plugins/modules/vyos_logging.py
@@ -166,9 +166,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import
get_config,
load_config,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- vyos_argument_spec,
-)
def spec_to_commands(updates, module):
@@ -308,7 +305,6 @@ def main():
argument_spec.update(element_spec)
- argument_spec.update(vyos_argument_spec)
required_if = [
("dest", "host", ["name", "facility", "level"]),
("dest", "file", ["name", "facility", "level"]),
diff --git a/plugins/modules/vyos_ping.py b/plugins/modules/vyos_ping.py
index eb89b4e..7934583 100644
--- a/plugins/modules/vyos_ping.py
+++ b/plugins/modules/vyos_ping.py
@@ -138,9 +138,6 @@ from ansible.module_utils.basic import AnsibleModule
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
run_commands,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- vyos_argument_spec,
-)
import re
@@ -158,8 +155,6 @@ def main():
),
)
- argument_spec.update(vyos_argument_spec)
-
module = AnsibleModule(argument_spec=argument_spec)
count = module.params["count"]
diff --git a/plugins/modules/vyos_static_route.py b/plugins/modules/vyos_static_route.py
deleted file mode 100644
index 7f3719d..0000000
--- a/plugins/modules/vyos_static_route.py
+++ /dev/null
@@ -1,335 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-
-# (c) 2017, Ansible by Red Hat, inc
-#
-# This file is part of Ansible by Red Hat
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-
-from __future__ import absolute_import, division, print_function
-
-__metaclass__ = type
-
-DOCUMENTATION = """
-module: vyos_static_route
-author: Trishna Guha (@trishnaguha)
-short_description: (deprecated, removed after 2022-06-01) Manage static IP routes
- on Vyatta VyOS network devices
-description:
-- This module provides declarative management of static IP routes on Vyatta VyOS network
- devices.
-version_added: 1.0.0
-deprecated:
- alternative: vyos_static_routes
- why: Updated modules released with more functionality.
- removed_at_date: '2022-06-01'
-notes:
-- Tested against VyOS 1.1.8 (helium).
-- This module works with connection C(ansible.netcommon.network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html).
-options:
- prefix:
- description:
- - Network prefix of the static route. C(mask) param should be ignored if C(prefix)
- is provided with C(mask) value C(prefix/mask).
- type: str
- mask:
- description:
- - Network prefix mask of the static route.
- type: str
- next_hop:
- description:
- - Next hop IP of the static route.
- type: str
- admin_distance:
- description:
- - Admin distance of the static route.
- type: int
- aggregate:
- description: List of static route definitions
- type: list
- elements: dict
- suboptions:
- prefix:
- description:
- - Network prefix of the static route. C(mask) param should be ignored if C(prefix)
- is provided with C(mask) value C(prefix/mask).
- required: True
- type: str
- mask:
- description:
- - Network prefix mask of the static route.
- type: str
- next_hop:
- description:
- - Next hop IP of the static route.
- type: str
- admin_distance:
- description:
- - Admin distance of the static route.
- type: int
- state:
- description:
- - State of the static route configuration.
- choices:
- - present
- - absent
- type: str
- state:
- description:
- - State of the static route configuration.
- default: present
- choices:
- - present
- - absent
- type: str
-extends_documentation_fragment:
-- vyos.vyos.vyos
-
-
-"""
-
-EXAMPLES = """
-- name: configure static route
- vyos.vyos.vyos_static_route:
- prefix: 192.168.2.0
- mask: 24
- next_hop: 10.0.0.1
-
-- name: configure static route prefix/mask
- vyos.vyos.vyos_static_route:
- prefix: 192.168.2.0/16
- next_hop: 10.0.0.1
-
-- name: remove configuration
- vyos.vyos.vyos_static_route:
- prefix: 192.168.2.0
- mask: 16
- next_hop: 10.0.0.1
- state: absent
-
-- name: configure aggregates of static routes
- vyos.vyos.vyos_static_route:
- aggregate:
- - {prefix: 192.168.2.0, mask: 24, next_hop: 10.0.0.1}
- - {prefix: 192.168.3.0, mask: 16, next_hop: 10.0.2.1}
- - {prefix: 192.168.3.0/16, next_hop: 10.0.2.1}
-
-- name: Remove static route collections
- vyos.vyos.vyos_static_route:
- aggregate:
- - {prefix: 172.24.1.0/24, next_hop: 192.168.42.64}
- - {prefix: 172.24.3.0/24, next_hop: 192.168.42.64}
- state: absent
-"""
-
-RETURN = """
-commands:
- description: The list of configuration mode commands to send to the device
- returned: always
- type: list
- sample:
- - set protocols static route 192.168.2.0/16 next-hop 10.0.0.1
-"""
-import re
-
-from copy import deepcopy
-
-from ansible.module_utils._text import to_text
-from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.common.validation import check_required_together
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
- remove_default_spec,
-)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- get_config,
- load_config,
-)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- vyos_argument_spec,
-)
-
-
-def spec_to_commands(updates, module):
- commands = list()
- want, have = updates
- for w in want:
- prefix = w["prefix"]
- mask = w["mask"]
- next_hop = w["next_hop"]
- admin_distance = w["admin_distance"]
- state = w["state"]
- del w["state"]
-
- if state == "absent" and w in have:
- commands.append(
- "delete protocols static route %s/%s" % (prefix, mask)
- )
- elif state == "present" and w not in have:
- cmd = "set protocols static route %s/%s next-hop %s" % (
- prefix,
- mask,
- next_hop,
- )
- if admin_distance != "None":
- cmd += " distance %s" % (admin_distance)
- commands.append(cmd)
-
- return commands
-
-
-def config_to_dict(module):
- data = get_config(module)
- obj = []
-
- for line in data.split("\n"):
- if line.startswith("set protocols static route"):
- match = re.search(r"static route (\S+)", line, re.M)
- prefix = match.group(1).split("/")[0]
- mask = match.group(1).split("/")[1]
- if "next-hop" in line:
- match_hop = re.search(r"next-hop (\S+)", line, re.M)
- next_hop = match_hop.group(1).strip("'")
-
- match_distance = re.search(r"distance (\S+)", line, re.M)
- if match_distance is not None:
- admin_distance = match_distance.group(1)[1:-1]
- else:
- admin_distance = None
-
- if admin_distance is not None:
- obj.append(
- {
- "prefix": prefix,
- "mask": mask,
- "next_hop": next_hop,
- "admin_distance": admin_distance,
- }
- )
- else:
- obj.append(
- {
- "prefix": prefix,
- "mask": mask,
- "next_hop": next_hop,
- "admin_distance": "None",
- }
- )
-
- return obj
-
-
-def map_params_to_obj(module, required_together=None):
- obj = []
- aggregate = module.params.get("aggregate")
- if aggregate:
- for item in aggregate:
- for key in item:
- if item.get(key) is None:
- item[key] = module.params[key]
-
- try:
- check_required_together(required_together, item)
- except TypeError as exc:
- module.fail_json(to_text(exc))
- d = item.copy()
- if "/" in d["prefix"]:
- d["mask"] = d["prefix"].split("/")[1]
- d["prefix"] = d["prefix"].split("/")[0]
-
- if "admin_distance" in d:
- d["admin_distance"] = str(d["admin_distance"])
-
- obj.append(d)
- else:
- prefix = module.params["prefix"].strip()
- if "/" in prefix:
- mask = prefix.split("/")[1]
- prefix = prefix.split("/")[0]
- else:
- mask = module.params["mask"].strip()
- next_hop = module.params["next_hop"].strip()
- admin_distance = str(module.params["admin_distance"])
- state = module.params["state"]
-
- obj.append(
- {
- "prefix": prefix,
- "mask": mask,
- "next_hop": next_hop,
- "admin_distance": admin_distance,
- "state": state,
- }
- )
-
- return obj
-
-
-def main():
- """main entry point for module execution"""
- element_spec = dict(
- prefix=dict(type="str"),
- mask=dict(type="str"),
- next_hop=dict(type="str"),
- admin_distance=dict(type="int"),
- state=dict(default="present", choices=["present", "absent"]),
- )
-
- aggregate_spec = deepcopy(element_spec)
- aggregate_spec["prefix"] = dict(required=True)
-
- # remove default in aggregate spec, to handle common arguments
- remove_default_spec(aggregate_spec)
-
- argument_spec = dict(
- aggregate=dict(type="list", elements="dict", options=aggregate_spec)
- )
-
- argument_spec.update(element_spec)
- argument_spec.update(vyos_argument_spec)
-
- required_one_of = [["aggregate", "prefix"]]
- required_together = [["prefix", "next_hop"]]
- mutually_exclusive = [["aggregate", "prefix"]]
-
- module = AnsibleModule(
- argument_spec=argument_spec,
- required_one_of=required_one_of,
- required_together=required_together,
- mutually_exclusive=mutually_exclusive,
- supports_check_mode=True,
- )
-
- warnings = list()
-
- result = {"changed": False}
- if warnings:
- result["warnings"] = warnings
- want = map_params_to_obj(module, required_together=required_together)
- have = config_to_dict(module)
-
- commands = spec_to_commands((want, have), module)
- result["commands"] = commands
-
- if commands:
- commit = not module.check_mode
- load_config(module, commands, commit=commit)
- result["changed"] = True
-
- module.exit_json(**result)
-
-
-if __name__ == "__main__":
- main()
diff --git a/plugins/modules/vyos_system.py b/plugins/modules/vyos_system.py
index 4a9fdcd..fd98507 100644
--- a/plugins/modules/vyos_system.py
+++ b/plugins/modules/vyos_system.py
@@ -99,9 +99,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import
get_config,
load_config,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- vyos_argument_spec,
-)
def spec_key_to_device_key(key):
@@ -197,8 +194,6 @@ def main():
),
)
- argument_spec.update(vyos_argument_spec)
-
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
diff --git a/plugins/modules/vyos_user.py b/plugins/modules/vyos_user.py
index 6d07f9d..b2e1acc 100644
--- a/plugins/modules/vyos_user.py
+++ b/plugins/modules/vyos_user.py
@@ -33,6 +33,8 @@ description:
collection of usernames in the current running config. It also supports purging
usernames from the configuration that are not explicitly defined.
version_added: 1.0.0
+extends_documentation_fragment:
+- vyos.vyos.vyos
notes:
- Tested against VyOS 1.1.8 (helium).
- This module works with connection C(ansible.netcommon.network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html).
@@ -51,8 +53,7 @@ options:
name:
description:
- The username to be configured on the VyOS device. This argument accepts a string
- value and is mutually exclusive with the C(aggregate) argument. Please note
- that this option is not same as C(provider username).
+ value and is mutually exclusive with the C(aggregate) argument.
required: True
type: str
full_name:
@@ -63,8 +64,7 @@ options:
configured_password:
description:
- The password to be configured on the VyOS device. The password needs to be provided
- in clear and it will be encrypted on the device. Please note that this option
- is not same as C(provider password).
+ in clear and it will be encrypted on the device.
type: str
update_password:
description:
@@ -96,8 +96,7 @@ options:
name:
description:
- The username to be configured on the VyOS device. This argument accepts a string
- value and is mutually exclusive with the C(aggregate) argument. Please note
- that this option is not same as C(provider username).
+ value and is mutually exclusive with the C(aggregate) argument.
type: str
full_name:
description:
@@ -107,8 +106,7 @@ options:
configured_password:
description:
- The password to be configured on the VyOS device. The password needs to be provided
- in clear and it will be encrypted on the device. Please note that this option
- is not same as C(provider password).
+ in clear and it will be encrypted on the device.
type: str
update_password:
description:
@@ -146,8 +144,6 @@ options:
choices:
- present
- absent
-extends_documentation_fragment:
-- vyos.vyos.vyos
"""
EXAMPLES = """
@@ -198,9 +194,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import
load_config,
)
from ansible.module_utils.six import iteritems
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- vyos_argument_spec,
-)
def validate_level(value, module):
@@ -368,7 +361,6 @@ def main():
)
argument_spec.update(element_spec)
- argument_spec.update(vyos_argument_spec)
mutually_exclusive = [("name", "aggregate")]
module = AnsibleModule(
diff --git a/plugins/modules/vyos_vlan.py b/plugins/modules/vyos_vlan.py
index 58d79d7..8325366 100644
--- a/plugins/modules/vyos_vlan.py
+++ b/plugins/modules/vyos_vlan.py
@@ -177,9 +177,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import
load_config,
run_commands,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- vyos_argument_spec,
-)
def search_obj_in_list(vlan_id, lst):
@@ -375,7 +372,6 @@ def main():
)
argument_spec.update(element_spec)
- argument_spec.update(vyos_argument_spec)
required_one_of = [
["vlan_id", "aggregate"],