From ef3c456a992cd33b89a2ff1b69783e0b808c6545 Mon Sep 17 00:00:00 2001 From: KB-perByte Date: Wed, 1 Nov 2023 15:06:50 +0530 Subject: [PATCH 1/3] fix lint - checkout before action --- .github/workflows/lint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6890c6a8d..4e45c595d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -8,5 +8,6 @@ jobs: name: Ansible Lint # Naming the build is important to use it as a status check runs-on: ubuntu-latest steps: + - uses: actions/checkout@v4 - name: Run ansible-lint uses: ansible/ansible-lint@main # or version tag instead of 'main' From bff8b37d164a49e7cb95439081ab2ea262a96c94 Mon Sep 17 00:00:00 2001 From: KB-perByte Date: Wed, 1 Nov 2023 15:50:14 +0530 Subject: [PATCH 2/3] fix lint issues --- plugins/filter/pop_ace.py | 12 +- plugins/modules/cli_command.py | 24 +-- plugins/modules/cli_config.py | 4 +- plugins/modules/grpc_config.py | 65 +++--- plugins/modules/grpc_get.py | 18 +- plugins/modules/netconf_config.py | 339 +++++++++++++++--------------- plugins/modules/netconf_get.py | 150 ++++++------- plugins/modules/telnet.py | 68 +++--- 8 files changed, 345 insertions(+), 335 deletions(-) diff --git a/plugins/filter/pop_ace.py b/plugins/filter/pop_ace.py index 27d4d8469..eefe07ca6 100644 --- a/plugins/filter/pop_ace.py +++ b/plugins/filter/pop_ace.py @@ -84,7 +84,7 @@ """ EXAMPLES = r""" -##Playbook with filter plugin example +## Playbook with filter plugin example vars: filter_options: match_all: true @@ -219,7 +219,7 @@ ansible.builtin.debug: msg: "{{ acls_data | ansible.netcommon.pop_ace(filter_options=filter_options, match_criteria=match_criteria) }}" -##Output +## Output # PLAY [Filter plugin example pop_ace] ****************************************************************************************************************** # TASK [Remove ace entries from a provided data] *********************************************************************************************************** @@ -353,8 +353,8 @@ # afi: ipv6 -##Playbook with workflow example -tasks: +## Playbook with workflow example +_tasks: - name: Gather ACLs config from device existing ACLs config cisco.ios.ios_acls: state: gathered @@ -379,8 +379,7 @@ state: overridden config: "{{ clean_acls['clean_acls']['acls'] | from_yaml }}" - -##Output +## Output # PLAYBOOK: pop_ace_example.yml *********************************************** @@ -989,7 +988,6 @@ # - ip access-list extended 110 # - no 10 deny icmp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 traceroute dscp ef ttl eq 10 # - no ip access-list extended test - """ from ansible.errors import AnsibleFilterError diff --git a/plugins/modules/cli_command.py b/plugins/modules/cli_command.py index e8505226b..7ad7bad91 100644 --- a/plugins/modules/cli_command.py +++ b/plugins/modules/cli_command.py @@ -79,7 +79,7 @@ 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: @@ -90,27 +90,27 @@ - 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 - - - - y + - y + - + - y """ RETURN = """ diff --git a/plugins/modules/cli_config.py b/plugins/modules/cli_config.py index 97190f539..abc5f84e4 100644 --- a/plugins/modules/cli_config.py +++ b/plugins/modules/cli_config.py @@ -167,7 +167,7 @@ - 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: @@ -190,7 +190,7 @@ - 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 diff --git a/plugins/modules/grpc_config.py b/plugins/modules/grpc_config.py index fbaa4deff..b289db981 100644 --- a/plugins/modules/grpc_config.py +++ b/plugins/modules/grpc_config.py @@ -78,39 +78,38 @@ """ 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: yes +- 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 = """ diff --git a/plugins/modules/grpc_get.py b/plugins/modules/grpc_get.py index 09547b6b0..528d0ce6a 100644 --- a/plugins/modules/grpc_get.py +++ b/plugins/modules/grpc_get.py @@ -63,15 +63,15 @@ """ 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 +- 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 = """ diff --git a/plugins/modules/netconf_config.py b/plugins/modules/netconf_config.py index 23fe32b00..87c1c9c01 100644 --- a/plugins/modules/netconf_config.py +++ b/plugins/modules/netconf_config.py @@ -13,203 +13,204 @@ 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 datastore and then commit - running, edit 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 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 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 _config.@ + - 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 _config.@ 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 = """ @@ -248,14 +249,14 @@ - 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 @@ -263,49 +264,54 @@ - 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 @@ -329,8 +335,8 @@ - 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 @@ -350,7 +356,6 @@ 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 @@ -368,28 +373,34 @@ # "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": "\n\n\n17.3R1.10...<--snip-->" "before": "\n\n\n 17.3R1.10...<--snip-->" + """ from ansible.module_utils._text import to_text diff --git a/plugins/modules/netconf_get.py b/plugins/modules/netconf_get.py index 590cc7a9a..1795bf54e 100644 --- a/plugins/modules/netconf_get.py +++ b/plugins/modules/netconf_get.py @@ -14,77 +14,77 @@ 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 = """ @@ -139,12 +139,12 @@ - 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 @@ -162,16 +162,17 @@ - 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 @@ -194,8 +195,8 @@ - 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 @@ -215,7 +216,6 @@ 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 @@ -238,25 +238,27 @@ 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: diff --git a/plugins/modules/telnet.py b/plugins/modules/telnet.py index 65311eede..41abf23bb 100644 --- a/plugins/modules/telnet.py +++ b/plugins/modules/telnet.py @@ -13,87 +13,87 @@ 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). + - 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 = """ @@ -101,30 +101,30 @@ 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"] """ From 582a0760dc7bf878a01206d1c3ab5e2b1fe45232 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 1 Nov 2023 10:22:36 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/ansible.netcommon.cli_command_module.rst | 24 +++--- docs/ansible.netcommon.cli_config_module.rst | 4 +- docs/ansible.netcommon.grpc_config_module.rst | 63 +++++++------- docs/ansible.netcommon.grpc_get_module.rst | 16 ++-- ...nsible.netcommon.netconf_config_module.rst | 86 ++++++++++--------- docs/ansible.netcommon.netconf_get_module.rst | 28 +++--- docs/ansible.netcommon.pop_ace_filter.rst | 11 ++- docs/ansible.netcommon.telnet_module.rst | 18 ++-- 8 files changed, 126 insertions(+), 124 deletions(-) diff --git a/docs/ansible.netcommon.cli_command_module.rst b/docs/ansible.netcommon.cli_command_module.rst index 8e69a80f9..11bd0eb82 100644 --- a/docs/ansible.netcommon.cli_command_module.rst +++ b/docs/ansible.netcommon.cli_command_module.rst @@ -167,7 +167,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: @@ -178,27 +178,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 - - - - y + - y + - + - y diff --git a/docs/ansible.netcommon.cli_config_module.rst b/docs/ansible.netcommon.cli_config_module.rst index 60048550e..1af9b2010 100644 --- a/docs/ansible.netcommon.cli_config_module.rst +++ b/docs/ansible.netcommon.cli_config_module.rst @@ -302,7 +302,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: @@ -325,7 +325,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 diff --git a/docs/ansible.netcommon.grpc_config_module.rst b/docs/ansible.netcommon.grpc_config_module.rst index 5e418250d..9e751804b 100644 --- a/docs/ansible.netcommon.grpc_config_module.rst +++ b/docs/ansible.netcommon.grpc_config_module.rst @@ -159,38 +159,37 @@ Examples .. code-block:: yaml - 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: yes + 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 diff --git a/docs/ansible.netcommon.grpc_get_module.rst b/docs/ansible.netcommon.grpc_get_module.rst index 607cdf186..480b5db11 100644 --- a/docs/ansible.netcommon.grpc_get_module.rst +++ b/docs/ansible.netcommon.grpc_get_module.rst @@ -123,14 +123,14 @@ Examples .. code-block:: yaml - 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 + grpc_get: + section: + Cisco-IOS-XR-ip-static-cfg:router-static: + - null + - name: run cli command + grpc_get: + command: "show version" + display: text diff --git a/docs/ansible.netcommon.netconf_config_module.rst b/docs/ansible.netcommon.netconf_config_module.rst index 53b1dfebb..f2c836686 100644 --- a/docs/ansible.netcommon.netconf_config_module.rst +++ b/docs/ansible.netcommon.netconf_config_module.rst @@ -431,14 +431,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 @@ -446,49 +446,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 @@ -512,8 +517,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 @@ -533,7 +538,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 diff --git a/docs/ansible.netcommon.netconf_get_module.rst b/docs/ansible.netcommon.netconf_get_module.rst index a0581c681..69edcec5d 100644 --- a/docs/ansible.netcommon.netconf_get_module.rst +++ b/docs/ansible.netcommon.netconf_get_module.rst @@ -188,12 +188,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 @@ -211,16 +211,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 @@ -243,8 +244,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 @@ -264,7 +265,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 diff --git a/docs/ansible.netcommon.pop_ace_filter.rst b/docs/ansible.netcommon.pop_ace_filter.rst index 721ae9a74..a8dfe8452 100644 --- a/docs/ansible.netcommon.pop_ace_filter.rst +++ b/docs/ansible.netcommon.pop_ace_filter.rst @@ -303,7 +303,7 @@ Examples .. code-block:: yaml - ##Playbook with filter plugin example + ## Playbook with filter plugin example vars: filter_options: match_all: true @@ -438,7 +438,7 @@ Examples ansible.builtin.debug: msg: "{{ acls_data | ansible.netcommon.pop_ace(filter_options=filter_options, match_criteria=match_criteria) }}" - ##Output + ## Output # PLAY [Filter plugin example pop_ace] ****************************************************************************************************************** # TASK [Remove ace entries from a provided data] *********************************************************************************************************** @@ -572,8 +572,8 @@ Examples # afi: ipv6 - ##Playbook with workflow example - tasks: + ## Playbook with workflow example + _tasks: - name: Gather ACLs config from device existing ACLs config cisco.ios.ios_acls: state: gathered @@ -598,8 +598,7 @@ Examples state: overridden config: "{{ clean_acls['clean_acls']['acls'] | from_yaml }}" - - ##Output + ## Output # PLAYBOOK: pop_ace_example.yml *********************************************** diff --git a/docs/ansible.netcommon.telnet_module.rst b/docs/ansible.netcommon.telnet_module.rst index e28190bdc..18a9769db 100644 --- a/docs/ansible.netcommon.telnet_module.rst +++ b/docs/ansible.netcommon.telnet_module.rst @@ -255,24 +255,24 @@ 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