collection 교체

This commit is contained in:
정훈 변
2024-02-23 16:37:40 +09:00
parent b494779b5b
commit 3fd554eee9
38862 changed files with 220204 additions and 6600073 deletions

View File

@@ -0,0 +1,126 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2018, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: cli_backup
author: Kate Case (@Qalthos)
short_description: Back up device configuration from network devices over network_cli
description:
- This module provides platform agnostic way of backing up text based configuration from
network devices over network_cli connection plugin.
version_added: 4.2.0
extends_documentation_fragment:
- ansible.netcommon.network_agnostic
options:
defaults:
description:
- The I(defaults) argument will influence how the running-config is collected
from the device. When the value is set to true, the command used to collect
the running-config is append with the all keyword. When the value is set to
false, the command is issued without the all keyword.
default: no
type: bool
filename:
description:
- The filename to be used to store the backup configuration. If the filename
is not given it will be generated based on the hostname, current time and
date in format defined by <hostname>_config.<current-date>@<current-time>
type: str
dir_path:
description:
- This option provides the path ending with directory name in which the backup
configuration file will be stored. If the directory does not exist it will
be first created and the filename is either the value of C(filename) or
default filename as described in C(filename) options description. If the
path value is not given in that case a I(backup) directory will be created
in the current working directory and backup configuration will be copied
in C(filename) within I(backup) directory.
type: path
"""
EXAMPLES = """
- name: configurable backup path
ansible.netcommon.cli_backup:
filename: backup.cfg
dir_path: /home/user
"""
RETURN = """
backup_path:
description: The full path to the backup file
returned: always
type: str
sample: /playbooks/ansible/backup/hostname_config.2016-07-16@22:28:34
"""
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.connection import Connection
def validate_args(module, device_operations):
"""validate param if it is supported on the platform"""
feature_list = [
"defaults",
]
for feature in feature_list:
if module.params[feature]:
supports_feature = device_operations.get("supports_%s" % feature)
if supports_feature is None:
module.fail_json(
msg="This platform does not specify whether %s is supported or not. "
"Please report an issue against this platform's cliconf plugin." % feature
)
elif not supports_feature:
module.fail_json(msg="Option %s is not supported on this platform" % feature)
def main():
"""main entry point for execution"""
argument_spec = dict(
defaults=dict(default=False, type="bool"),
filename=dict(),
dir_path=dict(type="path"),
)
module = AnsibleModule(
argument_spec=argument_spec,
)
result = {"changed": False}
connection = Connection(module._socket_path)
capabilities = module.from_json(connection.get_capabilities())
if capabilities:
device_operations = capabilities.get("device_operations", dict())
validate_args(module, device_operations)
else:
device_operations = dict()
if module.params["defaults"]:
if "get_default_flag" in capabilities.get("rpc"):
flags = connection.get_default_flag()
else:
flags = "all"
else:
flags = []
running = connection.get_config(flags=flags)
result["__backup__"] = running
module.exit_json(**result)
if __name__ == "__main__":
main()

View File

@@ -1,9 +1,11 @@
#!/usr/bin/python
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import absolute_import, division, print_function
__metaclass__ = type
@@ -77,7 +79,7 @@ EXAMPLES = """
ansible.netcommon.cli_command:
command: commit replace
prompt: This commit will replace or remove the entire running configuration
answer: yes
answer: "yes"
- name: run command expecting user confirmation
ansible.netcommon.cli_command:
@@ -88,27 +90,27 @@ EXAMPLES = """
- name: run config mode command and handle prompt/answer
ansible.netcommon.cli_command:
command: '{{ item }}'
command: "{{ item }}"
prompt:
- Exit with uncommitted changes
- Exit with uncommitted changes
answer: y
loop:
- configure
- set system syslog file test any any
- exit
- configure
- set system syslog file test any any
- exit
- name: multiple prompt, multiple answer (mandatory check for all prompts)
ansible.netcommon.cli_command:
command: copy sftp sftp://user@host//user/test.img
check_all: true
prompt:
- Confirm download operation
- Password
- Do you want to change that to the standby image
- Confirm download operation
- Password
- Do you want to change that to the standby image
answer:
- y
- <password>
- y
- y
- <password>
- y
"""
RETURN = """

View File

@@ -2,10 +2,12 @@
# -*- coding: utf-8 -*-
# (c) 2018, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import absolute_import, division, print_function
__metaclass__ = type
@@ -165,7 +167,7 @@ EXAMPLES = """
- name: configure device with config with defaults enabled
ansible.netcommon.cli_config:
config: "{{ lookup('template', 'basic/config.j2') }}"
defaults: yes
defaults: "yes"
- name: Use diff_match
ansible.netcommon.cli_config:
@@ -188,7 +190,7 @@ EXAMPLES = """
- name: configurable backup path
ansible.netcommon.cli_config:
config: "{{ lookup('template', 'basic/config.j2') }}"
backup: yes
backup: "yes"
backup_options:
filename: backup.cfg
dir_path: /home/user
@@ -224,9 +226,9 @@ backup_path:
import json
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.connection import Connection
from ansible.module_utils._text import to_text
def validate_args(module, device_operations):
@@ -248,18 +250,13 @@ def validate_args(module, device_operations):
if supports_feature is None:
module.fail_json(
msg="This platform does not specify whether %s is supported or not. "
"Please report an issue against this platform's cliconf plugin."
% feature
"Please report an issue against this platform's cliconf plugin." % feature
)
elif not supports_feature:
module.fail_json(
msg="Option %s is not supported on this platform" % feature
)
module.fail_json(msg="Option %s is not supported on this platform" % feature)
def run(
module, device_operations, connection, candidate, running, rollback_id
):
def run(module, device_operations, connection, candidate, running, rollback_id):
result = {}
resp = {}
config_diff = []
@@ -279,11 +276,7 @@ def run(
elif replace in ("no", "false", "False"):
replace = False
if (
replace is not None
and replace not in [True, False]
and candidate is not None
):
if replace is not None and replace not in [True, False] and candidate is not None:
module.fail_json(
msg="Replace value '%s' is a configuration file path already"
" present on the device. Hence 'replace' and 'config' options"
@@ -297,17 +290,11 @@ def run(
elif device_operations.get("supports_onbox_diff"):
if diff_replace:
module.warn(
"diff_replace is ignored as the device supports onbox diff"
)
module.warn("diff_replace is ignored as the device supports onbox diff")
if diff_match:
module.warn(
"diff_match is ignored as the device supports onbox diff"
)
module.warn("diff_match is ignored as the device supports onbox diff")
if diff_ignore_lines:
module.warn(
"diff_ignore_lines is ignored as the device supports onbox diff"
)
module.warn("diff_ignore_lines is ignored as the device supports onbox diff")
if candidate and not isinstance(candidate, list):
candidate = candidate.strip("\n").splitlines()
@@ -440,11 +427,7 @@ def main():
flags = []
candidate = module.params["config"]
candidate = (
to_text(candidate, errors="surrogate_then_replace")
if candidate
else None
)
candidate = to_text(candidate, errors="surrogate_then_replace") if candidate else None
running = connection.get_config(flags=flags)
rollback_id = module.params["rollback"]

View File

@@ -1,281 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright 2020 Red Hat
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: cli_parse
author: Bradley Thornton (@cidrblock)
short_description: Parse cli output or text using a variety of parsers
description:
- Parse cli output or text using a variety of parsers
version_added: 1.2.0
options:
command:
type: str
description:
- The command to run on the host
text:
type: str
description:
- Text to be parsed
parser:
type: dict
description:
- Parser specific parameters
required: True
suboptions:
name:
type: str
description:
- The name of the parser to use
required: True
command:
type: str
description:
- The command used to locate the parser's template
os:
type: str
description:
- Provide an operating system value to the parser
- For `ntc_templates` parser, this should be in the supported
`<vendor>_<os>` format.
template_path:
type: str
description:
- Path of the parser template on the Ansible controller
- This can be a relative or an absolute path
vars:
type: dict
description:
- Additional parser specific parameters
- See the cli_parse user guide for examples of parser specific variables
- U(https://docs.ansible.com/ansible/latest/network/user_guide/cli_parsing.html)
set_fact:
description:
- Set the resulting parsed data as a fact
type: str
notes:
- The default search path for a parser template is templates/{{ short_os }}_{{ command }}.{{ extension }}
- => short_os derived from ansible_network_os or ansible_distribution and set to lower case
- => command is the command passed to the module with spaces replaced with _
- => extension is specific to the parser used (native=yaml, textfsm=textfsm, ttp=ttp)
- The default Ansible search path for the templates directory is used for parser templates as well
- Some parsers may have additional configuration options available. See the parsers/vars key and the parser's documentation
- Some parsers require third-party python libraries be installed on the Ansible control node and a specific python version
- e.g. Pyats requires pyats and genie and requires Python 3
- e.g. ntc_templates requires ntc_templates
- e.g. textfsm requires textfsm
- e.g. ttp requires ttp
- e.g. xml requires xml_to_dict
- Support of 3rd party python libraries is limited to the use of their public APIs as documented
- "Additional information and examples can be found in the parsing user guide:"
- https://docs.ansible.com/ansible/latest/network/user_guide/cli_parsing.html
"""
EXAMPLES = r"""
# Using the native parser
# -------------
# templates/nxos_show_interface.yaml
# - example: Ethernet1/1 is up
# getval: '(?P<name>\S+) is (?P<oper_state>\S+)'
# result:
# "{{ name }}":
# name: "{{ name }}"
# state:
# operating: "{{ oper_state }}"
# shared: True
#
# - example: admin state is up, Dedicated Interface
# getval: 'admin state is (?P<admin_state>\S+)'
# result:
# "{{ name }}":
# name: "{{ name }}"
# state:
# admin: "{{ admin_state }}"
#
# - example: " Hardware: Ethernet, address: 0000.5E00.5301 (bia 0000.5E00.5301)"
# getval: '\s+Hardware: (?P<hardware>.*), address: (?P<mac>\S+)'
# result:
# "{{ name }}":
# hardware: "{{ hardware }}"
# mac_address: "{{ mac }}"
- name: Run command and parse with native
ansible.netcommon.cli_parse:
command: "show interface"
parser:
name: ansible.netcommon.native
set_fact: interfaces_fact
- name: Pass text and template_path
ansible.netcommon.cli_parse:
text: "{{ previous_command['stdout'] }}"
parser:
name: ansible.netcommon.native
template_path: "{{ role_path }}/templates/nxos_show_interface.yaml"
# Using the ntc_templates parser
# -------------
# The ntc_templates use 'vendor_platform' for the file name
# it will be derived from ansible_network_os if not provided
# e.g. cisco.ios.ios => cisco_ios
- name: Run command and parse with ntc_templates
ansible.netcommon.cli_parse:
command: "show interface"
parser:
name: ansible.netcommon.ntc_templates
register: parser_output
- name: Pass text and command
ansible.netcommon.cli_parse:
text: "{{ previous_command['stdout'] }}"
parser:
name: ansible.netcommon.ntc_templates
command: show interface
register: parser_output
# Using the pyats parser
# -------------
# The pyats parser uses 'os' to locate the appropriate parser
# it will be derived from ansible_network_os if not provided
# in the case of pyats: cisco.ios.ios => iosxe
- name: Run command and parse with pyats
ansible.netcommon.cli_parse:
command: "show interface"
parser:
name: ansible.netcommon.pyats
register: parser_output
- name: Pass text and command
ansible.netcommon.cli_parse:
text: "{{ previous_command['stdout'] }}"
parser:
name: ansible.netcommon.pyats
command: show interface
register: parser_output
- name: Provide an OS to pyats to use an ios parser
ansible.netcommon.cli_parse:
text: "{{ previous_command['stdout'] }}"
parser:
name: ansible.netcommon.pyats
command: show interface
os: ios
register: parser_output
# Using the textfsm parser
# -------------
# templates/nxos_show_version.textfsm
#
# Value UPTIME ((\d+\s\w+.s.,?\s?){4})
# Value LAST_REBOOT_REASON (.+)
# Value OS (\d+.\d+(.+)?)
# Value BOOT_IMAGE (.*)
# Value PLATFORM (\w+)
#
# Start
# ^\s+(NXOS: version|system:\s+version)\s+${OS}\s*$$
# ^\s+(NXOS|kickstart)\s+image\s+file\s+is:\s+${BOOT_IMAGE}\s*$$
# ^\s+cisco\s+${PLATFORM}\s+[cC]hassis
# ^\s+cisco\s+Nexus\d+\s+${PLATFORM}
# # Cisco N5K platform
# ^\s+cisco\s+Nexus\s+${PLATFORM}\s+[cC]hassis
# ^\s+cisco\s+.+-${PLATFORM}\s*
# ^Kernel\s+uptime\s+is\s+${UPTIME}
# ^\s+Reason:\s${LAST_REBOOT_REASON} -> Record
- name: Run command and parse with textfsm
ansible.netcommon.cli_parse:
command: "show version"
parser:
name: ansible.netcommon.textfsm
register: parser_output
- name: Pass text and command
ansible.netcommon.cli_parse:
text: "{{ previous_command['stdout'] }}"
parser:
name: ansible.netcommon.textfsm
command: show version
register: parser_output
# Using the ttp parser
# -------------
# templates/nxos_show_interface.ttp
#
# {{ interface }} is {{ state }}
# admin state is {{ admin_state }}{{ ignore(".*") }}
- name: Run command and parse with ttp
ansible.netcommon.cli_parse:
command: "show interface"
parser:
name: ansible.netcommon.ttp
set_fact: new_fact_key
- name: Pass text and template_path
ansible.netcommon.cli_parse:
text: "{{ previous_command['stdout'] }}"
parser:
name: ansible.netcommon.ttp
template_path: "{{ role_path }}/templates/nxos_show_interface.ttp"
register: parser_output
# Using the XML parser
# -------------
- name: Run command and parse with xml
ansible.netcommon.cli_parse:
command: "show interface | xml"
parser:
name: ansible.netcommon.xml
register: parser_output
- name: Pass text and parse with xml
ansible.netcommon.cli_parse:
text: "{{ previous_command['stdout'] }}"
parser:
name: ansible.netcommon.xml
register: parser_output
"""
RETURN = r"""
parsed:
description: The structured data resulting from the parsing of the text
returned: always
type: dict
sample:
stdout:
description: The output from the command run
returned: when provided a command
type: str
sample:
stdout_lines:
description: The output of the command run split into lines
returned: when provided a command
type: list
sample:
"""

View File

@@ -0,0 +1,245 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright 2022 Red Hat
# GNU General Public License v3.0+
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: grpc_config
version_added: "3.1.0"
author:
- "Gomathi Selvi S (@GomathiselviS)"
short_description: Fetch configuration/state data from gRPC enabled target hosts.
description:
- gRPC is a high performance, open-source universal RPC framework.
- This module allows the user to append configs to an existing configuration in a gRPC
enabled devices.
options:
config:
description:
- This option specifies the string which acts as a filter to restrict the portions of
the data to be retrieved from the target host device. If this option is not specified the entire
configuration or state data is returned in response provided it is supported by target host.
type: str
state:
description: action to be performed
type: str
backup:
description:
- This argument will cause the module to create a full backup of the current C(running-config)
from the remote device before any changes are made. If the C(backup_options)
value is not given, the backup file is written to the C(backup) folder in the
playbook root directory or role root directory, if playbook is part of an ansible
role. If the directory does not exist, it is created.
type: bool
default: no
backup_options:
description:
- This is a dict object containing configurable options related to backup file
path. The value of this option is read only when C(backup) is set to I(yes),
if C(backup) is set to I(no) this option will be silently ignored.
suboptions:
filename:
description:
- The filename to be used to store the backup configuration. If the filename
is not given it will be generated based on the hostname, current time and
date in format defined by <hostname>_config.<current-date>@<current-time>
type: str
dir_path:
description:
- This option provides the path ending with directory name in which the backup
configuration file will be stored. If the directory does not exist it will
be first created and the filename is either the value of C(filename) or
default filename as described in C(filename) options description. If the
path value is not given in that case a I(backup) directory will be created
in the current working directory and backup configuration will be copied
in C(filename) within I(backup) directory.
type: path
type: dict
requirements:
- grpcio
- protobuf
notes:
- This module requires the gRPC system service be enabled on
the target host being managed.
- This module supports the use of connection=connection=ansible.netcommon.grpc
- This module requires the value of 'ansible_network_os' or 'grpc_type' configuration option
(refer ansible.netcommon.grpc connection plugin documentation)
be defined as an inventory variable.
- Tested against iosxrv 9k version 6.1.2.
"""
EXAMPLES = """
- name: Merge static route config
ansible.netcommon.grpc_config:
config:
Cisco-IOS-XR-ip-static-cfg:router-static:
default-vrf:
address-family:
vrfipv4:
vrf-unicast:
vrf-prefixes:
vrf-prefix:
- prefix: "1.2.3.6"
prefix-length: 32
vrf-route:
vrf-next-hop-table:
vrf-next-hop-next-hop-address:
- next-hop-address: "10.0.2.2"
state: merged
- name: Merge bgp config
ansible.netcommon.grpc_config:
config: "{{ lookup('file', 'bgp.json') }}"
state: merged
- name: Find diff
diff: true
ansible.netcommon.grpc_config:
config: "{{ lookup('file', 'bgp_start.yml') }}"
state: merged
- name: Backup running config
ansible.netcommon.grpc_config:
backup: true
"""
RETURN = """
stdout:
description: The raw string containing response object
received from the gRPC server.
returned: error mesage, when failure happens.
empty , when the operation is successful
type: str
sample: '...'
stdout_lines:
description: The value of stdout split into a list
returned: always apart from low-level errors (such as action plugin)
type: list
sample: ['...', '...']
backup_path:
description: The full path to the backup file
returned: when backup is yes
type: str
sample: /playbooks/ansible/backup/config.2022-07-16@22:28:34
diff:
description: If --diff option in enabled while running, the before and after configuration change are
returned as part of before and after key.
returned: when diff is enabled
type: dict
"""
import json
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.connection import ConnectionError
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
dict_diff,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.grpc.grpc import (
delete_config,
merge_config,
replace_config,
run_cli,
sanitize_content,
validate_config,
)
try:
import yaml
HAS_YAML = True
except ImportError:
HAS_YAML = False
def main():
"""entry point for module execution"""
backup_spec = dict(filename=dict(), dir_path=dict(type="path"))
argument_spec = dict(
config=dict(type="str"),
state=dict(type="str"),
backup=dict(type="bool", default=False),
backup_options=dict(type="dict", options=backup_spec),
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
)
config = {}
if module.params["config"]:
config = json.dumps(yaml.safe_load(module.params["config"]))
config = json.loads(config)
state = module.params["state"]
result = {
"changed": False,
}
before = None
after = None
before_diff = None
after_diff = None
output = ""
try:
if module.params["backup"] or state in [
"merged",
"replaced",
"deleted",
]:
if not module.check_mode:
response, err = run_cli(module, "show running-config", "text")
before = to_text(response, errors="surrogate_then_replace").strip()
if module._diff or module.check_mode:
before_diff = validate_config(module, config)
if module.check_mode:
diff = dict_diff(before_diff, config)
if diff:
result["changed"] = True
result["diff"] = diff
else:
if module.params["backup"]:
result["__backup__"] = before.strip()
if state == "merged":
output = merge_config(module, config)
elif state == "replaced":
output = replace_config(module, config)
elif state == "deleted":
output = delete_config(module, config)
if state:
response, err = run_cli(module, "show running-config", "text")
after = to_text(response, errors="surrogate_then_replace").strip()
if before:
before = sanitize_content(before)
if after:
after = sanitize_content(after)
if before != after:
result["changed"] = True
if module._diff:
after_diff = validate_config(module, config)
result["diff"] = {
"before": before_diff,
"after": after_diff,
}
except ConnectionError as exc:
module.fail_json(msg=to_text(exc, errors="surrogate_then_replace"), code=exc.code)
result["stdout"] = output
module.exit_json(**result)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,217 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright 2022 Red Hat
# GNU General Public License v3.0+
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: grpc_get
version_added: "3.1.0"
author:
- "Ganesh Nalawade (@ganeshrn)"
- "Gomathi Selvi S (@GomathiselviS)"
short_description: Fetch configuration/state data from gRPC enabled target hosts.
description:
- gRPC is a high performance, open-source universal RPC framework.
- This module allows the user to fetch configuration and state data from gRPC
enabled devices.
options:
section:
description:
- This option specifies the string which acts as a filter to restrict the portions of
the data to be retrieved from the target host device. If this option is not specified the entire
configuration or state data is returned in response provided it is supported by target host.
aliases:
- filter
type: str
command:
description:
- The option specifies the command to be executed on the target host and return the response
in result. This option is supported if the gRPC target host supports executing CLI command
over the gRPC connection.
type: str
display:
description:
- Encoding scheme to use when serializing output from the device. The encoding scheme
value depends on the capability of the gRPC server running on the target host.
The values can be I(json), I(text) etc.
type: str
data_type:
description:
- The type of data that should be fetched from the target host. The value depends on the
capability of the gRPC server running on target host. The values can be I(config), I(oper)
etc. based on what is supported by the gRPC server. By default it will return both configuration
and operational state data in response.
type: str
requirements:
- grpcio
- protobuf
notes:
- This module requires the gRPC system service be enabled on
the target host being managed.
- This module supports the use of connection=ansible.netcommon.grpc.
- This module requires the value of 'ansible_network_os or grpc_type' configuration option (refer ansible.netcommon.grpc
connection plugin documentation) be defined as an inventory variable.
- Tested against iosxrv 9k version 6.1.2.
"""
EXAMPLES = """
- name: Get bgp configuration data
grpc_get:
section:
Cisco-IOS-XR-ip-static-cfg:router-static:
- null
- name: run cli command
grpc_get:
command: "show version"
display: text
"""
RETURN = """
stdout:
description: The raw string containing configuration or state data
received from the gRPC server.
returned: always apart from low-level errors (such as action plugin)
type: str
sample: '...'
stdout_lines:
description: The value of stdout split into a list
returned: always apart from low-level errors (such as action plugin)
type: list
sample: ['...', '...']
output:
description: A dictionary representing a JSON-formatted response, if the response
is a valid json string
returned: when the device response is valid JSON
type: list
sample: |
[{
"Cisco-IOS-XR-ip-static-cfg:router-static": {
"default-vrf": {
"address-family": {
"vrfipv4": {
"vrf-unicast": {
"vrf-prefixes": {
"vrf-prefix": [
{
"prefix": "0.0.0.0",
"prefix-length": 0,
"vrf-route": {
"vrf-next-hop-table": {
"vrf-next-hop-interface-name-next-hop-address": [
{
"interface-name": "MgmtEth0/RP0/CPU0/0",
"next-hop-address": "10.0.2.2"
}
]
}
}
}
]
}
}
}
}
}
}
}]
"""
import json
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.connection import ConnectionError
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import to_list
from ansible_collections.ansible.netcommon.plugins.module_utils.network.grpc.grpc import (
get,
get_capabilities,
run_cli,
)
try:
import yaml
HAS_YAML = True
except ImportError:
HAS_YAML = False
def main():
"""entry point for module execution"""
argument_spec = dict(
section=dict(type="str", aliases=["filter"]),
command=dict(type="str"),
display=dict(type="str"),
data_type=dict(type="str"),
)
mutually_exclusive = [["section", "command"]]
module = AnsibleModule(
argument_spec=argument_spec,
mutually_exclusive=mutually_exclusive,
supports_check_mode=True,
)
capabilities = get_capabilities(module)
operations = capabilities["server_capabilities"]
if module.params["section"]:
section = json.dumps(yaml.safe_load(module.params["section"]))
else:
section = None
command = module.params["command"]
display = module.params["display"]
data_type = module.params["data_type"]
supported_display = operations.get("display", [])
if display and display not in supported_display:
module.fail_json(
msg="display option '%s' is not supported on this target host. Valid value is one of '%s'"
% (display, supported_display.join(", "))
)
if command and not operations.get("supports_cli_command", False):
module.fail_json(msg="command option '%s' is not supported on this target host" % command)
supported_data_type = operations.get("data_type", [])
if data_type and data_type not in supported_data_type:
module.fail_json(
msg="data_type option '%s' is not supported on this target host. Valid value is one of %s"
% (data_type, supported_data_type.join(","))
)
result = {"changed": False}
output = []
try:
if command:
response, err = run_cli(module, command, display)
else:
response, err = get(module, section, data_type)
try:
output = json.loads(response)
except ValueError:
module.warn(to_text(err, errors="surrogate_then_replace"))
except ConnectionError as exc:
module.fail_json(msg=to_text(exc, errors="surrogate_then_replace"), code=exc.code)
result["stdout"] = response
if output:
result["output"] = to_list(output)
else:
result["output"] = to_list(response)
module.exit_json(**result)
if __name__ == "__main__":
main()

View File

@@ -1,81 +0,0 @@
#!/usr/bin/python
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: net_banner
author: Ricardo Carrillo Cruz (@rcarrillocruz)
short_description: (deprecated, removed after 2022-06-01) Manage multiline banners
on network devices
description:
- This will configure both login and motd banners on network devices. It allows playbooks
to add or remove banner text from the active running configuration.
version_added: 1.0.0
deprecated:
alternative: Use platform-specific "[netos]_banner" module
why: Updated modules released with more functionality
removed_at_date: '2022-06-01'
extends_documentation_fragment:
- ansible.netcommon.network_agnostic
options:
banner:
description:
- Specifies which banner that should be configured on the remote device.
required: true
choices:
- login
- motd
text:
description:
- The banner text that should be present in the remote device running configuration. This
argument accepts a multiline string, with no empty lines. Requires I(state=present).
state:
description:
- Specifies whether or not the configuration is present in the current devices
active running configuration.
default: present
choices:
- present
- absent
"""
EXAMPLES = """
- name: configure the login banner
ansible.netcommon.net_banner:
banner: login
text: |
this is my login banner
that contains a multiline
string
state: present
- name: remove the motd banner
ansible.netcommon.net_banner:
banner: motd
state: absent
- name: Configure banner from file
ansible.netcommon.net_banner:
banner: motd
text: "{{ lookup('file', './config_partial/raw_banner.cfg') }}"
state: present
"""
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:
- banner login
- this is my login banner
- that contains a multiline
- string
"""

View File

@@ -2,10 +2,12 @@
# -*- coding: utf-8 -*-
# (c) 2018, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import absolute_import, division, print_function
__metaclass__ = type

View File

@@ -1,148 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: net_interface
author: Ganesh Nalawade (@ganeshrn)
short_description: (deprecated, removed after 2022-06-01) Manage Interface on network
devices
description:
- This module provides declarative management of Interfaces on network devices.
version_added: 1.0.0
deprecated:
alternative: Use platform-specific "[netos]_interfaces" module
why: Updated modules released with more functionality
removed_at_date: '2022-06-01'
extends_documentation_fragment:
- ansible.netcommon.network_agnostic
options:
name:
description:
- Name of the Interface.
required: true
description:
description:
- Description of Interface.
enabled:
description:
- Configure interface link status.
speed:
description:
- Interface link speed.
mtu:
description:
- Maximum size of transmit packet.
duplex:
description:
- Interface link status
default: auto
choices:
- full
- half
- auto
tx_rate:
description:
- Transmit rate in bits per second (bps).
- This is state check parameter only.
- Supports conditionals, see L(Conditionals in Networking Modules,../network/user_guide/network_working_with_command_output.html)
rx_rate:
description:
- Receiver rate in bits per second (bps).
- This is state check parameter only.
- Supports conditionals, see L(Conditionals in Networking Modules,../network/user_guide/network_working_with_command_output.html)
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), I(tx_rate) and I(rx_rate).
default: 10
aggregate:
description: List of Interfaces definitions.
purge:
description:
- Purge Interfaces not defined in the aggregate parameter. This applies only for
logical interface.
default: false
state:
description:
- State of the Interface configuration, C(up) indicates present and operationally
up and C(down) indicates present and operationally C(down)
default: present
choices:
- present
- absent
- up
- down
"""
EXAMPLES = """
- name: configure interface
ansible.netcommon.net_interface:
name: ge-0/0/1
description: test-interface
- name: remove interface
ansible.netcommon.net_interface:
name: ge-0/0/1
state: absent
- name: make interface up
ansible.netcommon.net_interface:
name: ge-0/0/1
description: test-interface
enabled: true
- name: make interface down
ansible.netcommon.net_interface:
name: ge-0/0/1
description: test-interface
enabled: false
- name: Create interface using aggregate
ansible.netcommon.net_interface:
aggregate:
- {name: ge-0/0/1, description: test-interface-1}
- {name: ge-0/0/2, description: test-interface-2}
speed: 1g
duplex: full
mtu: 512
- name: Delete interface using aggregate
ansible.netcommon.net_interface:
aggregate:
- {name: ge-0/0/1}
- {name: ge-0/0/2}
state: absent
- name: Check intent arguments
ansible.netcommon.net_interface:
name: fxp0
state: up
tx_rate: ge(0)
rx_rate: le(0)
- name: Config + intent
ansible.netcommon.net_interface:
name: fxp0
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:
- interface 20
- name test-interface
"""

View File

@@ -1,84 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: net_l2_interface
author: Ganesh Nalawade (@ganeshrn)
short_description: (deprecated, removed after 2022-06-01) Manage Layer-2 interface
on network devices
description:
- This module provides declarative management of Layer-2 interface on network devices.
version_added: 1.0.0
deprecated:
alternative: Use platform-specific "[netos]_l2_interfaces" module
why: Updated modules released with more functionality
removed_at_date: '2022-06-01'
extends_documentation_fragment:
- ansible.netcommon.network_agnostic
options:
name:
description:
- Name of the interface excluding any logical unit number.
aggregate:
description:
- List of Layer-2 interface definitions.
mode:
description:
- Mode in which interface needs to be configured.
default: access
choices:
- access
- trunk
access_vlan:
description:
- Configure given VLAN in access port.
trunk_vlans:
description:
- List of VLANs to be configured in trunk port.
native_vlan:
description:
- Native VLAN to be configured in trunk port.
trunk_allowed_vlans:
description:
- List of allowed VLAN's in a given trunk port.
state:
description:
- State of the Layer-2 Interface configuration.
default: present
choices:
- present
- absent
"""
EXAMPLES = """
- name: configure Layer-2 interface
ansible.netcommon.net_l2_interface:
name: gigabitethernet0/0/1
mode: access
access_vlan: 30
- name: remove Layer-2 interface configuration
ansible.netcommon.net_l2_interface:
name: gigabitethernet0/0/1
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:
- interface gigabitethernet0/0/1
- switchport mode access
- switchport access vlan 30
"""

View File

@@ -1,90 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: net_l3_interface
author: Ricardo Carrillo Cruz (@rcarrillocruz)
short_description: (deprecated, removed after 2022-06-01) Manage L3 interfaces on
network devices
description:
- This module provides declarative management of L3 interfaces on network devices.
version_added: 1.0.0
deprecated:
alternative: Use platform-specific "[netos]_l3_interfaces" module
why: Updated modules released with more functionality
removed_at_date: '2022-06-01'
extends_documentation_fragment:
- ansible.netcommon.network_agnostic
options:
name:
description:
- Name of the L3 interface.
ipv4:
description:
- IPv4 of the L3 interface.
ipv6:
description:
- IPv6 of the L3 interface.
aggregate:
description: List of L3 interfaces definitions
purge:
description:
- Purge L3 interfaces not defined in the I(aggregate) parameter.
default: false
state:
description:
- State of the L3 interface configuration.
default: present
choices:
- present
- absent
"""
EXAMPLES = """
- name: Set eth0 IPv4 address
ansible.netcommon.net_l3_interface:
name: eth0
ipv4: 192.168.0.1/24
- name: Remove eth0 IPv4 address
ansible.netcommon.net_l3_interface:
name: eth0
state: absent
- name: Set IP addresses on aggregate
ansible.netcommon.net_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
ansible.netcommon.net_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'
"""

View File

@@ -1,105 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: net_linkagg
author: Ricardo Carrillo Cruz (@rcarrillocruz)
short_description: (deprecated, removed after 2022-06-01) Manage link aggregation
groups on network devices
description:
- This module provides declarative management of link aggregation groups on network
devices.
version_added: 1.0.0
deprecated:
alternative: Use platform-specific "[netos]_lag_interfaces" module
why: Updated modules released with more functionality
removed_at_date: '2022-06-01'
extends_documentation_fragment:
- ansible.netcommon.network_agnostic
options:
name:
description:
- Name of the link aggregation group.
required: true
mode:
description:
- Mode of the link aggregation group. A value of C(on) will enable LACP. C(active)
configures the link to actively information about the state of the link, or
it can be configured in C(passive) mode ie. send link state information only
when received them from another link.
default: true
choices:
- on
- active
- passive
members:
description:
- List of members interfaces of the link aggregation group. The value can be single
interface or list of interfaces.
required: true
min_links:
description:
- Minimum members that should be up before bringing up the link aggregation group.
aggregate:
description: List of link aggregation definitions.
purge:
description:
- Purge link aggregation groups not defined in the I(aggregate) parameter.
default: false
state:
description:
- State of the link aggregation group.
default: present
choices:
- present
- absent
- up
- down
"""
EXAMPLES = """
- name: configure link aggregation group
ansible.netcommon.net_linkagg:
name: bond0
members:
- eth0
- eth1
- name: remove configuration
ansible.netcommon.net_linkagg:
name: bond0
state: absent
- name: Create aggregate of linkagg definitions
ansible.netcommon.net_linkagg:
aggregate:
- {name: bond0, members: [eth1]}
- {name: bond1, members: [eth2]}
- name: Remove aggregate of linkagg definitions
ansible.netcommon.net_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'
"""

View File

@@ -1,55 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: net_lldp
author: Ricardo Carrillo Cruz (@rcarrillocruz)
short_description: (deprecated, removed after 2022-06-01) Manage LLDP service configuration
on network devices
description:
- This module provides declarative management of LLDP service configuration on network
devices.
version_added: 1.0.0
deprecated:
alternative: Use platform-specific "[netos]_lldp_global" module
why: Updated modules released with more functionality
removed_at_date: '2022-06-01'
extends_documentation_fragment:
- ansible.netcommon.network_agnostic
options:
state:
description:
- State of the LLDP service configuration.
default: present
choices:
- present
- absent
"""
EXAMPLES = """
- name: Enable LLDP service
ansible.netcommon.net_lldp:
state: present
- name: Disable LLDP service
ansible.netcommon.net_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
"""

View File

@@ -1,92 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: net_lldp_interface
author: Ganesh Nalawade (@ganeshrn)
short_description: (deprecated, removed after 2022-06-01) Manage LLDP interfaces configuration
on network devices
description:
- This module provides declarative management of LLDP interfaces configuration on
network devices.
version_added: 1.0.0
deprecated:
alternative: Use platform-specific "[netos]_lldp_interfaces" module
why: Updated modules released with more functionality
removed_at_date: '2022-06-01'
extends_documentation_fragment:
- ansible.netcommon.network_agnostic
options:
name:
description:
- Name of the interface LLDP should be configured on.
aggregate:
description: List of interfaces LLDP should be configured on.
purge:
description:
- Purge interfaces not defined in the aggregate parameter.
default: false
state:
description:
- State of the LLDP configuration.
default: present
choices:
- present
- absent
- enabled
- disabled
"""
EXAMPLES = """
- name: Configure LLDP on specific interfaces
ansible.netcommon.net_lldp_interface:
name: eth1
state: present
- name: Disable LLDP on specific interfaces
ansible.netcommon.net_lldp_interface:
name: eth1
state: disabled
- name: Enable LLDP on specific interfaces
ansible.netcommon.net_lldp_interface:
name: eth1
state: enabled
- name: Delete LLDP on specific interfaces
ansible.netcommon.net_lldp_interface:
name: eth1
state: absent
- name: Create aggregate of LLDP interface configurations
ansible.netcommon.net_lldp_interface:
aggregate:
- {name: eth1}
- {name: eth2}
state: present
- name: Delete aggregate of LLDP interface configurations
ansible.netcommon.net_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 disable
"""

View File

@@ -1,107 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: net_logging
author: Ganesh Nalawade (@ganeshrn)
short_description: (deprecated, removed after 2022-06-01) Manage logging on network
devices
description:
- This module provides declarative management of logging on network devices.
version_added: 1.0.0
deprecated:
alternative: Use platform-specific "[netos]_logging" module
why: Updated modules released with more functionality
removed_at_date: '2022-06-01'
extends_documentation_fragment:
- ansible.netcommon.network_agnostic
options:
dest:
description:
- Destination of the logs.
choices:
- console
- host
name:
description:
- If value of C(dest) is I(host) it indicates file-name the host name to be notified.
facility:
description:
- Set logging facility.
level:
description:
- Set logging severity levels.
aggregate:
description: List of logging definitions.
purge:
description:
- Purge logging not defined in the I(aggregate) parameter.
default: false
state:
description:
- State of the logging configuration.
default: present
choices:
- present
- absent
"""
EXAMPLES = """
- name: configure console logging
ansible.netcommon.net_logging:
dest: console
facility: any
level: critical
- name: remove console logging configuration
ansible.netcommon.net_logging:
dest: console
state: absent
- name: configure host logging
ansible.netcommon.net_logging:
dest: host
name: 192.0.2.1
facility: kernel
level: critical
- name: Configure file logging using aggregate
ansible.netcommon.net_logging:
dest: file
aggregate:
- name: test-1
facility: pfe
level: critical
- name: test-2
facility: kernel
level: emergency
- name: Delete file logging using aggregate
ansible.netcommon.net_logging:
dest: file
aggregate:
- name: test-1
facility: pfe
level: critical
- name: test-2
facility: kernel
level: emergency
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:
- logging console critical
"""

View File

@@ -2,10 +2,12 @@
# -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import absolute_import, division, print_function
__metaclass__ = type

View File

@@ -2,10 +2,12 @@
# -*- coding: utf-8 -*-
# (c) 2018, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import absolute_import, division, print_function
__metaclass__ = type

View File

@@ -1,94 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: net_static_route
author: Ricardo Carrillo Cruz (@rcarrillocruz)
short_description: (deprecated, removed after 2022-06-01) Manage static IP routes
on network appliances (routers, switches et. al.)
description:
- This module provides declarative management of static IP routes on network appliances
(routers, switches et. al.).
version_added: 1.0.0
deprecated:
alternative: Use platform-specific "[netos]_static_route" module
why: Updated modules released with more functionality
removed_at_date: '2022-06-01'
extends_documentation_fragment:
- ansible.netcommon.network_agnostic
options:
prefix:
description:
- Network prefix of the static route.
required: true
mask:
description:
- Network prefix mask of the static route.
required: true
next_hop:
description:
- Next hop IP of the static route.
required: true
admin_distance:
description:
- Admin distance of the static route.
aggregate:
description: List of static route definitions
purge:
description:
- Purge static routes not defined in the I(aggregate) parameter.
default: false
state:
description:
- State of the static route configuration.
default: present
choices:
- present
- absent
"""
EXAMPLES = """
- name: configure static route
ansible.netcommon.net_static_route:
prefix: 192.168.2.0
mask: 255.255.255.0
next_hop: 10.0.0.1
- name: remove configuration
ansible.netcommon.net_static_route:
prefix: 192.168.2.0
mask: 255.255.255.0
next_hop: 10.0.0.1
state: absent
- name: configure aggregates of static routes
ansible.netcommon.net_static_route:
aggregate:
- {prefix: 192.168.2.0, mask: 255.255.255.0, next_hop: 10.0.0.1}
- {prefix: 192.168.3.0, mask: 255.255.255.0, next_hop: 10.0.2.1}
- name: Remove static route collections
ansible.netcommon.net_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:
- ip route 192.168.2.0/24 10.0.0.1
"""

View File

@@ -1,100 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: net_system
author: Ricardo Carrillo Cruz (@rcarrillocruz)
short_description: (deprecated, removed after 2022-06-01) Manage the system attributes
on network devices
description:
- This module provides declarative management of node system attributes on network
devices. It provides an option to configure host system parameters or remove those
parameters from the device active configuration.
version_added: 1.0.0
deprecated:
alternative: Use platform-specific "[netos]_system" module
why: Updated modules released with more functionality
removed_at_date: '2022-06-01'
extends_documentation_fragment:
- ansible.netcommon.network_agnostic
options:
hostname:
description:
- Configure the device hostname parameter. This option takes an ASCII string value.
domain_name:
description:
- Configure the IP domain name on the remote device to the provided value. Value
should be in the dotted name form and will be appended to the C(hostname) to
create a fully-qualified domain name.
domain_search:
description:
- Provides the list of domain suffixes to append to the hostname for the purpose
of doing name resolution. This argument accepts a name or list of names and
will be reconciled with the current active configuration on the running node.
lookup_source:
description:
- Provides one or more source interfaces to use for performing DNS lookups. The
interface provided in C(lookup_source) must be a valid interface configured
on the device.
name_servers:
description:
- List of DNS name servers by IP address to use to perform name resolution lookups. This
argument accepts either a list of DNS servers See examples.
state:
description:
- State of the configuration values in the device's current active configuration. When
set to I(present), the values should be configured in the device active configuration
and when set to I(absent) the values should not be in the device active configuration
default: present
choices:
- present
- absent
"""
EXAMPLES = """
- name: configure hostname and domain name
ansible.netcommon.net_system:
hostname: ios01
domain_name: test.example.com
domain_search:
- ansible.com
- redhat.com
- cisco.com
- name: domain search on single domain
ansible.netcommon.net_system:
domain_search: ansible.com
- name: remove configuration
ansible.netcommon.net_system:
state: absent
- name: configure DNS lookup sources
ansible.netcommon.net_system:
lookup_source: MgmtEth0/0/CPU0/0
- name: configure name servers
ansible.netcommon.net_system:
name_servers:
- 8.8.8.8
- 8.8.4.4
"""
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:
- hostname ios01
- ip domain name test.example.com
"""

View File

@@ -1,128 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: net_user
author: Trishna Guha (@trishnaguha)
short_description: (deprecated, removed after 2022-06-01) Manage the aggregate of
local users on network device
description:
- This module provides declarative management of the local usernames configured on
network devices. It allows playbooks to manage either individual usernames or the
aggregate 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
deprecated:
alternative: Use platform-specific "[netos]_user" module
why: Updated modules released with more functionality
removed_at_date: '2022-06-01'
extends_documentation_fragment:
- ansible.netcommon.network_agnostic
options:
aggregate:
description:
- The set of username objects to be configured on the remote network device. The
list entries can either be the username or a hash of username and properties.
This argument is mutually exclusive with the C(name) argument.
name:
description:
- The username to be configured on the remote network 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).
configured_password:
description:
- The password to be configured on the remote network 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).
update_password:
description:
- Since passwords are encrypted in the device running config, this argument will
instruct the module when to change the password. When set to C(always), the
password will always be updated in the device and when set to C(on_create) the
password will be updated only if the username is created.
default: always
choices:
- on_create
- always
privilege:
description:
- The C(privilege) argument configures the privilege level of the user when logged
into the system. This argument accepts integer values in the range of 1 to 15.
role:
description:
- Configures the role for the username in the device running configuration. The
argument accepts a string value defining the role name. This argument does not
check if the role has been configured on the device.
sshkey:
description:
- Specifies the SSH public key to configure for the given username. This argument
accepts a valid SSH key value.
nopassword:
description:
- Defines the username without assigning a password. This will allow the user
to login to the system without being authenticated by a password.
type: bool
purge:
description:
- Instructs the module to consider the resource definition absolute. It will remove
any previously configured usernames on the device with the exception of the
`admin` user (the current defined set of users).
type: bool
default: false
state:
description:
- Configures the state of the username definition as it relates to the device
operational configuration. When set to I(present), the username(s) should be
configured in the device active configuration and when set to I(absent) the
username(s) should not be in the device active configuration
default: present
choices:
- present
- absent
"""
EXAMPLES = """
- name: create a new user
ansible.netcommon.net_user:
name: ansible
sshkey: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
state: present
- name: remove all users except admin
ansible.netcommon.net_user:
purge: yes
- name: set multiple users to privilege level 15
ansible.netcommon.net_user:
aggregate:
- {name: netop}
- {name: netend}
privilege: 15
state: present
- name: Change Password for User netop
ansible.netcommon.net_user:
name: netop
configured_password: '{{ new_password }}'
update_password: always
state: present
"""
RETURN = """
commands:
description: The list of configuration mode commands to send to the device
returned: always
type: list
sample:
- username ansible secret password
- username admin secret admin
"""

View File

@@ -1,79 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: net_vlan
author: Ricardo Carrillo Cruz (@rcarrillocruz)
short_description: (deprecated, removed after 2022-06-01) Manage VLANs on network
devices
description:
- This module provides declarative management of VLANs on network devices.
version_added: 1.0.0
deprecated:
alternative: Use platform-specific "[netos]_vlans" module
why: Updated modules released with more functionality
removed_at_date: '2022-06-01'
extends_documentation_fragment:
- ansible.netcommon.network_agnostic
options:
name:
description:
- Name of the VLAN.
vlan_id:
description:
- ID of the VLAN.
interfaces:
description:
- List of interfaces the VLAN should be configured on.
aggregate:
description: List of VLANs definitions.
purge:
description:
- Purge VLANs not defined in the I(aggregate) parameter.
default: false
state:
description:
- State of the VLAN configuration.
default: present
choices:
- present
- absent
- active
- suspend
"""
EXAMPLES = """
- name: configure VLAN ID and name
ansible.netcommon.net_vlan:
vlan_id: 20
name: test-vlan
- name: remove configuration
ansible.netcommon.net_vlan:
state: absent
- name: configure VLAN state
ansible.netcommon.net_vlan:
vlan_id:
state: suspend
"""
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:
- vlan 20
- name test-vlan
"""

View File

@@ -1,85 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: net_vrf
author: Ricardo Carrillo Cruz (@rcarrillocruz)
short_description: (deprecated, removed after 2022-06-01) Manage VRFs on network devices
description:
- This module provides declarative management of VRFs on network devices.
version_added: 1.0.0
deprecated:
alternative: Use platform-specific "[netos]_vrf" module
why: Updated modules released with more functionality
removed_at_date: '2022-06-01'
extends_documentation_fragment:
- ansible.netcommon.network_agnostic
options:
name:
description:
- Name of the VRF.
interfaces:
description:
- List of interfaces the VRF should be configured on.
aggregate:
description: List of VRFs definitions
purge:
description:
- Purge VRFs not defined in the I(aggregate) parameter.
default: false
state:
description:
- State of the VRF configuration.
default: present
choices:
- present
- absent
"""
EXAMPLES = """
- name: Create VRF named MANAGEMENT
ansible.netcommon.net_vrf:
name: MANAGEMENT
- name: remove VRF named MANAGEMENT
ansible.netcommon.net_vrf:
name: MANAGEMENT
state: absent
- name: Create aggregate of VRFs with purge
ansible.netcommon.net_vrf:
aggregate:
- name: test4
rd: 1:204
- name: test5
rd: 1:205
state: present
purge: yes
- name: Delete aggregate of VRFs
ansible.netcommon.net_vrf:
aggregate:
- name: test2
- name: test3
- name: test4
- name: test5
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:
- vrf definition MANAGEMENT
"""

View File

@@ -1,213 +1,216 @@
#!/usr/bin/python
# (c) 2016, Leandro Lisboa Penz <lpenz at lpenz.org>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: netconf_config
author:
- Leandro Lisboa Penz (@lpenz)
- Ganesh Nalawade (@ganeshrn)
- Leandro Lisboa Penz (@lpenz)
- Ganesh Nalawade (@ganeshrn)
short_description: netconf device configuration
description:
- Netconf is a network management protocol developed and standardized by the IETF.
It is documented in RFC 6241.
- This module allows the user to send a configuration XML file to a netconf device,
and detects if there was a configuration change.
- Netconf is a network management protocol developed and standardized by the IETF.
It is documented in RFC 6241.
- This module allows the user to send a configuration XML file to a netconf device,
and detects if there was a configuration change.
version_added: 1.0.0
extends_documentation_fragment:
- ansible.netcommon.network_agnostic
- ansible.netcommon.network_agnostic
options:
content:
description:
- The configuration data as defined by the device's data models, the value can
be either in xml string format or text format or python dictionary representation of JSON format.
- In case of json string format it will be converted to the corresponding xml string using
xmltodict library before pushing onto the remote host.
- In case the value of this option isn I(text) format the format should be supported by remote Netconf server.
- If the value of C(content) option is in I(xml) format in that case the xml value should
have I(config) as root tag.
- The configuration data as defined by the device's data models, the value can
be either in xml string format or text format or python dictionary representation of JSON format.
- In case of json string format it will be converted to the corresponding xml string using
xmltodict library before pushing onto the remote host.
- In case the value of this option isn I(text) format the format should be supported by remote Netconf server.
- If the value of C(content) option is in I(xml) format in that case the xml value should
have I(config) as root tag.
type: raw
aliases:
- xml
- xml
target:
description: Name of the configuration datastore to be edited. - auto, uses candidate
description:
Name of the configuration datastore to be edited. - auto, uses candidate
and fallback to running - candidate, edit <candidate/> datastore and then commit
- running, edit <running/> datastore directly
default: auto
type: str
choices:
- auto
- candidate
- running
- auto
- candidate
- running
aliases:
- datastore
- datastore
source_datastore:
description:
- Name of the configuration datastore to use as the source to copy the configuration
to the datastore mentioned by C(target) option. The values can be either I(running),
I(candidate), I(startup) or a remote URL
- Name of the configuration datastore to use as the source to copy the configuration
to the datastore mentioned by C(target) option. The values can be either I(running),
I(candidate), I(startup) or a remote URL
type: str
aliases:
- source
- source
format:
description:
- The format of the configuration provided as value of C(content).
- In case of json string format it will be converted to the corresponding xml string using
xmltodict library before pushing onto the remote host.
- In case of I(text) format of the configuration should be supported by remote Netconf server.
- If the value of C(format) options is not given it tries to guess the data format of
C(content) option as one of I(xml) or I(json) or I(text).
- If the data format is not identified it is set to I(xml) by default.
- The format of the configuration provided as value of C(content).
- In case of json string format it will be converted to the corresponding xml string using
xmltodict library before pushing onto the remote host.
- In case of I(text) format of the configuration should be supported by remote Netconf server.
- If the value of C(format) options is not given it tries to guess the data format of
C(content) option as one of I(xml) or I(json) or I(text).
- If the data format is not identified it is set to I(xml) by default.
type: str
choices:
- xml
- text
- json
- xml
- text
- json
lock:
description:
- Instructs the module to explicitly lock the datastore specified as C(target).
By setting the option value I(always) is will explicitly lock the datastore
mentioned in C(target) option. It the value is I(never) it will not lock the
C(target) datastore. The value I(if-supported) lock the C(target) datastore
only if it is supported by the remote Netconf server.
- Instructs the module to explicitly lock the datastore specified as C(target).
By setting the option value I(always) is will explicitly lock the datastore
mentioned in C(target) option. It the value is I(never) it will not lock the
C(target) datastore. The value I(if-supported) lock the C(target) datastore
only if it is supported by the remote Netconf server.
type: str
default: always
choices:
- never
- always
- if-supported
- never
- always
- if-supported
default_operation:
description:
- The default operation for <edit-config> rpc, valid values are I(merge), I(replace)
and I(none). If the default value is merge, the configuration data in the C(content)
option is merged at the corresponding level in the C(target) datastore. If the
value is replace the data in the C(content) option completely replaces the configuration
in the C(target) datastore. If the value is none the C(target) datastore is
unaffected by the configuration in the config option, unless and until the incoming
configuration data uses the C(operation) operation to request a different operation.
- The default operation for <edit-config> rpc, valid values are I(merge), I(replace)
and I(none). If the default value is merge, the configuration data in the C(content)
option is merged at the corresponding level in the C(target) datastore. If the
value is replace the data in the C(content) option completely replaces the configuration
in the C(target) datastore. If the value is none the C(target) datastore is
unaffected by the configuration in the config option, unless and until the incoming
configuration data uses the C(operation) operation to request a different operation.
type: str
choices:
- merge
- replace
- none
- merge
- replace
- none
confirm:
description:
- This argument will configure a timeout value for the commit to be confirmed
before it is automatically rolled back. If the C(confirm_commit) argument is
set to False, this argument is silently ignored. If the value of this argument
is set to 0, the commit is confirmed immediately. The remote host MUST support
:candidate and :confirmed-commit capability for this option to .
- This argument will configure a timeout value for the commit to be confirmed
before it is automatically rolled back. If the C(confirm_commit) argument is
set to False, this argument is silently ignored. If the value of this argument
is set to 0, the commit is confirmed immediately. The remote host MUST support
:candidate and :confirmed-commit capability for this option to .
type: int
default: 0
confirm_commit:
description:
- This argument will execute commit operation on remote device. It can be used
to confirm a previous commit.
- This argument will execute commit operation on remote device. It can be used
to confirm a previous commit.
type: bool
default: no
error_option:
description:
- This option controls the netconf server action after an error occurs while editing
the configuration.
- If I(error_option=stop-on-error), abort the config edit on first error.
- If I(error_option=continue-on-error), continue to process configuration data
on error. The error is recorded and negative response is generated if any errors
occur.
- If I(error_option=rollback-on-error), rollback to the original configuration
if any error occurs. This requires the remote Netconf server to support the
I(error_option=rollback-on-error) capability.
- This option controls the netconf server action after an error occurs while editing
the configuration.
- If I(error_option=stop-on-error), abort the config edit on first error.
- If I(error_option=continue-on-error), continue to process configuration data
on error. The error is recorded and negative response is generated if any errors
occur.
- If I(error_option=rollback-on-error), rollback to the original configuration
if any error occurs. This requires the remote Netconf server to support the
I(error_option=rollback-on-error) capability.
default: stop-on-error
type: str
choices:
- stop-on-error
- continue-on-error
- rollback-on-error
- stop-on-error
- continue-on-error
- rollback-on-error
save:
description:
- The C(save) argument instructs the module to save the configuration in C(target)
datastore to the startup-config if changed and if :startup capability is supported
by Netconf server.
- The C(save) argument instructs the module to save the configuration in C(target)
datastore to the startup-config if changed and if :startup capability is supported
by Netconf server.
default: false
type: bool
backup:
description:
- This argument will cause the module to create a full backup of the current C(running-config)
from the remote device before any changes are made. If the C(backup_options)
value is not given, the backup file is written to the C(backup) folder in the
playbook root directory or role root directory, if playbook is part of an ansible
role. If the directory does not exist, it is created.
- This argument will cause the module to create a full backup of the current C(running-config)
from the remote device before any changes are made. If the C(backup_options)
value is not given, the backup file is written to the C(backup) folder in the
playbook root directory or role root directory, if playbook is part of an ansible
role. If the directory does not exist, it is created.
type: bool
default: no
delete:
description:
- It instructs the module to delete the configuration from value mentioned in
C(target) datastore.
- It instructs the module to delete the configuration from value mentioned in
C(target) datastore.
type: bool
default: no
commit:
description:
- This boolean flag controls if the configuration changes should be committed
or not after editing the candidate datastore. This option is supported only
if remote Netconf server supports :candidate capability. If the value is set
to I(False) commit won't be issued after edit-config operation and user needs
to handle commit or discard-changes explicitly.
- This boolean flag controls if the configuration changes should be committed
or not after editing the candidate datastore. This option is supported only
if remote Netconf server supports :candidate capability. If the value is set
to I(False) commit won't be issued after edit-config operation and user needs
to handle commit or discard-changes explicitly.
type: bool
default: true
validate:
description:
- This boolean flag if set validates the content of datastore given in C(target)
option. For this option to work remote Netconf server should support :validate
capability.
- This boolean flag if set validates the content of datastore given in C(target)
option. For this option to work remote Netconf server should support :validate
capability.
type: bool
default: false
backup_options:
description:
- This is a dict object containing configurable options related to backup file
path. The value of this option is read only when C(backup) is set to I(yes),
if C(backup) is set to I(no) this option will be silently ignored.
- This is a dict object containing configurable options related to backup file
path. The value of this option is read only when C(backup) is set to I(yes),
if C(backup) is set to I(no) this option will be silently ignored.
suboptions:
filename:
description:
- The filename to be used to store the backup configuration. If the filename
is not given it will be generated based on the hostname, current time and
date in format defined by <hostname>_config.<current-date>@<current-time>
- The filename to be used to store the backup configuration. If the filename
is not given it will be generated based on the hostname, current time and
date in format defined by <hostname>_config.<current-date>@<current-time>
type: str
dir_path:
description:
- This option provides the path ending with directory name in which the backup
configuration file will be stored. If the directory does not exist it will
be first created and the filename is either the value of C(filename) or
default filename as described in C(filename) options description. If the
path value is not given in that case a I(backup) directory will be created
in the current working directory and backup configuration will be copied
in C(filename) within I(backup) directory.
- This option provides the path ending with directory name in which the backup
configuration file will be stored. If the directory does not exist it will
be first created and the filename is either the value of C(filename) or
default filename as described in C(filename) options description. If the
path value is not given in that case a I(backup) directory will be created
in the current working directory and backup configuration will be copied
in C(filename) within I(backup) directory.
type: path
type: dict
get_filter:
description:
- This argument specifies the XML string which acts as a filter to restrict the
portions of the data retrieved from the remote device when comparing the before
and after state of the device following calls to edit_config. When not specified,
the entire configuration or state data is returned for comparison depending
on the value of C(source) option. The C(get_filter) value can be either XML
string or XPath or JSON string or native python dictionary, if the filter is
in XPath format the NETCONF server running on remote host should support xpath
capability else it will result in an error.
- This argument specifies the XML string which acts as a filter to restrict the
portions of the data retrieved from the remote device when comparing the before
and after state of the device following calls to edit_config. When not specified,
the entire configuration or state data is returned for comparison depending
on the value of C(source) option. The C(get_filter) value can be either XML
string or XPath or JSON string or native python dictionary, if the filter is
in XPath format the NETCONF server running on remote host should support xpath
capability else it will result in an error.
type: raw
requirements:
- ncclient
- ncclient
notes:
- This module requires the netconf system service be enabled on the remote device
being managed.
- This module supports devices with and without the candidate and confirmed-commit
capabilities. It will always use the safer feature.
- This module supports the use of connection=netconf
- This module requires the netconf system service be enabled on the remote device
being managed.
- This module supports devices with and without the candidate and confirmed-commit
capabilities. It will always use the safer feature.
- This module supports the use of connection=netconf
"""
EXAMPLES = """
@@ -246,14 +249,14 @@ EXAMPLES = """
- name: configure interface while providing different private key file path (for connection=netconf)
ansible.netcommon.netconf_config:
backup: yes
backup: true
register: backup_junos_location
vars:
ansible_private_key_file: /home/admin/.ssh/newprivatekeyfile
- name: configurable backup path
ansible.netcommon.netconf_config:
backup: yes
backup: true
backup_options:
filename: backup.cfg
dir_path: /home/user
@@ -261,49 +264,54 @@ EXAMPLES = """
- name: "configure using direct native format configuration (cisco iosxr)"
ansible.netcommon.netconf_config:
format: json
content: {
"config": {
"interface-configurations": {
"@xmlns": "http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg",
"interface-configuration": {
"active": "act",
"description": "test for ansible Loopback999",
"interface-name": "Loopback999"
}
}
}
}
get_filter: {
"interface-configurations": {
"@xmlns": "http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg",
"interface-configuration": null
}
}
content:
{
"config":
{
"interface-configurations":
{
"@xmlns": "http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg",
"interface-configuration":
{
"active": "act",
"description": "test for ansible Loopback999",
"interface-name": "Loopback999",
},
},
},
}
get_filter:
{
"interface-configurations":
{
"@xmlns": "http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg",
"interface-configuration": null,
},
}
- name: "configure using json string format configuration (cisco iosxr)"
ansible.netcommon.netconf_config:
format: json
content: |
{
"config": {
"interface-configurations": {
"@xmlns": "http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg",
"interface-configuration": {
"active": "act",
"description": "test for ansible Loopback999",
"interface-name": "Loopback999"
}
}
}
}
get_filter: |
{
"interface-configurations": {
"@xmlns": "http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg",
"interface-configuration": null
{
"config": {
"interface-configurations": {
"@xmlns": "http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg",
"interface-configuration": {
"active": "act",
"description": "test for ansible Loopback999",
"interface-name": "Loopback999"
}
}
}
}
get_filter: |
{
"interface-configurations": {
"@xmlns": "http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg",
"interface-configuration": null
}
}
# Make a round-trip interface description change, diff the before and after
# this demonstrates the use of the native display format and several utilities
@@ -327,8 +335,8 @@ EXAMPLES = """
- name: Update the description
ansible.utils.update_fact:
updates:
- path: pre.output.data.interfaces.interface.config.description
value: "Configured by ansible {{ 100 | random }}"
- path: pre.output.data.interfaces.interface.config.description
value: "Configured by ansible {{ 100 | random }}"
register: updated
- name: Apply the new configuration
@@ -348,7 +356,6 @@ EXAMPLES = """
ansible.utils.fact_diff:
before: "{{ pre.output.data|ansible.utils.to_paths }}"
after: "{{ post.output.data|ansible.utils.to_paths }}"
# TASK [Show the differences between the pre and post configurations] ********
# --- before
# +++ after
@@ -366,47 +373,55 @@ EXAMPLES = """
# "interfaces.interface.config.enabled": "true",
# "interfaces.interface.config.mtu": "0",
# "interfaces.interface.config.name": "Ethernet2",
"""
RETURN = """
server_capabilities:
description: list of capabilities of the server
returned: success
type: list
sample: ['urn:ietf:params:netconf:base:1.1','urn:ietf:params:netconf:capability:confirmed-commit:1.0','urn:ietf:params:netconf:capability:candidate:1.0']
description: list of capabilities of the server
returned: success
type: list
sample:
[
"urn:ietf:params:netconf:base:1.1",
"urn:ietf:params:netconf:capability:confirmed-commit:1.0",
"urn:ietf:params:netconf:capability:candidate:1.0",
]
backup_path:
description: The full path to the backup file
returned: when backup is yes
type: str
sample: /playbooks/ansible/backup/config.2016-07-16@22:28:34
diff:
description: If --diff option in enabled while running, the before and after configuration change are
returned as part of before and after key.
description:
If --diff option in enabled while running, the before and after configuration change are
returned as part of before and after key.
returned: when diff is enabled
type: dict
sample:
"after": "<rpc-reply>\n<data>\n<configuration>\n<version>17.3R1.10</version>...<--snip-->"
"before": "<rpc-reply>\n<data>\n<configuration>\n <version>17.3R1.10</version>...<--snip-->"
"""
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.connection import Connection, ConnectionError
from ansible_collections.ansible.netcommon.plugins.module_utils.utils.data import (
validate_and_normalize_data,
dict_to_xml,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.netconf.netconf import (
get_capabilities,
get_config,
sanitize_xml,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.utils.data import (
dict_to_xml,
validate_and_normalize_data,
)
try:
from lxml.etree import tostring, fromstring
from lxml.etree import fromstring, tostring
except ImportError:
from xml.etree.ElementTree import tostring, fromstring
from xml.etree.ElementTree import fromstring, tostring
def validate_config(module, config, format="xml"):
@@ -436,9 +451,7 @@ def main():
),
source_datastore=dict(aliases=["source"]),
format=dict(choices=["xml", "text", "json"]),
lock=dict(
choices=["never", "always", "if-supported"], default="always"
),
lock=dict(choices=["never", "always", "if-supported"], default="always"),
default_operation=dict(choices=["merge", "replace", "none"]),
confirm=dict(type="int", default=0),
confirm_commit=dict(type="bool", default=False),
@@ -459,12 +472,8 @@ def main():
get_filter=dict(type="raw"),
)
mutually_exclusive = [
("content", "source_datastore", "delete", "confirm_commit")
]
required_one_of = [
("content", "source_datastore", "delete", "confirm_commit")
]
mutually_exclusive = [("content", "source_datastore", "delete", "confirm_commit")]
required_one_of = [("content", "source_datastore", "delete", "confirm_commit")]
module = AnsibleModule(
argument_spec=argument_spec,
@@ -512,8 +521,7 @@ def main():
pass
else:
module.fail_json(
msg="Invalid filter type detected %s for get_filter value %s"
% (filter_type, filter)
msg="Invalid filter type detected %s for get_filter value %s" % (filter_type, filter)
)
conn = Connection(module._socket_path)
@@ -521,20 +529,14 @@ def main():
operations = capabilities["device_operations"]
supports_commit = operations.get("supports_commit", False)
supports_writable_running = operations.get(
"supports_writable_running", False
)
supports_writable_running = operations.get("supports_writable_running", False)
supports_startup = operations.get("supports_startup", False)
# identify target datastore
if target == "candidate" and not supports_commit:
module.fail_json(
msg=":candidate is not supported by this netconf server"
)
module.fail_json(msg=":candidate is not supported by this netconf server")
elif target == "running" and not supports_writable_running:
module.fail_json(
msg=":writable-running is not supported by this netconf server"
)
module.fail_json(msg=":writable-running is not supported by this netconf server")
elif target == "auto":
if supports_commit:
target = "candidate"
@@ -548,14 +550,11 @@ def main():
# Netconf server capability validation against input options
if save and not supports_startup:
module.fail_json(
msg="cannot copy <%s/> to <startup/>, while :startup is not supported"
% target
msg="cannot copy <%s/> to <startup/>, while :startup is not supported" % target
)
if confirm_commit and not operations.get("supports_confirm_commit", False):
module.fail_json(
msg="confirm commit is not supported by Netconf server"
)
module.fail_json(msg="confirm commit is not supported by Netconf server")
if (confirm > 0) and not operations.get("supports_confirm_commit", False):
module.fail_json(
@@ -564,14 +563,11 @@ def main():
)
if validate and not operations.get("supports_validate", False):
module.fail_json(
msg="validate is not supported by this netconf server"
)
module.fail_json(msg="validate is not supported by this netconf server")
if filter_type == "xpath" and not operations.get("supports_xpath", False):
module.fail_json(
msg="filter value '%s' of type xpath is not supported on this device"
% filter
msg="filter value '%s' of type xpath is not supported on this device" % filter
)
filter_spec = (filter_type, filter) if filter_type else None
@@ -583,10 +579,7 @@ def main():
execute_lock = True
else:
# lock is requested (always/if-supported) but not supported => issue warning
module.warn(
"lock operation on '%s' source is not supported on this device"
% target
)
module.warn("lock operation on '%s' source is not supported on this device" % target)
execute_lock = lock == "always"
result = {
@@ -598,12 +591,8 @@ def main():
locked = False
try:
if module.params["backup"]:
response = get_config(
module, target, filter_spec, lock=execute_lock
)
before = to_text(
tostring(response), errors="surrogate_then_replace"
).strip()
response = get_config(module, target, filter_spec, lock=execute_lock)
before = to_text(tostring(response), errors="surrogate_then_replace").strip()
result["__backup__"] = before.strip()
if validate:
conn.validate(target)
@@ -639,9 +628,7 @@ def main():
if format != "text":
# check for format of type json/xml/xpath
try:
config_obj, config_format = validate_and_normalize_data(
config, format
)
config_obj, config_format = validate_and_normalize_data(config, format)
except Exception as exc:
module.fail_json(msg=to_text(exc))
@@ -679,9 +666,7 @@ def main():
if not module.check_mode:
confirm_timeout = confirm if confirm > 0 else None
confirmed_commit = True if confirm_timeout else False
conn.commit(
confirmed=confirmed_commit, timeout=confirm_timeout
)
conn.commit(confirmed=confirmed_commit, timeout=confirm_timeout)
else:
conn.discard_changes()
@@ -706,9 +691,7 @@ def main():
}
except ConnectionError as e:
module.fail_json(
msg=to_text(e, errors="surrogate_then_replace").strip()
)
module.fail_json(msg=to_text(e, errors="surrogate_then_replace").strip())
finally:
if locked:
conn.unlock(target=target)

View File

@@ -2,87 +2,89 @@
# -*- coding: utf-8 -*-
# (c) 2018, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: netconf_get
author:
- Ganesh Nalawade (@ganeshrn)
- Sven Wisotzky (@wisotzky)
- Ganesh Nalawade (@ganeshrn)
- Sven Wisotzky (@wisotzky)
short_description: Fetch configuration/state data from NETCONF enabled network devices.
description:
- NETCONF is a network management protocol developed and standardized by the IETF.
It is documented in RFC 6241.
- This module allows the user to fetch configuration and state data from NETCONF enabled
network devices.
- NETCONF is a network management protocol developed and standardized by the IETF.
It is documented in RFC 6241.
- This module allows the user to fetch configuration and state data from NETCONF enabled
network devices.
version_added: 1.0.0
extends_documentation_fragment:
- ansible.netcommon.network_agnostic
- ansible.netcommon.network_agnostic
options:
source:
description:
- This argument specifies the datastore from which configuration data should be
fetched. Valid values are I(running), I(candidate) and I(startup). If the C(source)
value is not set both configuration and state information are returned in response
from running datastore.
- This argument specifies the datastore from which configuration data should be
fetched. Valid values are I(running), I(candidate) and I(startup). If the C(source)
value is not set both configuration and state information are returned in response
from running datastore.
type: str
choices:
- running
- candidate
- startup
- running
- candidate
- startup
filter:
description:
- This argument specifies the string which acts as a filter to restrict the
portions of the data to be are retrieved from the remote device. If this option
is not specified entire configuration or state data is returned in result depending
on the value of C(source) option. The C(filter) value can be either XML string
or XPath or JSON string or native python dictionary, if the filter is in XPath
format the NETCONF server running on remote host should support xpath capability
else it will result in an error. If the filter is in JSON format the xmltodict library
should be installed on the control node for JSON to XML conversion.
- This argument specifies the string which acts as a filter to restrict the
portions of the data to be are retrieved from the remote device. If this option
is not specified entire configuration or state data is returned in result depending
on the value of C(source) option. The C(filter) value can be either XML string
or XPath or JSON string or native python dictionary, if the filter is in XPath
format the NETCONF server running on remote host should support xpath capability
else it will result in an error. If the filter is in JSON format the xmltodict library
should be installed on the control node for JSON to XML conversion.
type: raw
display:
description:
- Encoding scheme to use when serializing output from the device. The option I(json)
will serialize the output as JSON data. If the option value is I(json) it requires
jxmlease to be installed on control node. The option I(pretty) is similar to
received XML response but is using human readable format (spaces, new lines).
The option value I(xml) is similar to received XML response but removes all
XML namespaces.
- Encoding scheme to use when serializing output from the device. The option I(json)
will serialize the output as JSON data. If the option value is I(json) it requires
jxmlease to be installed on control node. The option I(pretty) is similar to
received XML response but is using human readable format (spaces, new lines).
The option value I(xml) is similar to received XML response but removes all
XML namespaces.
type: str
choices:
- json
- pretty
- xml
- native
- json
- pretty
- xml
- native
lock:
description:
- Instructs the module to explicitly lock the datastore specified as C(source).
If no I(source) is defined, the I(running) datastore will be locked. By setting
the option value I(always) is will explicitly lock the datastore mentioned in
C(source) option. By setting the option value I(never) it will not lock the
C(source) datastore. The value I(if-supported) allows better interworking with
NETCONF servers, which do not support the (un)lock operation for all supported
datastores.
- Instructs the module to explicitly lock the datastore specified as C(source).
If no I(source) is defined, the I(running) datastore will be locked. By setting
the option value I(always) is will explicitly lock the datastore mentioned in
C(source) option. By setting the option value I(never) it will not lock the
C(source) datastore. The value I(if-supported) allows better interworking with
NETCONF servers, which do not support the (un)lock operation for all supported
datastores.
type: str
default: never
choices:
- never
- always
- if-supported
- never
- always
- if-supported
requirements:
- ncclient (>=v0.5.2)
- jxmlease (for display=json)
- xmltodict (for display=native)
- ncclient (>=v0.5.2)
- jxmlease (for display=json)
- xmltodict (for display=native)
notes:
- This module requires the NETCONF system service be enabled on the remote device
being managed.
- This module supports the use of connection=netconf
- This module requires the NETCONF system service be enabled on the remote device
being managed.
- This module supports the use of connection=netconf
"""
EXAMPLES = """
@@ -137,12 +139,12 @@ EXAMPLES = """
- name: "get configuration with json filter string and native output (using xmltodict)"
netconf_get:
filter: |
{
"interface-configurations": {
"@xmlns": "http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg",
"interface-configuration": null
}
}
{
"interface-configurations": {
"@xmlns": "http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg",
"interface-configuration": null
}
}
display: native
- name: Define the Cisco IOSXR interface filter
@@ -160,16 +162,17 @@ EXAMPLES = """
- name: "get configuration with direct native filter type"
ansible.netcommon.netconf_get:
filter: {
"interface-configurations": {
filter:
{
"interface-configurations":
{
"@xmlns": "http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg",
"interface-configuration": null
"interface-configuration": null,
},
}
}
display: native
register: result
# Make a round-trip interface description change, diff the before and after
# this demonstrates the use of the native display format and several utilities
# from the ansible.utils collection
@@ -192,8 +195,8 @@ EXAMPLES = """
- name: Update the description
ansible.utils.update_fact:
updates:
- path: pre.output.data.interfaces.interface.config.description
value: "Configured by ansible {{ 100 | random }}"
- path: pre.output.data.interfaces.interface.config.description
value: "Configured by ansible {{ 100 | random }}"
register: updated
- name: Apply the new configuration
@@ -213,7 +216,6 @@ EXAMPLES = """
ansible.utils.fact_diff:
before: "{{ pre.output.data|ansible.utils.to_paths }}"
after: "{{ post.output.data|ansible.utils.to_paths }}"
# TASK [Show the differences between the pre and post configurations] ********
# --- before
# +++ after
@@ -236,25 +238,27 @@ EXAMPLES = """
RETURN = """
stdout:
description: The raw XML string containing configuration or state data
received from the underlying ncclient library.
received from the underlying ncclient library.
returned: always apart from low-level errors (such as action plugin)
type: str
sample: '...'
sample: "..."
stdout_lines:
description: The value of stdout split into a list
returned: always apart from low-level errors (such as action plugin)
type: list
sample: ['...', '...']
sample: ["...", "..."]
output:
description: Based on the value of display option will return either the set of
transformed XML to JSON format from the RPC response with type dict
or pretty XML string response (human-readable) or response with
namespace removed from XML string.
returned: If the display format is selected as I(json) it is returned as dict type
and the conversion is done using jxmlease python library. If the display
format is selected as I(native) it is returned as dict type and the conversion
is done using xmltodict python library. If the display format is xml or pretty
it is returned as a string apart from low-level errors (such as action plugin).
description:
Based on the value of display option will return either the set of
transformed XML to JSON format from the RPC response with type dict
or pretty XML string response (human-readable) or response with
namespace removed from XML string.
returned:
If the display format is selected as I(json) it is returned as dict type
and the conversion is done using jxmlease python library. If the display
format is selected as I(native) it is returned as dict type and the conversion
is done using xmltodict python library. If the display format is xml or pretty
it is returned as a string apart from low-level errors (such as action plugin).
type: complex
contains:
formatted_output:
@@ -267,21 +271,23 @@ try:
except ImportError:
from xml.etree.ElementTree import tostring
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.ansible.netcommon.plugins.module_utils.network.netconf.netconf import (
get_capabilities,
get_config,
get,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.netconf import (
remove_namespaces,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.netconf.netconf import (
get,
get_capabilities,
get_config,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.utils.data import (
dict_to_xml,
validate_and_normalize_data,
xml_to_dict,
dict_to_xml,
)
from ansible.module_utils._text import to_text
try:
import jxmlease
@@ -297,14 +303,10 @@ def main():
source=dict(choices=["running", "candidate", "startup"]),
filter=dict(type="raw"),
display=dict(choices=["json", "pretty", "xml", "native"]),
lock=dict(
default="never", choices=["never", "always", "if-supported"]
),
lock=dict(default="never", choices=["never", "always", "if-supported"]),
)
module = AnsibleModule(
argument_spec=argument_spec, supports_check_mode=True
)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
capabilities = get_capabilities(module)
operations = capabilities["device_operations"]
@@ -339,25 +341,21 @@ def main():
pass
elif filter_type:
module.fail_json(
msg="Invalid filter type detected %s for filter value %s"
% (filter_type, filter)
msg="Invalid filter type detected %s for filter value %s" % (filter_type, filter)
)
lock = module.params["lock"]
display = module.params["display"]
if source == "candidate" and not operations.get("supports_commit", False):
module.fail_json(
msg="candidate source is not supported on this device"
)
module.fail_json(msg="candidate source is not supported on this device")
if source == "startup" and not operations.get("supports_startup", False):
module.fail_json(msg="startup source is not supported on this device")
if filter_type == "xpath" and not operations.get("supports_xpath", False):
module.fail_json(
msg="filter value '%s' of type xpath is not supported on this device"
% filter
msg="filter value '%s' of type xpath is not supported on this device" % filter
)
# If source is None, NETCONF <get> operation is issued, reading config/state data
@@ -372,8 +370,7 @@ def main():
else:
# lock is requested (always/if-supported) but not supported => issue warning
module.warn(
"lock operation on '%s' source is not supported on this device"
% (source or "running")
"lock operation on '%s' source is not supported on this device" % (source or "running")
)
execute_lock = lock == "always"

View File

@@ -2,10 +2,12 @@
# -*- coding: utf-8 -*-
# (c) 2018, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import absolute_import, division, print_function
__metaclass__ = type
@@ -151,18 +153,21 @@ output:
import ast
try:
from lxml.etree import tostring
except ImportError:
from xml.etree.ElementTree import tostring
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.ansible.netcommon.plugins.module_utils.network.netconf.netconf import (
dispatch,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.netconf import (
remove_namespaces,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.netconf.netconf import (
dispatch,
)
try:
import jxmlease
@@ -208,9 +213,7 @@ def get_xml_request(module, request, xmlns, content):
"It can be installed using `pip install jxmlease`"
)
payload = jxmlease.XMLDictNode(content).emit_xml(
pretty=False, full_document=False
)
payload = jxmlease.XMLDictNode(content).emit_xml(pretty=False, full_document=False)
if xmlns is None:
return "<%s>%s</%s>" % (request, payload, request)
else:
@@ -221,9 +224,7 @@ def get_xml_request(module, request, xmlns, content):
request,
)
module.fail_json(
msg="unsupported content data-type `%s`" % type(content).__name__
)
module.fail_json(msg="unsupported content data-type `%s`" % type(content).__name__)
def main():
@@ -235,9 +236,7 @@ def main():
display=dict(choices=["json", "pretty", "xml"]),
)
module = AnsibleModule(
argument_spec=argument_spec, supports_check_mode=True
)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
rpc = module.params["rpc"]
xmlns = module.params["xmlns"]

View File

@@ -2,10 +2,12 @@
# -*- coding: utf-8 -*-
# Copyright 2021 Red Hat
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import absolute_import, division, print_function
__metaclass__ = type

View File

@@ -1,9 +1,11 @@
#!/usr/bin/python
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import absolute_import, division, print_function
__metaclass__ = type
@@ -120,16 +122,15 @@ running:
import json
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.connection import ConnectionError
from ansible.module_utils.six import string_types
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
dict_diff,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.restconf import (
restconf,
)
from ansible.module_utils.six import string_types
from ansible_collections.ansible.netcommon.plugins.module_utils.network.restconf import restconf
def main():
@@ -137,9 +138,7 @@ def main():
argument_spec = dict(
path=dict(required=True),
content=dict(),
method=dict(
choices=["post", "put", "patch", "delete"], default="post"
),
method=dict(choices=["post", "put", "patch", "delete"], default="post"),
format=dict(choices=["json", "xml"], default="json"),
)
required_if = [
@@ -182,17 +181,13 @@ def main():
restconf.edit_config(module, path=path, method="DELETE")
result["changed"] = True
else:
warnings.append(
"delete not executed as resource '%s' does not exist"
% path
)
warnings.append("delete not executed as resource '%s' does not exist" % path)
else:
if running:
diff = dict_diff(running, candidate)
result["candidate"] = candidate
result["running"] = running
else:
method = "POST"
diff = candidate
if diff:

View File

@@ -1,9 +1,11 @@
#!/usr/bin/python
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import absolute_import, division, print_function
__metaclass__ = type
@@ -84,12 +86,9 @@ response:
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.connection import ConnectionError
from ansible_collections.ansible.netcommon.plugins.module_utils.network.restconf import (
restconf,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.utils.data import (
dict_to_xml,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.restconf import restconf
from ansible_collections.ansible.netcommon.plugins.module_utils.utils.data import xml_to_dict
def main():
@@ -100,9 +99,7 @@ def main():
output=dict(choices=["json", "xml"], default="json"),
)
module = AnsibleModule(
argument_spec=argument_spec, supports_check_mode=True
)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
result = {"changed": False}
@@ -113,7 +110,7 @@ def main():
if module.params["output"] == "xml":
try:
response = dict_to_xml(response)
response = xml_to_dict(response)
except Exception as exc:
module.fail_json(msg=to_text(exc))

View File

@@ -1,9 +1,11 @@
# this is a virtual module that is entirely implemented server side
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import absolute_import, division, print_function
__metaclass__ = type
@@ -11,81 +13,87 @@ DOCUMENTATION = """
module: telnet
short_description: Executes a low-down and dirty telnet command
description:
- Executes a low-down and dirty telnet command, not going through the module subsystem.
- This is mostly to be used for enabling ssh on devices that only have telnet enabled
by default.
- Executes a low-down and dirty telnet command, not going through the module subsystem.
- This is mostly to be used for enabling ssh on devices that only have telnet enabled
by default.
version_added: 1.0.0
options:
command:
description:
- List of commands to be executed in the telnet session.
- List of commands to be executed in the telnet session.
required: true
type: list
elements: str
aliases:
- commands
- commands
host:
description:
- The host/target on which to execute the command
- The host/target on which to execute the command
required: false
type: str
default: remote_addr
user:
description:
- The user for login
- The user for login
required: false
type: str
default: remote_user
password:
description:
- The password for login
- The password for login
type: str
port:
description:
- Remote port to use
- Remote port to use
type: int
default: 23
timeout:
description:
- timeout for remote operations
- timeout for remote operations
type: int
default: 120
prompts:
description:
- List of prompts expected before sending next command
- List of prompts expected before sending next command
required: false
type: list
elements: str
default:
- $
- $
login_prompt:
description:
- Login or username prompt to expect
- Login or username prompt to expect
required: false
type: str
default: 'login: '
default: "login: "
password_prompt:
description:
- Login or username prompt to expect
- Login or username prompt to expect
required: false
type: str
default: 'Password: '
default: "Password: "
pause:
description:
- Seconds to pause between each command issued
- Seconds to pause between each command issued
required: false
type: int
default: 1
send_newline:
description:
- Sends a newline character upon successful connection to start the terminal session.
- Sends a newline character upon successful connection to start the terminal session.
required: false
type: bool
default: false
crlf:
description:
- Sends a CRLF (Carrage Return) instead of just a LF (Line Feed).
required: false
type: bool
default: false
notes:
- The C(environment) keyword does not work with this task
- The C(environment) keyword does not work with this task
author:
- Ansible Core Team
- Ansible Core Team
"""
EXAMPLES = """
@@ -93,30 +101,30 @@ EXAMPLES = """
ansible.netcommon.telnet:
user: cisco
password: cisco
login_prompt: 'Username: '
login_prompt: "Username: "
prompts:
- '[>#]'
- "[>#]"
command:
- terminal length 0
- configure terminal
- hostname ios01
- terminal length 0
- configure terminal
- hostname ios01
- name: run show commands
ansible.netcommon.telnet:
user: cisco
password: cisco
login_prompt: 'Username: '
login_prompt: "Username: "
prompts:
- '[>#]'
- "[>#]"
command:
- terminal length 0
- show version
- terminal length 0
- show version
"""
RETURN = """
output:
description: output of each command is an element in this list
type: list
returned: always
sample: [ 'success', 'success', '', 'warning .. something' ]
description: output of each command is an element in this list
type: list
returned: always
sample: ["success", "success", "", "warning .. something"]
"""