diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 000000000..8d9bb70b8 --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,5 @@ +--- +profile: production + +exclude_paths: + - changelogs/changelog.yaml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..b6559bdca --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +--- +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 3 + labels: + - "skip-changelog" diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 000000000..e3e5966e4 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,3 @@ +--- +# see https://github.com/ansible-community/devtools +_extends: ansible-community/devtools diff --git a/.github/workflows/check_label.yml b/.github/workflows/check_label.yml new file mode 100644 index 000000000..b120bfa32 --- /dev/null +++ b/.github/workflows/check_label.yml @@ -0,0 +1,11 @@ +--- +name: "Check label" +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true +on: # yamllint disable-line rule:truthy + pull_request_target: + types: [opened, labeled, unlabeled, synchronize] +jobs: + check_label: + uses: ansible/ansible-content-actions/.github/workflows/check_label.yaml@main diff --git a/.github/workflows/codecoverage.yml b/.github/workflows/codecoverage.yml new file mode 100644 index 000000000..034589bc1 --- /dev/null +++ b/.github/workflows/codecoverage.yml @@ -0,0 +1,16 @@ +--- +name: "Code coverage" + +on: # yamllint disable-line rule:truthy + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + codecoverage: + uses: ansible-network/github_actions/.github/workflows/coverage_network_devices.yml@main + with: + collection_pre_install: >- + git+https://github.com/ansible-collections/ansible.utils.git + git+https://github.com/ansible-collections/ansible.netcommon.git diff --git a/.github/workflows/draft_release.yml b/.github/workflows/draft_release.yml new file mode 100644 index 000000000..618f8a379 --- /dev/null +++ b/.github/workflows/draft_release.yml @@ -0,0 +1,18 @@ +--- +name: "Draft release" +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true +on: # yamllint disable-line rule:truthy + workflow_dispatch: +env: + NAMESPACE: ${{ github.repository_owner }} + COLLECTION_NAME: nxos + ANSIBLE_COLLECTIONS_PATHS: ./ +jobs: + update_release_draft: + uses: ansible/ansible-content-actions/.github/workflows/draft_release.yaml@main + with: + repo: ${{ github.event.pull_request.head.repo.full_name }} + secrets: + BOT_PAT: ${{ secrets.BOT_PAT }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..6dbb1aa39 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,14 @@ +--- +name: "Release collection" +on: # yamllint disable-line rule:truthy + release: + types: [published] + +jobs: + release: + uses: ansible/ansible-content-actions/.github/workflows/release.yaml@main + with: + environment: release + secrets: + ah_token: ${{ secrets.AH_TOKEN }} + ansible_galaxy_api_key: ${{ secrets.ANSIBLE_GALAXY_API_KEY }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 000000000..27291dc81 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,48 @@ +--- +name: "CI" + +concurrency: + group: ${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +on: # yamllint disable-line rule:truthy + pull_request: + branches: [main] + workflow_dispatch: + schedule: + - cron: '0 0 * * *' + +jobs: + changelog: + uses: ansible/ansible-content-actions/.github/workflows/changelog.yaml@main + if: github.event_name == 'pull_request' + ansible-lint: + uses: ansible/ansible-content-actions/.github/workflows/ansible_lint.yaml@main + sanity: + uses: ansible/ansible-content-actions/.github/workflows/sanity.yaml@main + unit-galaxy: + uses: ansible/ansible-content-actions/.github/workflows/unit.yaml@main + unit-source: + uses: ansible-network/github_actions/.github/workflows/unit_source.yml@main + with: + collection_pre_install: >- + git+https://github.com/ansible-collections/ansible.utils.git + git+https://github.com/ansible-collections/ansible.netcommon.git + all_green: + if: ${{ always() }} + needs: + - changelog + - sanity + - unit-galaxy + - ansible-lint + runs-on: ubuntu-latest + steps: + - run: >- + python -c "assert 'failure' not in + set([ + '${{ needs.changelog.result }}', + '${{ needs.sanity.result }}', + '${{ needs.unit-galaxy.result }}' + '${{ needs.ansible-lint.result }}' + '${{ needs.unit-source.result }}' + ])" diff --git a/.gitignore b/.gitignore index 7116e16dc..1f9858c45 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ -# Linked collection directory +# CML/virl lab cache +.virl/ + +# A collection directory, resulting from the use of the pytest-ansible-units plugin collections/ -# Any virl residue -.virl # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 000000000..be4904528 --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,6 @@ +[settings] +known_first_party=ansible_collections.cisco.nxos +line_length=100 +lines_after_imports=2 +lines_between_types=1 +profile=black diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 356dbb80a..9661257ae 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,12 @@ --- repos: + - repo: https://github.com/ansible-network/collection_prep + rev: 1.1.1 + hooks: + - id: update-docs + - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.2.0 + rev: v4.5.0 hooks: - id: check-merge-conflict - id: check-symlinks @@ -11,24 +16,15 @@ repos: args: [--branch, main] - id: trailing-whitespace + - repo: https://github.com/asottile/add-trailing-comma + rev: v3.1.0 + hooks: + - id: add-trailing-comma + - repo: https://github.com/pre-commit/mirrors-prettier - rev: "v2.6.2" + rev: "v4.0.0-alpha.8" hooks: - id: prettier - # Original hook implementation is flaky due to *several* bugs described - # in https://github.com/prettier/prettier/issues/12364 - # a) CI=1 needed to avoid incomplete output - # b) two executions are needed because --list-different works correctly - # only when run with --check as with --write the output will also - # include other entries and logging level cannot be used to keep only - # modified files listed (any file is listed using the log level, regardless if - # is modified or not). - # c) We avoid letting pre-commit pass each filename in order to avoid - # running multiple instances in parallel. This also ensures that running - # prettier from the command line behaves identically with the pre-commit - # one. No real performance downsides. - # d) exit with the return code from list-different (0=none, 1=some) - # rather than the write (0=successfully rewrote files). pre-commit.ci entry: env CI=1 bash -c "prettier --list-different . || ec=$? && prettier --loglevel=error --write . && exit $ec" pass_filenames: false args: [] @@ -36,13 +32,14 @@ repos: - prettier - prettier-plugin-toml - - repo: https://github.com/psf/black - rev: 22.3.0 + - repo: https://github.com/PyCQA/isort + rev: 5.13.2 hooks: - - id: black - args: [-l, "79"] + - id: isort + name: Sort import statements using isort + args: ["--filter-files"] - - repo: https://github.com/ansible-network/collection_prep - rev: 1.0.0 + - repo: https://github.com/psf/black + rev: 23.12.1 hooks: - - id: update-docs + - id: black diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f287a258b..b92e441a2 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,290 @@ Cisco Nxos Collection Release Notes .. contents:: Topics +v6.0.2 +====== + +Bugfixes +-------- + +- nxos_interfaces - Correctly enable L3 interfaces on supported N3K platforms (https://github.com/ansible-collections/cisco.nxos/issues/749). + +v6.0.1 +====== + +Bugfixes +-------- + +- Prevents module_defaults from were being incorrectly applied to the platform action, instead of the concerned module. +- nxos_file_copy - correctly set file_pull_timeout/persistent_command_timeout value. + +v6.0.0 +====== + +Release Summary +--------------- + +Starting from this release, the minimum `ansible-core` version this collection requires is `2.14.0`. The last known version compatible with ansible-core<2.14 is `v5.3.0`. + +Major Changes +------------- + +- Bumping `requires_ansible` to `>=2.14.0`, since previous ansible-core versions are EoL now. + +v5.3.0 +====== + +Minor Changes +------------- + +- nxos_config - Relax restrictions on I(src) parameter so it can be used more like I(lines). (https://github.com/ansible-collections/cisco.nxos/issues/89). + +v5.2.1 +====== + +Bugfixes +-------- + +- nxos_acls - fix parsing of ACE with named source/dest port range (https://github.com/ansible-collections/cisco.nxos/issues/763). +- vtp_version - allow VTP version 3 to be configured (https://github.com/ansible-collections/cisco.nxos/issues/704). + +Documentation Changes +--------------------- + +- nxos_acls - update examples and use YAML output in them for better readibility. + +v5.2.0 +====== + +Minor Changes +------------- + +- Added new module fc_interfaces +- bgp_global - support remote-as as a route-map (https://github.com/ansible-collections/cisco.nxos/issues/741). +- bgp_neighbor_address_family - support rewrite-rt-asn for ipv4 mvpn (https://github.com/ansible-collections/cisco.nxos/issues/741). +- bgp_templates - Add support for safi evpn (https://github.com/ansible-collections/cisco.nxos/issues/739). +- bgp_templates - Add support for send_community (https://github.com/ansible-collections/cisco.nxos/issues/740). +- route_maps - support extcommunity rt option (https://github.com/ansible-collections/cisco.nxos/issues/743). + +Bugfixes +-------- + +- acls - Fix parsing error when ACE has a source port range (https://github.com/ansible-collections/cisco.nxos/issues/713). +- interfaces - Re-apply existing non-default MTU when changing mode to L2 (https://github.com/ansible-collections/cisco.nxos/issues/730). +- lag_interfaces - Allow force option to be idempotent (https://github.com/ansible-collections/cisco.nxos/issues/742). +- snmp_server - fix host delete when authentication options are present (https://github.com/ansible-collections/cisco.nxos/issues/439). + +Documentation Changes +--------------------- + +- Update examples for bgp_address_family resource modules using yaml callback plugin. +- Update examples for bgp_global resource modules using yaml callback plugin. +- Update examples for bgp_neighbor_address_family resource modules using yaml callback plugin. +- Update examples for bgp_templates resource modules using yaml callback plugin. +- Update examples for ospf_interfaces resource modules using yaml callback plugin. +- Update examples for ospfv2 resource modules using yaml callback plugin. +- Update examples for ospfv3 resource modules using yaml callback plugin. + +New Modules +----------- + +- nxos_fc_interfaces - Fc Interfaces resource module + +v5.1.0 +====== + +Minor Changes +------------- + +- nxos_facts - add cpu utilization data to facts. + +v5.0.0 +====== + +Major Changes +------------- + +- Refer to **Removed Features** section for details. +- This release removes four of the previously deprecated modules from this collection. + +Minor Changes +------------- + +- Add nxos_bgp_templates module. +- nxos_user - Added dev-ops role to BUILTINS (https://github.com/ansible-collections/cisco.nxos/issues/690) + +Removed Features (previously deprecated) +---------------------------------------- + +- The nxos_bgp module has been removed with this release. +- The nxos_bgp_af module has been removed with this release. +- The nxos_bgp_neighbor module has been removed with this release. +- The nxos_bgp_neighbor_af module has been removed with this release. + +Bugfixes +-------- + +- nxos_static_routes - Prevent action states to generate terminal configuration command. +- nxos_static_routes - Update the delete operation of static routes to be similar to other platforms. (https://github.com/ansible-collections/cisco.nxos/issues/666) + +v4.4.0 +====== + +Minor Changes +------------- + +- nxos_user - Add support for hashed passwords. (https://github.com/ansible-collections/cisco.nxos/issues/370). + +Bugfixes +-------- + +- l3_interfaces - Append tag when updating IP address with state replaced (https://github.com/ansible-collections/cisco.nxos/issues/678). +- ntp_global - Fix incorrect handling of prefer option (https://github.com/ansible-collections/cisco.nxos/issues/670). +- nxos_banner - Add support for a custom multiline delimiter +- nxos_facts - Fix missing SVI facts (https://github.com/ansible-collections/cisco.nxos/issues/440). +- terminal - attempt privilege escalation only when prompt does not end with # + +Documentation Changes +--------------------- + +- Fix docs of static-routes resource module. +- nxos_interfaces - Fixed module documentation and examples. +- nxos_l2_interfaces - Fixed module documentation and examples. +- nxos_l3_interfaces - Fixed module documentation and examples. + +v4.3.0 +====== + +Release Summary +--------------- + +Re-releasing v4.2.0 of this collection since the previously build failed to upload in Automation Hub. + +v4.2.0 +====== + +Minor Changes +------------- + +- `nxos_route_maps` - add support for 'set ip next-hop <>' command in route-maps +- `nxos_vxlan_vtep` - add support for 'advertise virtual-rmac' command under nve interface + +Bugfixes +-------- + +- `bgp` - Fix parsing remote-as for Nexus 3K (https://github.com/ansible-collections/cisco.nxos/issues/653). +- `facts` - Attempt to execute json output commands with | json-pretty first and fall back to | json if unsupported. This is a temporary workaround until https://github.com/ansible/pylibssh/issues/208 is fixed. +- `interfaces` - Correctly enable/disable VLAN interfaces (https://github.com/ansible-collections/cisco.nxos/issues/539). +- `route_maps` - resolve route-map description parameter idempotency +- `snmp_server` - fix community option to produce proper configuration with ipv4acl and ipv6acl. + +v4.1.0 +====== + +Minor Changes +------------- + +- `nxos_acls` - Support ICMPv6 option. Please refer to module doc for all new options (https://github.com/ansible-collections/cisco.nxos/issues/624). +- `nxos_facts` - Update facts gathering logic to ensure that `gather_network_resources: all` does not fail for NX-OS on MDS switches. +- `nxos_l2_interfaces` - Add new mode dot1q-tunnel (https://github.com/ansible-collections/cisco.nxos/issues/600). + +Bugfixes +-------- + +- `nxos_acls` - Fix how IPv6 prefixes are converted to hosts (https://github.com/ansible-collections/cisco.nxos/issues/623). +- `nxos_file_copy` - stop prepending redundant bootflash: to remote file names +- nxos_acls - Detect duplicate ACE error message from CLI and fail (https://github.com/ansible-collections/cisco.nxos/issues/611). +- nxos_command - Run & evaluate commands at least once even when retries is set to 0 (https://github.com/ansible-collections/cisco.nxos/issues/607). + +v4.0.1 +====== + +Bugfixes +-------- + +- `nxos_acls` - Parse ICMP echo-reply and echo options correctly (https://github.com/ansible-collections/cisco.nxos/issues/583). +- `nxos_acls` - Parse ICMP port-unreachable and unreachable options correctly (https://github.com/ansible-collections/cisco.nxos/issues/529). +- `nxos_acls` - Parse port-protocol options with hypenated names correctly (https://github.com/ansible-collections/cisco.nxos/issues/557). + +v4.0.0 +====== + +Major Changes +------------- + +- Please use either of the following connection types - network_cli, httpapi or netconf. +- This release drops support for `connection: local` and provider dictionary. + +Removed Features (previously deprecated) +---------------------------------------- + +- This release removes the following deprecated plugins that have reached their end-of-life. +- nxos_acl +- nxos_acl_interface +- nxos_interface +- nxos_interface_ospf +- nxos_l2_interface +- nxos_l3_interface +- nxos_linkagg +- nxos_lldp +- nxos_ospf +- nxos_ospf_vrf +- nxos_smu +- nxos_static_route +- nxos_vlan + +v3.2.0 +====== + +Minor Changes +------------- + +- `nxos_l3_interfaces` - Add support for toggling ipv6 redirects (https://github.com/ansible-collections/cisco.nxos/issues/569). + +Bugfixes +-------- + +- `nxos_telemetry` - Allow destination-group & sensor-group id to be strings. +- `nxos_telemetry` - Allow sensor-group paths to be generated without additional properties. + +v3.1.2 +====== + +Bugfixes +-------- + +- `nxos_facts` - Fixes parsing of module info json data when TABLE_modinfo entry is a list (https://github.com/ansible-collections/cisco.nxos/issues/559). + +v3.1.1 +====== + +Bugfixes +-------- + +- Fix issue with modules related to OSPF interfaces failing when the target NXOS device has subinterfaces. + +v3.1.0 +====== + +Minor Changes +------------- + +- `nxos_snmp_server` - Add support for localizedV2key (https://github.com/ansible-collections/cisco.nxos/issues/415). +- `nxos_snmp_server` - Add support for sha-256 based based user authentication. + +Bugfixes +-------- + +- `nxos_file_copy` - Skip `vrf` when running against MDS switches (https://github.com/ansible-collections/cisco.nxos/issues/508). +- `nxos_interfaces` - Enable all virtual interfaces with `enabled` set to True (https://github.com/ansible-collections/cisco.nxos/issues/335). +- `nxos_ntp_global` - Ensure idempotence for aliased keys (https://github.com/ansible-collections/cisco.nxos/issues/484). +- `nxos_snmp_server` - Fix typo for traps link cisco-xcvr-mon-status-chg. + +Documentation Changes +--------------------- + +- Updated documentation in nxos_snmp_server, nxos_ntp_global and nxos_logging_global modules to reflect which options are unsupported on MDS switches. + v3.0.0 ====== @@ -70,8 +354,7 @@ v2.8.2 Release Summary --------------- -- The v2.8.1 of the cisco.nxos collection is not available on Ansible Automation Hub. Please download and use v2.8.2 which - also contains an additional bug fix for the `nxos_ntp_global` module. +The v2.8.1 of the cisco.nxos collection is not available on Ansible Automation Hub. Please download and use v2.8.2 which also contains an additional bug fix. Bugfixes -------- @@ -298,8 +581,8 @@ v2.0.0 Major Changes ------------- -- Requires ansible.netcommon v2.0.0+ to support `ansible_network_single_user_mode` and `ansible_network_import_modules`. - Please refer to ansible.netcommon `changelog `_ for more details. +- Requires ansible.netcommon v2.0.0+ to support `ansible_network_single_user_mode` and `ansible_network_import_modules`. Minor Changes ------------- diff --git a/README.md b/README.md index bcb5c6407..1878c8646 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ - - # Cisco NX-OS Collection -[![CI](https://zuul-ci.org/gated.svg)](https://dashboard.zuul.ansible.com/t/ansible/project/github.com/ansible-collections/cisco.nxos) +[![CI](https://zuul-ci.org/gated.svg)](https://dashboard.zuul.ansible.com/t/ansible/project/github.com/ansible-collections/cisco.nxos) +[![Codecov](https://codecov.io/gh/ansible-collections/cisco.nxos/branch/main/graph/badge.svg)](https://codecov.io/gh/ansible-collections/cisco.nxos) +[![CI](https://github.com/ansible-collections/cisco.nxos/actions/workflows/tests.yml/badge.svg?branch=main&event=schedule)](https://github.com/ansible-collections/cisco.nxos/actions/workflows/tests.yml) The Ansible Cisco NX-OS collection includes a variety of Ansible content to help automate the management of Cisco NX-OS network appliances. @@ -13,7 +13,7 @@ The modules with full support for Cisco MDS are tested against NX-OS 8.4(1) on M ## Ansible version compatibility -This collection has been tested against following Ansible versions: **>=2.9.10**. +This collection has been tested against following Ansible versions: **>=2.14.0**. For collections that support Ansible 2.9, please ensure you update your `network_os` to use the fully qualified collection name (for example, `cisco.ios.ios`). @@ -23,7 +23,7 @@ PEP440 is the schema used to describe the versions of Ansible. ### Supported connections -The Cisco NX-OS collection supports ``network_cli`` and ``httpapi`` connections. +The Cisco NX-OS collection supports ``network_cli`` and ``httpapi`` connections. A detailed platform guide can be found [here](https://github.com/ansible-collections/cisco.nxos/blob/main/platform_guide.rst). ## Included content @@ -47,26 +47,22 @@ Name | Description --- | --- [cisco.nxos.nxos_aaa_server](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_aaa_server_module.rst)|Manages AAA server global configuration. [cisco.nxos.nxos_aaa_server_host](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_aaa_server_host_module.rst)|Manages AAA server host-specific configuration. -[cisco.nxos.nxos_acl](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_acl_module.rst)|(deprecated, removed after 2022-06-01) Manages access list entries for ACLs. -[cisco.nxos.nxos_acl_interface](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_acl_interface_module.rst)|(deprecated, removed after 2022-06-01) Manages applying ACLs to interfaces. [cisco.nxos.nxos_acl_interfaces](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_acl_interfaces_module.rst)|ACL interfaces resource module [cisco.nxos.nxos_acls](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_acls_module.rst)|ACLs resource module [cisco.nxos.nxos_banner](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_banner_module.rst)|Manage multiline banners on Cisco NXOS devices [cisco.nxos.nxos_bfd_global](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_bfd_global_module.rst)|Bidirectional Forwarding Detection (BFD) global-level configuration [cisco.nxos.nxos_bfd_interfaces](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_bfd_interfaces_module.rst)|BFD interfaces resource module -[cisco.nxos.nxos_bgp](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_bgp_module.rst)|(deprecated, removed after 2023-01-27) Manages BGP configuration. [cisco.nxos.nxos_bgp_address_family](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_bgp_address_family_module.rst)|BGP Address Family resource module. -[cisco.nxos.nxos_bgp_af](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_bgp_af_module.rst)|(deprecated, removed after 2023-02-24) Manages BGP Address-family configuration. [cisco.nxos.nxos_bgp_global](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_bgp_global_module.rst)|BGP Global resource module. -[cisco.nxos.nxos_bgp_neighbor](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_bgp_neighbor_module.rst)|(deprecated, removed after 2023-01-27) Manages BGP neighbors configurations. [cisco.nxos.nxos_bgp_neighbor_address_family](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_bgp_neighbor_address_family_module.rst)|BGP Neighbor Address Family resource module. -[cisco.nxos.nxos_bgp_neighbor_af](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_bgp_neighbor_af_module.rst)|(deprecated, removed after 2023-02-24) Manages BGP address-family's neighbors configuration. +[cisco.nxos.nxos_bgp_templates](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_bgp_templates_module.rst)|BGP Templates resource module. [cisco.nxos.nxos_command](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_command_module.rst)|Run arbitrary command on Cisco NXOS devices [cisco.nxos.nxos_config](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_config_module.rst)|Manage Cisco NXOS configuration sections [cisco.nxos.nxos_devicealias](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_devicealias_module.rst)|Configuration of device alias for Cisco NXOS MDS Switches. [cisco.nxos.nxos_evpn_global](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_evpn_global_module.rst)|Handles the EVPN control plane for VXLAN. [cisco.nxos.nxos_evpn_vni](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_evpn_vni_module.rst)|Manages Cisco EVPN VXLAN Network Identifier (VNI). [cisco.nxos.nxos_facts](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_facts_module.rst)|Gets facts about NX-OS switches +[cisco.nxos.nxos_fc_interfaces](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_fc_interfaces_module.rst)|Fc Interfaces resource module [cisco.nxos.nxos_feature](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_feature_module.rst)|Manage features in NX-OS switches. [cisco.nxos.nxos_file_copy](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_file_copy_module.rst)|Copy a file to a remote NXOS device. [cisco.nxos.nxos_gir](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_gir_module.rst)|Trigger a graceful removal or insertion (GIR) of the switch. @@ -78,18 +74,12 @@ Name | Description [cisco.nxos.nxos_igmp_interface](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_igmp_interface_module.rst)|Manages IGMP interface configuration. [cisco.nxos.nxos_igmp_snooping](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_igmp_snooping_module.rst)|Manages IGMP snooping global configuration. [cisco.nxos.nxos_install_os](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_install_os_module.rst)|Set boot options like boot, kickstart image and issu. -[cisco.nxos.nxos_interface](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_interface_module.rst)|(deprecated, removed after 2022-06-01) Manages physical attributes of interfaces. -[cisco.nxos.nxos_interface_ospf](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_interface_ospf_module.rst)|(deprecated, removed after 2022-10-26) Manages configuration of an OSPF interface instance. [cisco.nxos.nxos_interfaces](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_interfaces_module.rst)|Interfaces resource module -[cisco.nxos.nxos_l2_interface](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_l2_interface_module.rst)|(deprecated, removed after 2022-06-01) Manage Layer-2 interface on Cisco NXOS devices. [cisco.nxos.nxos_l2_interfaces](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_l2_interfaces_module.rst)|L2 interfaces resource module -[cisco.nxos.nxos_l3_interface](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_l3_interface_module.rst)|(deprecated, removed after 2022-06-01) Manage L3 interfaces on Cisco NXOS network devices [cisco.nxos.nxos_l3_interfaces](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_l3_interfaces_module.rst)|L3 interfaces resource module [cisco.nxos.nxos_lacp](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_lacp_module.rst)|LACP resource module [cisco.nxos.nxos_lacp_interfaces](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_lacp_interfaces_module.rst)|LACP interfaces resource module [cisco.nxos.nxos_lag_interfaces](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_lag_interfaces_module.rst)|LAG interfaces resource module -[cisco.nxos.nxos_linkagg](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_linkagg_module.rst)|(deprecated, removed after 2022-06-01) Manage link aggregation groups on Cisco NXOS devices. -[cisco.nxos.nxos_lldp](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_lldp_module.rst)|(deprecated, removed after 2022-06-01) Manage LLDP configuration on Cisco NXOS network devices. [cisco.nxos.nxos_lldp_global](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_lldp_global_module.rst)|LLDP resource module [cisco.nxos.nxos_lldp_interfaces](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_lldp_interfaces_module.rst)|LLDP interfaces resource module [cisco.nxos.nxos_logging](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_logging_module.rst)|Manage logging on network devices @@ -99,9 +89,7 @@ Name | Description [cisco.nxos.nxos_ntp_global](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_ntp_global_module.rst)|NTP Global resource module. [cisco.nxos.nxos_ntp_options](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_ntp_options_module.rst)|Manages NTP options. [cisco.nxos.nxos_nxapi](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_nxapi_module.rst)|Manage NXAPI configuration on an NXOS device. -[cisco.nxos.nxos_ospf](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_ospf_module.rst)|(deprecated, removed after 2022-06-01) Manages configuration of an ospf instance. [cisco.nxos.nxos_ospf_interfaces](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_ospf_interfaces_module.rst)|OSPF Interfaces Resource Module. -[cisco.nxos.nxos_ospf_vrf](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_ospf_vrf_module.rst)|(deprecated, removed after 2022-10-01)Manages a VRF for an OSPF router. [cisco.nxos.nxos_ospfv2](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_ospfv2_module.rst)|OSPFv2 resource module [cisco.nxos.nxos_ospfv3](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_ospfv3_module.rst)|OSPFv3 resource module [cisco.nxos.nxos_overlay_global](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_overlay_global_module.rst)|Configures anycast gateway MAC of the switch. @@ -114,7 +102,6 @@ Name | Description [cisco.nxos.nxos_rollback](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_rollback_module.rst)|Set a checkpoint or rollback to a checkpoint. [cisco.nxos.nxos_route_maps](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_route_maps_module.rst)|Route Maps resource module. [cisco.nxos.nxos_rpm](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_rpm_module.rst)|Install patch or feature rpms on Cisco NX-OS devices. -[cisco.nxos.nxos_smu](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_smu_module.rst)|(deprecated, removed after 2022-10-01) Perform SMUs on Cisco NX-OS devices. [cisco.nxos.nxos_snapshot](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_snapshot_module.rst)|Manage snapshots of the running states of selected features. [cisco.nxos.nxos_snmp_community](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_snmp_community_module.rst)|(deprecated, removed after 2024-01-01) Manages SNMP community configs. [cisco.nxos.nxos_snmp_contact](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_snmp_contact_module.rst)|(deprecated, removed after 2024-01-01) Manages SNMP contact info. @@ -123,14 +110,12 @@ Name | Description [cisco.nxos.nxos_snmp_server](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_snmp_server_module.rst)|SNMP Server resource module. [cisco.nxos.nxos_snmp_traps](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_snmp_traps_module.rst)|(deprecated, removed after 2024-01-01) Manages SNMP traps. [cisco.nxos.nxos_snmp_user](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_snmp_user_module.rst)|(deprecated, removed after 2024-01-01) Manages SNMP users for monitoring. -[cisco.nxos.nxos_static_route](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_static_route_module.rst)|(deprecated, removed after 2022-06-01) Manages static route configuration [cisco.nxos.nxos_static_routes](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_static_routes_module.rst)|Static routes resource module [cisco.nxos.nxos_system](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_system_module.rst)|Manage the system attributes on Cisco NXOS devices [cisco.nxos.nxos_telemetry](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_telemetry_module.rst)|TELEMETRY resource module [cisco.nxos.nxos_udld](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_udld_module.rst)|Manages UDLD global configuration params. [cisco.nxos.nxos_udld_interface](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_udld_interface_module.rst)|Manages UDLD interface configuration params. [cisco.nxos.nxos_user](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_user_module.rst)|Manage the collection of local users on Nexus devices -[cisco.nxos.nxos_vlan](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_vlan_module.rst)|(deprecated, removed after 2022-06-01) Manages VLAN resources and attributes. [cisco.nxos.nxos_vlans](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_vlans_module.rst)|VLANs resource module [cisco.nxos.nxos_vpc](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_vpc_module.rst)|Manages global VPC configuration [cisco.nxos.nxos_vpc_interface](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_vpc_interface_module.rst)|Manages interface VPC configuration diff --git a/bindep.txt b/bindep.txt index ba9c980fb..70fd8dfa5 100644 --- a/bindep.txt +++ b/bindep.txt @@ -2,5 +2,3 @@ # see https://docs.openstack.org/infra/bindep/ for additional information. gcc-c++ [doc test platform:rpm] -python3-devel [test platform:rpm] -python3 [test platform:rpm] diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index d4cd78675..e043cc061 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -1,4 +1,5 @@ -ancestor: null +--- +ancestor: releases: 1.0.0: modules: @@ -8,14 +9,10 @@ releases: - description: Manages AAA server host-specific configuration. name: nxos_aaa_server_host namespace: "" - - description: - (deprecated, removed after 2022-06-01) Manages access list entries - for ACLs. + - description: (deprecated, removed after 2022-06-01) Manages access list entries for ACLs. name: nxos_acl namespace: "" - - description: - (deprecated, removed after 2022-06-01) Manages applying ACLs to - interfaces. + - description: (deprecated, removed after 2022-06-01) Manages applying ACLs to interfaces. name: nxos_acl_interface namespace: "" - description: ACL interfaces resource module @@ -93,9 +90,7 @@ releases: - description: Set boot options like boot, kickstart image and issu. name: nxos_install_os namespace: "" - - description: - (deprecated, removed after 2022-06-01) Manages physical attributes - of interfaces. + - description: (deprecated, removed after 2022-06-01) Manages physical attributes of interfaces. name: nxos_interface namespace: "" - description: Manages configuration of an OSPF interface instance. @@ -104,17 +99,13 @@ releases: - description: Interfaces resource module name: nxos_interfaces namespace: "" - - description: - (deprecated, removed after 2022-06-01) Manage Layer-2 interface - on Cisco NXOS devices. + - description: (deprecated, removed after 2022-06-01) Manage Layer-2 interface on Cisco NXOS devices. name: nxos_l2_interface namespace: "" - description: L2 interfaces resource module name: nxos_l2_interfaces namespace: "" - - description: - (deprecated, removed after 2022-06-01) Manage L3 interfaces on - Cisco NXOS network devices + - description: (deprecated, removed after 2022-06-01) Manage L3 interfaces on Cisco NXOS network devices name: nxos_l3_interface namespace: "" - description: L3 interfaces resource module @@ -129,14 +120,10 @@ releases: - description: LAG interfaces resource module name: nxos_lag_interfaces namespace: "" - - description: - (deprecated, removed after 2022-06-01) Manage link aggregation - groups on Cisco NXOS devices. + - description: (deprecated, removed after 2022-06-01) Manage link aggregation groups on Cisco NXOS devices. name: nxos_linkagg namespace: "" - - description: - (deprecated, removed after 2022-06-01) Manage LLDP configuration - on Cisco NXOS network devices. + - description: (deprecated, removed after 2022-06-01) Manage LLDP configuration on Cisco NXOS network devices. name: nxos_lldp namespace: "" - description: LLDP resource module @@ -160,9 +147,7 @@ releases: - description: Manage NXAPI configuration on an NXOS device. name: nxos_nxapi namespace: "" - - description: - (deprecated, removed after 2022-06-01) Manages configuration of - an ospf instance. + - description: (deprecated, removed after 2022-06-01) Manages configuration of an ospf instance. name: nxos_ospf namespace: "" - description: Manages a VRF for an OSPF router. @@ -240,9 +225,7 @@ releases: - description: Manage the collection of local users on Nexus devices name: nxos_user namespace: "" - - description: - (deprecated, removed after 2022-06-01) Manages VLAN resources and - attributes. + - description: (deprecated, removed after 2022-06-01) Manages VLAN resources and attributes. name: nxos_vlan namespace: "" - description: VLANs resource module @@ -291,23 +274,20 @@ releases: cliconf: - description: Use NX-OS cliconf to run commands on Cisco NX-OS platform name: nxos - namespace: null + namespace: httpapi: - description: Use NX-API to run commands on Cisco NX-OS platform name: nxos - namespace: null + namespace: release_date: "2020-06-23" 1.0.1: changes: bugfixes: - - Element type of `commands` key should be `raw` since it accepts both strings - and dicts (https://github.com/ansible-collections/cisco.nxos/pull/126). + - Element type of `commands` key should be `raw` since it accepts both strings and dicts (https://github.com/ansible-collections/cisco.nxos/pull/126). - Fix nxos_interfaces states replaced and overridden (https://github.com/ansible-collections/cisco.nxos/pull/102). - Fixed force option in lag_interfaces.py (https://github.com/ansible-collections/cisco.nxos/pull/111). - - Make `src`, `backup` and `backup_options` in nxos_config work when module - alias is used (https://github.com/ansible-collections/cisco.nxos/pull/121). - - Makes sure that docstring and argspec are in sync and removes sanity ignores - (https://github.com/ansible-collections/cisco.nxos/pull/112). + - Make `src`, `backup` and `backup_options` in nxos_config work when module alias is used (https://github.com/ansible-collections/cisco.nxos/pull/121). + - Makes sure that docstring and argspec are in sync and removes sanity ignores (https://github.com/ansible-collections/cisco.nxos/pull/112). - Update docs after sanity fixes to modules. - nxos_user - do not fail when a custom role is used (https://github.com/ansible-collections/cisco.nxos/pull/130) minor_changes: @@ -349,13 +329,11 @@ releases: - Preserve whitespaces in banner text (https://github.com/ansible-collections/cisco.nxos/pull/146). deprecated_features: - Deprecated `nxos_smu` in favour of `nxos_rpm` module. - - The `nxos_ospf_vrf` module is deprecated by `nxos_ospfv2` and `nxos_ospfv3` - Resource Modules. + - The `nxos_ospf_vrf` module is deprecated by `nxos_ospfv2` and `nxos_ospfv3` Resource Modules. minor_changes: - Add nxos_ospfv3 module. - - Allow other transfer protocols than scp to pull files from a NXOS device in - nxos_file_copy module. sftp, http, https, tftp and ftp can be choosen as a - transfer protocol, when the file_pull parameter is true.. + - Allow other transfer protocols than scp to pull files from a NXOS device in nxos_file_copy module. sftp, http, https, tftp and ftp can be choosen as a transfer + protocol, when the file_pull parameter is true.. fragments: - 161-transfer_protocol_file_copy.yaml - add_nxos_ospfv3.yaml @@ -378,8 +356,7 @@ releases: - Update regex to accept the platform "N77" as supporting fabricpath. - Vlan config diff was not removing default values deprecated_features: - - Deprecated `nxos_interface_ospf` in favor of `nxos_ospf_interfaces` Resource - Module. + - Deprecated `nxos_interface_ospf` in favor of `nxos_ospf_interfaces` Resource Module. minor_changes: - Add nxos_ospf_interfaces resource module. fragments: @@ -399,8 +376,7 @@ releases: - Add version key to galaxy.yaml to work around ansible-galaxy bug - Allow nxos_user to run with MDS (https://github.com/ansible-collections/cisco.nxos/issues/163). - Fix for nxos_lag_interfaces issue (https://github.com/ansible-collections/cisco.nxos/pull/194). - - Make sure that the OSPF modules work properly when process_id is a string - (https://github.com/ansible-collections/cisco.nxos/issues/198). + - Make sure that the OSPF modules work properly when process_id is a string (https://github.com/ansible-collections/cisco.nxos/issues/198). fragments: - fix_nxos_lag_interfaces_1.yaml - fix_ospf_process_id.yaml @@ -413,24 +389,18 @@ releases: - Add support for interfaces in mode 'fabricpath' to l2_interfaces (https://github.com/ansible-collections/cisco.nxos/issues/220). - Allow enabling `fabric forwarding` feature through nxos_feature (https://github.com/ansible-collections/cisco.nxos/issues/213). - Allow tag updates with state replaced (https://github.com/ansible-collections/cisco.nxos/issues/197). - - Fixes traceback while parsing power supply info in nxos_facts for newer NX-OS - releases (https://github.com/ansible-collections/cisco.nxos/issues/192). + - Fixes traceback while parsing power supply info in nxos_facts for newer NX-OS releases (https://github.com/ansible-collections/cisco.nxos/issues/192). - Handle domain-name properly with vrf contexts (https://github.com/ansible-collections/cisco.nxos/issues/234). - Parse interface contexts properly (https://github.com/ansible-collections/cisco.nxos/issues/195). - Properly handle partial matches in community string (https://github.com/ansible-collections/cisco.nxos/issues/203). - Update argspecs with default value for parameters. - - Update docs to clarify the idemptonecy releated caveat and add it in the output - warnings (https://github.com/ansible-collections/ansible.netcommon/pull/189) - - config replace is actually supported for devices other than N9K and hence - we should not fail, and instead let the device handle it (https://github.com/ansible-collections/cisco.nxos/issues/215). + - Update docs to clarify the idemptonecy releated caveat and add it in the output warnings (https://github.com/ansible-collections/ansible.netcommon/pull/189) + - config replace is actually supported for devices other than N9K and hence we should not fail, and instead let the device handle it (https://github.com/ansible-collections/cisco.nxos/issues/215). deprecated_features: - - Deprecated `nxos_bgp` and `nxos_bgp_neighbor` modules in favor of `nxos_bgp_global` - resource module. + - Deprecated `nxos_bgp` and `nxos_bgp_neighbor` modules in favor of `nxos_bgp_global` resource module. doc_changes: - - Fix error in ``host_reachability`` parameter's example where a default value - is used, which the ``host_reachability`` parameter does not support. Improve - descriptions of some parameters to be more explicit. Correct spelling and - grammar where errors were noticed. + - Fix error in ``host_reachability`` parameter's example where a default value is used, which the ``host_reachability`` parameter does not support. Improve + descriptions of some parameters to be more explicit. Correct spelling and grammar where errors were noticed. minor_changes: - Add `echo_request` option for ICMP. - Add nxos_bgp_global resource module. @@ -460,30 +430,24 @@ releases: 2.0.0: changes: bugfixes: - - Fail gracefully when BGP is already configured with a different ASN when states - merged or replaced is used. - - Fixes to nxos_logging, nxos_igmp_snooping, nxos_l3_interfaces, nxos_ospf_interfaces - and nxos_static_routes to conform with latest CLI behaviour. + - Fail gracefully when BGP is already configured with a different ASN when states merged or replaced is used. + - Fixes to nxos_logging, nxos_igmp_snooping, nxos_l3_interfaces, nxos_ospf_interfaces and nxos_static_routes to conform with latest CLI behaviour. - Properly configure neighbor timers and shutdown state (https://github.com/ansible-collections/cisco.nxos/issues/240). deprecated_features: - Deprecated nxos_bgp_af in favour of nxos_bgp_address_family resource module. - - Deprecated nxos_bgp_neighbor_af in favour of nxos_bgp_neighbor_address_family - resource module. + - Deprecated nxos_bgp_neighbor_af in favour of nxos_bgp_neighbor_address_family resource module. major_changes: - - Requires ansible.netcommon v2.0.0+ to support `ansible_network_single_user_mode` - and `ansible_network_import_modules`. - Please refer to ansible.netcommon `changelog `_ for more details. + - Requires ansible.netcommon v2.0.0+ to support `ansible_network_single_user_mode` and `ansible_network_import_modules`. minor_changes: - Add bfd option for neighbors (https://github.com/ansible-collections/cisco.nxos/issues/241). - - Add hello_interval_ms option in nxos_pim_interface module to support sub-second - intervals (https://github.com/ansible-collections/cisco.nxos/issues/226). + - Add hello_interval_ms option in nxos_pim_interface module to support sub-second intervals (https://github.com/ansible-collections/cisco.nxos/issues/226). - Add nxos_bgp_address_family Resource Module. - Add nxos_bgp_neighbor_address_family Resource Module. - Add support df_bit and size option for nxos_ping (https://github.com/ansible-collections/cisco.nxos/pull/237). - Adds support for `single_user_mode` command output caching. - - Move nxos_config idempotent warning message with the task response under `warnings` - key if `changed` is `True` + - Move nxos_config idempotent warning message with the task response under `warnings` key if `changed` is `True` fragments: - 237_nxos_ping_df_size.yaml - add_caching_support.yaml @@ -507,8 +471,7 @@ releases: 2.1.0: changes: bugfixes: - - Allow commands to be properly generated with Jinja2 2.10.3 (workaround for - https://github.com/pallets/jinja/issues/710). + - Allow commands to be properly generated with Jinja2 2.10.3 (workaround for https://github.com/pallets/jinja/issues/710). - Allow integer values to be set for dscp key (https://github.com/ansible-collections/cisco.nxos/issues/253). - Do not fail when parsing non rule entries in access-list config (https://github.com/ansible-collections/cisco.nxos/issues/262). minor_changes: @@ -527,8 +490,7 @@ releases: changes: bugfixes: - For versions >=2.1.0, this collection requires ansible.netcommon >=2.0.1. - - Re-releasing this collection with ansible.netcommon dependency requirements - updated. + - Re-releasing this collection with ansible.netcommon dependency requirements updated. fragments: - 275-add_ignore_txt.yml - update_requirement.yaml @@ -537,8 +499,7 @@ releases: changes: minor_changes: - Add nxos_route_maps resource module. - - Add support for ansible_network_resources key allows to fetch the available - resources for a platform (https://github.com/ansible-collections/cisco.nxos/issues/268). + - Add support for ansible_network_resources key allows to fetch the available resources for a platform (https://github.com/ansible-collections/cisco.nxos/issues/268). fragments: - 268_available_network_resources.yaml - add_nxos_route_maps.yaml @@ -551,13 +512,11 @@ releases: 2.3.0: changes: bugfixes: - - Fix how `send_community` attribute is handled in `nxos_bgp_neighbor_address_family` - (https://github.com/ansible-collections/cisco.nxos/issues/281). + - Fix how `send_community` attribute is handled in `nxos_bgp_neighbor_address_family` (https://github.com/ansible-collections/cisco.nxos/issues/281). - Make `passive_interface` work properly when set to False. minor_changes: - Add `default_passive_interface` option in `nxos_ospf_interfaces`. - - Add a netconf subplugin to make netconf_* modules work with older NX-OS versions - (https://github.com/ansible-collections/ansible.netcommon/issues/252). + - Add a netconf subplugin to make netconf_* modules work with older NX-OS versions (https://github.com/ansible-collections/ansible.netcommon/issues/252). fragments: - bgp_nbr_af.yaml - changelog.yaml @@ -569,11 +528,9 @@ releases: - pre_sort.yaml plugins: netconf: - - description: - Use nxos netconf plugin to run netconf commands on Cisco NX-OS - platform. + - description: Use nxos netconf plugin to run netconf commands on Cisco NX-OS platform. name: nxos - namespace: null + namespace: release_date: "2021-05-18" 2.4.0: changes: @@ -596,12 +553,10 @@ releases: changes: bugfixes: - Convert vlan lists to ranges in nxos_l2_interfaces (https://github.com/ansible-collections/cisco.nxos/issues/95). - - Do not expand direction 'both' into 'import' and 'export' for Nexus 9000 platforms - (https://github.com/ansible-collections/cisco.nxos/issues/303). + - Do not expand direction 'both' into 'import' and 'export' for Nexus 9000 platforms (https://github.com/ansible-collections/cisco.nxos/issues/303). - Prevent traceback when parsing unexpected line in nxos_static_routes. deprecated_features: - - The nxos_logging module has been deprecated in favor of the new nxos_logging_global - resource module and will be removed in a release after '2023-08-01'. + - The nxos_logging module has been deprecated in favor of the new nxos_logging_global resource module and will be removed in a release after '2023-08-01'. doc_changes: - Broken link in documentation fixed. minor_changes: @@ -624,8 +579,7 @@ releases: changes: bugfixes: - "`nxos_facts` - Fix gathering CDP neighbor facts from certain N7Ks (https://github.com/ansible-collections/cisco.nxos/issues/329)." - - "`nxos_zone_zoneset` - zone member addition with smart zoning in an already - existing zone should be a no-op (https://github.com/ansible-collections/cisco.nxos/issues/339)." + - "`nxos_zone_zoneset` - zone member addition with smart zoning in an already existing zone should be a no-op (https://github.com/ansible-collections/cisco.nxos/issues/339)." doc_changes: - Added notes in module docs to indicate supportability for Cisco MDS. fragments: @@ -641,8 +595,7 @@ releases: - "`nxos_acls` - Fix traceback with 'port_protocol' range (https://github.com/ansible-collections/cisco.nxos/issues/356)" - "`nxos_facts` - Fix KeyError while gathering CDP neighbor facts (https://github.com/ansible-collections/cisco.nxos/issues/354)." - "`nxos_ospf_interfaces` - Correctly sort interface names before rendering." - - "`nxos_vlans` - switching to `| json-pretty` instead of `| json` as a workaround - for the timeout issue with `libssh` (https://github.com/ansible/pylibssh/issues/208)" + - "`nxos_vlans` - switching to `| json-pretty` instead of `| json` as a workaround for the timeout issue with `libssh` (https://github.com/ansible/pylibssh/issues/208)" deprecated_features: - Deprecated `nxos_ntp`, `nxos_ntp_options`, `nxos_ntp_auth` modules. doc_changes: @@ -670,15 +623,14 @@ releases: minor_changes: - "`nxos_telemetry` - Add support for state gathered" fragments: - - 0-copy_ignore_txt.yml + - "0-copy_ignore_txt.yml" - nxos_telemetry.yaml - readme.yaml release_date: "2021-10-01" 2.7.1: changes: bugfixes: - - "`nxos_acls` - Updating an existing ACE can only be done with states replaced - or overridden. Using state merged will result in a failure." + - "`nxos_acls` - Updating an existing ACE can only be done with states replaced or overridden. Using state merged will result in a failure." - "`nxos_logging_global` - Fix vlan_mgr not being gathered in facts (https://github.com/ansible-collections/cisco.nxos/issues/380)." - "`nxos_vlans` - Fallback to json when json-pretty is not supported (https://github.com/ansible-collections/cisco.nxos/issues/377)." fragments: @@ -708,19 +660,17 @@ releases: 2.8.1: changes: bugfixes: - - nxos_acls - Fix incorrect parsing of remarks if it has 'ip/ipv6 access-list' - in it. + - nxos_acls - Fix incorrect parsing of remarks if it has 'ip/ipv6 access-list' in it. fragments: - nxos_acls.yaml release_date: "2021-12-10" 2.8.2: changes: - release_summary: - - The v2.8.1 of the cisco.nxos collection is not available on Ansible Automation Hub. Please download and use v2.8.2 which - also contains an additional bug fix. bugfixes: - - "`nxos_ntp_global` - In some cases, there is an extra whitespace in the source-interface - line. This patch accounts for this behaviour in config (https://github.com/ansible-collections/cisco.nxos/issues/399)." + - "`nxos_ntp_global` - In some cases, there is an extra whitespace in the source-interface line. This patch accounts for this behaviour in config (https://github.com/ansible-collections/cisco.nxos/issues/399)." + release_summary: + The v2.8.1 of the cisco.nxos collection is not available on Ansible Automation Hub. Please download and use v2.8.2 which also contains an additional + bug fix. fragments: - ignore.yaml - nxos_ntp.yaml @@ -729,8 +679,7 @@ releases: 2.9.0: changes: bugfixes: - - "`nxos_bgp_address_family` - Add hmm as valid option for redistribute protocol - (https://github.com/ansible-collections/cisco.nxos/issues/385)." + - "`nxos_bgp_address_family` - Add hmm as valid option for redistribute protocol (https://github.com/ansible-collections/cisco.nxos/issues/385)." - "`nxos_snmp_server` - Fix rendering context command (https://github.com/ansible-collections/cisco.nxos/issues/406)." minor_changes: - Add nxos_hostname resource module. @@ -749,8 +698,7 @@ releases: bugfixes: - Fix action plugin redirection to make module defaults work properly. - Fix for nxos_vlans issue (https://github.com/ansible-collections/cisco.nxos/issues/425). - - "`nxos_ntp_global` - Aliased `vrf` to `use_vrf` wherever applicable to maintain - consistency with models for other platforms." + - "`nxos_ntp_global` - Aliased `vrf` to `use_vrf` wherever applicable to maintain consistency with models for other platforms." - nxos_snmp_server - Add alias for community (https://github.com/ansible-collections/cisco.nxos/issues/433) doc_changes: - Added notes in module docs to indicate supportability for Cisco MDS. @@ -767,22 +715,17 @@ releases: 3.0.0: changes: bugfixes: - - "`nxos_lag_interfaces` - Fix KeyError with state overridden when port-channel - has no members (https://github.com/ansible-collections/cisco.nxos/issues/452)." - - "`nxos_ntp_global` - correctly propagate CLI failure for non-existent auth - keys (https://github.com/ansible-collections/cisco.nxos/issues/467)." + - "`nxos_lag_interfaces` - Fix KeyError with state overridden when port-channel has no members (https://github.com/ansible-collections/cisco.nxos/issues/452)." + - "`nxos_ntp_global` - correctly propagate CLI failure for non-existent auth keys (https://github.com/ansible-collections/cisco.nxos/issues/467)." - "`nxos_snmp_server` - Properly handle corner cases for snmp-server user (https://github.com/ansible-collections/cisco.nxos/issues/454)." - - "`snmp_server` - Snmp contact/location and location were not gathered if containing - whitespaces." + - "`snmp_server` - Snmp contact/location and location were not gathered if containing whitespaces." major_changes: - The minimum required ansible.netcommon version has been bumped to v2.6.1. - Updated base plugin references to ansible.netcommon. - "`nxos_facts` - change default gather_subset to `min` from `!config` (https://github.com/ansible-collections/cisco.nxos/issues/418)." - - nxos_file_copy has been rewritten as a module. This change also removes the - dependency on pexpect for file_pull operation. Since this now uses AnsibleModule - class for argspec validation, the validation messages will be slighlty different. - Expect changes in the return payload in some cases. All functionality remains - unchanged. + - nxos_file_copy has been rewritten as a module. This change also removes the dependency on pexpect for file_pull operation. Since this now uses AnsibleModule + class for argspec validation, the validation messages will be slighlty different. Expect changes in the return payload in some cases. All functionality + remains unchanged. minor_changes: - "`nxos_snmp_server` - add support for BGP, OSPF and OSPFv3 traps." fragments: @@ -798,3 +741,317 @@ releases: - snmp_server_PR444.yaml - stderr.yaml release_date: "2022-04-28" + 3.1.0: + changes: + bugfixes: + - "`nxos_file_copy` - Skip `vrf` when running against MDS switches (https://github.com/ansible-collections/cisco.nxos/issues/508)." + - "`nxos_interfaces` - Enable all virtual interfaces with `enabled` set to True (https://github.com/ansible-collections/cisco.nxos/issues/335)." + - "`nxos_ntp_global` - Ensure idempotence for aliased keys (https://github.com/ansible-collections/cisco.nxos/issues/484)." + - "`nxos_snmp_server` - Fix typo for traps link cisco-xcvr-mon-status-chg." + doc_changes: + - Updated documentation in nxos_snmp_server, nxos_ntp_global and nxos_logging_global modules to reflect which options are unsupported on MDS switches. + minor_changes: + - "`nxos_snmp_server` - Add support for localizedV2key (https://github.com/ansible-collections/cisco.nxos/issues/415)." + - "`nxos_snmp_server` - Add support for sha-256 based based user authentication." + fragments: + - 459.yaml + - 500.yaml + - 507.yaml + - 510.yaml + - 512.yaml + - 513.yaml + - 514.yaml + - 515.yaml + - 516.yaml + - 517.yaml + - 518.yaml + - 520.yaml + - 521.yaml + - 522.yaml + - 523.yaml + - cleanup_1.yaml + - file_copy.yaml + - file_cp.yaml + - filecopy_mds.yaml + - include_prepare.yaml + - include_test_case.yaml + - mds_docs.yaml + - ntp_global.yaml + - nxos_interfaces.yaml + - pre-commit.yaml + - sanity.yaml + - sanity_devel.yaml + - set_fact_name.yaml + - snmp_server.yaml + - snmp_server_526.yml + - snmp_server_localized.yaml + - unstyle_equal_debug.yaml + release_date: "2022-06-28" + 3.1.1: + changes: + bugfixes: + - Fix issue with modules related to OSPF interfaces failing when the target NXOS device has subinterfaces. + fragments: + - ospf_subinterface_failure.yaml + - paramiko.yaml + - sanity_fix.yaml + release_date: "2022-09-07" + 3.1.2: + changes: + bugfixes: + - "`nxos_facts` - Fixes parsing of module info json data when TABLE_modinfo entry is a list (https://github.com/ansible-collections/cisco.nxos/issues/559)." + fragments: + - nxos_facts.yaml + release_date: "2022-09-19" + 3.2.0: + changes: + bugfixes: + - "`nxos_telemetry` - Allow destination-group & sensor-group id to be strings." + - "`nxos_telemetry` - Allow sensor-group paths to be generated without additional properties." + minor_changes: + - "`nxos_l3_interfaces` - Add support for toggling ipv6 redirects (https://github.com/ansible-collections/cisco.nxos/issues/569)." + fragments: + - ignore_2.15.yaml + - l3_interfaces.yaml + - passwd_lookup.yaml + - telemetry.yaml + release_date: "2022-10-12" + 4.0.0: + changes: + major_changes: + - Please use either of the following connection types - network_cli, httpapi or netconf. + - "This release drops support for `connection: local` and provider dictionary." + removed_features: + - This release removes the following deprecated plugins that have reached their end-of-life. + - nxos_acl + - nxos_acl_interface + - nxos_interface + - nxos_interface_ospf + - nxos_l2_interface + - nxos_l3_interface + - nxos_linkagg + - nxos_lldp + - nxos_ospf + - nxos_ospf_vrf + - nxos_smu + - nxos_static_route + - nxos_vlan + fragments: + - remove_deprecated.yaml + - remove_net_changes.yaml + - remove_provider.yaml + release_date: "2022-10-13" + 4.0.1: + changes: + bugfixes: + - "`nxos_acls` - Parse ICMP echo-reply and echo options correctly (https://github.com/ansible-collections/cisco.nxos/issues/583)." + - "`nxos_acls` - Parse ICMP port-unreachable and unreachable options correctly (https://github.com/ansible-collections/cisco.nxos/issues/529)." + - "`nxos_acls` - Parse port-protocol options with hypenated names correctly (https://github.com/ansible-collections/cisco.nxos/issues/557)." + fragments: + - nxos_acls.yaml + - nxos_pim.yaml + release_date: "2022-11-30" + 4.1.0: + changes: + bugfixes: + - "`nxos_acls` - Fix how IPv6 prefixes are converted to hosts (https://github.com/ansible-collections/cisco.nxos/issues/623)." + - "`nxos_file_copy` - stop prepending redundant bootflash: to remote file names" + - nxos_acls - Detect duplicate ACE error message from CLI and fail (https://github.com/ansible-collections/cisco.nxos/issues/611). + - nxos_command - Run & evaluate commands at least once even when retries is set to 0 (https://github.com/ansible-collections/cisco.nxos/issues/607). + minor_changes: + - "`nxos_acls` - Support ICMPv6 option. Please refer to module doc for all new options (https://github.com/ansible-collections/cisco.nxos/issues/624)." + - "`nxos_facts` - Update facts gathering logic to ensure that `gather_network_resources: all` does not fail for NX-OS on MDS switches." + - "`nxos_l2_interfaces` - Add new mode dot1q-tunnel (https://github.com/ansible-collections/cisco.nxos/issues/600)." + fragments: + - acls.yaml + - acls_icmp.yaml + - command.yaml + - l2_mode.yaml + - mds.yaml + - nxos_acls.yaml + - nxos_file_copy.yaml + - nxos_snmp_revert.yaml + - rm_base.yaml + - snmp.yaml + - unused_imports.yaml + release_date: "2023-02-16" + 4.2.0: + changes: + bugfixes: + - "`bgp` - Fix parsing remote-as for Nexus 3K (https://github.com/ansible-collections/cisco.nxos/issues/653)." + - "`facts` - Attempt to execute json output commands with | json-pretty first and fall back to | json if unsupported. This is a temporary workaround until + https://github.com/ansible/pylibssh/issues/208 is fixed." + - "`interfaces` - Correctly enable/disable VLAN interfaces (https://github.com/ansible-collections/cisco.nxos/issues/539)." + - "`route_maps` - resolve route-map description parameter idempotency" + - "`snmp_server` - fix community option to produce proper configuration with ipv4acl and ipv6acl." + minor_changes: + - "`nxos_route_maps` - add support for 'set ip next-hop <>' command in route-maps" + - "`nxos_vxlan_vtep` - add support for 'advertise virtual-rmac' command under nve interface" + fragments: + - bgp.yaml + - bool.yaml + - ci_codecov.yml + - codecov_from_repo.yml + - facts_libssh.yaml + - intf_vlans.yaml + - nxos_route_maps.yaml + - nxos_vxlan_vtep.yaml + - route_maps.yaml + - snmp_server_issues_fix.yaml + release_date: "2023-04-04" + 4.3.0: + changes: + release_summary: Re-releasing v4.2.0 of this collection since the previously build failed to upload in Automation Hub. + fragments: + - release_430.yaml + release_date: "2023-04-05" + 4.4.0: + changes: + bugfixes: + - l3_interfaces - Append tag when updating IP address with state replaced (https://github.com/ansible-collections/cisco.nxos/issues/678). + - ntp_global - Fix incorrect handling of prefer option (https://github.com/ansible-collections/cisco.nxos/issues/670). + - nxos_banner - Add support for a custom multiline delimiter + - nxos_facts - Fix missing SVI facts (https://github.com/ansible-collections/cisco.nxos/issues/440). + - "terminal - attempt privilege escalation only when prompt does not end with #" + doc_changes: + - Fix docs of static-routes resource module. + - nxos_interfaces - Fixed module documentation and examples. + - nxos_l2_interfaces - Fixed module documentation and examples. + - nxos_l3_interfaces - Fixed module documentation and examples. + minor_changes: + - nxos_user - Add support for hashed passwords. (https://github.com/ansible-collections/cisco.nxos/issues/370). + fragments: + - banner.yaml + - downstream.yaml + - fix_docs_static_routes.yaml + - l3.yaml + - lint.yaml + - ntp_global.yaml + - ntp_user.yaml + - nxos_facts.yaml + - terminal.yaml + - tests.yaml + - update_inft_docs.yaml + release_date: "2023-05-29" + 5.0.0: + changes: + bugfixes: + - nxos_static_routes - Prevent action states to generate terminal configuration command. + - nxos_static_routes - Update the delete operation of static routes to be similar to other platforms. (https://github.com/ansible-collections/cisco.nxos/issues/666) + major_changes: + - Refer to **Removed Features** section for details. + - This release removes four of the previously deprecated modules from this collection. + minor_changes: + - Add nxos_bgp_templates module. + - nxos_user - Added dev-ops role to BUILTINS (https://github.com/ansible-collections/cisco.nxos/issues/690) + removed_features: + - The nxos_bgp module has been removed with this release. + - The nxos_bgp_af module has been removed with this release. + - The nxos_bgp_neighbor module has been removed with this release. + - The nxos_bgp_neighbor_af module has been removed with this release. + fragments: + - drop.yaml + - nxos_user.yml + - overridden.yaml + - templates.yaml + - update_static_routes.yml + release_date: "2023-07-05" + 5.1.0: + changes: + minor_changes: + - nxos_facts - add cpu utilization data to facts. + fragments: + - cpu_utilization.yml + release_date: "2023-07-05" + 5.2.0: + changes: + bugfixes: + - acls - Fix parsing error when ACE has a source port range (https://github.com/ansible-collections/cisco.nxos/issues/713). + - interfaces - Re-apply existing non-default MTU when changing mode to L2 (https://github.com/ansible-collections/cisco.nxos/issues/730). + - lag_interfaces - Allow force option to be idempotent (https://github.com/ansible-collections/cisco.nxos/issues/742). + - snmp_server - fix host delete when authentication options are present (https://github.com/ansible-collections/cisco.nxos/issues/439). + doc_changes: + - Update examples for bgp_address_family resource modules using yaml callback plugin. + - Update examples for bgp_global resource modules using yaml callback plugin. + - Update examples for bgp_neighbor_address_family resource modules using yaml callback plugin. + - Update examples for bgp_templates resource modules using yaml callback plugin. + - Update examples for ospf_interfaces resource modules using yaml callback plugin. + - Update examples for ospfv2 resource modules using yaml callback plugin. + - Update examples for ospfv3 resource modules using yaml callback plugin. + minor_changes: + - Added new module fc_interfaces + - bgp_global - support remote-as as a route-map (https://github.com/ansible-collections/cisco.nxos/issues/741). + - bgp_neighbor_address_family - support rewrite-rt-asn for ipv4 mvpn (https://github.com/ansible-collections/cisco.nxos/issues/741). + - bgp_templates - Add support for safi evpn (https://github.com/ansible-collections/cisco.nxos/issues/739). + - bgp_templates - Add support for send_community (https://github.com/ansible-collections/cisco.nxos/issues/740). + - route_maps - support extcommunity rt option (https://github.com/ansible-collections/cisco.nxos/issues/743). + fragments: + - _health_check_update_docs.yaml + - bgp_assorted.yaml + - bgp_templates.yaml + - codecov_pr.yml + - fix_713.yaml + - fix_730.yaml + - lag_interfaces.yaml + - nxos.yaml + - nxos_mds_fc.yaml + - route_maps.yaml + - snmp_server_fix.yml + modules: + - description: Fc Interfaces resource module + name: nxos_fc_interfaces + namespace: "" + release_date: "2023-09-14" + 5.2.1: + changes: + bugfixes: + - nxos_acls - fix parsing of ACE with named source/dest port range (https://github.com/ansible-collections/cisco.nxos/issues/763). + - vtp_version - allow VTP version 3 to be configured (https://github.com/ansible-collections/cisco.nxos/issues/704). + doc_changes: + - nxos_acls - update examples and use YAML output in them for better readibility. + fragments: + - acls.yaml + - fix_763.yaml + - vtp_version.yaml + release_date: "2023-10-03" + 5.3.0: + changes: + minor_changes: + - nxos_config - Relax restrictions on I(src) parameter so it can be used more + like I(lines). (https://github.com/ansible-collections/cisco.nxos/issues/89). + fragments: + - fix_config_module.yaml + - trivial.yaml + release_date: "2023-11-29" + 6.0.0: + changes: + major_changes: + - Bumping `requires_ansible` to `>=2.14.0`, since previous ansible-core versions + are EoL now. + release_summary: + Starting from this release, the minimum `ansible-core` version + this collection requires is `2.14.0`. The last known version compatible with + ansible-core<2.14 is `v5.3.0`. + fragments: + - prep_300.yaml + - trivial_lint.yaml + release_date: "2023-11-30" + 6.0.1: + changes: + bugfixes: + - Prevents module_defaults from were being incorrectly applied to the platform + action, instead of the concerned module. + - nxos_file_copy - correctly set file_pull_timeout/persistent_command_timeout + value. + fragments: + - file_copy.yaml + - module_defaults.yaml + release_date: "2024-01-30" + 6.0.2: + changes: + bugfixes: + - nxos_interfaces - Correctly enable L3 interfaces on supported N3K platforms + (https://github.com/ansible-collections/cisco.nxos/issues/749). + fragments: + - fix_749.yaml + release_date: "2024-02-06" diff --git a/changelogs/fragments/500.yaml b/changelogs/fragments/500.yaml deleted file mode 100644 index 90b5f9053..000000000 --- a/changelogs/fragments/500.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - Undo `=` style formatting for set_fact tasks diff --git a/changelogs/fragments/507.yaml b/changelogs/fragments/507.yaml deleted file mode 100644 index e54054947..000000000 --- a/changelogs/fragments/507.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - Fixes line length, bools, and anchor/aliases diff --git a/changelogs/fragments/510.yaml b/changelogs/fragments/510.yaml deleted file mode 100644 index eb5a1d3e0..000000000 --- a/changelogs/fragments/510.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - Switch to FQCN and ansible.builtin plugins diff --git a/changelogs/fragments/512.yaml b/changelogs/fragments/512.yaml deleted file mode 100644 index 9146f793f..000000000 --- a/changelogs/fragments/512.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - Capitalize all task names diff --git a/changelogs/fragments/cleanup_1.yaml b/changelogs/fragments/cleanup_1.yaml deleted file mode 100644 index 9ee4e861c..000000000 --- a/changelogs/fragments/cleanup_1.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - Begin switch from include to ansible.builtin.include_tasks diff --git a/changelogs/fragments/file_copy.yaml b/changelogs/fragments/file_copy.yaml deleted file mode 100644 index 852888d0e..000000000 --- a/changelogs/fragments/file_copy.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - Fix file copy test validation message. diff --git a/changelogs/fragments/file_cp.yaml b/changelogs/fragments/file_cp.yaml deleted file mode 100644 index acc507ba7..000000000 --- a/changelogs/fragments/file_cp.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - Make file_copy validation test assertions work across multiple ansible versions. diff --git a/changelogs/fragments/include_prepare.yaml b/changelogs/fragments/include_prepare.yaml deleted file mode 100644 index abd1c5e11..000000000 --- a/changelogs/fragments/include_prepare.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - Replace conditional block with include_tasks for prepare. diff --git a/changelogs/fragments/include_test_case.yaml b/changelogs/fragments/include_test_case.yaml deleted file mode 100644 index f4cd7e416..000000000 --- a/changelogs/fragments/include_test_case.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - Switch to FQCN for include of test case diff --git a/changelogs/fragments/ntp_global.yaml b/changelogs/fragments/ntp_global.yaml deleted file mode 100644 index db68faf2c..000000000 --- a/changelogs/fragments/ntp_global.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -bugfixes: - - "`nxos_ntp_global` - Ensure idempotence for aliased keys (https://github.com/ansible-collections/cisco.nxos/issues/484)." diff --git a/changelogs/fragments/pre-commit.yaml b/changelogs/fragments/pre-commit.yaml deleted file mode 100644 index d03d12be2..000000000 --- a/changelogs/fragments/pre-commit.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - Enable pre-commit with prettier diff --git a/changelogs/fragments/sanity.yaml b/changelogs/fragments/sanity.yaml deleted file mode 100644 index 32da1f4e4..000000000 --- a/changelogs/fragments/sanity.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - "Vendor in Version to fix sanity failures with >2.13 and Python 3.10." diff --git a/changelogs/fragments/sanity_devel.yaml b/changelogs/fragments/sanity_devel.yaml deleted file mode 100644 index fcef487c7..000000000 --- a/changelogs/fragments/sanity_devel.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - Sanity fixes for latest devel. diff --git a/changelogs/fragments/set_fact_name.yaml b/changelogs/fragments/set_fact_name.yaml deleted file mode 100644 index 1a39f8e41..000000000 --- a/changelogs/fragments/set_fact_name.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - Add name to `set_fact` where missing and update to FQCN diff --git a/changelogs/fragments/unstyle_equal_debug.yaml b/changelogs/fragments/unstyle_equal_debug.yaml deleted file mode 100644 index eb0269bbb..000000000 --- a/changelogs/fragments/unstyle_equal_debug.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - Remove = style formatting for debug statements diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 000000000..c77c91a90 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,15 @@ +--- +codecov: + require_ci_to_pass: true +comment: + layout: " diff, flags, files" + behavior: default + require_changes: false + require_base: false + require_head: true +coverage: + status: + patch: false + project: + default: + threshold: 0.3% diff --git a/plugins/modules/storage/__init__.py b/docs/__init__.py similarity index 100% rename from plugins/modules/storage/__init__.py rename to docs/__init__.py diff --git a/docs/cisco.nxos.nxos_aaa_server_host_module.rst b/docs/cisco.nxos.nxos_aaa_server_host_module.rst index c129e1b20..5730e6359 100644 --- a/docs/cisco.nxos.nxos_aaa_server_host_module.rst +++ b/docs/cisco.nxos.nxos_aaa_server_host_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
acct_port @@ -49,7 +49,7 @@ Parameters
+
address @@ -65,7 +65,7 @@ Parameters
+
auth_port @@ -80,7 +80,7 @@ Parameters
+
encrypt_type @@ -99,7 +99,7 @@ Parameters
+
host_timeout @@ -114,7 +114,7 @@ Parameters
+
key @@ -129,241 +129,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
server_type @@ -383,7 +149,7 @@ Parameters
+
state @@ -402,7 +168,7 @@ Parameters
+
tacacs_port diff --git a/docs/cisco.nxos.nxos_aaa_server_module.rst b/docs/cisco.nxos.nxos_aaa_server_module.rst index 065d5eb76..1307c9033 100644 --- a/docs/cisco.nxos.nxos_aaa_server_module.rst +++ b/docs/cisco.nxos.nxos_aaa_server_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2347,46 +3111,89 @@ Examples # Before state: # ------------- - # + # nxos-9k# show running-config | section '^ip(v6)* access-list' - - name: Merge new ACLs configuration + - name: Merge provided ACLs configuration with device configuration cisco.nxos.nxos_acls: - config: - - afi: ipv4 - acls: - - name: ACL1v4 - aces: - - grant: deny - destination: - address: 192.0.2.64 - wildcard_bits: 0.0.0.255 - source: - any: true - port_protocol: - lt: 55 - protocol: tcp - protocol_options: - tcp: - ack: true - fin: true - sequence: 50 - - - afi: ipv6 - acls: - - name: ACL1v6 - aces: - - grant: permit - sequence: 10 - source: - any: true - destination: - prefix: 2001:db8:12::/32 - protocol: sctp state: merged + config: + - afi: ipv4 + acls: + - name: ACL1v4 + aces: + - grant: deny + destination: + address: 192.0.2.64 + wildcard_bits: 0.0.0.255 + source: + any: true + port_protocol: + lt: 55 + protocol: tcp + protocol_options: + tcp: + ack: true + fin: true + sequence: 50 + + - afi: ipv6 + acls: + - name: ACL1v6 + aces: + - grant: permit + sequence: 10 + source: + any: true + destination: + prefix: 2001:db8:12::/32 + protocol: sctp + + # Task Output + # ----------- + # before: [] + # + # commands: + # - ip access-list ACL1v4 + # - 50 deny tcp any lt 55 192.0.2.64 0.0.0.255 ack fin + # - ipv6 access-list ACL1v6 + # - 10 permit sctp any 2001:db8:12::/32 + # + # after: + # - acls: + # - aces: + # - destination: + # prefix: 2001:db8:12::/32 + # grant: permit + # protocol: sctp + # sequence: 10 + # source: + # any: true + # name: ACL1v6 + # afi: ipv6 + # - acls: + # - aces: + # - destination: + # address: 192.0.2.64 + # wildcard_bits: 0.0.0.255 + # grant: deny + # protocol: tcp + # protocol_options: + # tcp: + # ack: true + # fin: true + # sequence: 50 + # source: + # any: true + # port_protocol: + # lt: '55' + # name: ACL1v4 + # afi: ipv4 + # After state: # ------------ # + # nxos-9k# show running-config | section '^ip(v6)* access-list' # ip access-list ACL1v4 # 50 deny tcp any lt 55 192.0.2.64 0.0.0.255 ack fin # ipv6 access-list ACL1v6 @@ -2396,94 +3203,269 @@ Examples # Before state: # ---------------- - # + # nxos-9k# show running-config | section '^ip(v6)* access-list' # ip access-list ACL1v4 # 10 permit ip any any # 20 deny udp any any # ip access-list ACL2v4 # 10 permit ahp 192.0.2.0 0.0.0.255 any - # ip access-list ACL1v6 + # ipv6 access-list ACL1v6 # 10 permit sctp any any # 20 remark IPv6 ACL - # ip access-list ACL2v6 + # ipv6 access-list ACL2v6 # 10 deny ipv6 any 2001:db8:3000::/36 # 20 permit tcp 2001:db8:2000:2::2/128 2001:db8:2000:ab::2/128 - name: Replace existing ACL configuration with provided configuration cisco.nxos.nxos_acls: config: - - afi: ipv4 - - afi: ipv6 - acls: - - name: ACL1v6 - aces: - - sequence: 20 - grant: permit - source: - any: true - destination: - any: true - protocol: pip - - - remark: Replaced ACE - - - name: ACL2v6 + - afi: ipv4 + - afi: ipv6 + acls: + - name: ACL1v6 + aces: + - sequence: 20 + grant: permit + source: + any: true + destination: + any: true + protocol: pim + + - remark: Replaced ACE + - name: ACL2v6 state: replaced + # Task Output + # ----------- + # before: + # - acls: + # - aces: + # - destination: + # any: true + # grant: permit + # protocol: sctp + # sequence: 10 + # source: + # any: true + # - remark: IPv6 ACL + # sequence: 20 + # name: ACL1v6 + # - aces: + # - destination: + # prefix: 2001:db8:3000::/36 + # grant: deny + # protocol: ipv6 + # sequence: 10 + # source: + # any: true + # - destination: + # host: 2001:db8:2000:ab::2 + # grant: permit + # protocol: tcp + # sequence: 20 + # source: + # host: 2001:db8:2000:2::2 + # name: ACL2v6 + # afi: ipv6 + # - acls: + # - aces: + # - destination: + # any: true + # grant: permit + # protocol: ip + # sequence: 10 + # source: + # any: true + # - destination: + # any: true + # grant: deny + # protocol: udp + # sequence: 20 + # source: + # any: true + # name: ACL1v4 + # - aces: + # - destination: + # any: true + # grant: permit + # protocol: ahp + # sequence: 10 + # source: + # address: 192.0.2.0 + # wildcard_bits: 0.0.0.255 + # name: ACL2v4 + # afi: ipv4 + # + # commands: + # - no ip access-list ACL1v4 + # - no ip access-list ACL2v4 + # - ipv6 access-list ACL1v6 + # - no 10 permit sctp any any + # - no 20 remark IPv6 ACL + # - remark Replaced ACE + # - 20 permit pim any any + # - ipv6 access-list ACL2v6 + # - no 10 deny ipv6 any 2001:db8:3000::/36 + # - no 20 permit tcp host 2001:db8:2000:2::2 host 2001:db8:2000:ab::2 + # + # after: + # - acls: + # - aces: + # - remark: Replaced ACE + # sequence: 10 + # - destination: + # any: true + # grant: permit + # protocol: pim + # sequence: 20 + # source: + # any: true + # name: ACL1v6 + # - name: ACL2v6 + # afi: ipv6 + # After state: # --------------- - # + # nxos-9k# show running-config | section '^ip(v6)* access-list' # ipv6 access-list ACL1v6 - # 20 permit pip any any - # 30 remark Replaced ACE + # 10 remark Replaced ACE + # 20 permit pim any any # ipv6 access-list ACL2v6 # Using overridden # Before state: # ---------------- - # + # nxos-9k# show running-config | section '^ip(v6)* access-list' # ip access-list ACL1v4 # 10 permit ip any any # 20 deny udp any any # ip access-list ACL2v4 # 10 permit ahp 192.0.2.0 0.0.0.255 any - # ip access-list ACL1v6 + # ipv6 access-list ACL1v6 # 10 permit sctp any any # 20 remark IPv6 ACL - # ip access-list ACL2v6 + # ipv6 access-list ACL2v6 # 10 deny ipv6 any 2001:db8:3000::/36 # 20 permit tcp 2001:db8:2000:2::2/128 2001:db8:2000:ab::2/128 - name: Override existing configuration with provided configuration cisco.nxos.nxos_acls: config: - - afi: ipv4 - acls: - - name: NewACL - aces: - - grant: deny - source: - address: 192.0.2.0 - wildcard_bits: 0.0.255.255 - destination: - any: true - protocol: eigrp - - remark: Example for overridden state + - afi: ipv4 + acls: + - name: NewACL + aces: + - grant: deny + source: + address: 192.0.2.0 + wildcard_bits: 0.0.255.255 + destination: + any: true + protocol: eigrp + - remark: Example for overridden state state: overridden + # Task Output + # ----------- + # + # before: + # - acls: + # - aces: + # - destination: + # any: true + # grant: permit + # protocol: sctp + # sequence: 10 + # source: + # any: true + # - remark: IPv6 ACL + # sequence: 20 + # name: ACL1v6 + # - aces: + # - destination: + # prefix: 2001:db8:3000::/36 + # grant: deny + # protocol: ipv6 + # sequence: 10 + # source: + # any: true + # - destination: + # host: 2001:db8:2000:ab::2 + # grant: permit + # protocol: tcp + # sequence: 20 + # source: + # host: 2001:db8:2000:2::2 + # name: ACL2v6 + # afi: ipv6 + # - acls: + # - aces: + # - destination: + # any: true + # grant: permit + # protocol: ip + # sequence: 10 + # source: + # any: true + # - destination: + # any: true + # grant: deny + # protocol: udp + # sequence: 20 + # source: + # any: true + # name: ACL1v4 + # - aces: + # - destination: + # any: true + # grant: permit + # protocol: ahp + # sequence: 10 + # source: + # address: 192.0.2.0 + # wildcard_bits: 0.0.0.255 + # name: ACL2v4 + # afi: ipv4 + # + # commands: + # - no ipv6 access-list ACL1v6 + # - no ipv6 access-list ACL2v6 + # - no ip access-list ACL1v4 + # - no ip access-list ACL2v4 + # - ip access-list NewACL + # - deny eigrp 192.0.2.0 0.0.255.255 any + # - remark Example for overridden state + # + # after: + # - acls: + # - aces: + # - destination: + # any: true + # grant: deny + # protocol: eigrp + # sequence: 10 + # source: + # address: 192.0.2.0 + # wildcard_bits: 0.0.255.255 + # - remark: Example for overridden state + # sequence: 20 + # name: NewACL + # afi: ipv4 + # After state: # ------------ - # + # nxos-9k# show running-config | section '^ip(v6)* access-list' # ip access-list NewACL # 10 deny eigrp 192.0.2.0 0.0.255.255 any # 20 remark Example for overridden state - # Using deleted: + # Using deleted - delete all # # Before state: # ------------- - # + # nxos-9k# show running-config | section '^ip(v6)* access-list' # ip access-list ACL1v4 # 10 permit ip any any # 20 deny udp any any @@ -2498,17 +3480,89 @@ Examples - name: Delete all ACLs cisco.nxos.nxos_acls: - config: state: deleted + # Task Output + # ----------- + # + # before: + # - acls: + # - aces: + # - destination: + # any: true + # grant: permit + # protocol: sctp + # sequence: 10 + # source: + # any: true + # - remark: IPv6 ACL + # sequence: 20 + # name: ACL1v6 + # - aces: + # - destination: + # prefix: 2001:db8:3000::/36 + # grant: deny + # protocol: ipv6 + # sequence: 10 + # source: + # any: true + # - destination: + # host: 2001:db8:2000:ab::2 + # grant: permit + # protocol: tcp + # sequence: 20 + # source: + # host: 2001:db8:2000:2::2 + # name: ACL2v6 + # afi: ipv6 + # - acls: + # - aces: + # - destination: + # any: true + # grant: permit + # protocol: ip + # sequence: 10 + # source: + # any: true + # - destination: + # any: true + # grant: deny + # protocol: udp + # sequence: 20 + # source: + # any: true + # name: ACL1v4 + # - aces: + # - destination: + # any: true + # grant: permit + # protocol: ahp + # sequence: 10 + # source: + # address: 192.0.2.0 + # wildcard_bits: 0.0.0.255 + # name: ACL2v4 + # afi: ipv4 + # + # commands: + # - no ip access-list ACL1v4 + # - no ip access-list ACL2v4 + # - no ipv6 access-list ACL1v6 + # - no ipv6 access-list ACL2v6 + # + # after: [] + + # After state: # ----------- + # nxos-9k# show running-config | section '^ip(v6)* access-list' # + # Using deleted - delete AFI # Before state: # ------------- - # + # nxos-9k# show running-config | section '^ip(v6)* access-list' # ip access-list ACL1v4 # 10 permit ip any any # 20 deny udp any any @@ -2524,12 +3578,109 @@ Examples - name: Delete all ACLs in given AFI cisco.nxos.nxos_acls: config: - - afi: ipv4 + - afi: ipv4 state: deleted + # Task Output + # ----------- + # + # before: + # - acls: + # - aces: + # - destination: + # any: true + # grant: permit + # protocol: sctp + # sequence: 10 + # source: + # any: true + # - remark: IPv6 ACL + # sequence: 20 + # name: ACL1v6 + # - aces: + # - destination: + # prefix: 2001:db8:3000::/36 + # grant: deny + # protocol: ipv6 + # sequence: 10 + # source: + # any: true + # - destination: + # host: 2001:db8:2000:ab::2 + # grant: permit + # protocol: tcp + # sequence: 20 + # source: + # host: 2001:db8:2000:2::2 + # name: ACL2v6 + # afi: ipv6 + # - acls: + # - aces: + # - destination: + # any: true + # grant: permit + # protocol: ip + # sequence: 10 + # source: + # any: true + # - destination: + # any: true + # grant: deny + # protocol: udp + # sequence: 20 + # source: + # any: true + # name: ACL1v4 + # - aces: + # - destination: + # any: true + # grant: permit + # protocol: ahp + # sequence: 10 + # source: + # address: 192.0.2.0 + # wildcard_bits: 0.0.0.255 + # name: ACL2v4 + # afi: ipv4 + # + # commands: + # - no ip access-list ACL1v4 + # - no ip access-list ACL2v4 + # + # after: + # - acls: + # - aces: + # - destination: + # any: true + # grant: permit + # protocol: sctp + # sequence: 10 + # source: + # any: true + # - remark: IPv6 ACL + # sequence: 20 + # name: ACL1v6 + # - aces: + # - destination: + # prefix: 2001:db8:3000::/36 + # grant: deny + # protocol: ipv6 + # sequence: 10 + # source: + # any: true + # - destination: + # host: 2001:db8:2000:ab::2 + # grant: permit + # protocol: tcp + # sequence: 20 + # source: + # host: 2001:db8:2000:2::2 + # name: ACL2v6 + # afi: ipv6 + # After state: # ------------ - # + # nxos-9k# show running-config | section '^ip(v6)* access-list' # ip access-list ACL1v6 # 10 permit sctp any any # 20 remark IPv6 ACL @@ -2537,11 +3688,11 @@ Examples # 10 deny ipv6 any 2001:db8:3000::/36 # 20 permit tcp 2001:db8:2000:2::2/128 2001:db8:2000:ab::2/128 - + # Using deleted - delete ACLs # Before state: # ------------- - # + # nxos-9k# show running-config | section '^ip(v6)* access-list' # ip access-list ACL1v4 # 10 permit ip any any # 20 deny udp any any @@ -2556,18 +3707,106 @@ Examples - name: Delete specific ACLs cisco.nxos.nxos_acls: - config: - - afi: ipv4 - acls: - - name: ACL1v4 - - name: ACL2v4 - - afi: ipv6 - acls: - - name: ACL1v6 state: deleted + config: + - afi: ipv4 + acls: + - name: ACL1v4 + - name: ACL2v4 + - afi: ipv6 + acls: + - name: ACL1v6 + + # Task Output + # ----------- + # + # before: + # - acls: + # - aces: + # - destination: + # any: true + # grant: permit + # protocol: sctp + # sequence: 10 + # source: + # any: true + # - remark: IPv6 ACL + # sequence: 20 + # name: ACL1v6 + # - aces: + # - destination: + # prefix: 2001:db8:3000::/36 + # grant: deny + # protocol: ipv6 + # sequence: 10 + # source: + # any: true + # - destination: + # host: 2001:db8:2000:ab::2 + # grant: permit + # protocol: tcp + # sequence: 20 + # source: + # host: 2001:db8:2000:2::2 + # name: ACL2v6 + # afi: ipv6 + # - acls: + # - aces: + # - destination: + # any: true + # grant: permit + # protocol: ip + # sequence: 10 + # source: + # any: true + # - destination: + # any: true + # grant: deny + # protocol: udp + # sequence: 20 + # source: + # any: true + # name: ACL1v4 + # - aces: + # - destination: + # any: true + # grant: permit + # protocol: ahp + # sequence: 10 + # source: + # address: 192.0.2.0 + # wildcard_bits: 0.0.0.255 + # name: ACL2v4 + # afi: ipv4 + # + # commands: + # - no ip access-list ACL1v4 + # - no ip access-list ACL2v4 + # - no ipv6 access-list ACL1v6 + # + # after: + # - acls: + # - aces: + # - destination: + # prefix: 2001:db8:3000::/36 + # grant: deny + # protocol: ipv6 + # sequence: 10 + # source: + # any: true + # - destination: + # host: 2001:db8:2000:ab::2 + # grant: permit + # protocol: tcp + # sequence: 20 + # source: + # host: 2001:db8:2000:2::2 + # name: ACL2v6 + # afi: ipv6 # After state: # ------------ + # nxos-9k# show running-config | section '^ip(v6)* access-list' # ipv6 access-list ACL2v6 # 10 deny ipv6 any 2001:db8:3000::/36 # 20 permit tcp 2001:db8:2000:2::2/128 2001:db8:2000:ab::2/128 @@ -2583,7 +3822,9 @@ Examples 10 permit sctp any any state: parsed - # returns: + # Task Output + # ------------ + # # parsed: # - afi: ipv4 # acls: @@ -2621,7 +3862,7 @@ Examples # Before state: # ------------ - # + # nxos-9k# show running-config | section '^ip(v6)* access-list' # ip access-list ACL1v4 # 50 deny tcp any lt 55 192.0.2.64 0.0.0.255 ack fin # ipv6 access-list ACL1v6 @@ -2631,7 +3872,9 @@ Examples cisco.nxos.nxos_acls: state: gathered - # returns: + # Task Output + # ----------- + # # gathered: # - afi: ipv4 # acls: @@ -2670,39 +3913,41 @@ Examples - name: Render required configuration to be pushed to the device cisco.nxos.nxos_acls: config: - - afi: ipv4 - acls: - - name: ACL1v4 - aces: - - grant: deny - destination: - address: 192.0.2.64 - wildcard_bits: 0.0.0.255 - source: - any: true - port_protocol: - lt: 55 - protocol: tcp - protocol_options: - tcp: - ack: true - fin: true - sequence: 50 - - - afi: ipv6 - acls: - - name: ACL1v6 - aces: - - grant: permit - sequence: 10 - source: - any: true - destination: - prefix: 2001:db8:12::/32 - protocol: sctp + - afi: ipv4 + acls: + - name: ACL1v4 + aces: + - grant: deny + destination: + address: 192.0.2.64 + wildcard_bits: 0.0.0.255 + source: + any: true + port_protocol: + lt: 55 + protocol: tcp + protocol_options: + tcp: + ack: true + fin: true + sequence: 50 + - afi: ipv6 + acls: + - name: ACL1v6 + aces: + - grant: permit + sequence: 10 + source: + any: true + destination: + prefix: '2001:db8:12::/32' + protocol: sctp state: rendered - # returns: + + # Task Output + # ----------- + # # rendered: # ip access-list ACL1v4 # 50 deny tcp any lt 55 192.0.2.64 0.0.0.255 ack fin @@ -2776,6 +4021,57 @@ Common return values are documented `here ['ip access-list ACL1v4', '10 permit ip any any precedence critical log', '20 deny tcp any lt smtp host 192.0.2.64 ack fin'] + + + + + + + + + + + + + + +
ParameterParameter Choices/Defaults Comments
+
deadtime @@ -49,7 +49,7 @@ Parameters
+
directed_request @@ -69,7 +69,7 @@ Parameters
+
encrypt_type @@ -88,7 +88,7 @@ Parameters
+
global_key @@ -103,241 +103,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
server_timeout @@ -352,7 +118,7 @@ Parameters
+
server_type @@ -372,7 +138,7 @@ Parameters
+
state diff --git a/docs/cisco.nxos.nxos_acl_interface_module.rst b/docs/cisco.nxos.nxos_acl_interface_module.rst deleted file mode 100644 index 1266f6cab..000000000 --- a/docs/cisco.nxos.nxos_acl_interface_module.rst +++ /dev/null @@ -1,438 +0,0 @@ -.. _cisco.nxos.nxos_acl_interface_module: - - -***************************** -cisco.nxos.nxos_acl_interface -***************************** - -**(deprecated, removed after 2022-06-01) Manages applying ACLs to interfaces.** - - -Version added: 1.0.0 - -.. contents:: - :local: - :depth: 1 - -DEPRECATED ----------- -:Removed in collection release after 2022-06-01 -:Why: Updated modules released with more functionality -:Alternative: nxos_acl_interfaces - - - -Synopsis --------- -- Manages applying ACLs to interfaces. - - - - -Parameters ----------- - -.. raw:: html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterChoices/DefaultsComments
-
- direction - -
- string - / required -
-
-
    Choices: -
  • ingress
  • -
  • egress
  • -
-
-
Direction ACL to be applied in on the interface.
-
-
- interface - -
- string - / required -
-
- -
Full name of interface, e.g. Ethernet1/1.
-
-
- name - -
- string - / required -
-
- -
Case sensitive name of the access list (ACL).
-
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
-
- state - -
- string -
-
-
    Choices: -
  • present ←
  • -
  • absent
  • -
-
-
Specify desired state of the resource.
-
-
- - -Notes ------ - -.. note:: - - For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide ` - - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide ` - - For more information on using Ansible to manage Cisco devices see the `Cisco integration page `_. - - - -Examples --------- - -.. code-block:: yaml - - - name: apply egress acl to ethernet1/41 - cisco.nxos.nxos_acl_interface: - name: ANSIBLE - interface: ethernet1/41 - direction: egress - state: present - - - -Return Values -------------- -Common return values are documented `here `_, the following are the fields unique to this module: - -.. raw:: html - - - - - - - - - - - - - - - - - -
KeyReturnedDescription
-
- acl_applied_to - -
- list -
-
always -
list of interfaces the ACL is applied to
-
-
Sample:
-
[{'acl_type': 'Router ACL', 'direction': 'egress', 'interface': 'Ethernet1/41', 'name': 'ANSIBLE'}]
-
-
- commands - -
- list -
-
always -
commands sent to the device
-
-
Sample:
-
['interface ethernet1/41', 'ip access-group ANSIBLE out']
-
-

- - -Status ------- - - -- This module will be removed in a release after 2022-06-01. *[deprecated]* -- For more information see `DEPRECATED`_. - - -Authors -~~~~~~~ - -- Jason Edelman (@jedelman8) -- Gabriele Gerbino (@GGabriele) diff --git a/docs/cisco.nxos.nxos_acl_interfaces_module.rst b/docs/cisco.nxos.nxos_acl_interfaces_module.rst index 938e0cafe..a2885df02 100644 --- a/docs/cisco.nxos.nxos_acl_interfaces_module.rst +++ b/docs/cisco.nxos.nxos_acl_interfaces_module.rst @@ -258,28 +258,28 @@ Examples - name: Merge ACL interfaces configuration cisco.nxos.nxos_acl_interfaces: config: - - name: Ethernet1/2 - access_groups: - - afi: ipv6 - acls: - - name: ACL1v6 - direction: in - - - name: Eth1/5 - access_groups: - - afi: ipv4 - acls: - - name: PortACL - direction: in - port: true - - - name: ACL1v4 - direction: out - - - afi: ipv6 - acls: - - name: ACL1v6 - direction: in + - name: Ethernet1/2 + access_groups: + - afi: ipv6 + acls: + - name: ACL1v6 + direction: in + + - name: Eth1/5 + access_groups: + - afi: ipv4 + acls: + - name: PortACL + direction: in + port: true + + - name: ACL1v4 + direction: out + + - afi: ipv6 + acls: + - name: ACL1v6 + direction: in state: merged # After state: @@ -305,20 +305,20 @@ Examples - name: Replace interface configuration with given configuration cisco.nxos.nxos_acl_interfaces: config: - - name: Eth1/5 - access_groups: - - afi: ipv4 - acls: - - name: NewACLv4 - direction: out - - - name: Ethernet1/3 - access_groups: - - afi: ipv6 - acls: - - name: NewACLv6 - direction: in - port: true + - name: Eth1/5 + access_groups: + - afi: ipv4 + acls: + - name: NewACLv4 + direction: out + + - name: Ethernet1/3 + access_groups: + - afi: ipv6 + acls: + - name: NewACLv6 + direction: in + port: true state: replaced # After state: @@ -344,21 +344,21 @@ Examples - name: Override interface configuration with given configuration cisco.nxos.nxos_acl_interfaces: config: - - name: Ethernet1/3 - access_groups: - - afi: ipv4 - acls: - - name: ACL1v4 - direction: out - - - name: PortACL - port: true - direction: in - - afi: ipv6 - acls: - - name: NewACLv6 - direction: in - port: true + - name: Ethernet1/3 + access_groups: + - afi: ipv4 + acls: + - name: ACL1v4 + direction: out + + - name: PortACL + port: true + direction: in + - afi: ipv6 + acls: + - name: NewACLv6 + direction: in + port: true state: overridden # After state: @@ -384,8 +384,8 @@ Examples - name: Delete ACL configuration on interfaces cisco.nxos.nxos_acl_interfaces: config: - - name: Ethernet1/5 - - name: Ethernet1/2 + - name: Ethernet1/5 + - name: Ethernet1/2 state: deleted # After state: @@ -498,28 +498,28 @@ Examples - name: Render required configuration to be pushed to the device cisco.nxos.nxos_acl_interfaces: config: - - name: Ethernet1/2 - access_groups: - - afi: ipv6 - acls: - - name: ACL1v6 - direction: in - - - name: Ethernet1/5 - access_groups: - - afi: ipv4 - acls: - - name: PortACL - direction: in - port: true - - name: ACL1v4 - direction: out - - afi: ipv6 - acls: - - name: ACL1v6 - direction: in + - name: Ethernet1/2 + access_groups: + - afi: ipv6 + acls: + - name: ACL1v6 + direction: in + - name: Ethernet1/5 + access_groups: + - afi: ipv4 + acls: + - name: PortACL + direction: in + port: true + - name: ACL1v4 + direction: out + - afi: ipv6 + acls: + - name: ACL1v6 + direction: in state: rendered + # returns # rendered: # interface Ethernet1/2 diff --git a/docs/cisco.nxos.nxos_acl_module.rst b/docs/cisco.nxos.nxos_acl_module.rst deleted file mode 100644 index 974509303..000000000 --- a/docs/cisco.nxos.nxos_acl_module.rst +++ /dev/null @@ -1,836 +0,0 @@ -.. _cisco.nxos.nxos_acl_module: - - -******************* -cisco.nxos.nxos_acl -******************* - -**(deprecated, removed after 2022-06-01) Manages access list entries for ACLs.** - - -Version added: 1.0.0 - -.. contents:: - :local: - :depth: 1 - -DEPRECATED ----------- -:Removed in collection release after 2022-06-01 -:Why: Updated modules released with more functionality -:Alternative: nxos_acls - - - -Synopsis --------- -- Manages access list entries for ACLs. - - - - -Parameters ----------- - -.. raw:: html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterChoices/DefaultsComments
-
- ack - -
- string -
-
-
    Choices: -
  • enable
  • -
-
-
Match on the ACK bit.
-
-
- action - -
- string -
-
-
    Choices: -
  • permit
  • -
  • deny
  • -
  • remark
  • -
-
-
Action of the ACE.
-
-
- dest - -
- string -
-
- -
Destination ip and mask using IP/MASK notation and supports the keyword 'any'.
-
-
- dest_port1 - -
- string -
-
- -
Port/protocol and also first (lower) port when using range operand.
-
-
- dest_port2 - -
- string -
-
- -
Second (end) port when using range operand.
-
-
- dest_port_op - -
- string -
-
-
    Choices: -
  • any
  • -
  • eq
  • -
  • gt
  • -
  • lt
  • -
  • neq
  • -
  • range
  • -
-
-
Destination port operands such as eq, neq, gt, lt, range.
-
-
- dscp - -
- string -
-
-
    Choices: -
  • af11
  • -
  • af12
  • -
  • af13
  • -
  • af21
  • -
  • af22
  • -
  • af23
  • -
  • af31
  • -
  • af32
  • -
  • af33
  • -
  • af41
  • -
  • af42
  • -
  • af43
  • -
  • cs1
  • -
  • cs2
  • -
  • cs3
  • -
  • cs4
  • -
  • cs5
  • -
  • cs6
  • -
  • cs7
  • -
  • default
  • -
  • ef
  • -
-
-
Match packets with given dscp value.
-
-
- established - -
- string -
-
-
    Choices: -
  • enable
  • -
-
-
Match established connections.
-
-
- fin - -
- string -
-
-
    Choices: -
  • enable
  • -
-
-
Match on the FIN bit.
-
-
- fragments - -
- string -
-
-
    Choices: -
  • enable
  • -
-
-
Check non-initial fragments.
-
-
- log - -
- string -
-
-
    Choices: -
  • enable
  • -
-
-
Log matches against this entry.
-
-
- name - -
- string - / required -
-
- -
Case sensitive name of the access list (ACL).
-
-
- precedence - -
- string -
-
-
    Choices: -
  • critical
  • -
  • flash
  • -
  • flash-override
  • -
  • immediate
  • -
  • internet
  • -
  • network
  • -
  • priority
  • -
  • routine
  • -
-
-
Match packets with given precedence.
-
-
- proto - -
- string -
-
- -
Port number or protocol (as supported by the switch).
-
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
-
- psh - -
- string -
-
-
    Choices: -
  • enable
  • -
-
-
Match on the PSH bit.
-
-
- remark - -
- string -
-
- -
If action is set to remark, this is the description.
-
-
- rst - -
- string -
-
-
    Choices: -
  • enable
  • -
-
-
Match on the RST bit.
-
-
- seq - -
- string -
-
- -
Sequence number of the entry (ACE).
-
-
- src - -
- string -
-
- -
Source ip and mask using IP/MASK notation and supports keyword 'any'.
-
-
- src_port1 - -
- string -
-
- -
Port/protocol and also first (lower) port when using range operand.
-
-
- src_port2 - -
- string -
-
- -
Second (end) port when using range operand.
-
-
- src_port_op - -
- string -
-
-
    Choices: -
  • any
  • -
  • eq
  • -
  • gt
  • -
  • lt
  • -
  • neq
  • -
  • range
  • -
-
-
Source port operands such as eq, neq, gt, lt, range.
-
-
- state - -
- string -
-
-
    Choices: -
  • present ←
  • -
  • absent
  • -
  • delete_acl
  • -
-
-
Specify desired state of the resource.
-
-
- syn - -
- string -
-
-
    Choices: -
  • enable
  • -
-
-
Match on the SYN bit.
-
-
- time_range - -
- string -
-
- -
Name of time-range to apply.
-
-
- urg - -
- string -
-
-
    Choices: -
  • enable
  • -
-
-
Match on the URG bit.
-
-
- - -Notes ------ - -.. note:: - - Tested against NXOSv 7.3.(0)D1(1) on VIRL - - Unsupported for Cisco MDS - - ``state=absent`` removes the ACE if it exists. - - ``state=delete_acl`` deletes the ACL if it exists. - - For idempotency, use port numbers for the src/dest port params like *src_port1* and names for the well defined protocols for the *proto* param. - - Although this module is idempotent in that if the ace as presented in the task is identical to the one on the switch, no changes will be made. If there is any difference, what is in Ansible will be pushed (configured options will be overridden). This is to improve security, but at the same time remember an ACE is removed, then re-added, so if there is a change, the new ACE will be exactly what parameters you are sending to the module. - - For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide ` - - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide ` - - For more information on using Ansible to manage Cisco devices see the `Cisco integration page `_. - - - -Examples --------- - -.. code-block:: yaml - - # configure ACL ANSIBLE - - cisco.nxos.nxos_acl: - name: ANSIBLE - seq: 10 - action: permit - proto: tcp - src: 192.0.2.1/24 - dest: any - state: present - - - -Return Values -------------- -Common return values are documented `here `_, the following are the fields unique to this module: - -.. raw:: html - - - - - - - - - - - - -
KeyReturnedDescription
-
- commands - -
- list -
-
always -
commands sent to the device
-
-
Sample:
-
['ip access-list ANSIBLE', '10 permit tcp 192.0.2.1/24 any']
-
-

- - -Status ------- - - -- This module will be removed in a release after 2022-06-01. *[deprecated]* -- For more information see `DEPRECATED`_. - - -Authors -~~~~~~~ - -- Jason Edelman (@jedelman8) -- Gabriele Gerbino (@GGabriele) diff --git a/docs/cisco.nxos.nxos_acls_module.rst b/docs/cisco.nxos.nxos_acls_module.rst index a6db4aeb9..1b806511d 100644 --- a/docs/cisco.nxos.nxos_acls_module.rst +++ b/docs/cisco.nxos.nxos_acls_module.rst @@ -1643,6 +1643,770 @@ Parameters
+
+ icmpv6 + +
+ dictionary +
+
+ +
ICMPv6 protocol options.
+
+
+ beyond_scope + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Destination beyond scope.
+
+
+ destination_unreachable + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Destination address is unreachable.
+
+
+ echo_reply + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Echo reply.
+
+
+ echo_request + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Echo request (ping).
+
+
+ fragments + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Check non-initial fragments.
+
+
+ header + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Parameter header problem.
+
+
+ hop_limit + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Hop limit exceeded in transit.
+
+
+ mld_query + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Multicast Listener Discovery Query.
+
+
+ mld_reduction + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Multicast Listener Discovery Reduction.
+
+
+ mld_report + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Multicast Listener Discovery Report.
+
+
+ mldv2 + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Multicast Listener Discovery Protocol.
+
+
+ nd_na + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Neighbor discovery neighbor advertisements.
+
+
+ nd_ns + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Neighbor discovery neighbor solicitations.
+
+
+ next_header + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Parameter next header problems.
+
+
+ no_admin + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Administration prohibited destination.
+
+
+ no_route + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
No route to destination.
+
+
+ packet_too_big + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Packet too big.
+
+
+ parameter_option + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Parameter option problems.
+
+
+ parameter_problem + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
All parameter problems.
+
+
+ port_unreachable + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Port unreachable.
+
+
+ reassembly_timeout + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Reassembly timeout.
+
+
+ renum_command + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Router renumbering command.
+
+
+ renum_result + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Router renumbering result.
+
+
+ renum_seq_number + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Router renumbering sequence number reset.
+
+
+ router_advertisement + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Neighbor discovery router advertisements.
+
+
+ router_renumbering + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
All router renumbering.
+
+
+ router_solicitation + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Neighbor discovery router solicitations.
+
+
+ telemetry_path + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
IPT enabled.
+
+
+ telemetry_queue + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Flow of interest for BDC/HDC.
+
+
+ time_exceeded + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
All time exceeded.
+
+
+ unreachable + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
All unreachable.
+
+
+ gathered + +
+ list +
+
when state is gathered +
Facts about the network resource gathered from the remote device as structured data.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ parsed + +
+ list +
+
when state is parsed +
The device native config provided in running_config option parsed into structured data as per module argspec.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ rendered + +
+ list +
+
when state is rendered +
The provided configuration in the task rendered in device-native format (offline).
+
+
Sample:
+
['ip access-list ACL1v4', '10 permit ip any any precedence critical log', '20 deny tcp any lt smtp host 192.0.2.64 ack fin']
+


diff --git a/docs/cisco.nxos.nxos_banner_module.rst b/docs/cisco.nxos.nxos_banner_module.rst index 77a556ad2..7502173b7 100644 --- a/docs/cisco.nxos.nxos_banner_module.rst +++ b/docs/cisco.nxos.nxos_banner_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + @@ -2073,6 +2095,29 @@ Parameters
Auto generate RTs for EBGP neighbor.
+ + + + + + + + + @@ -2587,9 +2632,9 @@ Examples address_family: - afi: ipv4 safi: unicast - suppress_inactive: True + suppress_inactive: true next_hop_self: - set: True + set: true - neighbor_address: 203.0.113.2 address_family: - afi: ipv6 @@ -2597,10 +2642,10 @@ Examples - afi: ipv4 safi: multicast send_community: - set: True + set: true - # Task output - # ------------- + # Task output: + # ------------ # before: {} # # commands: @@ -2663,12 +2708,12 @@ Examples # - afi: ipv4 # safi: multicast # send_community: - # set: True + # set: true # - afi: ipv6 # safi: unicast # After state: - # ------------- + # ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65536 # neighbor 192.0.2.32 @@ -2752,11 +2797,11 @@ Examples - afi: ipv4 safi: multicast send_community: - set: True + set: true state: replaced - # Task output - # ------------- + # Task output: + # ------------ # before: # as_number: "65536" # neighbors: @@ -2795,7 +2840,7 @@ Examples # - afi: ipv4 # safi: multicast # send_community: - # set: True + # set: true # - afi: ipv6 # safi: unicast # @@ -2842,12 +2887,12 @@ Examples # - afi: ipv4 # safi: multicast # send_community: - # set: True + # set: true # - afi: ipv6 # safi: unicast # After state: - # ------------- + # ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65536 # neighbor 192.0.2.32 @@ -2909,13 +2954,13 @@ Examples address_family: - afi: ipv4 safi: unicast - suppress_inactive: True + suppress_inactive: true next_hop_self: - set: True + set: true state: overridden - # Task output - # ------------- + # Task output: + # ------------ # before: # as_number: "65536" # neighbors: @@ -2954,7 +2999,7 @@ Examples # - afi: ipv4 # safi: multicast # send_community: - # set: True + # set: true # - afi: ipv6 # safi: unicast # @@ -2988,12 +3033,12 @@ Examples # address_family: # - afi: ipv4 # safi: unicast - # suppress_inactive: True + # suppress_inactive: true # next_hop_self: - # set: True + # set: true # After state: - # ------------- + # ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65536 # neighbor 192.0.2.32 @@ -3049,8 +3094,8 @@ Examples safi: unicast state: deleted - # Task output - # ------------- + # Task output: + # ------------ # before: # as_number: "65536" # neighbors: @@ -3089,7 +3134,7 @@ Examples # - afi: ipv4 # safi: multicast # send_community: - # set: True + # set: true # - afi: ipv6 # safi: unicast # @@ -3130,10 +3175,10 @@ Examples # - afi: ipv4 # safi: multicast # send_community: - # set: True + # set: true # # After state: - # ------------- + # ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65536 # neighbor 192.0.2.32 @@ -3182,8 +3227,8 @@ Examples cisco.nxos.nxos_bgp_neighbor_address_family: state: deleted - # Task output - # ------------- + # Task output: + # ------------ # before: # as_number: "65536" # neighbors: @@ -3222,7 +3267,7 @@ Examples # - afi: ipv4 # safi: multicast # send_community: - # set: True + # set: true # - afi: ipv6 # safi: unicast # @@ -3244,7 +3289,7 @@ Examples # as_number: "65536" # # After state: - # ------------- + # ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65536 # neighbor 192.0.2.32 @@ -3288,9 +3333,9 @@ Examples address_family: - afi: ipv4 safi: unicast - suppress_inactive: True + suppress_inactive: true next_hop_self: - set: True + set: true - neighbor_address: 203.0.113.2 address_family: - afi: ipv6 @@ -3298,11 +3343,11 @@ Examples - afi: ipv4 safi: multicast send_community: - set: True + set: true state: rendered - # Task Output (redacted) - # ----------------------- + # Task output: + # ------------ # rendered: # - router bgp 65536 # - neighbor 192.0.2.32 @@ -3356,8 +3401,8 @@ Examples running_config: "{{ lookup('file', 'parsed.cfg') }}" state: parsed - # Task output (redacted) - # ----------------------- + # Task output: + # ------------ # parsed: # as_number: "65536" # neighbors: @@ -3396,12 +3441,129 @@ Examples # - afi: ipv4 # safi: multicast # send_community: - # set: True + # set: true # - afi: ipv6 # safi: unicast +Return Values +------------- +Common return values are documented `here `_, the following are the fields unique to this module: + +.. raw:: html + +
ParameterParameter Choices/Defaults Comments
+
banner @@ -54,241 +54,23 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
- ssh_keyfile + multiline_delimiter
string
+ Default:
"@"
-
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
+
Specify the delimiting character than will be used for configuration.
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
state @@ -307,7 +89,7 @@ Parameters
+
text diff --git a/docs/cisco.nxos.nxos_bfd_global_module.rst b/docs/cisco.nxos.nxos_bfd_global_module.rst index 601382588..8cd86ec48 100644 --- a/docs/cisco.nxos.nxos_bfd_global_module.rst +++ b/docs/cisco.nxos.nxos_bfd_global_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + @@ -4002,6 +4019,24 @@ Parameters
Specify Autonomous System Number of the neighbor.
+ + + + + + + + @@ -4544,6 +4579,7 @@ Parameters
    Choices:
  • merged ←
  • replaced
  • +
  • overridden
  • deleted
  • purged
  • parsed
  • @@ -4556,7 +4592,8 @@ Parameters
    State purged removes all the BGP configurations from the target device. Use caution with this state.
    State deleted only removes BGP attributes that this modules manages and does not negate the BGP process completely. Thereby, preserving address-family related configurations under BGP context.
    Running states deleted and replaced will result in an error if there are address-family configuration lines present under a neighbor, or a vrf context that is to be removed. Please use the cisco.nxos.nxos_bgp_af or cisco.nxos.nxos_bgp_neighbor_af modules for prior cleanup.
    -
    States merged and replaced will result in a failure if BGP is already configured with a different ASN than what is provided in the task. In such cases, please use state purged to remove the existing BGP process and proceed further.
    +
    States merged and replaced will result in a failure if BGP is already configured with a different ASN than what is provided in the task. In such cases, please use state purged to remove the existing BGP process and proceed further.
    +
    States replaced and overridden have the same behaviour for this module.
    Refer to examples for more details.
@@ -4593,16 +4630,16 @@ Examples router_id: 192.168.1.1 bestpath: as_path: - multipath_relax: True - compare_neighborid: True - cost_community_ignore: True + multipath_relax: true + compare_neighborid: true + cost_community_ignore: true confederation: identifier: 42 peers: - 65020 - 65030 - 65040 - log_neighbor_changes: True + log_neighbor_changes: true maxas_limit: 20 neighbors: - neighbor_address: 192.168.1.100 @@ -4612,19 +4649,19 @@ Examples remote_as: 65563 description: NBR-1 low_memory: - exempt: True + exempt: true - neighbor_address: 192.168.1.101 remote_as: 65563 password: encryption: 7 key: 12090404011C03162E neighbor_down: - fib_accelerate: True + fib_accelerate: true vrfs: - vrf: site-1 allocate_index: 5000 local_as: 200 - log_neighbor_changes: True + log_neighbor_changes: true neighbors: - neighbor_address: 198.51.100.1 description: site-1-nbr-1 @@ -4637,7 +4674,7 @@ Examples description: site-1-nbr-2 - vrf: site-2 local_as: 300 - log_neighbor_changes: True + log_neighbor_changes: true neighbors: - neighbor_address: 203.0.113.2 description: site-2-nbr-1 @@ -4646,10 +4683,10 @@ Examples key: AF92F4C16A0A0EC5BDF56CF58BC030F6 remote_as: 65568 neighbor_down: - fib_accelerate: True + fib_accelerate: true - # Task output - # ------------- + # Task output: + # ------------ # before: {} # # commands: @@ -4754,7 +4791,7 @@ Examples # After state: - # ------------- + # ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65563 # router-id 192.168.1.1 @@ -4845,8 +4882,8 @@ Examples as_number: 65563 router_id: 192.168.1.1 bestpath: - compare_neighborid: True - cost_community_ignore: True + compare_neighborid: true + cost_community_ignore: true confederation: identifier: 42 peers: @@ -4862,24 +4899,24 @@ Examples remote_as: 65563 description: NBR-1 low_memory: - exempt: True + exempt: true neighbor_down: - fib_accelerate: True + fib_accelerate: true vrfs: - vrf: site-2 local_as: 300 - log_neighbor_changes: True + log_neighbor_changes: true neighbors: - neighbor_address: 203.0.113.2 password: encryption: 7 key: 12090404011C03162E neighbor_down: - fib_accelerate: True + fib_accelerate: true state: replaced - # Task output - # ------------- + # Task output: + # ------------ # before: # as_number: '65563' # bestpath: @@ -4992,7 +5029,7 @@ Examples # vrf: site-2 # # After state: - # ------------- + # ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65563 # router-id 192.168.1.1 @@ -5073,8 +5110,8 @@ Examples cisco.nxos.nxos_bgp_global: state: deleted - # Task output - # ------------- + # Task output: + # ------------ # before: # as_number: '65563' @@ -5156,7 +5193,7 @@ Examples # as_number: '65563' # # After state: - # ------------- + # ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65563 # address-family ipv4 unicast @@ -5226,8 +5263,8 @@ Examples cisco.nxos.nxos_bgp_global: state: purged - # Task output - # ------------- + # Task output: + # ------------ # before: # as_number: '65563' @@ -5295,7 +5332,7 @@ Examples # after: {} # # After state: - # ------------- + # ------------ # Nexus9000v# show running-config | section "^router bgp" # Nexus9000v# @@ -5308,16 +5345,16 @@ Examples router_id: 192.168.1.1 bestpath: as_path: - multipath_relax: True - compare_neighborid: True - cost_community_ignore: True + multipath_relax: true + compare_neighborid: true + cost_community_ignore: true confederation: identifier: 42 peers: - 65020 - 65030 - 65040 - log_neighbor_changes: True + log_neighbor_changes: true maxas_limit: 20 neighbors: - neighbor_address: 192.168.1.100 @@ -5327,19 +5364,19 @@ Examples remote_as: 65563 description: NBR-1 low_memory: - exempt: True + exempt: true - neighbor_address: 192.168.1.101 remote_as: 65563 password: encryption: 7 key: 12090404011C03162E neighbor_down: - fib_accelerate: True + fib_accelerate: true vrfs: - vrf: site-1 allocate_index: 5000 local_as: 200 - log_neighbor_changes: True + log_neighbor_changes: true neighbors: - neighbor_address: 198.51.100.1 description: site-1-nbr-1 @@ -5352,7 +5389,7 @@ Examples description: site-1-nbr-2 - vrf: site-2 local_as: 300 - log_neighbor_changes: True + log_neighbor_changes: true neighbors: - neighbor_address: 203.0.113.2 description: site-1-nbr-1 @@ -5361,10 +5398,10 @@ Examples key: AF92F4C16A0A0EC5BDF56CF58BC030F6 remote_as: 65568 neighbor_down: - fib_accelerate: True + fib_accelerate: true - # Task Output (redacted) - # ----------------------- + # Task output: + # ------------ # rendered: # - router bgp 65563 # - bestpath as-path multipath-relax @@ -5453,8 +5490,8 @@ Examples running_config: "{{ lookup('file', 'parsed.cfg') }}" state: parsed - # Task output (redacted) - # ----------------------- + # Task output: + # ------------ # parsed: # as_number: '65563' # bestpath: @@ -5546,8 +5583,8 @@ Examples cisco.nxos.nxos_bgp_global: state: gathered - # Task output (redacted) - # ----------------------- + # Task output: + # ------------ # gathered: # as_number: '65563' # bestpath: @@ -5611,7 +5648,7 @@ Examples as_number: 65536 router_id: 198.51.100.2 maxas_limit: 20 - log_neighbor_changes: True + log_neighbor_changes: true neighbors: - neighbor_address: 192.0.2.1 remote_as: 65537 @@ -5620,8 +5657,8 @@ Examples key: 12090404011C03162E state: replaced - # Task output (redacted) - # ----------------------- + # Task output: + # ------------ # fatal: [Nexus9000v]: FAILED! => changed=false # msg: Neighbor 203.0.113.2 has address-family configurations. # Please use the nxos_bgp_neighbor_af module to remove those first. @@ -5655,7 +5692,7 @@ Examples as_number: 65536 router_id: 198.51.100.2 maxas_limit: 20 - log_neighbor_changes: True + log_neighbor_changes: true neighbors: - neighbor_address: 192.0.2.1 remote_as: 65537 @@ -5665,11 +5702,11 @@ Examples vrfs: - vrf: site-2 neighbor_down: - fib_accelerate: True + fib_accelerate: true state: replaced - # Task output (redacted) - # ----------------------- + # Task output: + # ------------ # fatal: [Nexus9000v]: FAILED! => changed=false # msg: VRF site-1 has address-family configurations. # Please use the nxos_bgp_af module to remove those first. @@ -5741,6 +5778,57 @@ Common return values are documented `here ['router bgp 65563', 'maxas-limit 20', 'router-id 192.168.1.1', 'confederation peers 65020 65030 65040', 'neighbor 192.168.1.100', 'remote-as 65563', 'affinity-group 160', 'bmp-activate-server 1', 'description NBR-1', 'low-memory exempt', 'vrf site-1', 'log-neighbor-changes', 'neighbor 198.51.100.1', 'remote-as 65562', 'description site-1-nbr-1', 'password 3 13D4D3549493D2877B1DC116EE27A6BE'] + + + + + + + + + + + + + + +
ParameterParameter Choices/Defaults Comments
+
echo_interface @@ -51,7 +51,7 @@ Parameters
+
echo_rx_interval @@ -66,7 +66,7 @@ Parameters
+
fabricpath_interval @@ -82,7 +82,7 @@ Parameters
+
fabricpath_slow_timer @@ -97,7 +97,7 @@ Parameters
+
fabricpath_vlan @@ -112,7 +112,7 @@ Parameters
+
interval @@ -128,7 +128,7 @@ Parameters
+
ipv4_echo_rx_interval @@ -143,7 +143,7 @@ Parameters
+
ipv4_interval @@ -159,7 +159,7 @@ Parameters
+
ipv4_slow_timer @@ -174,7 +174,7 @@ Parameters
+
ipv6_echo_rx_interval @@ -189,7 +189,7 @@ Parameters
+
ipv6_interval @@ -205,7 +205,7 @@ Parameters
+
ipv6_slow_timer @@ -220,241 +220,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
slow_timer @@ -469,7 +235,7 @@ Parameters
+
startup_timer diff --git a/docs/cisco.nxos.nxos_bfd_interfaces_module.rst b/docs/cisco.nxos.nxos_bfd_interfaces_module.rst index 17aac421c..975de891c 100644 --- a/docs/cisco.nxos.nxos_bfd_interfaces_module.rst +++ b/docs/cisco.nxos.nxos_bfd_interfaces_module.rst @@ -178,12 +178,12 @@ Examples - name: Configure interfaces cisco.nxos.nxos_bfd_interfaces: config: - - name: Ethernet1/1 - bfd: enable - echo: enable - - name: Ethernet1/2 - bfd: disable - echo: disable + - name: Ethernet1/1 + bfd: enable + echo: enable + - name: Ethernet1/2 + bfd: disable + echo: disable state: merged @@ -192,12 +192,12 @@ Examples - name: Configure interfaces cisco.nxos.nxos_bfd_interfaces: config: - - name: Ethernet1/1 - bfd: enable - echo: enable - - name: Ethernet1/2 - bfd: disable - echo: disable + - name: Ethernet1/1 + bfd: enable + echo: enable + - name: Ethernet1/2 + bfd: disable + echo: disable state: overridden @@ -206,12 +206,12 @@ Examples - name: Configure interfaces cisco.nxos.nxos_bfd_interfaces: config: - - name: Ethernet1/1 - bfd: enable - echo: enable - - name: Ethernet1/2 - bfd: disable - echo: disable + - name: Ethernet1/1 + bfd: enable + echo: enable + - name: Ethernet1/2 + bfd: disable + echo: disable state: replaced # Using rendered @@ -219,12 +219,12 @@ Examples - name: Use rendered state to convert task input to device specific commands cisco.nxos.nxos_bfd_interfaces: config: - - name: Ethernet1/800 - bfd: enable - echo: enable - - name: Ethernet1/801 - bfd: disable - echo: disable + - name: Ethernet1/800 + bfd: enable + echo: enable + - name: Ethernet1/801 + bfd: disable + echo: disable state: rendered # Task Output (redacted) diff --git a/docs/cisco.nxos.nxos_bgp_address_family_module.rst b/docs/cisco.nxos.nxos_bgp_address_family_module.rst index 10444549a..d16dbee7d 100644 --- a/docs/cisco.nxos.nxos_bgp_address_family_module.rst +++ b/docs/cisco.nxos.nxos_bgp_address_family_module.rst @@ -1674,11 +1674,11 @@ Examples safi: unicast vrf: site-1 default_information: - originate: True + originate: true aggregate_address: - prefix: 203.0.113.0/24 - as_set: True - summary_only: True + as_set: true + summary_only: true - afi: ipv6 safi: multicast vrf: site-1 @@ -1690,8 +1690,8 @@ Examples id: 101 route_map: rmap-eigrp-1 - # Task output - # ------------- + # Task output: + # ------------ # before: {} # # commands: @@ -1727,11 +1727,11 @@ Examples # safi: unicast # vrf: site-1 # default_information: - # originate: True + # originate: true # aggregate_address: # - prefix: 203.0.113.0/24 - # as_set: True - # summary_only: True + # as_set: true + # summary_only: true # - afi: ipv6 # safi: multicast # vrf: site-1 @@ -1744,7 +1744,7 @@ Examples # route_map: rmap-eigrp-1 # After state: - # ------------- + # ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65536 # address-family ipv4 multicast @@ -1797,15 +1797,15 @@ Examples non_critical_delay: 180 aggregate_address: - prefix: 203.0.113.0/24 - as_set: True - summary_only: True + as_set: true + summary_only: true - afi: ipv4 safi: unicast vrf: site-1 state: replaced - # Task output - # ------------- + # Task output: + # ------------ # before: # as_number: "65536" # address_family: @@ -1824,11 +1824,11 @@ Examples # safi: unicast # vrf: site-1 # default_information: - # originate: True + # originate: true # aggregate_address: # - prefix: 203.0.113.0/24 - # as_set: True - # summary_only: True + # as_set: true + # summary_only: true # - afi: ipv6 # safi: multicast # vrf: site-1 @@ -1865,8 +1865,8 @@ Examples # non_critical_delay: 180 # aggregate_address: # - prefix: 203.0.113.0/24 - # as_set: True - # summary_only: True + # as_set: true + # summary_only: true # # - afi: ipv4 # safi: unicast @@ -1884,7 +1884,7 @@ Examples # route_map: rmap-eigrp-1 # After state: - # ------------- + # ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65536 # address-family ipv4 multicast @@ -1929,15 +1929,15 @@ Examples route_map: rmap1 aggregate_address: - prefix: 203.0.113.0/24 - as_set: True - summary_only: True + as_set: true + summary_only: true - afi: ipv4 safi: unicast vrf: site-1 state: overridden - # Task output - # ------------- + # Task output: + # ------------ # before: # as_number: "65536" # address_family: @@ -1956,11 +1956,11 @@ Examples # safi: unicast # vrf: site-1 # default_information: - # originate: True + # originate: true # aggregate_address: # - prefix: 203.0.113.0/24 - # as_set: True - # summary_only: True + # as_set: true + # summary_only: true # - afi: ipv6 # safi: multicast # vrf: site-1 @@ -1997,15 +1997,15 @@ Examples # route_map: rmap1 # aggregate_address: # - prefix: 203.0.113.0/24 - # as_set: True - # summary_only: True + # as_set: true + # summary_only: true # - afi: ipv4 # safi: unicast # vrf: site-1 # # After state: - # ------------- + # ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65536 # address-family ipv4 multicast @@ -2046,8 +2046,8 @@ Examples safi: multicast state: deleted - # Task output - # ------------- + # Task output: + # ------------ # before: # as_number: "65536" # address_family: @@ -2066,11 +2066,11 @@ Examples # safi: unicast # vrf: site-1 # default_information: - # originate: True + # originate: true # aggregate_address: # - prefix: 203.0.113.0/24 - # as_set: True - # summary_only: True + # as_set: true + # summary_only: true # - afi: ipv6 # safi: multicast # vrf: site-1 @@ -2095,14 +2095,14 @@ Examples # safi: unicast # vrf: site-1 # default_information: - # originate: True + # originate: true # aggregate_address: # - prefix: 203.0.113.0/24 - # as_set: True - # summary_only: True + # as_set: true + # summary_only: true # After state: - # ------------- + # ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65536 # vrf site-1 @@ -2133,8 +2133,8 @@ Examples cisco.nxos.nxos_bgp_address_family: state: deleted - # Task output - # ------------- + # Task output: + # ------------ # before: # as_number: "65536" # address_family: @@ -2153,11 +2153,11 @@ Examples # safi: unicast # vrf: site-1 # default_information: - # originate: True + # originate: true # aggregate_address: # - prefix: 203.0.113.0/24 - # as_set: True - # summary_only: True + # as_set: true + # summary_only: true # - afi: ipv6 # safi: multicast # vrf: site-1 @@ -2180,7 +2180,7 @@ Examples # as_number: "65536" # After state: - # ------------- + # ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65536 # Nexus9000v# @@ -2207,11 +2207,11 @@ Examples safi: unicast vrf: site-1 default_information: - originate: True + originate: true aggregate_address: - prefix: 203.0.113.0/24 - as_set: True - summary_only: True + as_set: true + summary_only: true - afi: ipv6 safi: multicast vrf: site-1 @@ -2224,8 +2224,8 @@ Examples route_map: rmap-eigrp-1 state: rendered - # Task Output (redacted) - # ----------------------- + # Task Output: + # ------------ # rendered: # - router bgp 65536 # - address-family ipv4 multicast @@ -2264,8 +2264,8 @@ Examples running_config: "{{ lookup('file', 'parsed.cfg') }}" state: parsed - # Task output (redacted) - # ----------------------- + # Task output: + # ------------ # parsed: # as_number: "65536" # address_family: @@ -2284,11 +2284,11 @@ Examples # safi: unicast # vrf: site-1 # default_information: - # originate: True + # originate: true # aggregate_address: # - prefix: 203.0.113.0/24 - # as_set: True - # summary_only: True + # as_set: true + # summary_only: true # - afi: ipv6 # safi: multicast # vrf: site-1 @@ -2302,6 +2302,123 @@ Examples +Return Values +------------- +Common return values are documented `here `_, the following are the fields unique to this module: + +.. raw:: html + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
KeyReturnedDescription
+
+ after + +
+ dictionary +
+
when changed +
The resulting configuration after module execution.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ before + +
+ dictionary +
+
when state is merged, replaced, overridden, deleted or purged +
The configuration prior to the module execution.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ commands + +
+ list +
+
when state is merged, replaced, overridden, deleted or purged +
The set of commands pushed to the remote device.
+
+
Sample:
+
['router bgp 65536', 'address-family ipv4 multicast', 'nexthop route-map rmap2']
+
+
+ gathered + +
+ dictionary +
+
when state is gathered +
Facts about the network resource gathered from the remote device as structured data.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ parsed + +
+ dictionary +
+
when state is parsed +
The device native config provided in running_config option parsed into structured data as per module argspec.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ rendered + +
+ list +
+
when state is rendered +
The provided configuration in the task rendered in device-native format (offline).
+
+
Sample:
+
['router bgp 65536', 'address-family ipv4 multicast', 'nexthop route-map rmap2']
+
+

+ Status ------ diff --git a/docs/cisco.nxos.nxos_bgp_af_module.rst b/docs/cisco.nxos.nxos_bgp_af_module.rst deleted file mode 100644 index eaeb00f50..000000000 --- a/docs/cisco.nxos.nxos_bgp_af_module.rst +++ /dev/null @@ -1,911 +0,0 @@ -.. _cisco.nxos.nxos_bgp_af_module: - - -********************** -cisco.nxos.nxos_bgp_af -********************** - -**(deprecated, removed after 2023-02-24) Manages BGP Address-family configuration.** - - -Version added: 1.0.0 - -.. contents:: - :local: - :depth: 1 - -DEPRECATED ----------- -:Removed in collection release after 2023-02-24 -:Why: Updated module released with more functionality. -:Alternative: nxos_bgp_address_family - - - -Synopsis --------- -- Manages BGP Address-family configurations on NX-OS switches. - - - - -Parameters ----------- - -.. raw:: html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterChoices/DefaultsComments
-
- additional_paths_install - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Install a backup path into the forwarding table and provide prefix independent convergence (PIC) in case of a PE-CE link failure.
-
-
- additional_paths_receive - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enables the receive capability of additional paths for all of the neighbors under this address family for which the capability has not been disabled.
-
-
- additional_paths_selection - -
- string -
-
- -
Configures the capability of selecting additional paths for a prefix. Valid values are a string defining the name of the route-map.
-
-
- additional_paths_send - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enables the send capability of additional paths for all of the neighbors under this address family for which the capability has not been disabled.
-
-
- advertise_l2vpn_evpn - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Advertise evpn routes.
-
-
- afi - -
- string - / required -
-
-
    Choices: -
  • ipv4
  • -
  • ipv6
  • -
  • vpnv4
  • -
  • vpnv6
  • -
  • l2vpn
  • -
-
-
Address Family Identifier.
-
-
- asn - -
- string - / required -
-
- -
BGP autonomous system number. Valid values are String, Integer in ASPLAIN or ASDOT notation.
-
-
- client_to_client - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Configure client-to-client route reflection.
-
-
- dampen_igp_metric - -
- string -
-
- -
Specify dampen value for IGP metric-related changes, in seconds. Valid values are integer and keyword 'default'.
-
-
- dampening_half_time - -
- string -
-
- -
Specify decay half-life in minutes for route-flap dampening. Valid values are integer and keyword 'default'.
-
-
- dampening_max_suppress_time - -
- string -
-
- -
Specify max suppress time for route-flap dampening stable route. Valid values are integer and keyword 'default'.
-
-
- dampening_reuse_time - -
- string -
-
- -
Specify route reuse time for route-flap dampening. Valid values are integer and keyword 'default'.
-
-
- dampening_routemap - -
- string -
-
- -
Specify route-map for route-flap dampening. Valid values are a string defining the name of the route-map.
-
-
- dampening_state - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enable/disable route-flap dampening.
-
-
- dampening_suppress_time - -
- string -
-
- -
Specify route suppress time for route-flap dampening. Valid values are integer and keyword 'default'.
-
-
- default_information_originate - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Default information originate.
-
-
- default_metric - -
- string -
-
- -
Sets default metrics for routes redistributed into BGP. Valid values are Integer or keyword 'default'
-
-
- distance_ebgp - -
- string -
-
- -
Sets the administrative distance for eBGP routes. Valid values are Integer or keyword 'default'.
-
-
- distance_ibgp - -
- string -
-
- -
Sets the administrative distance for iBGP routes. Valid values are Integer or keyword 'default'.
-
-
- distance_local - -
- string -
-
- -
Sets the administrative distance for local BGP routes. Valid values are Integer or keyword 'default'.
-
-
- inject_map - -
- list - / elements=list -
-
- -
An array of route-map names which will specify prefixes to inject. Each array entry must first specify the inject-map name, secondly an exist-map name, and optionally the copy-attributes keyword which indicates that attributes should be copied from the aggregate. For example [['lax_inject_map', 'lax_exist_map'], ['nyc_inject_map', 'nyc_exist_map', 'copy-attributes'], ['fsd_inject_map', 'fsd_exist_map']].
-
-
- maximum_paths - -
- string -
-
- -
Configures the maximum number of equal-cost paths for load sharing. Valid value is an integer in the range 1-64.
-
-
- maximum_paths_ibgp - -
- string -
-
- -
Configures the maximum number of ibgp equal-cost paths for load sharing. Valid value is an integer in the range 1-64.
-
-
- networks - -
- list - / elements=list -
-
- -
Networks to configure. Valid value is a list of network prefixes to advertise. The list must be in the form of an array. Each entry in the array must include a prefix address and an optional route-map. For example [['10.0.0.0/16', 'routemap_LA'], ['192.168.1.1', 'Chicago'], ['192.168.2.0/24'], ['192.168.3.0/24', 'routemap_NYC']].
-
-
- next_hop_route_map - -
- string -
-
- -
Configure a route-map for valid nexthops. Valid values are a string defining the name of the route-map.
-
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
-
- redistribute - -
- list - / elements=list -
-
- -
A list of redistribute directives. Multiple redistribute entries are allowed. The list must be in the form of a nested array. the first entry of each array defines the source-protocol to redistribute from; the second entry defines a route-map name. A route-map is highly advised but may be optional on some platforms, in which case it may be omitted from the array list. For example [['direct', 'rm_direct'], ['lisp', 'rm_lisp']].
-
-
- retain_route_target - -
- string -
-
added in 1.1.0
-
- -
Retains all of the routes or the routes which are part of configured route-map. Valid values are route-map names or keyword all or keyword default. all retains all the routes regardless of Target-VPN community. default will disable the retain route target option. If you are using route-map name please ensure that the name is not same as all and default.
-
-
- safi - -
- string - / required -
-
-
    Choices: -
  • unicast
  • -
  • multicast
  • -
  • evpn
  • -
-
-
Sub Address Family Identifier.
-
-
- state - -
- string -
-
-
    Choices: -
  • present ←
  • -
  • absent
  • -
-
-
Determines whether the config should be present or not on the device.
-
-
- suppress_inactive - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Advertises only active routes to peers.
-
-
- table_map - -
- string -
-
- -
Apply table-map to filter routes downloaded into URIB. Valid values are a string.
-
-
- table_map_filter - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Filters routes rejected by the route-map and does not download them to the RIB.
-
-
- vrf - -
- string -
-
- Default:
"default"
-
-
Name of the VRF. The name 'default' is a valid VRF representing the global bgp.
-
-
- - -Notes ------ - -.. note:: - - Tested against NXOSv 7.3.(0)D1(1) on VIRL - - Unsupported for Cisco MDS - - ``state=absent`` removes the whole BGP ASN configuration - - Default, where supported, restores params default value. - - For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide ` - - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide ` - - For more information on using Ansible to manage Cisco devices see the `Cisco integration page `_. - - - -Examples --------- - -.. code-block:: yaml - - # configure a simple address-family - - cisco.nxos.nxos_bgp_af: - asn: 65535 - vrf: TESTING - afi: ipv4 - safi: unicast - advertise_l2vpn_evpn: true - state: present - retain_route_target: all - - - -Return Values -------------- -Common return values are documented `here `_, the following are the fields unique to this module: - -.. raw:: html - - - - - - - - - - - - -
KeyReturnedDescription
-
- commands - -
- list -
-
always -
commands sent to the device
-
-
Sample:
-
['router bgp 65535', 'vrf TESTING', 'address-family ipv4 unicast', 'advertise l2vpn evpn', 'retain route-target all']
-
-

- - -Status ------- - - -- This module will be removed in a release after 2023-02-24. *[deprecated]* -- For more information see `DEPRECATED`_. - - -Authors -~~~~~~~ - -- Gabriele Gerbino (@GGabriele) diff --git a/docs/cisco.nxos.nxos_bgp_global_module.rst b/docs/cisco.nxos.nxos_bgp_global_module.rst index a658b46ad..19ee2709e 100644 --- a/docs/cisco.nxos.nxos_bgp_global_module.rst +++ b/docs/cisco.nxos.nxos_bgp_global_module.rst @@ -1887,6 +1887,23 @@ Parameters
Specify Autonomous System Number of the neighbor.
+
+ remote_as_route_map + +
+ string +
+
+ +
Route-map to match prefix peer AS number.
+
+
+ remote_as_route_map + +
+ string +
+
+ +
Route-map to match prefix peer AS number.
+
+
+ gathered + +
+ dictionary +
+
when state is gathered +
Facts about the network resource gathered from the remote device as structured data.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ parsed + +
+ dictionary +
+
when state is parsed +
The device native config provided in running_config option parsed into structured data as per module argspec.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ rendered + +
+ list +
+
when state is rendered +
The provided configuration in the task rendered in device-native format (offline).
+
+
Sample:
+
['router bgp 65563', 'maxas-limit 20', 'router-id 192.168.1.1']
+


diff --git a/docs/cisco.nxos.nxos_bgp_module.rst b/docs/cisco.nxos.nxos_bgp_module.rst deleted file mode 100644 index 3fc82991e..000000000 --- a/docs/cisco.nxos.nxos_bgp_module.rst +++ /dev/null @@ -1,1074 +0,0 @@ -.. _cisco.nxos.nxos_bgp_module: - - -******************* -cisco.nxos.nxos_bgp -******************* - -**(deprecated, removed after 2023-01-27) Manages BGP configuration.** - - -Version added: 1.0.0 - -.. contents:: - :local: - :depth: 1 - -DEPRECATED ----------- -:Removed in collection release after 2023-01-27 -:Why: Updated module released with more functionality. -:Alternative: nxos_bgp_global - - - -Synopsis --------- -- Manages BGP configurations on NX-OS switches. - - - - -Parameters ----------- - -.. raw:: html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterChoices/DefaultsComments
-
- asn - -
- string - / required -
-
- -
BGP autonomous system number. Valid values are String, Integer in ASPLAIN or ASDOT notation.
-
-
- bestpath_always_compare_med - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enable/Disable MED comparison on paths from different autonomous systems.
-
-
- bestpath_aspath_multipath_relax - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enable/Disable load sharing across the providers with different (but equal-length) AS paths.
-
-
- bestpath_compare_neighborid - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enable/Disable neighborid. Use this when more paths available than max path config.
-
-
- bestpath_compare_routerid - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enable/Disable comparison of router IDs for identical eBGP paths.
-
-
- bestpath_cost_community_ignore - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enable/Disable Ignores the cost community for BGP best-path calculations.
-
-
- bestpath_med_confed - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enable/Disable enforcement of bestpath to do a MED comparison only between paths originated within a confederation.
-
-
- bestpath_med_missing_as_worst - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enable/Disable assigns the value of infinity to received routes that do not carry the MED attribute, making these routes the least desirable.
-
-
- bestpath_med_non_deterministic - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enable/Disable deterministic selection of the best MED pat from among the paths from the same autonomous system.
-
-
- cluster_id - -
- string -
-
- -
Route Reflector Cluster-ID.
-
-
- confederation_id - -
- string -
-
- -
Routing domain confederation AS.
-
-
- confederation_peers - -
- list - / elements=string -
-
- -
AS confederation parameters.
-
-
- disable_policy_batching - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enable/Disable the batching evaluation of prefix advertisement to all peers.
-
-
- disable_policy_batching_ipv4_prefix_list - -
- string -
-
- -
Enable/Disable the batching evaluation of prefix advertisements to all peers with prefix list.
-
-
- disable_policy_batching_ipv6_prefix_list - -
- string -
-
- -
Enable/Disable the batching evaluation of prefix advertisements to all peers with prefix list.
-
-
- enforce_first_as - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enable/Disable enforces the neighbor autonomous system to be the first AS number listed in the AS path attribute for eBGP. On NX-OS, this property is only supported in the global BGP context.
-
-
- event_history_cli - -
- string -
-
-
    Choices: -
  • size_small
  • -
  • size_medium
  • -
  • size_large
  • -
  • size_disable
  • -
  • default
  • -
  • true
  • -
  • false
  • -
-
-
Enable/Disable cli event history buffer.
-
-
- event_history_detail - -
- string -
-
-
    Choices: -
  • size_small
  • -
  • size_medium
  • -
  • size_large
  • -
  • size_disable
  • -
  • default
  • -
  • true
  • -
  • false
  • -
-
-
Enable/Disable detail event history buffer.
-
-
- event_history_events - -
- string -
-
-
    Choices: -
  • size_small
  • -
  • size_medium
  • -
  • size_large
  • -
  • size_disable
  • -
  • default
  • -
  • true
  • -
  • false
  • -
-
-
Enable/Disable event history buffer.
-
-
- event_history_periodic - -
- string -
-
-
    Choices: -
  • size_small
  • -
  • size_medium
  • -
  • size_large
  • -
  • size_disable
  • -
  • default
  • -
  • true
  • -
  • false
  • -
-
-
Enable/Disable periodic event history buffer.
-
-
- fast_external_fallover - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enable/Disable immediately reset the session if the link to a directly connected BGP peer goes down. Only supported in the global BGP context.
-
-
- flush_routes - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enable/Disable flush routes in RIB upon controlled restart. On NX-OS, this property is only supported in the global BGP context.
-
-
- graceful_restart - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enable/Disable graceful restart.
-
-
- graceful_restart_helper - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enable/Disable graceful restart helper mode.
-
-
- graceful_restart_timers_restart - -
- string -
-
- -
Set maximum time for a restart sent to the BGP peer.
-
-
- graceful_restart_timers_stalepath_time - -
- string -
-
- -
Set maximum time that BGP keeps the stale routes from the restarting BGP peer.
-
-
- isolate - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enable/Disable isolate this router from BGP perspective.
-
-
- local_as - -
- string -
-
- -
Local AS number to be used within a VRF instance.
-
-
- log_neighbor_changes - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enable/Disable message logging for neighbor up/down event.
-
-
- maxas_limit - -
- string -
-
- -
Specify Maximum number of AS numbers allowed in the AS-path attribute. Valid values are between 1 and 512.
-
-
- neighbor_down_fib_accelerate - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enable/Disable handle BGP neighbor down event, due to various reasons.
-
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
-
- reconnect_interval - -
- string -
-
- -
The BGP reconnection interval for dropped sessions. Valid values are between 1 and 60.
-
-
- router_id - -
- string -
-
- -
Router Identifier (ID) of the BGP router VRF instance.
-
-
- shutdown - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Administratively shutdown the BGP protocol.
-
-
- state - -
- string -
-
-
    Choices: -
  • present ←
  • -
  • absent
  • -
-
-
Determines whether the config should be present or not on the device.
-
-
- suppress_fib_pending - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enable/Disable advertise only routes programmed in hardware to peers.
-
-
- timer_bestpath_limit - -
- string -
-
- -
Specify timeout for the first best path after a restart, in seconds.
-
-
- timer_bgp_hold - -
- string -
-
- -
Set BGP hold timer.
-
-
- timer_bgp_keepalive - -
- string -
-
- -
Set BGP keepalive timer.
-
-
- vrf - -
- string -
-
- Default:
"default"
-
-
Name of the VRF. The name 'default' is a valid VRF representing the global BGP.
-
-
- - -Notes ------ - -.. note:: - - Tested against NXOSv 7.3.(0)D1(1) on VIRL - - Unsupported for Cisco MDS - - ``state=absent`` removes the whole BGP ASN configuration when ``vrf=default`` or the whole VRF instance within the BGP process when using a different VRF. - - Default when supported restores params default value. - - Configuring global params is only permitted if ``vrf=default``. - - For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide ` - - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide ` - - For more information on using Ansible to manage Cisco devices see the `Cisco integration page `_. - - - -Examples --------- - -.. code-block:: yaml - - - name: Configure a simple ASN - cisco.nxos.nxos_bgp: - asn: 65535 - vrf: test - router_id: 192.0.2.1 - state: present - - - -Return Values -------------- -Common return values are documented `here `_, the following are the fields unique to this module: - -.. raw:: html - - - - - - - - - - - - -
KeyReturnedDescription
-
- commands - -
- list -
-
always -
commands sent to the device
-
-
Sample:
-
['router bgp 65535', 'vrf test', 'router-id 192.0.2.1']
-
-

- - -Status ------- - - -- This module will be removed in a release after 2023-01-27. *[deprecated]* -- For more information see `DEPRECATED`_. - - -Authors -~~~~~~~ - -- Jason Edelman (@jedelman8) -- Gabriele Gerbino (@GGabriele) diff --git a/docs/cisco.nxos.nxos_bgp_neighbor_address_family_module.rst b/docs/cisco.nxos.nxos_bgp_neighbor_address_family_module.rst index 0473c5d76..8668a0b9f 100644 --- a/docs/cisco.nxos.nxos_bgp_neighbor_address_family_module.rst +++ b/docs/cisco.nxos.nxos_bgp_neighbor_address_family_module.rst @@ -853,6 +853,28 @@ Parameters
Auto generate RTs for EBGP neighbor.
+
+ rewrite_rt_asn + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Auto generate RTs for EBGP neighbor.
+
+
+ rewrite_rt_asn + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Auto generate RTs for EBGP neighbor.
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
KeyReturnedDescription
+
+ after + +
+ dictionary +
+
when changed +
The resulting configuration after module execution.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ before + +
+ dictionary +
+
when state is merged, replaced, overridden, deleted or purged +
The configuration prior to the module execution.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ commands + +
+ list +
+
when state is merged, replaced, overridden, deleted or purged +
The set of commands pushed to the remote device.
+
+
Sample:
+
['router bgp 65536', 'neighbor 192.0.2.32', 'address-family ipv4 unicast']
+
+
+ gathered + +
+ dictionary +
+
when state is gathered +
Facts about the network resource gathered from the remote device as structured data.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ parsed + +
+ dictionary +
+
when state is parsed +
The device native config provided in running_config option parsed into structured data as per module argspec.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ rendered + +
+ list +
+
when state is rendered +
The provided configuration in the task rendered in device-native format (offline).
+
+
Sample:
+
['router bgp 65536', 'neighbor 192.0.2.32', 'address-family ipv4 unicast']
+
+

+ Status ------ diff --git a/docs/cisco.nxos.nxos_bgp_neighbor_af_module.rst b/docs/cisco.nxos.nxos_bgp_neighbor_af_module.rst deleted file mode 100644 index 78af0017d..000000000 --- a/docs/cisco.nxos.nxos_bgp_neighbor_af_module.rst +++ /dev/null @@ -1,983 +0,0 @@ -.. _cisco.nxos.nxos_bgp_neighbor_af_module: - - -******************************* -cisco.nxos.nxos_bgp_neighbor_af -******************************* - -**(deprecated, removed after 2023-02-24) Manages BGP address-family's neighbors configuration.** - - -Version added: 1.0.0 - -.. contents:: - :local: - :depth: 1 - -DEPRECATED ----------- -:Removed in collection release after 2023-02-24 -:Why: Updated module released with more functionality. -:Alternative: nxos_bgp_neighbor_address_family - - - -Synopsis --------- -- Manages BGP address-family's neighbors configurations on NX-OS switches. - - - - -Parameters ----------- - -.. raw:: html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterChoices/DefaultsComments
-
- additional_paths_receive - -
- string -
-
-
    Choices: -
  • enable
  • -
  • disable
  • -
  • inherit
  • -
-
-
Valid values are enable for basic command enablement; disable for disabling the command at the neighbor af level (it adds the disable keyword to the basic command); and inherit to remove the command at this level (the command value is inherited from a higher BGP layer).
-
-
- additional_paths_send - -
- string -
-
-
    Choices: -
  • enable
  • -
  • disable
  • -
  • inherit
  • -
-
-
Valid values are enable for basic command enablement; disable for disabling the command at the neighbor af level (it adds the disable keyword to the basic command); and inherit to remove the command at this level (the command value is inherited from a higher BGP layer).
-
-
- advertise_map_exist - -
- list - / elements=string -
-
- -
Conditional route advertisement. This property requires two route maps, an advertise-map and an exist-map. Valid values are an array specifying both the advertise-map name and the exist-map name, or simply 'default' e.g. ['my_advertise_map', 'my_exist_map']. This command is mutually exclusive with the advertise_map_non_exist property.
-
-
- advertise_map_non_exist - -
- list - / elements=string -
-
- -
Conditional route advertisement. This property requires two route maps, an advertise-map and an exist-map. Valid values are an array specifying both the advertise-map name and the non-exist-map name, or simply 'default' e.g. ['my_advertise_map', 'my_non_exist_map']. This command is mutually exclusive with the advertise_map_exist property.
-
-
- afi - -
- string - / required -
-
-
    Choices: -
  • ipv4
  • -
  • ipv6
  • -
  • vpnv4
  • -
  • vpnv6
  • -
  • l2vpn
  • -
-
-
Address Family Identifier.
-
-
- allowas_in - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Activate allowas-in property
-
-
- allowas_in_max - -
- string -
-
- -
Max-occurrences value for allowas_in. Valid values are an integer value or 'default'. This is mutually exclusive with allowas_in.
-
-
- as_override - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Activate the as-override feature.
-
-
- asn - -
- string - / required -
-
- -
BGP autonomous system number. Valid values are String, Integer in ASPLAIN or ASDOT notation.
-
-
- default_originate - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Activate the default-originate feature.
-
-
- default_originate_route_map - -
- string -
-
- -
Route-map for the default_originate property. Valid values are a string defining a route-map name, or 'default'. This is mutually exclusive with default_originate.
-
-
- disable_peer_as_check - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Disable checking of peer AS-number while advertising
-
-
- filter_list_in - -
- string -
-
- -
Valid values are a string defining a filter-list name, or 'default'.
-
-
- filter_list_out - -
- string -
-
- -
Valid values are a string defining a filter-list name, or 'default'.
-
-
- max_prefix_interval - -
- string -
-
- -
Optional restart interval. Valid values are an integer. Requires max_prefix_limit. May not be combined with max_prefix_warning.
-
-
- max_prefix_limit - -
- string -
-
- -
maximum-prefix limit value. Valid values are an integer value or 'default'.
-
-
- max_prefix_threshold - -
- string -
-
- -
Optional threshold percentage at which to generate a warning. Valid values are an integer value. Requires max_prefix_limit.
-
-
- max_prefix_warning - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Optional warning-only keyword. Requires max_prefix_limit. May not be combined with max_prefix_interval.
-
-
- neighbor - -
- string - / required -
-
- -
Neighbor Identifier. Valid values are string. Neighbors may use IPv4 or IPv6 notation, with or without prefix length.
-
-
- next_hop_self - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Activate the next-hop-self feature.
-
-
- next_hop_third_party - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Activate the next-hop-third-party feature.
-
-
- prefix_list_in - -
- string -
-
- -
Valid values are a string defining a prefix-list name, or 'default'.
-
-
- prefix_list_out - -
- string -
-
- -
Valid values are a string defining a prefix-list name, or 'default'.
-
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
-
- rewrite_evpn_rt_asn - -
- boolean -
-
added in 1.1.0
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Auto generate route targets for EBGP neighbor.
-
-
- route_map_in - -
- string -
-
- -
Valid values are a string defining a route-map name, or 'default'.
-
-
- route_map_out - -
- string -
-
- -
Valid values are a string defining a route-map name, or 'default'.
-
-
- route_reflector_client - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Router reflector client.
-
-
- safi - -
- string - / required -
-
-
    Choices: -
  • unicast
  • -
  • multicast
  • -
  • evpn
  • -
-
-
Sub Address Family Identifier.
-
-
- send_community - -
- string -
-
-
    Choices: -
  • none
  • -
  • both
  • -
  • extended
  • -
  • standard
  • -
  • default
  • -
-
-
send-community attribute.
-
-
- soft_reconfiguration_in - -
- string -
-
-
    Choices: -
  • enable
  • -
  • always
  • -
  • inherit
  • -
-
-
Valid values are 'enable' for basic command enablement; 'always' to add the always keyword to the basic command; and 'inherit' to remove the command at this level (the command value is inherited from a higher BGP layer).
-
-
- soo - -
- string -
-
- -
Site-of-origin. Valid values are a string defining a VPN extcommunity or 'default'.
-
-
- state - -
- string -
-
-
    Choices: -
  • present ←
  • -
  • absent
  • -
-
-
Determines whether the config should be present or not on the device.
-
-
- suppress_inactive - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
suppress-inactive feature.
-
-
- unsuppress_map - -
- string -
-
- -
unsuppress-map. Valid values are a string defining a route-map name or 'default'.
-
-
- vrf - -
- string -
-
- Default:
"default"
-
-
Name of the VRF. The name 'default' is a valid VRF representing the global bgp.
-
-
- weight - -
- string -
-
- -
Weight value. Valid values are an integer value or 'default'.
-
-
- - -Notes ------ - -.. note:: - - Tested against NXOSv 7.3.(0)D1(1) on VIRL - - Unsupported for Cisco MDS - - ``state=absent`` removes the whole BGP address-family's neighbor configuration. - - Default, when supported, removes properties - - In order to default maximum-prefix configuration, only ``max_prefix_limit=default`` is needed. - - For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide ` - - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide ` - - For more information on using Ansible to manage Cisco devices see the `Cisco integration page `_. - - - -Examples --------- - -.. code-block:: yaml - - - name: configure RR client - cisco.nxos.nxos_bgp_neighbor_af: - asn: 65535 - neighbor: 192.0.2.3 - afi: ipv4 - safi: unicast - route_reflector_client: true - state: present - rewrite_evpn_rt_asn: true - - - -Return Values -------------- -Common return values are documented `here `_, the following are the fields unique to this module: - -.. raw:: html - - - - - - - - - - - - -
KeyReturnedDescription
-
- commands - -
- list -
-
always -
commands sent to the device
-
-
Sample:
-
['router bgp 65535', 'neighbor 192.0.2.3', 'address-family ipv4 unicast', 'route-reflector-client', 'rewrite-evpn-rt-asn']
-
-

- - -Status ------- - - -- This module will be removed in a release after 2023-02-24. *[deprecated]* -- For more information see `DEPRECATED`_. - - -Authors -~~~~~~~ - -- Gabriele Gerbino (@GGabriele) diff --git a/docs/cisco.nxos.nxos_bgp_neighbor_module.rst b/docs/cisco.nxos.nxos_bgp_neighbor_module.rst deleted file mode 100644 index e8b5d56fd..000000000 --- a/docs/cisco.nxos.nxos_bgp_neighbor_module.rst +++ /dev/null @@ -1,795 +0,0 @@ -.. _cisco.nxos.nxos_bgp_neighbor_module: - - -**************************** -cisco.nxos.nxos_bgp_neighbor -**************************** - -**(deprecated, removed after 2023-01-27) Manages BGP neighbors configurations.** - - -Version added: 1.0.0 - -.. contents:: - :local: - :depth: 1 - -DEPRECATED ----------- -:Removed in collection release after 2023-01-27 -:Why: Updated module released with more functionality. -:Alternative: nxos_bgp_global - - - -Synopsis --------- -- Manages BGP neighbors configurations on NX-OS switches. - - - - -Parameters ----------- - -.. raw:: html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterChoices/DefaultsComments
-
- asn - -
- string - / required -
-
- -
BGP autonomous system number. Valid values are string, Integer in ASPLAIN or ASDOT notation.
-
-
- bfd - -
- string -
-
-
    Choices: -
  • enable
  • -
  • disable
  • -
-
-
Enables/Disables BFD for a given neighbor.
-
Dependency: ''feature bfd''
-
-
- capability_negotiation - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Configure whether or not to negotiate capability with this neighbor.
-
-
- connected_check - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Configure whether or not to check for directly connected peer.
-
-
- description - -
- string -
-
- -
Description of the neighbor.
-
-
- dynamic_capability - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Configure whether or not to enable dynamic capability.
-
-
- ebgp_multihop - -
- string -
-
- -
Specify multihop TTL for a remote peer. Valid values are integers between 2 and 255, or keyword 'default' to disable this property.
-
-
- local_as - -
- string -
-
- -
Specify the local-as number for the eBGP neighbor. Valid values are String or Integer in ASPLAIN or ASDOT notation, or 'default', which means not to configure it.
-
-
- log_neighbor_changes - -
- string -
-
-
    Choices: -
  • enable
  • -
  • disable
  • -
  • inherit
  • -
-
-
Specify whether or not to enable log messages for neighbor up/down event.
-
-
- low_memory_exempt - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Specify whether or not to shut down this neighbor under memory pressure.
-
-
- maximum_peers - -
- string -
-
- -
Specify Maximum number of peers for this neighbor prefix Valid values are between 1 and 1000, or 'default', which does not impose the limit. Note that this parameter is accepted only on neighbors with address/prefix.
-
-
- neighbor - -
- string - / required -
-
- -
Neighbor Identifier. Valid values are string. Neighbors may use IPv4 or IPv6 notation, with or without prefix length.
-
-
- peer_type - -
- string -
-
added in 1.1.0
-
-
    Choices: -
  • fabric_border_leaf
  • -
  • fabric_external
  • -
  • disable
  • -
-
-
Specify the peer type for BGP session.
-
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
-
- pwd - -
- string -
-
- -
Specify the password for neighbor. Valid value is string.
-
-
- pwd_type - -
- string -
-
-
    Choices: -
  • 3des
  • -
  • cisco_type_7
  • -
  • default
  • -
-
-
Specify the encryption type the password will use. Valid values are '3des' or 'cisco_type_7' encryption or keyword 'default'.
-
-
- remote_as - -
- string -
-
- -
Specify Autonomous System Number of the neighbor. Valid values are String or Integer in ASPLAIN or ASDOT notation, or 'default', which means not to configure it.
-
-
- remove_private_as - -
- string -
-
-
    Choices: -
  • enable
  • -
  • disable
  • -
  • all
  • -
  • replace-as
  • -
-
-
Specify the config to remove private AS number from outbound updates. Valid values are 'enable' to enable this config, 'disable' to disable this config, 'all' to remove all private AS number, or 'replace-as', to replace the private AS number.
-
-
- shutdown - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Configure to administratively shutdown this neighbor.
-
-
- state - -
- string -
-
-
    Choices: -
  • present ←
  • -
  • absent
  • -
-
-
Determines whether the config should be present or not on the device.
-
-
- suppress_4_byte_as - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Configure to suppress 4-byte AS Capability.
-
-
- timers_holdtime - -
- string -
-
- -
Specify holdtime timer value. Valid values are integers between 0 and 3600 in terms of seconds, or 'default', which is 180.
-
-
- timers_keepalive - -
- string -
-
- -
Specify keepalive timer value. Valid values are integers between 0 and 3600 in terms of seconds, or 'default', which is 60.
-
-
- transport_passive_only - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Specify whether or not to only allow passive connection setup. Valid values are 'true', 'false', and 'default', which defaults to 'false'. This property can only be configured when the neighbor is in 'ip' address format without prefix length.
-
-
- update_source - -
- string -
-
- -
Specify source interface of BGP session and updates.
-
-
- vrf - -
- string -
-
- Default:
"default"
-
-
Name of the VRF. The name 'default' is a valid VRF representing the global bgp.
-
-
- - -Notes ------ - -.. note:: - - Tested against NXOSv 7.3.(0)D1(1) on VIRL - - Unsupported for Cisco MDS - - ``state=absent`` removes the whole BGP neighbor configuration. - - Default, where supported, restores params default value. - - For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide ` - - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide ` - - For more information on using Ansible to manage Cisco devices see the `Cisco integration page `_. - - - -Examples --------- - -.. code-block:: yaml - - # create a new neighbor - - cisco.nxos.nxos_bgp_neighbor: - asn: 65535 - neighbor: 192.0.2.3 - local_as: 20 - remote_as: 30 - bfd: enable - description: just a description - update_source: Ethernet1/3 - state: present - peer_type: fabric_external - - - -Return Values -------------- -Common return values are documented `here `_, the following are the fields unique to this module: - -.. raw:: html - - - - - - - - - - - - -
KeyReturnedDescription
-
- commands - -
- list -
-
always -
commands sent to the device
-
-
Sample:
-
['router bgp 65535', 'neighbor 192.0.2.3', 'remote-as 30', 'update-source Ethernet1/3', 'description just a description', 'local-as 20', 'peer-type fabric-external']
-
-

- - -Status ------- - - -- This module will be removed in a release after 2023-01-27. *[deprecated]* -- For more information see `DEPRECATED`_. - - -Authors -~~~~~~~ - -- Gabriele Gerbino (@GGabriele) diff --git a/docs/cisco.nxos.nxos_bgp_templates_module.rst b/docs/cisco.nxos.nxos_bgp_templates_module.rst new file mode 100644 index 000000000..9287d7a60 --- /dev/null +++ b/docs/cisco.nxos.nxos_bgp_templates_module.rst @@ -0,0 +1,2841 @@ +.. _cisco.nxos.nxos_bgp_templates_module: + + +***************************** +cisco.nxos.nxos_bgp_templates +***************************** + +**BGP Templates resource module.** + + +Version added: 4.2.0 + +.. contents:: + :local: + :depth: 1 + + +Synopsis +-------- +- This module manages BGP templates on devices running Cisco NX-OS. + + + + +Parameters +---------- + +.. raw:: html + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ParameterChoices/DefaultsComments
+
+ config + +
+ dictionary +
+
+ +
A list of BGP templates.
+
+
+ as_number + +
+ string +
+
+ +
Autonomous System Number of the router.
+
+
+ neighbor + +
+ list + / elements=dictionary +
+
+ +
Configure BGP peer templates.
+
+
+ address_family + +
+ list + / elements=dictionary +
+
+ +
Configure an address-family for peer.
+
+
+ advertise_map + +
+ dictionary +
+
+ +
Specify route-map for conditional advertisement.
+
+
+ exist_map + +
+ string +
+
+ +
Condition route-map to advertise only when prefix in condition exists.
+
+
+ non_exist_map + +
+ string +
+
+ +
Condition route-map to advertise only when prefix in condition does not exist.
+
+
+ route_map + +
+ string + / required +
+
+ +
Route-map name.
+
+
+ advertisement_interval + +
+ integer +
+
+ +
Minimum interval between sending BGP routing updates.
+
+
+ afi + +
+ string + / required +
+
+
    Choices: +
  • ipv4
  • +
  • ipv6
  • +
  • link-state
  • +
  • l2vpn
  • +
+
+
Address Family indicator.
+
+
+ allowas_in + +
+ dictionary +
+
+ +
Accept as-path with my AS present in it.
+
+
+ max_occurences + +
+ integer +
+
+ +
Number of occurrences of AS number, default is 3.
+
+
+ set + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Activate allowas-in property.
+
+
+ as_override + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Override matching AS-number while sending update.
+
+
+ capability + +
+ dictionary +
+
+ +
Advertise capability to the peer.
+
+
+ additional_paths + +
+ dictionary +
+
+ +
Additional paths capability.
+
+
+ receive + +
+ string +
+
+
    Choices: +
  • enable
  • +
  • disable
  • +
+
+
Additional paths Receive capability.
+
+
+ send + +
+ string +
+
+
    Choices: +
  • enable
  • +
  • disable
  • +
+
+
Additional paths Send capability.
+
+
+ default_originate + +
+ dictionary +
+
+ +
Originate a default toward this peer.
+
+
+ route_map + +
+ string +
+
+ +
Route-map to specify criteria for originating default.
+
+
+ set + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Set default-originate attribute.
+
+
+ disable_peer_as_check + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Disable checking of peer AS-number while advertising.
+
+
+ filter_list + +
+ dictionary +
+
+ +
Name of filter-list.
+
+
+ inbound + +
+ string +
+
+ +
Apply policy to incoming routes.
+
+
+ outbound + +
+ string +
+
+ +
Apply policy to outgoing routes.
+
+
+ inherit + +
+ dictionary +
+
+ +
Inherit a peer-policy template.
+
+
+ peer_policy + +
+ string +
+
+ +
Peer-policy template to inherit.
+
+
+ maximum_prefix + +
+ dictionary +
+
+ +
Maximum number of prefixes from this neighbor.
+
+
+ generate_warning_threshold + +
+ integer +
+
+ +
Threshold percentage at which to generate a warning.
+
+
+ max_prefix_limit + +
+ integer +
+
+ +
Maximum prefix limit.
+
+
+ restart_interval + +
+ integer +
+
+ +
Restart bgp connection after limit is exceeded.
+
+
+ warning_only + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Only give a warning message when limit is exceeded.
+
+
+ next_hop_self + +
+ dictionary +
+
+ +
Set our address as nexthop (non-reflected).
+
+
+ all_routes + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Set our address as nexthop for all routes.
+
+
+ set + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Set next-hop-self attribute.
+
+
+ next_hop_third_party + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Compute a third-party nexthop if possible.
+
+
+ prefix_list + +
+ dictionary +
+
+ +
Apply prefix-list.
+
+
+ inbound + +
+ string +
+
+ +
Apply policy to incoming routes.
+
+
+ outbound + +
+ string +
+
+ +
Apply policy to outgoing routes.
+
+
+ route_map + +
+ dictionary +
+
+ +
Apply route-map to neighbor.
+
+
+ inbound + +
+ string +
+
+ +
Name of policy to apply to incoming routes.
+
+
+ outbound + +
+ string +
+
+ +
Name of policy to apply to outgoing routes.
+
+
+ route_reflector_client + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Configure a neighbor as Route reflector client.
+
+
+ safi + +
+ string +
+
+
    Choices: +
  • unicast
  • +
  • multicast
  • +
  • mvpn
  • +
  • evpn
  • +
+
+
Sub Address Family indicator.
+
+
+ send_community + +
+ string +
+
+
    Choices: +
  • standard
  • +
  • extended
  • +
  • both
  • +
+
+
Send Community attribute to this neighbor.
+
+
+ soft_reconfiguration_inbound + +
+ dictionary +
+
+ +
Soft reconfiguration.
+
+
+ always + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Always perform inbound soft reconfiguration.
+
+
+ set + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Set soft-reconfiguration inbound attribute.
+
+
+ soo + +
+ string +
+
+ +
Specify Site-of-origin extcommunity.
+
+
+ suppress_inactive + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Advertise only active routes to peer.
+
+
+ unsuppress_map + +
+ string +
+
+ +
Route-map to selectively unsuppress suppressed routes.
+
+
+ weight + +
+ integer +
+
+ +
Set default weight for routes from this neighbor.
+
+
+ bfd + +
+ dictionary +
+
+ +
Bidirectional Fast Detection for the neighbor.
+
+
+ multihop + +
+ dictionary +
+
+ +
Multihop session.
+
+
+ interval + +
+ dictionary +
+
+ +
Configure BFD session interval parameters.
+
+
+ min_rx_interval + +
+ integer + / required +
+
+ +
Minimum RX interval.
+
+
+ multiplier + +
+ integer + / required +
+
+ +
Detect Multiplier.
+
+
+ tx_interval + +
+ integer + / required +
+
+ +
TX interval in milliseconds.
+
+
+ set + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Set BFD multihop.
+
+
+ set + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Set BFD for this neighbor.
+
+
+ singlehop + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Single-hop session.
+
+
+ bmp_activate_server + +
+ integer +
+
+ +
Specify server ID for activating BMP monitoring for the peer.
+
+
+ capability + +
+ dictionary +
+
+ +
Capability.
+
+
+ suppress_4_byte_as + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Suppress 4-byte AS Capability.
+
+
+ description + +
+ string +
+
+ +
Neighbor specific descripion.
+
+
+ disable_connected_check + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Disable check for directly connected peer.
+
+
+ dont_capability_negotiate + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Don't negotiate capability with this neighbor.
+
+
+ dscp + +
+ string +
+
+ +
Set dscp value for tcp transport.
+
+
+ dynamic_capability + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Dynamic Capability
+
+
+ ebgp_multihop + +
+ integer +
+
+ +
Specify multihop TTL for remote peer.
+
+
+ graceful_shutdown + +
+ dictionary +
+
+ +
Graceful-shutdown for this neighbor.
+
+
+ activate + +
+ dictionary +
+
+ +
Send graceful-shutdown community.
+
+
+ route_map + +
+ string +
+
+ +
Apply route-map to modify attributes for outbound.
+
+
+ set + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Set activate.
+
+
+ inherit + +
+ dictionary +
+
+ +
Inherit a template.
+
+
+ peer_session + +
+ string +
+
+ +
Peer-session template to inherit.
+
+
+ local_as + +
+ string +
+
+ +
Specify the local-as number for the eBGP neighbor.
+
+
+ log_neighbor_changes + +
+ dictionary +
+
+ +
Log message for neighbor up/down event.
+
+
+ disable + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Disable logging of neighbor up/down event.
+
+
+ set + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Set log-neighbor-changes.
+
+
+ low_memory + +
+ dictionary +
+
+ +
Behaviour in low memory situations.
+
+
+ exempt + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Do not shutdown this peer when under memory pressure.
+
+
+ name + +
+ string +
+
+ +
Name of the BGP peer template.
+
+
+ password + +
+ dictionary +
+
+ +
Configure a password for neighbor.
+
+
+ encryption + +
+ integer +
+
+ +
0 specifies an UNENCRYPTED neighbor password.
+
3 specifies an 3DES ENCRYPTED neighbor password will follow.
+
7 specifies a Cisco type 7 ENCRYPTED neighbor password will follow.
+
+
+ key + +
+ string +
+
+ +
Authentication password.
+
+
+ path_attribute + +
+ list + / elements=dictionary +
+
+ +
BGP path attribute optional filtering.
+
+
+ action + +
+ string +
+
+
    Choices: +
  • discard
  • +
  • treat-as-withdraw
  • +
+
+
Action.
+
+
+ range + +
+ dictionary +
+
+ +
Path attribute range.
+
+
+ end + +
+ integer +
+
+ +
Path attribute range end value.
+
+
+ start + +
+ integer +
+
+ +
Path attribute range start value.
+
+
+ type + +
+ integer +
+
+ +
Path attribute type
+
+
+ remote_as + +
+ string +
+
+ +
Specify Autonomous System Number of the neighbor.
+
+
+ remove_private_as + +
+ dictionary +
+
+ +
Remove private AS number from outbound updates.
+
+
+ all + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
All.
+
+
+ replace_as + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Replace.
+
+
+ set + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Remove private AS.
+
+
+ shutdown + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Administratively shutdown this neighbor.
+
+
+ timers + +
+ dictionary +
+
+ +
Configure keepalive and hold timers.
+
+
+ holdtime + +
+ integer +
+
+ +
Holdtime (seconds).
+
+
+ keepalive + +
+ integer +
+
+ +
Keepalive interval (seconds).
+
+
+ transport + +
+ dictionary +
+
+ +
BGP transport connection.
+
+
+ connection_mode + +
+ dictionary +
+
+ +
Specify type of connection.
+
+
+ passive + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Allow passive connection setup only.
+
+
+ ttl_security + +
+ dictionary +
+
+ +
Enable TTL Security Mechanism.
+
+
+ hops + +
+ integer +
+
+ +
Specify hop count for remote peer.
+
+
+ update_source + +
+ string +
+
+ +
Specify source of BGP session and updates.
+
+
+ running_config + +
+ string +
+
+ +
This option is used only with state parsed.
+
The value of this option should be the output received from the NX-OS device by executing the command show running-config bgp | section 'template'.
+
The state parsed reads the configuration from running_config option and transforms it into Ansible structured data as per the resource module's argspec and the value is then returned in the parsed key within the result.
+
+
+ state + +
+ string +
+
+
    Choices: +
  • merged ←
  • +
  • replaced
  • +
  • overridden
  • +
  • deleted
  • +
  • parsed
  • +
  • gathered
  • +
  • rendered
  • +
+
+
The state the configuration should be left in.
+
Refer to examples for more details.
+
+
+ + +Notes +----- + +.. note:: + - Tested against NX-OS 9.3.6. + - Unsupported for Cisco MDS + - This module works with connection ``network_cli`` and ``httpapi``. + + + +Examples +-------- + +.. code-block:: yaml + + # Using merged + + # Before state: + # -------------- + # + # nxos9k# show running-config | section "^router bgp" + # nxos9k# + + - name: Merge the provided configuration with the existing running configuration + cisco.nxos.nxos_bgp_templates: + config: + as_number: 65536 + neighbor: + - name: neighbor_tmplt_1 + address_family: + - afi: ipv4 + safi: unicast + advertise_map: + route_map: rmap1 + non_exist_map: nemap1 + advertisement_interval: 60 + disable_peer_as_check: true + bmp_activate_server: 2 + capability: + suppress_4_byte_as: true + description: Test_BGP_PEER_TEMPLATE_1 + local_as: 65536 + remote_as: 65001 + + - name: neighbor_tmplt_2 + description: Test_BGP_PEER_TEMPLATE_2 + address_family: + - afi: ipv4 + safi: multicast + advertise_map: + route_map: rmap1 + exist_map: emap1 + as_override: true + filter_list: + inbound: flist1 + outbound: flist2 + inherit: + peer_session: psession1 + timers: + holdtime: 100 + keepalive: 45 + # Task Output: + # ------------ + # before: {} + # + # commands: + # - router bgp 65536 + # - template peer neighbor_tmplt_1 + # - bmp-activate-server 2 + # - capability suppress 4-byte-as + # - description Test_BGP_PEER_TEMPLATE_1 + # - local-as 65536 + # - remote-as 65001 + # - address-family ipv4 unicast + # - advertise-map rmap1 non-exist-map nemap1 + # - advertisement-interval 60 + # - disable-peer-as-check + # - template peer neighbor_tmplt_2 + # - description Test_BGP_PEER_TEMPLATE_2 + # - inherit peer-session psession1 + # - timers 45 100 + # - address-family ipv4 multicast + # - advertise-map rmap1 exist-map emap1 + # - as-override + # - filter-list flist1 in + # - filter-list flist2 out + # + # after: + # as_number: "65536" + # neighbor: + # - name: neighbor_tmplt_1 + # address_family: + # - afi: ipv4 + # safi: unicast + # advertise_map: + # non_exist_map: nemap1 + # route_map: rmap1 + # advertisement_interval: 60 + # disable_peer_as_check: true + # bmp_activate_server: 2 + # capability: + # suppress_4_byte_as: true + # description: Test_BGP_PEER_TEMPLATE_1 + # local_as: "65536" + # remote_as: "65001" + # + # - name: neighbor_tmplt_2 + # description: Test_BGP_PEER_TEMPLATE_2 + # address_family: + # - afi: ipv4 + # safi: multicast + # advertise_map: + # exist_map: emap1 + # route_map: rmap1 + # as_override: true + # filter_list: + # inbound: flist1 + # outbound: flist2 + # inherit: + # peer_session: psession1 + # timers: + # holdtime: 100 + # keepalive: 45 + + # After state: + # -------------- + # + # nxos9k# show running-config | section "^router bgp" + # router bgp 65536 + # template peer neighbor_tmplt_1 + # capability suppress 4-byte-as + # bmp-activate-server 2 + # description Test_BGP_PEER_TEMPLATE_1 + # local-as 65536 + # remote-as 65001 + # address-family ipv4 unicast + # advertise-map rmap1 non-exist-map nemap1 + # advertisement-interval 60 + # disable-peer-as-check + # template peer neighbor_tmplt_2 + # description Test_BGP_PEER_TEMPLATE_2 + # inherit peer-session psession1 + # timers 45 100 + # address-family ipv4 multicast + # advertise-map rmap1 exist-map emap1 + # as-override + # filter-list flist1 in + # filter-list flist2 out + + # Using replaced + + # Before state: + # ------------- + # + # nxos9k# show running-config | section "^router bgp" + # router bgp 65536 + # template peer neighbor_tmplt_1 + # capability suppress 4-byte-as + # description Test_BGP_PEER_TEMPLATE_1 + # bmp-activate-server 2 + # local-as 65536 + # remote-as 65001 + # address-family ipv4 unicast + # advertise-map rmap1 non-exist-map nemap1 + # advertisement-interval 60 + # disable-peer-as-check + # template peer neighbor_tmplt_2 + # description Test_BGP_PEER_TEMPLATE_2 + # inherit peer-session psession1 + # timers 45 100 + # address-family ipv4 multicast + # advertise-map rmap1 exist-map emap1 + # as-override + # filter-list flist1 in + # filter-list flist2 out + + - name: Replace BGP templates configuration with provided configuration + cisco.nxos.nxos_bgp_templates: + config: + as_number: 65536 + neighbor: + - name: neighbor_tmplt_1 + address_family: + - afi: ipv4 + safi: unicast + advertise_map: + route_map: rmap1 + non_exist_map: nemap1 + advertisement_interval: 60 + disable_peer_as_check: true + inherit: + peer_session: psession1 + description: Test_BGP_PEER_TEMPLATE_1 + local_as: 65537 + state: replaced + + # Task output: + # ------------ + # + # before: + # as_number: "65536" + # neighbor: + # - name: neighbor_tmplt_1 + # address_family: + # - afi: ipv4 + # safi: unicast + # advertise_map: + # non_exist_map: nemap1 + # route_map: rmap1 + # advertisement_interval: 60 + # disable_peer_as_check: true + # bmp_activate_server: 2 + # capability: + # suppress_4_byte_as: true + # description: Test_BGP_PEER_TEMPLATE_1 + # local_as: "65536" + # remote_as: "65001" + # + # - name: neighbor_tmplt_2 + # description: Test_BGP_PEER_TEMPLATE_2 + # address_family: + # - afi: ipv4 + # safi: multicast + # advertise_map: + # exist_map: emap1 + # route_map: rmap1 + # as_override: true + # filter_list: + # inbound: flist1 + # outbound: flist2 + # inherit: + # peer_session: psession1 + # timers: + # holdtime: 100 + # keepalive: 45 + # + # commands: + # - router bgp 65536 + # - template peer neighbor_tmplt_1 + # - no bmp-activate-server 2 + # - no capability suppress 4-byte-as + # - inherit peer-session psession1 + # - local-as 65537 + # - no remote-as 65001 + # + # after: + # as_number: "65536" + # neighbor: + # - name: neighbor_tmplt_1 + # address_family: + # - afi: ipv4 + # safi: unicast + # advertise_map: + # non_exist_map: nemap1 + # route_map: rmap1 + # advertisement_interval: 60 + # disable_peer_as_check: true + # description: Test_BGP_PEER_TEMPLATE_1 + # inherit: + # peer_session: psession1 + # local_as: "65537" + # + # - name: neighbor_tmplt_2 + # description: Test_BGP_PEER_TEMPLATE_2 + # address_family: + # - afi: ipv4 + # safi: multicast + # advertise_map: + # exist_map: emap1 + # route_map: rmap1 + # as_override: true + # filter_list: + # inbound: flist1 + # outbound: flist2 + # inherit: + # peer_session: psession1 + # timers: + # holdtime: 100 + # keepalive: 45 + + # After state: + # ------------ + # + # nxos9k# show running-config | section "^router bgp" + # router bgp 65536 + # template peer neighbor_tmplt_1 + # inherit peer-session psession1 + # description Test_BGP_PEER_TEMPLATE_1 + # local-as 65537 + # address-family ipv4 unicast + # advertise-map rmap1 non-exist-map nemap1 + # advertisement-interval 60 + # disable-peer-as-check + # template peer neighbor_tmplt_2 + # description Test_BGP_PEER_TEMPLATE_2 + # inherit peer-session psession1 + # bmp-activate-server 2 + # timers 45 100 + # address-family ipv4 multicast + # advertise-map rmap1 exist-map emap1 + # as-override + # filter-list flist1 in + # filter-list flist2 out + + # Using overridden + # + # Before state: + # ------------- + # + # nxos9k# show running-config | section "^router bgp" + # router bgp 65536 + # template peer neighbor_tmplt_1 + # capability suppress 4-byte-as + # description Test_BGP_PEER_TEMPLATE_1 + # bmp-activate-server 2 + # local-as 65536 + # remote-as 65001 + # address-family ipv4 unicast + # advertise-map rmap1 non-exist-map nemap1 + # advertisement-interval 60 + # disable-peer-as-check + # template peer neighbor_tmplt_2 + # description Test_BGP_PEER_TEMPLATE_2 + # inherit peer-session psession1 + # timers 45 100 + # address-family ipv4 multicast + # advertise-map rmap1 exist-map emap1 + # as-override + # filter-list flist1 in + # filter-list flist2 out + + - name: Override BGP templates configuration with provided configuration + cisco.nxos.nxos_bgp_templates: + config: + as_number: 65536 + neighbor: + - name: neighbor_tmplt_1 + address_family: + - afi: ipv4 + safi: unicast + advertise_map: + route_map: rmap1 + non_exist_map: nemap1 + advertisement_interval: 60 + disable_peer_as_check: true + inherit: + peer_session: psession1 + description: Test_BGP_PEER_TEMPLATE_1 + local_as: 65537 + state: overridden + + # Task output: + # ------------ + # + # before: + # as_number: "65536" + # neighbor: + # - name: neighbor_tmplt_1 + # address_family: + # - afi: ipv4 + # safi: unicast + # advertise_map: + # non_exist_map: nemap1 + # route_map: rmap1 + # advertisement_interval: 60 + # disable_peer_as_check: true + # bmp_activate_server: 2 + # capability: + # suppress_4_byte_as: true + # description: Test_BGP_PEER_TEMPLATE_1 + # local_as: "65536" + # remote_as: "65001" + # + # - name: neighbor_tmplt_2 + # description: Test_BGP_PEER_TEMPLATE_2 + # address_family: + # - afi: ipv4 + # safi: multicast + # advertise_map: + # exist_map: emap1 + # route_map: rmap1 + # as_override: true + # filter_list: + # inbound: flist1 + # outbound: flist2 + # inherit: + # peer_session: psession1 + # timers: + # holdtime: 100 + # keepalive: 45 + # + # commands: + # - router bgp 65536 + # - template peer neighbor_tmplt_1 + # - no bmp-activate-server 2 + # - no capability suppress 4-byte-as + # - inherit peer-session psession1 + # - local-as 65537 + # - no remote-as 65001 + # - no template peer neighbor_tmplt_2 + # + # after: + # as_number: "65536" + # neighbor: + # - name: neighbor_tmplt_1 + # address_family: + # - afi: ipv4 + # safi: unicast + # advertise_map: + # non_exist_map: nemap1 + # route_map: rmap1 + # advertisement_interval: 60 + # disable_peer_as_check: true + # description: Test_BGP_PEER_TEMPLATE_1 + # inherit: + # peer_session: psession1 + # local_as: "65537" + + # After state: + # ------------ + # + # nxos9k# show running-config | section "^router bgp" + # router bgp 65536 + # template peer neighbor_tmplt_1 + # inherit peer-session psession1 + # description Test_BGP_PEER_TEMPLATE_1 + # local-as 65537 + # address-family ipv4 unicast + # advertise-map rmap1 non-exist-map nemap1 + # advertisement-interval 60 + # disable-peer-as-check + + # Using deleted + + # Before state: + # -------------- + # + # nxos9k# show running-config | section "^router bgp" + # router bgp 65536 + # template peer neighbor_tmplt_1 + # capability suppress 4-byte-as + # description Test_BGP_PEER_TEMPLATE_1 + # bmp-activate-server 2 + # local-as 65536 + # remote-as 65001 + # address-family ipv4 unicast + # advertise-map rmap1 non-exist-map nemap1 + # advertisement-interval 60 + # disable-peer-as-check + # template peer neighbor_tmplt_2 + # description Test_BGP_PEER_TEMPLATE_2 + # inherit peer-session psession1 + # timers 45 100 + # address-family ipv4 multicast + # advertise-map rmap1 exist-map emap1 + # as-override + # filter-list flist1 in + # filter-list flist2 out + + - name: Delete BGP configs handled by this module + cisco.nxos.nxos_bgp_templates: + state: deleted + + # Task output: + # ------------ + # + # before: + # as_number: "65536" + # neighbor: + # - name: neighbor_tmplt_1 + # address_family: + # - afi: ipv4 + # safi: unicast + # advertise_map: + # non_exist_map: nemap1 + # route_map: rmap1 + # advertisement_interval: 60 + # disable_peer_as_check: true + # bmp_activate_server: 2 + # capability: + # suppress_4_byte_as: true + # description: Test_BGP_PEER_TEMPLATE_1 + # local_as: "65536" + # remote_as: "65001" + # + # - name: neighbor_tmplt_2 + # description: Test_BGP_PEER_TEMPLATE_2 + # address_family: + # - afi: ipv4 + # safi: multicast + # advertise_map: + # exist_map: emap1 + # route_map: rmap1 + # as_override: true + # filter_list: + # inbound: flist1 + # outbound: flist2 + # inherit: + # peer_session: psession1 + # timers: + # holdtime: 100 + # keepalive: 45 + # + # commands: + # - router bgp 65536 + # - no template peer neighbor_tmplt_1 + # - no template peer neighbor_tmplt_2 + # + # after: {} + + # After state: + # ------------- + # nxos9k# show running-config | section "^router bgp" + # nxos9k# + + + +Return Values +------------- +Common return values are documented `here `_, the following are the fields unique to this module: + +.. raw:: html + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
KeyReturnedDescription
+
+ after + +
+ dictionary +
+
when changed +
The resulting configuration after module execution.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ before + +
+ dictionary +
+
when state is merged, replaced, overridden, deleted or purged +
The configuration prior to the module execution.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ commands + +
+ list +
+
when state is merged, replaced, overridden, deleted or purged +
The set of commands pushed to the remote device.
+
+
Sample:
+
['router bgp 65536', 'template peer neighbor_tmplt_1', 'no bmp-activate-server 2', 'no capability suppress 4-byte-as', 'inherit peer-session psession1', 'local-as 65537', 'no remote-as 65001', 'no template peer neighbor_tmplt_2']
+
+
+ gathered + +
+ dictionary +
+
when state is gathered +
Facts about the network resource gathered from the remote device as structured data.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ parsed + +
+ dictionary +
+
when state is parsed +
The device native config provided in running_config option parsed into structured data as per module argspec.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ rendered + +
+ list +
+
when state is rendered +
The provided configuration in the task rendered in device-native format (offline).
+
+
Sample:
+
['router bgp 65536', 'template peer neighbor_tmplt_1', 'bmp-activate-server 2', 'no capability suppress 4-byte-as', 'no template peer neighbor_tmplt_2']
+
+

+ + +Status +------ + + +Authors +~~~~~~~ + +- Nilashish Chakraborty (@NilashishC) diff --git a/docs/cisco.nxos.nxos_command_module.rst b/docs/cisco.nxos.nxos_command_module.rst index 9581bb9c2..4308a6582 100644 --- a/docs/cisco.nxos.nxos_command_module.rst +++ b/docs/cisco.nxos.nxos_command_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
commands @@ -53,7 +53,7 @@ Parameters
+
interval @@ -69,7 +69,7 @@ Parameters
+
match @@ -88,241 +88,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
retries @@ -331,14 +97,15 @@ Parameters
- Default:
10
+ Default:
9
-
Specifies the number of retries a command should by tried before it is considered failed. The command is run on the target device every retry and evaluated against the wait_for conditionals.
+
Specifies the number of retries a command should by tried before it is considered failed. The command is run on the target device every retry and evaluated against the wait_for conditionals.
+
The commands are run once when retries is set to 0.
+
wait_for @@ -386,31 +153,31 @@ Examples - name: run multiple commands on remote nodes cisco.nxos.nxos_command: commands: - - show version - - show interfaces + - show version + - show interfaces - name: run multiple commands and evaluate the output cisco.nxos.nxos_command: commands: - - show version - - show interfaces + - show version + - show interfaces wait_for: - - result[0] contains Cisco - - result[1] contains loopback0 + - result[0] contains Cisco + - result[1] contains loopback0 - name: run commands and specify the output format cisco.nxos.nxos_command: commands: - - command: show version - output: json + - command: show version + output: json - name: run commands that require answering a prompt cisco.nxos.nxos_command: commands: - - configure terminal - - command: no feature npv - prompt: Do you want to continue - answer: y + - configure terminal + - command: no feature npv + prompt: Do you want to continue + answer: y diff --git a/docs/cisco.nxos.nxos_config_module.rst b/docs/cisco.nxos.nxos_config_module.rst index cf2534891..3ead5ab50 100644 --- a/docs/cisco.nxos.nxos_config_module.rst +++ b/docs/cisco.nxos.nxos_config_module.rst @@ -259,240 +259,6 @@ Parameters
The ordered set of parents that uniquely identify the section or hierarchy the commands should be checked against. If the parents argument is omitted, the commands are checked against the set of top level or global commands.
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
@@ -614,21 +380,21 @@ Examples - cisco.nxos.nxos_config: lines: - - 10 permit ip 192.0.2.1/32 any log - - 20 permit ip 192.0.2.2/32 any log - - 30 permit ip 192.0.2.3/32 any log - - 40 permit ip 192.0.2.4/32 any log - - 50 permit ip 192.0.2.5/32 any log + - 10 permit ip 192.0.2.1/32 any log + - 20 permit ip 192.0.2.2/32 any log + - 30 permit ip 192.0.2.3/32 any log + - 40 permit ip 192.0.2.4/32 any log + - 50 permit ip 192.0.2.5/32 any log parents: ip access-list test before: no ip access-list test match: exact - cisco.nxos.nxos_config: lines: - - 10 permit ip 192.0.2.1/32 any log - - 20 permit ip 192.0.2.2/32 any log - - 30 permit ip 192.0.2.3/32 any log - - 40 permit ip 192.0.2.4/32 any log + - 10 permit ip 192.0.2.1/32 any log + - 20 permit ip 192.0.2.2/32 any log + - 30 permit ip 192.0.2.3/32 any log + - 40 permit ip 192.0.2.4/32 any log parents: ip access-list test before: no ip access-list test replace: block @@ -642,13 +408,13 @@ Examples cisco.nxos.nxos_config: lines: # - shut - - shutdown + - shutdown # parents: int eth1/1 parents: interface Ethernet1/1 - name: configurable backup path cisco.nxos.nxos_config: - backup: yes + backup: true backup_options: filename: backup.cfg dir_path: /home/user diff --git a/docs/cisco.nxos.nxos_devicealias_module.rst b/docs/cisco.nxos.nxos_devicealias_module.rst index 9e33f93ea..081c8759f 100644 --- a/docs/cisco.nxos.nxos_devicealias_module.rst +++ b/docs/cisco.nxos.nxos_devicealias_module.rst @@ -212,21 +212,21 @@ Examples - name: Test that device alias module works cisco.nxos.nxos_devicealias: da: - - name: test1_add - pwwn: 56:2:22:11:22:88:11:67 - - name: test2_add - pwwn: 65:22:22:11:22:22:11:d - - name: dev1 - remove: true - - name: dev2 - remove: true + - name: test1_add + pwwn: 56:2:22:11:22:88:11:67 + - name: test2_add + pwwn: 65:22:22:11:22:22:11:d + - name: dev1 + remove: true + - name: dev2 + remove: true distribute: true mode: enhanced rename: - - new_name: bcd - old_name: abc - - new_name: bcd1 - old_name: abc1 + - new_name: bcd + old_name: abc + - new_name: bcd1 + old_name: abc1 diff --git a/docs/cisco.nxos.nxos_evpn_global_module.rst b/docs/cisco.nxos.nxos_evpn_global_module.rst index 7e7ee4e02..d1b2a8241 100644 --- a/docs/cisco.nxos.nxos_evpn_global_module.rst +++ b/docs/cisco.nxos.nxos_evpn_global_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
nv_overlay_evpn @@ -53,240 +53,6 @@ Parameters
EVPN control plane.
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-

diff --git a/docs/cisco.nxos.nxos_evpn_vni_module.rst b/docs/cisco.nxos.nxos_evpn_vni_module.rst index 1231db8eb..530a9ff18 100644 --- a/docs/cisco.nxos.nxos_evpn_vni_module.rst +++ b/docs/cisco.nxos.nxos_evpn_vni_module.rst @@ -29,246 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
route_distinguisher @@ -283,7 +49,7 @@ Parameters
+
route_target_both @@ -299,7 +65,7 @@ Parameters
+
route_target_export @@ -315,7 +81,7 @@ Parameters
+
route_target_import @@ -331,7 +97,7 @@ Parameters
+
state @@ -350,7 +116,7 @@ Parameters
+
vni @@ -396,8 +162,8 @@ Examples vni: 6000 route_distinguisher: 60:10 route_target_import: - - 5000:10 - - 4100:100 + - "5000:10" + - "4100:100" route_target_export: auto route_target_both: default diff --git a/docs/cisco.nxos.nxos_facts_module.rst b/docs/cisco.nxos.nxos_facts_module.rst index f9931835c..3ce96abea 100644 --- a/docs/cisco.nxos.nxos_facts_module.rst +++ b/docs/cisco.nxos.nxos_facts_module.rst @@ -17,7 +17,7 @@ Version added: 1.0.0 Synopsis -------- -- Collects facts from Cisco Nexus devices running the NX-OS operating system. Fact collection is supported over both Cli and Nxapi transports. This module prepends all of the base network fact keys with ``ansible_net_``. The facts module will always collect a base set of facts from the device and can enable or disable collection of additional facts. +- Collects facts from Cisco Nexus devices running the NX-OS operating system. Fact collection is supported over both ``network_cli`` and ``httpapi``. This module prepends all of the base network fact keys with ``ansible_net_``. The facts module will always collect a base set of facts from the device and can enable or disable collection of additional facts. @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
available_network_resources @@ -49,11 +49,11 @@ Parameters
-
When 'True' a list of network resources for which resource modules are available will be provided.
+
When set to true a list of network resources for which resource modules are available will be provided.
+
gather_network_resources @@ -65,11 +65,12 @@ Parameters
-
When supplied, this argument will restrict the facts collected to a given subset. Possible values for this argument include all and the resources like interfaces, vlans etc. Can specify a list of values to include a larger subset. Values can also be used with an initial ! to specify that a specific subset should not be collected. Valid subsets are all, bfd_interfaces, lag_interfaces, telemetry, vlans, lacp, lacp_interfaces, interfaces, l3_interfaces, l2_interfaces, lldp_global, acls, acl_interfaces, ospfv2, ospfv3, ospf_interfaces, bgp_global, bgp_address_family, route_maps, prefix_lists, logging_global, ntp_global, snmp_server.
+
When supplied, this argument will gather configuration facts only for the given subset. Can specify a list of values to include a larger subset. Values can also be used with an initial ! to specify that a specific subset should not be collected.
+
Valid subsets are all, bfd_interfaces, lag_interfaces, telemetry, vlans, lacp, lacp_interfaces, interfaces, l3_interfaces, l2_interfaces, lldp_global, acls, acl_interfaces, ospfv2, ospfv3, ospf_interfaces, bgp_global, bgp_address_family, route_maps, prefix_lists, logging_global, ntp_global, snmp_server, hostname.
+
gather_subset @@ -82,243 +83,9 @@ Parameters Default:
"min"
-
When supplied, this argument will restrict the facts collected to a given subset. Possible values for this argument include all, hardware, config, legacy, interfaces, and min. Can specify a list of values to include a larger subset. Values can also be used with an initial ! to specify that a specific subset should not be collected.
-
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
+
When supplied, this argument will gather operational facts only for the given subset. Possible values for this argument include all, hardware, config, legacy, interfaces, and min. Can specify a list of values to include a larger subset. Values can also be used with an initial ! to specify that a specific subset should not be collected.
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-

@@ -346,11 +113,11 @@ Examples - name: Gather only the config and default facts cisco.nxos.nxos_facts: gather_subset: - - config + - config - name: Do not gather hardware facts cisco.nxos.nxos_facts: gather_subset: - - '!hardware' + - '!hardware' - name: Gather legacy and resource facts cisco.nxos.nxos_facts: gather_subset: all @@ -358,10 +125,10 @@ Examples - name: Gather only the interfaces resource facts and no legacy facts cisco.nxos.nxos_facts: gather_subset: - - '!all' - - '!min' + - '!all' + - '!min' gather_network_resources: - - interfaces + - interfaces - name: Gather interfaces resource and minimal legacy facts cisco.nxos.nxos_facts: gather_subset: min diff --git a/docs/cisco.nxos.nxos_fc_interfaces_module.rst b/docs/cisco.nxos.nxos_fc_interfaces_module.rst new file mode 100644 index 000000000..048ddc0f0 --- /dev/null +++ b/docs/cisco.nxos.nxos_fc_interfaces_module.rst @@ -0,0 +1,771 @@ +.. _cisco.nxos.nxos_fc_interfaces_module: + + +***************************** +cisco.nxos.nxos_fc_interfaces +***************************** + +**Fc Interfaces resource module** + + +Version added: 5.2.0 + +.. contents:: + :local: + :depth: 1 + + +Synopsis +-------- +- This module manages the interface attributes of NX-OS fc interfaces. + + + + +Parameters +---------- + +.. raw:: html + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ParameterChoices/DefaultsComments
+
+ config + +
+ list + / elements=dictionary +
+
+ +
A dictionary of interface options
+
+
+ analytics + +
+ string +
+
+
    Choices: +
  • fc-scsi
  • +
  • fc-nvme
  • +
  • fc-all
  • +
+
+
Analytics type on the fc interface
+
+
+ description + +
+ string +
+
+ +
Interface description.
+
+
+ enabled + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Administrative state of the interface. Set the value to true to administratively enable the interface or true to disable it
+
+
+ mode + +
+ string +
+
+
    Choices: +
  • auto
  • +
  • E
  • +
  • F
  • +
  • Fx
  • +
  • NP
  • +
  • SD
  • +
+
+
Port mode of the fc interface
+
+
+ name + +
+ string + / required +
+
+ +
Full name of interface, e.g. fc1/1, fc18/48
+
+
+ speed + +
+ string +
+
+
    Choices: +
  • auto
  • +
  • 1000
  • +
  • 2000
  • +
  • 4000
  • +
  • 8000
  • +
  • 10000
  • +
  • 16000
  • +
  • 32000
  • +
  • 64000
  • +
  • auto max 2000
  • +
  • auto max 4000
  • +
  • auto max 8000
  • +
  • auto max 16000
  • +
  • auto max 32000
  • +
  • auto max 64000
  • +
+
+
Interface link speed.
+
+
+ trunk_mode + +
+ string +
+
+
    Choices: +
  • auto
  • +
  • on
  • +
  • off
  • +
+
+
Trunk mode of the fc interface
+
+
+ running_config + +
+ string +
+
+ +
This option is used only with state parsed.
+
The value of this option should be the output received from the NX-OS device by executing the command show running-config interface
+
The state parsed reads the configuration from running_config option and transforms it into Ansible structured data as per the resource module's argspec and the value is then returned in the parsed key within the result.
+
+
+ state + +
+ string +
+
+
    Choices: +
  • merged ←
  • +
  • replaced
  • +
  • overridden
  • +
  • deleted
  • +
  • gathered
  • +
  • rendered
  • +
  • parsed
  • +
+
+
The state of the configuration after module completion
+
+
+ + +Notes +----- + +.. note:: + - Tested against NXOS 9.3(2) on Cisco MDS Switches + + + +Examples +-------- + +.. code-block:: yaml + + # Using merged + + # Before state: + # ------------- + # + # switch# show running-config interface all + # interface fc18/10 + # analytics type fc-nvme + # switchport speed auto max 16000 + # switchport mode auto + # switchport description $ + # switchport trunk mode on + # shutdown + + - name: Merge provided configuration with device configuration + cisco.nxos.nxos_fc_interfaces: + config: + - name: fc18/10 + analytics: fc-scsi + state: merged + + # Task Output + # ----------- + # + # before: + # - name: fc18/10 + # speed: auto max 16000 + # mode: auto + # trunk_mode: on + # enabled: true + # description: $ + # analytics: fc-nvme + # commands: + # - interface fc18/10 + # - analytics type fc-scsi + # after: + # - name: fc18/10 + # speed: auto max 16000 + # mode: auto + # trunk_mode: on + # enabled: true + # description: $ + # analytics: fc-all + + # After state: + # ------------ + # + # switch# show running-config interface all + # interface fc18/10 + # analytics type fc-scsi + # analytics type fc-nvme + # switchport speed auto max 16000 + # switchport mode auto + # switchport description $ + # switchport trunk mode on + # shutdown + + # Using replaced + + # Before state: + # ------------- + # + # switch# show running-config interface all + # interface fc18/12 + # analytics type fc-scsi + # analytics type fc-nvme + # switchport speed auto max 64000 + # switchport mode auto + # switchport description 1 + # switchport trunk mode on + # no shutdown + + - name: Replaces device configuration of listed interfaces with provided configuration + cisco.nxos.nxos_fc_interfaces: + config: + - name: fc18/12 + speed: auto max 64000 + mode: auto + trunk_mode: "on" + enabled: true + description: 1 + analytics: fc-scsi + state: replaced + + # Task Output + # ----------- + # + # before: + # - name: fc18/12 + # speed: auto max 64000 + # mode: auto + # trunk_mode: on + # enabled: true + # description: 1 + # analytics: fc-all + # commands: + # - interface fc18/12 + # - no analytics type fc-all + # - analytics type fc-scsi + # after: + # - name: fc18/12 + # speed: auto max 64000 + # mode: auto + # trunk_mode: on + # enabled: true + # description: 1 + # analytics: fc-scsi + + # After state: + # ------------ + # + # switch# show running-config interface all + # interface fc18/12 + # analytics type fc-scsi + # switchport speed auto max 64000 + # switchport mode auto + # switchport description 1 + # switchport trunk mode on + # no shutdown + + + # Using deleted + + # Before state: + # ------------- + # + # switch# show running-config interface all + # interface fc1/2 + # switchport speed 1000 + # switchport mode E + # no switchport description + # switchport trunk mode off + # no shutdown + + - name: Delete or return interface parameters to default settings + cisco.nxos.nxos_fc_interfaces: + config: + - name: fc1/2 + state: deleted + + # Task Output + # ----------- + # + # before: + # - name: fc1/2 + # speed: 1000 + # mode: E + # trunk_mode: off + # enabled: true + # commands: + # - interface fc1/2 + # - no switchport speed 1000 + # - no switchport mode E + # - switchport trunk mode on + # - shutdown + # after: + # - name: fc1/2 + # speed: auto + # mode: auto + # trunk_mode: on + # enabled: true + + # After state: + # ------------ + # + # switch# show running-config interface all + # interface fc1/2 + # switchport speed auto + # switchport mode auto + # no switchport description + # switchport trunk mode on + # shutdown + + # Using overridden + + # Before state: + # ------------- + # + # switch# show running-config interface all + # interface fc18/12 + # analytics type fc-scsi + # analytics type fc-nvme + # switchport speed auto max 64000 + # switchport mode auto + # switchport description 1 + # switchport trunk mode on + # no shutdown + # interface fc18/13 + # analytics type fc-scsi + # analytics type fc-nvme + # switchport speed auto max 64000 + # switchport mode auto + # switchport description 1 + # switchport trunk mode on + # no shutdown + + - name: Replaces device configuration of listed interfaces with provided configuration + cisco.nxos.nxos_fc_interfaces: + config: + - name: fc18/12 + speed: auto max 64000 + mode: auto + trunk_mode: "on" + enabled: true + description: 1 + analytics: fc-scsi + state: overridden + + # Task Output + # ----------- + # + # before: + # - name: fc18/12 + # speed: auto max 64000 + # mode: auto + # trunk_mode: on + # enabled: true + # description: 1 + # analytics: fc-all + # - name: fc18/13 + # speed: auto max 64000 + # mode: auto + # trunk_mode: on + # enabled: true + # description: 1 + # analytics: fc-all + # commands: + # - interface fc18/12 + # no analytics type fc-all + # analytics type fc-scsi + # - interface fc18/13 + # no switchport description + # no switchport speed auto max 64000 + # no switchport mode auto + # switchport trunk mode on + # shutdown + # after: + # - name: fc18/12 + # speed: auto max 64000 + # mode: auto + # trunk_mode: on + # enabled: true + # description: 1 + # analytics: fc-scsi + # - name: fc18/13 + # speed: auto max 64000 + # mode: auto + # trunk_mode: on + # enabled: true + + # After state: + # ------------ + # + # switch# show running-config interface all + # interface fc18/12 + # analytics type fc-scsi + # switchport speed auto max 64000 + # switchport mode auto + # switchport description 1 + # switchport trunk mode on + # no shutdown + # interface fc18/13 + # switchport mode auto + # switchport trunk mode on + # shutdown + + # Using rendered + + - name: Use rendered state to convert task input to device specific commands + cisco.nxos.nxos_fc_interfaces: + config: + - name: fc1/1 + speed: auto + mode: auto + trunk_mode: "on" + enabled: true + description: This is a sample line + - name: fc1/2 + speed: 1000 + mode: E + trunk_mode: "off" + enabled: true + state: rendered + + # Task Output + # ----------- + # + # rendered: + # interface fc1/1 + # switchport speed auto + # switchport mode auto + # switchport description This is a sample line + # switchport trunk mode on + # no shutdown + # + # interface fc1/2 + # switchport speed 1000 + # switchport mode E + # no switchport description + # switchport trunk mode off + # no shutdown + + # Using parsed + + # parsed.cfg + # ------------ + # + # interface fc1/1 + # switchport speed auto + # switchport mode auto + # switchport description This is a sample line + # switchport trunk mode on + # no shutdown + # + # interface fc1/2 + # switchport speed 1000 + # switchport mode E + # no switchport description + # switchport trunk mode off + # no shutdown + + - name: Use parsed state to convert externally supplied config to structured format + cisco.nxos.nxos_fc_interfaces: + running_config: "{{ lookup('file', 'parsed.cfg') }}" + state: parsed + + # Task output + # ----------- + # + # parsed: + # - name: fc1/1 + # speed: auto + # mode: auto + # trunk_mode: on + # enabled: true + # description: This is a sample line + # - name: fc1/2 + # speed: 1000 + # mode: E + # trunk_mode: off + # enabled: true + + # Using gathered + + # Before state: + # ------------- + # + # switch# show running-config | section interface + # interface fc1/1 + # switchport speed auto + # switchport mode auto + # switchport description This is a sample line + # switchport trunk mode on + # no shutdown + # + # interface fc1/2 + # switchport speed 1000 + # switchport mode E + # no switchport description + # switchport trunk mode off + # no shutdown + # + - name: Gather interfaces facts from the device using nxos_fc_interfaces + cisco.nxos.nxos_fc_interfaces: + state: gathered + # + # Task output + # ----------- + # + # - name: fc1/1 + # speed: auto + # mode: auto + # trunk_mode: on + # enabled: true + # description: This is a sample line + # - name: fc1/2 + # speed: 1000 + # mode: E + # trunk_mode: off + # enabled: true + + + +Return Values +------------- +Common return values are documented `here `_, the following are the fields unique to this module: + +.. raw:: html + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
KeyReturnedDescription
+
+ after + +
+ dictionary +
+
when changed +
The resulting configuration after module execution.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ before + +
+ dictionary +
+
when state is merged, replaced, overridden, deleted or purged +
The configuration prior to the module execution.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ commands + +
+ list +
+
when state is merged, replaced, overridden, deleted or purged +
The set of commands pushed to the remote device.
+
+
Sample:
+
['interface fc1/1', 'description sample description', 'shutdown']
+
+
+ gathered + +
+ list +
+
when state is gathered +
Facts about the network resource gathered from the remote device as structured data.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ parsed + +
+ list +
+
when state is parsed +
The device native config provided in running_config option parsed into structured data as per module argspec.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ rendered + +
+ list +
+
when state is rendered +
The provided configuration in the task rendered in device-native format (offline).
+
+
Sample:
+
['interface fc1/1', 'description sample description', 'shutdown']
+
+

+ + +Status +------ + + +Authors +~~~~~~~ + +- Suhas Bharadwaj (@srbharadwaj) diff --git a/docs/cisco.nxos.nxos_feature_module.rst b/docs/cisco.nxos.nxos_feature_module.rst index 030b32243..ee2539180 100644 --- a/docs/cisco.nxos.nxos_feature_module.rst +++ b/docs/cisco.nxos.nxos_feature_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
feature @@ -50,241 +50,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
state diff --git a/docs/cisco.nxos.nxos_file_copy_module.rst b/docs/cisco.nxos.nxos_file_copy_module.rst index f5e4bebf1..c73b16aba 100644 --- a/docs/cisco.nxos.nxos_file_copy_module.rst +++ b/docs/cisco.nxos.nxos_file_copy_module.rst @@ -36,12 +36,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
connect_ssh_port @@ -62,7 +62,7 @@ Parameters
+
file_pull @@ -83,7 +83,7 @@ Parameters
+
file_pull_compact @@ -103,7 +103,7 @@ Parameters
+
file_pull_kstack @@ -123,7 +123,7 @@ Parameters
+
file_pull_protocol @@ -147,7 +147,7 @@ Parameters
+
file_pull_timeout @@ -168,7 +168,7 @@ Parameters
+
file_system @@ -184,7 +184,7 @@ Parameters
+
local_file @@ -200,7 +200,7 @@ Parameters
+
local_file_directory @@ -216,241 +216,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
remote_file @@ -466,7 +232,7 @@ Parameters
+
remote_scp_server @@ -482,7 +248,7 @@ Parameters
+
remote_scp_server_password @@ -498,7 +264,7 @@ Parameters
+
remote_scp_server_user @@ -514,7 +280,7 @@ Parameters
+
vrf @@ -526,7 +292,8 @@ Parameters Default:
"management"
-
The VRF used to pull the file. Useful when no vrf management is defined
+
The VRF used to pull the file. Useful when no vrf management is defined.
+
This option is not applicable for MDS switches.
diff --git a/docs/cisco.nxos.nxos_gir_module.rst b/docs/cisco.nxos.nxos_gir_module.rst index 787a78844..61c809ea0 100644 --- a/docs/cisco.nxos.nxos_gir_module.rst +++ b/docs/cisco.nxos.nxos_gir_module.rst @@ -30,246 +30,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
state @@ -288,7 +54,7 @@ Parameters
+
system_mode_maintenance @@ -307,7 +73,7 @@ Parameters
+
system_mode_maintenance_dont_generate_profile @@ -326,7 +92,7 @@ Parameters
+
system_mode_maintenance_on_reload_reset_reason @@ -353,7 +119,7 @@ Parameters
+
system_mode_maintenance_shutdown @@ -372,7 +138,7 @@ Parameters
+
system_mode_maintenance_timeout diff --git a/docs/cisco.nxos.nxos_gir_profile_management_module.rst b/docs/cisco.nxos.nxos_gir_profile_management_module.rst index c18fe0e48..95d85ae9b 100644 --- a/docs/cisco.nxos.nxos_gir_profile_management_module.rst +++ b/docs/cisco.nxos.nxos_gir_profile_management_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
commands @@ -50,7 +50,7 @@ Parameters
+
mode @@ -70,241 +70,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
state @@ -348,8 +114,8 @@ Examples - cisco.nxos.nxos_gir_profile_management: mode: maintenance commands: - - router eigrp 11 - - isolate + - router eigrp 11 + - isolate # Remove the maintenance-mode profile - cisco.nxos.nxos_gir_profile_management: diff --git a/docs/cisco.nxos.nxos_hsrp_interfaces_module.rst b/docs/cisco.nxos.nxos_hsrp_interfaces_module.rst index 1fd8dcded..163612413 100644 --- a/docs/cisco.nxos.nxos_hsrp_interfaces_module.rst +++ b/docs/cisco.nxos.nxos_hsrp_interfaces_module.rst @@ -151,8 +151,8 @@ Examples - name: Configure hsrp attributes on interfaces cisco.nxos.nxos_hsrp_interfaces: config: - - name: Ethernet1/1 - - name: Ethernet1/2 + - name: Ethernet1/1 + - name: Ethernet1/2 operation: deleted @@ -161,10 +161,10 @@ Examples - name: Configure hsrp attributes on interfaces cisco.nxos.nxos_hsrp_interfaces: config: - - name: Ethernet1/1 - bfd: enable - - name: Ethernet1/2 - bfd: disable + - name: Ethernet1/1 + bfd: enable + - name: Ethernet1/2 + bfd: disable operation: merged @@ -173,10 +173,10 @@ Examples - name: Configure hsrp attributes on interfaces cisco.nxos.nxos_hsrp_interfaces: config: - - name: Ethernet1/1 - bfd: enable - - name: Ethernet1/2 - bfd: disable + - name: Ethernet1/1 + bfd: enable + - name: Ethernet1/2 + bfd: disable operation: overridden @@ -185,10 +185,10 @@ Examples - name: Configure hsrp attributes on interfaces cisco.nxos.nxos_hsrp_interfaces: config: - - name: Ethernet1/1 - bfd: enable - - name: Ethernet1/2 - bfd: disable + - name: Ethernet1/1 + bfd: enable + - name: Ethernet1/2 + bfd: disable operation: replaced # Using rendered @@ -196,10 +196,10 @@ Examples - name: Use rendered state to convert task input to device specific commands cisco.nxos.nxos_hsrp_interfaces: config: - - name: Ethernet1/800 - bfd: enable - - name: Ethernet1/801 - bfd: enable + - name: Ethernet1/800 + bfd: enable + - name: Ethernet1/801 + bfd: enable state: rendered # Task Output (redacted) diff --git a/docs/cisco.nxos.nxos_hsrp_module.rst b/docs/cisco.nxos.nxos_hsrp_module.rst index d3a90dcab..0a55a4423 100644 --- a/docs/cisco.nxos.nxos_hsrp_module.rst +++ b/docs/cisco.nxos.nxos_hsrp_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
auth_string @@ -49,7 +49,7 @@ Parameters
+
auth_type @@ -68,7 +68,7 @@ Parameters
+
group @@ -84,7 +84,7 @@ Parameters
+
interface @@ -100,7 +100,7 @@ Parameters
+
preempt @@ -119,7 +119,7 @@ Parameters
+
priority @@ -134,241 +134,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
state @@ -387,7 +153,7 @@ Parameters
+
version @@ -406,7 +172,7 @@ Parameters
+
vip diff --git a/docs/cisco.nxos.nxos_igmp_interface_module.rst b/docs/cisco.nxos.nxos_igmp_interface_module.rst index b1a1ca9d9..80384f85a 100644 --- a/docs/cisco.nxos.nxos_igmp_interface_module.rst +++ b/docs/cisco.nxos.nxos_igmp_interface_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
group_timeout @@ -49,7 +49,7 @@ Parameters
+
immediate_leave @@ -68,7 +68,7 @@ Parameters
+
interface @@ -84,7 +84,7 @@ Parameters
+
last_member_qrt @@ -99,7 +99,7 @@ Parameters
+
last_member_query_count @@ -114,7 +114,7 @@ Parameters
+
oif_ps @@ -129,7 +129,7 @@ Parameters
+
oif_routemap @@ -144,241 +144,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
querier_timeout @@ -393,7 +159,7 @@ Parameters
+
query_interval @@ -408,7 +174,7 @@ Parameters
+
query_mrt @@ -423,7 +189,7 @@ Parameters
+
report_llg @@ -442,7 +208,7 @@ Parameters
+
restart @@ -461,7 +227,7 @@ Parameters
+
robustness @@ -476,7 +242,7 @@ Parameters
+
startup_query_count @@ -491,7 +257,7 @@ Parameters
+
startup_query_interval @@ -506,7 +272,7 @@ Parameters
+
state @@ -526,7 +292,7 @@ Parameters
+
version @@ -576,8 +342,8 @@ Examples interface: ethernet1/32 startup_query_interval: 30 oif_ps: - - {prefix: 238.2.2.6} - - {source: 192.168.0.1, prefix: 238.2.2.5} + - {prefix: 238.2.2.6} + - {source: 192.168.0.1, prefix: 238.2.2.5} state: present diff --git a/docs/cisco.nxos.nxos_igmp_module.rst b/docs/cisco.nxos.nxos_igmp_module.rst index ce1a14d5f..dbb46206f 100644 --- a/docs/cisco.nxos.nxos_igmp_module.rst +++ b/docs/cisco.nxos.nxos_igmp_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -561,6 +562,7 @@ Parameters @@ -770,6 +772,7 @@ Parameters @@ -1082,6 +1085,7 @@ Parameters @@ -1098,6 +1102,7 @@ Parameters @@ -1173,9 +1178,10 @@ Notes ----- .. note:: - - Tested against NX-OS 9.3.6. + - Tested against NX-OS 9.3.6 on Cisco Nexus Switches. - Limited Support for Cisco MDS - This module works with connection ``network_cli`` and ``httpapi``. + - Tested against Cisco MDS NX-OS 9.2(2) with connection ``network_cli``. @@ -1220,7 +1226,7 @@ Examples facility: local6 use_vrf: default origin_id: - hostname: True + hostname: true # Task output # ------------- @@ -1506,7 +1512,7 @@ Examples facility: local6 use_vrf: default origin_id: - hostname: True + hostname: true # Task Output (redacted) # ----------------------- diff --git a/docs/cisco.nxos.nxos_logging_module.rst b/docs/cisco.nxos.nxos_logging_module.rst index 20c3d64b0..9dafd8e33 100644 --- a/docs/cisco.nxos.nxos_logging_module.rst +++ b/docs/cisco.nxos.nxos_logging_module.rst @@ -36,12 +36,12 @@ Parameters
ParameterParameter Choices/Defaults Comments
+
enforce_rtr_alert @@ -53,7 +53,7 @@ Parameters
+
flush_routes @@ -72,241 +72,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
restart @@ -325,7 +91,7 @@ Parameters
+
state diff --git a/docs/cisco.nxos.nxos_igmp_snooping_module.rst b/docs/cisco.nxos.nxos_igmp_snooping_module.rst index dd35f3cd8..31af97509 100644 --- a/docs/cisco.nxos.nxos_igmp_snooping_module.rst +++ b/docs/cisco.nxos.nxos_igmp_snooping_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
group_timeout @@ -49,7 +49,7 @@ Parameters
+
link_local_grp_supp @@ -68,241 +68,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
report_supp @@ -321,7 +87,7 @@ Parameters
+
snooping @@ -340,7 +106,7 @@ Parameters
+
state @@ -359,7 +125,7 @@ Parameters
+
v3_report_supp diff --git a/docs/cisco.nxos.nxos_install_os_module.rst b/docs/cisco.nxos.nxos_install_os_module.rst index 2e73196c1..ddd630d01 100644 --- a/docs/cisco.nxos.nxos_install_os_module.rst +++ b/docs/cisco.nxos.nxos_install_os_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + @@ -265,7 +285,7 @@ Parameters @@ -334,39 +354,93 @@ Examples # Before state: # ------------- # + # router# show running-config | section interface # interface Ethernet1/6 + # description Configured by Ansible Network + # no switchport + # no shutdown + # interface Ethernet1/7 + # description Configured by Ansible + # no switchport + # no shutdown + # interface mgmt0 + # description mgmt interface + # ip address dhcp + # vrf member management - name: Merge provided configuration with device configuration. cisco.nxos.nxos_l3_interfaces: config: - - name: Ethernet1/6 - ipv4: - - address: 192.168.1.1/24 - tag: 5 - - address: 10.1.1.1/24 - secondary: true - tag: 10 - ipv6: - - address: fd5d:12c9:2201:2::1/64 - tag: 6 - - name: Ethernet1/7.42 - dot1q: 42 - redirects: false - unreachables: false + - name: Ethernet1/6 + ipv4: + - address: 192.168.1.1/24 + tag: 5 + - address: 10.1.1.1/24 + secondary: true + tag: 10 + ipv6: + - address: fd5d:12c9:2201:2::1/64 + tag: 6 + - name: Ethernet1/7.42 + redirects: false + unreachables: false state: merged + # Task Output + # ----------- + # + # before: + # - name: Ethernet1/6 + # - name: Ethernet1/7 + # - ipv4: + # - address: dhcp + # name: mgmt0 + # commands: + # - interface Ethernet1/6 + # - ip address 192.168.1.1/24 tag 5 + # - ip address 10.1.1.1/24 secondary tag 10 + # - ipv6 address fd5d:12c9:2201:2::1/64 tag 6 + # - interface Ethernet1/7 + # - no ip redirects + # after: + # - ipv4: + # - address: 192.168.1.1/24 + # tag: 5 + # - address: 10.1.1.1/24 + # secondary: true + # tag: 10 + # ipv6: + # - address: fd5d:12c9:2201:2::1/64 + # tag: 6 + # name: Ethernet1/6 + # redirects: false + # - name: Ethernet1/7 + # redirects: false + # - ipv4: + # - address: dhcp + # name: mgmt0 + # After state: # ------------ # + # router# show running-config | section interface # interface Ethernet1/6 - # ip address 192.168.22.1/24 tag 5 + # description Configured by Ansible Network + # no switchport + # no ip redirects + # ip address 192.168.1.1/24 tag 5 # ip address 10.1.1.1/24 secondary tag 10 - # interface Ethernet1/6 # ipv6 address fd5d:12c9:2201:2::1/64 tag 6 - # interface Ethernet1/7.42 - # encapsulation dot1q 42 + # no shutdown + # interface Ethernet1/7 + # description Configured by Ansible + # no switchport # no ip redirects - # no ip unreachables + # no shutdown + # interface mgmt0 + # description mgmt interface + # ip address dhcp + # vrf member management # Using replaced @@ -374,107 +448,295 @@ Examples # Before state: # ------------- # + # router# show running-config | section interface # interface Ethernet1/6 - # ip address 192.168.22.1/24 - # ipv6 address "fd5d:12c9:2201:1::1/64" + # description Configured by Ansible Network + # no switchport + # no ip redirects + # ip address 192.168.1.1/24 tag 5 + # ip address 10.1.1.1/24 secondary tag 10 + # ipv6 address fd5d:12c9:2201:2::1/64 tag 6 + # no shutdown + # interface Ethernet1/7 + # description Configured by Ansible + # no switchport + # no ip redirects + # no shutdown + # interface mgmt0 + # description mgmt interface + # ip address dhcp + # vrf member management - name: Replace device configuration of specified L3 interfaces with provided configuration. cisco.nxos.nxos_l3_interfaces: config: - - name: Ethernet1/6 - ipv4: - - address: 192.168.22.3/24 + - name: Ethernet1/6 + ipv4: + - address: 192.168.22.3/24 state: replaced + # Task Output + # ----------- + # + # before: + # - ipv4: + # - address: 192.168.1.1/24 + # tag: 5 + # - address: 10.1.1.1/24 + # secondary: true + # tag: 10 + # ipv6: + # - address: fd5d:12c9:2201:2::1/64 + # tag: 6 + # name: Ethernet1/6 + # redirects: false + # - name: Ethernet1/7 + # redirects: false + # - ipv4: + # - address: dhcp + # name: mgmt0 + # commands: + # - interface Ethernet1/6 + # - ip address 192.168.22.3/24 + # - no ipv6 address fd5d:12c9:2201:2::1/64 + # - ip redirects + # after: + # - ipv4: + # - address: 192.168.22.3/24 + # - address: 10.1.1.1/24 + # secondary: true + # tag: 10 + # name: Ethernet1/6 + # redirects: false + # - name: Ethernet1/7 + # redirects: false + # - ipv4: + # - address: dhcp + # name: mgmt0 + # After state: # ------------ # + # router# show running-config | section interface # interface Ethernet1/6 + # description Configured by Ansible Network + # no switchport + # no ip redirects # ip address 192.168.22.3/24 - + # ip address 10.1.1.1/24 secondary tag 10 + # no shutdown + # interface Ethernet1/7 + # description Configured by Ansible + # no switchport + # no ip redirects + # no shutdown + # interface mgmt0 + # description mgmt interface + # ip address dhcp + # vrf member management # Using overridden # Before state: # ------------- # - # interface Ethernet1/2 - # ip address 192.168.22.1/24 + # router# show running-config | section interface # interface Ethernet1/6 - # ipv6 address "fd5d:12c9:2201:1::1/64" + # description Configured by Ansible Network + # no switchport + # no ip redirects + # ip address 192.168.1.1/24 tag 5 + # ip address 10.1.1.1/24 secondary tag 10 + # ipv6 address fd5d:12c9:2201:2::1/64 tag 6 + # no shutdown + # interface Ethernet1/7 + # description Configured by Ansible + # no switchport + # no ip redirects + # no shutdown + # interface Ethernet1/7.42 + # no ip redirects + # interface mgmt0 + # description mgmt interface + # ip address dhcp + # vrf member management - - name: Override device configuration of all L3 interfaces on device with provided - configuration. + - name: Override device configuration with provided configuration. cisco.nxos.nxos_l3_interfaces: config: - - name: Ethernet1/2 - ipv4: 192.168.22.3/4 + - ipv4: + - address: dhcp + name: mgmt0 + - name: Ethernet1/6 + ipv4: + - address: 192.168.22.3/24 state: overridden + # Task Output + # ----------- + # + # before: + # - ipv4: + # - address: 192.168.1.1/24 + # tag: 5 + # - address: 10.1.1.1/24 + # secondary: true + # tag: 10 + # ipv6: + # - address: fd5d:12c9:2201:2::1/64 + # tag: 6 + # name: Ethernet1/6 + # redirects: false + # - name: Ethernet1/7 + # redirects: false + # - name: Ethernet1/7.42 + # redirects: false + # - ipv4: + # - address: dhcp + # name: mgmt0 + # commands: + # - interface Ethernet1/6 + # - no ipv6 address fd5d:12c9:2201:2::1/64 + # - no ip address 10.1.1.1/24 secondary + # - ip address 192.168.22.3/24 + # - ip redirects + # - interface Ethernet1/7 + # - ip redirects + # - interface Ethernet1/7.42 + # - ip redirects + # after: + # - ipv4: + # - address: 192.168.22.3/24 + # name: Ethernet1/6 + # - name: Ethernet1/7 + # - name: Ethernet1/7.42 + # - ipv4: + # - address: dhcp + # name: mgmt0 + # After state: # ------------ # - # interface Ethernet1/2 - # ipv4 address 192.168.22.3/24 + # router# show running-config | section interface # interface Ethernet1/6 - + # description Configured by Ansible Network + # no switchport + # ip address 192.168.22.3/24 + # no shutdown + # interface Ethernet1/7 + # description Configured by Ansible + # no switchport + # no shutdown + # interface Ethernet1/7.42 + # interface mgmt0 + # description mgmt interface + # ip address dhcp + # vrf member management # Using deleted # Before state: # ------------- # + # router# show running-config | section interface # interface Ethernet1/6 - # ip address 192.168.22.1/24 - # interface Ethernet1/2 - # ipv6 address "fd5d:12c9:2201:1::1/64" + # description Configured by Ansible Network + # no switchport + # ip address 192.168.22.3/24 + # no shutdown + # interface Ethernet1/7 + # description Configured by Ansible + # no switchport + # no shutdown + # interface Ethernet1/7.42 + # interface mgmt0 + # description mgmt interface + # ip address dhcp + # vrf member management - name: Delete L3 attributes of given interfaces (This won't delete the interface itself). cisco.nxos.nxos_l3_interfaces: config: - - name: Ethernet1/6 - - name: Ethernet1/2 + - name: Ethernet1/6 + - name: Ethernet1/2 state: deleted + # Task Output + # ----------- + # + # before: + # - name: Ethernet1/2 + # - ipv4: + # - address: 192.168.22.3/24 + # name: Ethernet1/6 + # - name: Ethernet1/7 + # - name: Ethernet1/7.42 + # - ipv4: + # - address: dhcp + # name: mgmt0 + # commands: + # - interface Ethernet1/6 + # - no ip address + # after: + # - name: Ethernet1/2 + # - name: Ethernet1/7 + # - name: Ethernet1/7.42 + # - ipv4: + # - address: dhcp + # name: mgmt0 + # After state: # ------------ # + # router# show running-config | section interface # interface Ethernet1/6 - # interface Ethernet1/2 + # description Configured by Ansible Network + # no switchport + # no shutdown + # interface Ethernet1/7 + # description Configured by Ansible + # no switchport + # no shutdown + # interface Ethernet1/7.42 + # interface mgmt0 + # description mgmt interface + # ip address dhcp + # vrf member management # Using rendered - name: Use rendered state to convert task input to device specific commands cisco.nxos.nxos_l3_interfaces: config: - - name: Ethernet1/800 - ipv4: - - address: 192.168.1.100/24 - tag: 5 - - address: 10.1.1.1/24 - secondary: true - tag: 10 - - name: Ethernet1/800 - ipv6: - - address: fd5d:12c9:2201:2::1/64 - tag: 6 + - name: Ethernet1/800 + ipv4: + - address: 192.168.1.100/24 + tag: 5 + - address: 10.1.1.1/24 + secondary: true + tag: 10 + - name: Ethernet1/800 + ipv6: + - address: fd5d:12c9:2201:2::1/64 + tag: 6 state: rendered - # Task Output (redacted) - # ----------------------- - + # Task Output + # ----------- + # # rendered: - # - "interface Ethernet1/800" - # - "ip address 192.168.1.100/24 tag 5" - # - "ip address 10.1.1.1/24 secondary tag 10" - # - "interface Ethernet1/800" - # - "ipv6 address fd5d:12c9:2201:2::1/64 tag 6" + # - interface Ethernet1/800 + # - ip address 192.168.1.100/24 tag 5 + # - ip address 10.1.1.1/24 secondary tag 10 + # - interface Ethernet1/800 + # - ipv6 address fd5d:12c9:2201:2::1/64 tag 6 # Using parsed # parsed.cfg - # ------------ + # ---------- + # # interface Ethernet1/800 # ip address 192.168.1.100/24 tag 5 # ip address 10.1.1.1/24 secondary tag 10 @@ -491,9 +753,9 @@ Examples running_config: "{{ lookup('file', 'parsed.cfg') }}" state: parsed - # Task output (redacted) - # ----------------------- - + # Task output + # ----------- + # # parsed: # - name: Ethernet1/800 # ipv4: @@ -511,8 +773,9 @@ Examples # Using gathered - # Existing device config state - # ------------------------------- + # Before state: + # ------------- + # # interface Ethernet1/1 # ip address 192.0.2.100/24 # interface Ethernet1/2 @@ -525,9 +788,9 @@ Examples cisco.nxos.nxos_l3_interfaces: state: gathered - # Task output (redacted) - # ----------------------- - + # Task output + # ----------- + # # gathered: # - name: Ethernet1/1 # ipv4: diff --git a/docs/cisco.nxos.nxos_lacp_interfaces_module.rst b/docs/cisco.nxos.nxos_lacp_interfaces_module.rst index 63a082c80..76724ede0 100644 --- a/docs/cisco.nxos.nxos_lacp_interfaces_module.rst +++ b/docs/cisco.nxos.nxos_lacp_interfaces_module.rst @@ -320,9 +320,9 @@ Examples - name: Merge provided configuration with device configuration. cisco.nxos.nxos_lacp_interfaces: config: - - name: Ethernet1/3 - port_priority: 5 - rate: fast + - name: Ethernet1/3 + port_priority: 5 + rate: fast state: merged # After state: @@ -346,9 +346,9 @@ Examples - name: Replace device lacp interfaces configuration with the given configuration. cisco.nxos.nxos_lacp_interfaces: config: - - name: port-channel11 - links: - min: 4 + - name: port-channel11 + links: + min: 4 state: replaced # After state: @@ -374,9 +374,9 @@ Examples on device with provided configuration. cisco.nxos.nxos_lacp_interfaces: config: - - name: port-channel11 - links: - min: 4 + - name: port-channel11 + links: + min: 4 state: overridden # After state: @@ -409,17 +409,17 @@ Examples - name: Use rendered state to convert task input to device specific commands cisco.nxos.nxos_lacp_interfaces: config: - - name: Ethernet1/800 - rate: fast - - name: Ethernet1/801 - rate: fast - port_priority: 32 - - name: port-channel10 - links: - max: 15 - min: 2 - convergence: - graceful: true + - name: Ethernet1/800 + rate: fast + - name: Ethernet1/801 + rate: fast + port_priority: 32 + - name: port-channel10 + links: + max: 15 + min: 2 + convergence: + graceful: true state: rendered # Task Output (redacted) diff --git a/docs/cisco.nxos.nxos_lacp_module.rst b/docs/cisco.nxos.nxos_lacp_module.rst index 81fcb8fc2..b0410c783 100644 --- a/docs/cisco.nxos.nxos_lacp_module.rst +++ b/docs/cisco.nxos.nxos_lacp_module.rst @@ -171,6 +171,7 @@ Parameters
    Choices:
  • merged ←
  • replaced
  • +
  • overridden
  • deleted
  • gathered
  • rendered
  • @@ -179,6 +180,7 @@ Parameters
ParameterParameter Choices/Defaults Comments
+
issu @@ -58,7 +58,7 @@ Parameters
+
kickstart_image_file @@ -73,241 +73,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
system_image_file @@ -349,7 +115,7 @@ Examples .. code-block:: yaml - name: Install OS on N9k - check_mode: no + check_mode: false cisco.nxos.nxos_install_os: system_image_file: nxos.7.0.3.I6.1.bin issu: desired @@ -365,11 +131,11 @@ Examples - name: Check installed OS for newly installed version nxos_command: commands: [show version | json] - provider: '{{ connection }}' register: output + - assert: that: - - output['stdout'][0]['kickstart_ver_str'] == '7.0(3)I6(1)' + - output['stdout'][0]['kickstart_ver_str'] == '7.0(3)I6(1)' diff --git a/docs/cisco.nxos.nxos_interface_module.rst b/docs/cisco.nxos.nxos_interface_module.rst deleted file mode 100644 index 644581a92..000000000 --- a/docs/cisco.nxos.nxos_interface_module.rst +++ /dev/null @@ -1,1043 +0,0 @@ -.. _cisco.nxos.nxos_interface_module: - - -************************* -cisco.nxos.nxos_interface -************************* - -**(deprecated, removed after 2022-06-01) Manages physical attributes of interfaces.** - - -Version added: 1.0.0 - -.. contents:: - :local: - :depth: 1 - -DEPRECATED ----------- -:Removed in collection release after 2022-06-01 -:Why: Updated modules released with more functionality -:Alternative: nxos_interfaces - - - -Synopsis --------- -- Manages physical attributes of interfaces of NX-OS switches. - - - - -Parameters ----------- - -.. raw:: html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterChoices/DefaultsComments
-
- admin_state - -
- string -
-
-
    Choices: -
  • up ←
  • -
  • down
  • -
-
-
Administrative state of the interface.
-
-
- aggregate - -
- list - / elements=dictionary -
-
- -
List of Interfaces definitions.
-
-
- admin_state - -
- string -
-
-
    Choices: -
  • up
  • -
  • down
  • -
-
-
Administrative state of the interface.
-
-
- delay - -
- integer -
-
- -
Time in seconds to wait before checking for the operational state on remote device. This wait is applicable for operational state arguments.
-
-
- description - -
- string -
-
- -
Interface description.
-
-
- duplex - -
- string -
-
-
    Choices: -
  • full
  • -
  • half
  • -
  • auto
  • -
-
-
Interface link status. Applicable for ethernet interface only.
-
-
- fabric_forwarding_anycast_gateway - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Associate SVI with anycast gateway under VLAN configuration mode. Applicable for SVI interface only.
-
-
- interface_type - -
- string -
-
-
    Choices: -
  • loopback
  • -
  • portchannel
  • -
  • svi
  • -
  • nve
  • -
-
-
Interface type to be unconfigured from the device.
-
-
- ip_forward - -
- string -
-
-
    Choices: -
  • enable
  • -
  • disable
  • -
-
-
Enable/Disable ip forward feature on SVIs.
-
-
- mode - -
- string -
-
-
    Choices: -
  • layer2
  • -
  • layer3
  • -
-
-
Manage Layer 2 or Layer 3 state of the interface. This option is supported for ethernet and portchannel interface. Applicable for ethernet and portchannel interface only.
-
-
- mtu - -
- string -
-
- -
MTU for a specific interface. Must be an even number between 576 and 9216. Applicable for ethernet interface only.
-
-
- name - -
- string - / required -
-
- -
Full name of interface, i.e. Ethernet1/1, port-channel10.
-
-
- neighbors - -
- list - / elements=dictionary -
-
- -
Check the operational state of given interface name for LLDP neighbor.
-
The following suboptions are available. This is state check parameter only.
-
-
- host - -
- string -
-
- -
LLDP neighbor host for given interface name.
-
-
- port - -
- string -
-
- -
LLDP neighbor port to which given interface name is connected.
-
-
- rx_rate - -
- string -
-
- -
Receiver rate in bits per second (bps).
-
This is state check parameter only.
- -
-
- speed - -
- string -
-
- -
Interface link speed. Applicable for ethernet interface only.
-
-
- state - -
- string -
-
-
    Choices: -
  • present
  • -
  • absent
  • -
  • default
  • -
-
-
Specify desired state of the resource.
-
-
- tx_rate - -
- string -
-
- -
Transmit rate in bits per second (bps).
-
This is state check parameter only.
- -
-
- delay - -
- integer -
-
- Default:
10
-
-
Time in seconds to wait before checking for the operational state on remote device. This wait is applicable for operational state arguments.
-
-
- description - -
- string -
-
- -
Interface description.
-
-
- duplex - -
- string -
-
-
    Choices: -
  • full
  • -
  • half
  • -
  • auto
  • -
-
-
Interface link status. Applicable for ethernet interface only.
-
-
- fabric_forwarding_anycast_gateway - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Associate SVI with anycast gateway under VLAN configuration mode. Applicable for SVI interface only.
-
-
- interface_type - -
- string -
-
-
    Choices: -
  • loopback
  • -
  • portchannel
  • -
  • svi
  • -
  • nve
  • -
-
-
Interface type to be unconfigured from the device.
-
-
- ip_forward - -
- string -
-
-
    Choices: -
  • enable
  • -
  • disable
  • -
-
-
Enable/Disable ip forward feature on SVIs.
-
-
- mode - -
- string -
-
-
    Choices: -
  • layer2
  • -
  • layer3
  • -
-
-
Manage Layer 2 or Layer 3 state of the interface. This option is supported for ethernet and portchannel interface. Applicable for ethernet and portchannel interface only.
-
-
- mtu - -
- string -
-
- -
MTU for a specific interface. Must be an even number between 576 and 9216. Applicable for ethernet interface only.
-
-
- name - -
- string -
-
- -
Full name of interface, i.e. Ethernet1/1, port-channel10.
-

aliases: interface
-
-
- neighbors - -
- list - / elements=dictionary -
-
- -
Check the operational state of given interface name for LLDP neighbor.
-
The following suboptions are available. This is state check parameter only.
-
-
- host - -
- string -
-
- -
LLDP neighbor host for given interface name.
-
-
- port - -
- string -
-
- -
LLDP neighbor port to which given interface name is connected.
-
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
-
- rx_rate - -
- string -
-
- -
Receiver rate in bits per second (bps).
-
This is state check parameter only.
- -
-
- speed - -
- string -
-
- -
Interface link speed. Applicable for ethernet interface only.
-
-
- state - -
- string -
-
-
    Choices: -
  • present ←
  • -
  • absent
  • -
  • default
  • -
-
-
Specify desired state of the resource.
-
-
- tx_rate - -
- string -
-
- -
Transmit rate in bits per second (bps).
-
This is state check parameter only.
- -
-
- - -Notes ------ - -.. note:: - - Tested against NXOSv 7.3.(0)D1(1) on VIRL - - Unsupported for Cisco MDS - - This module is also used to create logical interfaces such as svis and loopbacks. - - Be cautious of platform specific idiosyncrasies. For example, when you default a loopback interface, the admin state toggles on certain versions of NX-OS. - - The :ref:`cisco.nxos.nxos_overlay_global ` ``anycast_gateway_mac`` attribute must be set before setting the ``fabric_forwarding_anycast_gateway`` property. - - For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide ` - - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide ` - - For more information on using Ansible to manage Cisco devices see the `Cisco integration page `_. - - - -Examples --------- - -.. code-block:: yaml - - - name: Ensure an interface is a Layer 3 port and that it has the proper description - cisco.nxos.nxos_interface: - name: Ethernet1/1 - description: Configured by Ansible - mode: layer3 - - - name: Admin down an interface - cisco.nxos.nxos_interface: - name: Ethernet2/1 - admin_state: down - - - name: Remove all loopback interfaces - cisco.nxos.nxos_interface: - name: loopback - state: absent - - - name: Remove all logical interfaces - cisco.nxos.nxos_interface: - interface_type: '{{ item }} ' - state: absent - loop: - - loopback - - portchannel - - svi - - nve - - - name: Admin up all loopback interfaces - cisco.nxos.nxos_interface: - name: loopback 0-1023 - admin_state: up - - - name: Admin down all loopback interfaces - cisco.nxos.nxos_interface: - name: loopback 0-1023 - admin_state: down - - - name: Check neighbors intent arguments - cisco.nxos.nxos_interface: - name: Ethernet2/3 - neighbors: - - port: Ethernet2/3 - host: abc.mycompany.com - - - name: Add interface using aggregate - cisco.nxos.nxos_interface: - aggregate: - - {name: Ethernet0/1, mtu: 256, description: test-interface-1} - - {name: Ethernet0/2, mtu: 516, description: test-interface-2} - duplex: full - speed: 100 - state: present - - - name: Delete interface using aggregate - cisco.nxos.nxos_interface: - aggregate: - - name: Loopback9 - - name: Loopback10 - state: absent - - - name: Check intent arguments - cisco.nxos.nxos_interface: - name: Ethernet0/2 - state: up - tx_rate: ge(0) - rx_rate: le(0) - - - -Return Values -------------- -Common return values are documented `here `_, the following are the fields unique to this module: - -.. raw:: html - - - - - - - - - - - - -
KeyReturnedDescription
-
- commands - -
- list -
-
always -
command list sent to the device
-
-
Sample:
-
['interface Ethernet2/3', 'mtu 1500', 'speed 10']
-
-

- - -Status ------- - - -- This module will be removed in a release after 2022-06-01. *[deprecated]* -- For more information see `DEPRECATED`_. - - -Authors -~~~~~~~ - -- Jason Edelman (@jedelman8) -- Trishna Guha (@trishnaguha) diff --git a/docs/cisco.nxos.nxos_interface_ospf_module.rst b/docs/cisco.nxos.nxos_interface_ospf_module.rst deleted file mode 100644 index 02e9f4143..000000000 --- a/docs/cisco.nxos.nxos_interface_ospf_module.rst +++ /dev/null @@ -1,623 +0,0 @@ -.. _cisco.nxos.nxos_interface_ospf_module: - - -****************************** -cisco.nxos.nxos_interface_ospf -****************************** - -**(deprecated, removed after 2022-10-26) Manages configuration of an OSPF interface instance.** - - -Version added: 1.0.0 - -.. contents:: - :local: - :depth: 1 - -DEPRECATED ----------- -:Removed in collection release after 2022-10-26 -:Why: Updated modules released with more functionality -:Alternative: nxos_ospf_interfaces - - - -Synopsis --------- -- Manages configuration of an OSPF interface instance. - - - - -Parameters ----------- - -.. raw:: html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterChoices/DefaultsComments
-
- area - -
- string - / required -
-
- -
Ospf area associated with this cisco_interface_ospf instance. Valid values are a string, formatted as an IP address (i.e. "0.0.0.0") or as an integer.
-
-
- bfd - -
- string -
-
-
    Choices: -
  • enable
  • -
  • disable
  • -
  • default
  • -
-
-
Enables bfd at interface level. This overrides the bfd variable set at the ospf router level.
-
Valid values are 'enable', 'disable' or 'default'.
-
Dependency: ''feature bfd''
-
-
- cost - -
- string -
-
- -
The cost associated with this cisco_interface_ospf instance.
-
-
- dead_interval - -
- string -
-
- -
Time interval an ospf neighbor waits for a hello packet before tearing down adjacencies. Valid values are an integer or the keyword 'default'.
-
-
- hello_interval - -
- string -
-
- -
Time between sending successive hello packets. Valid values are an integer or the keyword 'default'.
-
-
- interface - -
- string - / required -
-
- -
Name of this cisco_interface resource. Valid value is a string.
-
-
- message_digest - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enables or disables the usage of message digest authentication.
-
-
- message_digest_algorithm_type - -
- string -
-
-
    Choices: -
  • md5
  • -
  • default
  • -
-
-
Algorithm used for authentication among neighboring routers within an area. Valid values are 'md5' and 'default'.
-
-
- message_digest_encryption_type - -
- string -
-
-
    Choices: -
  • cisco_type_7
  • -
  • 3des
  • -
  • default
  • -
-
-
Specifies the scheme used for encrypting message_digest_password. Valid values are '3des' or 'cisco_type_7' encryption or 'default'.
-
-
- message_digest_key_id - -
- string -
-
- -
Md5 authentication key-id associated with the ospf instance. If this is present, message_digest_encryption_type, message_digest_algorithm_type and message_digest_password are mandatory. Valid value is an integer and 'default'.
-
-
- message_digest_password - -
- string -
-
- -
Specifies the message_digest password. Valid value is a string.
-
-
- network - -
- string -
-
-
    Choices: -
  • point-to-point
  • -
  • broadcast
  • -
-
-
Specifies interface ospf network type. Valid values are 'point-to-point' or 'broadcast'.
-
-
- ospf - -
- string - / required -
-
- -
Name of the ospf instance.
-
-
- passive_interface - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enable or disable passive-interface state on this interface. true - (enable) Prevent OSPF from establishing an adjacency or sending routing updates on this interface. false - (disable) Override global 'passive-interface default' for this interface.
-
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
-
- state - -
- string -
-
-
    Choices: -
  • present ←
  • -
  • absent
  • -
-
-
Determines whether the config should be present or not on the device.
-
-
- - -Notes ------ - -.. note:: - - Tested against NXOSv 7.3.(0)D1(1) on VIRL - - Unsupported for Cisco MDS - - Default, where supported, restores params default value. - - To remove an existing authentication configuration you should use ``message_digest_key_id=default`` plus all other options matching their existing values. - - Loopback interfaces only support ospf network type 'point-to-point'. - - ``state=absent`` removes the whole OSPF interface configuration. - - For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide ` - - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide ` - - For more information on using Ansible to manage Cisco devices see the `Cisco integration page `_. - - - -Examples --------- - -.. code-block:: yaml - - - cisco.nxos.nxos_interface_ospf: - interface: ethernet1/32 - ospf: 1 - area: 1 - bfd: disable - cost: default - - - cisco.nxos.nxos_interface_ospf: - interface: loopback0 - ospf: prod - area: 0.0.0.0 - bfd: enable - network: point-to-point - state: present - - - -Return Values -------------- -Common return values are documented `here `_, the following are the fields unique to this module: - -.. raw:: html - - - - - - - - - - - - -
KeyReturnedDescription
-
- commands - -
- list -
-
always -
commands sent to the device
-
-
Sample:
-
['interface Ethernet1/32', 'ip router ospf 1 area 0.0.0.1', 'ip ospf bfd disable']
-
-

- - -Status ------- - - -- This module will be removed in a release after 2022-10-26. *[deprecated]* -- For more information see `DEPRECATED`_. - - -Authors -~~~~~~~ - -- Gabriele Gerbino (@GGabriele) diff --git a/docs/cisco.nxos.nxos_interfaces_module.rst b/docs/cisco.nxos.nxos_interfaces_module.rst index 687232c90..bf9e5d9c9 100644 --- a/docs/cisco.nxos.nxos_interfaces_module.rst +++ b/docs/cisco.nxos.nxos_interfaces_module.rst @@ -283,146 +283,265 @@ Examples # Before state: # ------------- # + # switch# show running-config | section interface # interface Ethernet1/1 # description testing - # mtu 1800 + # interface mgmt0 + # description mgmt interface + # ip address dhcp + # vrf member management - name: Merge provided configuration with device configuration cisco.nxos.nxos_interfaces: config: - - name: Ethernet1/1 - description: Configured by Ansible - enabled: true - - name: Ethernet1/2 - description: Configured by Ansible Network - enabled: false + - name: Ethernet1/1 + description: Configured by Ansible + enabled: true + - name: Ethernet1/2 + description: Configured by Ansible Network + enabled: false state: merged + # Task Output + # ----------- + # + # before: + # - description: testing + # name: Ethernet1/1 + # - description: mgmt interface + # name: mgmt0 + # commands: + # - interface Ethernet1/1 + # - description Configured by Ansible + # - interface Ethernet1/2 + # - description Configured by Ansible Network + # - shutdown + # after: + # - description: Configured by Ansible + # name: Ethernet1/1 + # - description: Configured by Ansible Network + # enabled: false + # name: Ethernet1/2 + # - description: mgmt interface + # name: mgmt0 + # After state: # ------------ # + # switch# show running-config | section interface # interface Ethernet1/1 - # description Configured by Ansible - # no shutdown - # mtu 1800 - # interface Ethernet2 - # description Configured by Ansible Network - # shutdown - + # description Configured by Ansible + # interface Ethernet1/2 + # description Configured by Ansible Network + # shutdown + # interface mgmt0 + # description mgmt interface + # ip address dhcp + # vrf member management # Using replaced # Before state: # ------------- # + # switch# show running-config | section interface # interface Ethernet1/1 - # description Interface 1/1 + # description Updated by Ansible # interface Ethernet1/2 + # description Configured by Ansible Network + # shutdown + # interface mgmt0 + # description mgmt interface + # ip address dhcp + # vrf member management - name: Replaces device configuration of listed interfaces with provided configuration cisco.nxos.nxos_interfaces: config: - - name: Ethernet1/1 - description: Configured by Ansible - enabled: true - mtu: 2000 - - name: Ethernet1/2 - description: Configured by Ansible Network - enabled: false - mode: layer2 + - name: Ethernet1/1 + description: Configured by Ansible + enabled: true + mtu: 9000 + - name: Ethernet1/2 + description: Configured by Ansible Network + enabled: false + mode: layer2 state: replaced + # Task Output + # ----------- + # + # before: + # - description: Updated by Ansible + # name: Ethernet1/1 + # - description: Configured by Ansible Network + # enabled: false + # name: Ethernet1/2 + # - description: mgmt interface + # name: mgmt0 + # commands: + # - interface Ethernet1/1 + # - mtu 1500 + # - interface Ethernet1/2 + # - description Updated by Ansible + # after: + # - description: Updated by Ansible + # name: Ethernet1/1 + # - description: Updated by Ansible + # enabled: false + # name: Ethernet1/2 + # - description: mgmt interface + # name: mgmt0 + # After state: # ------------ # + # switch# show running-config | section interface # interface Ethernet1/1 - # description Configured by Ansible - # no shutdown - # mtu 1500 - # interface Ethernet2/2 - # description Configured by Ansible Network - # shutdown - # switchport - + # description Updated by Ansible + # interface Ethernet1/2 + # description Updated by Ansible + # shutdown + # interface mgmt0 + # description mgmt interface + # ip address dhcp + # vrf member management # Using overridden # Before state: # ------------- # + # switch# show running-config | section interface # interface Ethernet1/1 - # description Interface Ethernet1/1 + # description Updated by Ansible # interface Ethernet1/2 + # description Updated by Ansible + # shutdown # interface mgmt0 - # description Management interface - # ip address dhcp + # description mgmt interface + # ip address dhcp + # vrf member management - name: Override device configuration of all interfaces with provided configuration cisco.nxos.nxos_interfaces: config: - - name: Ethernet1/1 - enabled: true - - name: Ethernet1/2 - description: Configured by Ansible Network - enabled: false + - name: Ethernet1/1 + enabled: true + - name: Ethernet1/2 + description: Configured by Ansible Network + enabled: false + - description: mgmt interface + name: mgmt0 state: overridden + # Task Output + # ----------- + # + # before: + # - description: Updated by Ansible + # name: Ethernet1/1 + # - description: Updated by Ansible + # enabled: false + # name: Ethernet1/2 + # - description: mgmt interface + # name: mgmt0 + # commands: + # - interface Ethernet1/1 + # - no description + # - interface Ethernet1/2 + # - description Configured by Ansible Network + # after: + # - name: Ethernet1/1 + # - description: Configured by Ansible Network + # enabled: false + # name: Ethernet1/2 + # - description: mgmt interface + # name: mgmt0 + # After state: # ------------ # + # switch# show running-config | section interface # interface Ethernet1/1 # interface Ethernet1/2 - # description Configured by Ansible Network - # shutdown + # description Configured by Ansible Network + # shutdown # interface mgmt0 - # ip address dhcp - + # description mgmt interface + # ip address dhcp + # vrf member management # Using deleted # Before state: # ------------- # + # switch# show running-config | section interface # interface Ethernet1/1 - # description Interface Ethernet1/1 # interface Ethernet1/2 + # description Configured by Ansible Network + # shutdown # interface mgmt0 - # description Management interface - # ip address dhcp + # description mgmt interface + # ip address dhcp + # vrf member management - name: Delete or return interface parameters to default settings cisco.nxos.nxos_interfaces: config: - - name: Ethernet1/1 + - name: Ethernet1/2 state: deleted + # Task Output + # ----------- + # + # before: + # - name: Ethernet1/1 + # - description: Configured by Ansible Network + # enabled: false + # name: Ethernet1/2 + # - description: mgmt interface + # name: mgmt0 + # commands: + # - interface Ethernet1/2 + # - no description + # - no shutdown + # after: + # - name: Ethernet1/1 + # - name: Ethernet1/2 + # - description: mgmt interface + # name: mgmt0 + # After state: # ------------ # + # switch# show running-config | section interface # interface Ethernet1/1 # interface Ethernet1/2 # interface mgmt0 - # description Management interface - # ip address dhcp + # description mgmt interface + # ip address dhcp + # vrf member management # Using rendered - name: Use rendered state to convert task input to device specific commands cisco.nxos.nxos_interfaces: config: - - name: Ethernet1/1 - description: outbound-intf - mode: layer3 - speed: 100 - - name: Ethernet1/2 - mode: layer2 - enabled: true - duplex: full + - name: Ethernet1/1 + description: outbound-intf + mode: layer3 + speed: 100 + - name: Ethernet1/2 + mode: layer2 + enabled: true + duplex: full state: rendered - # Task Output (redacted) - # ----------------------- - + # Task Output + # ----------- + # # rendered: # - "interface Ethernet1/1" # - "description outbound-intf" @@ -436,6 +555,7 @@ Examples # parsed.cfg # ------------ + # # interface Ethernet1/800 # description test-1 # speed 1000 @@ -453,8 +573,9 @@ Examples running_config: "{{ lookup('file', 'parsed.cfg') }}" state: parsed - # Task output (redacted) - # ----------------------- + # Task output + # ----------- + # # parsed: # - description: "test-1" # duplex: "half" @@ -462,7 +583,6 @@ Examples # mode: "layer3" # name: "Ethernet1/800" # speed: "1000" - # # - description: "test-2" # enabled: true # mode: "layer2" @@ -471,8 +591,10 @@ Examples # Using gathered - # Existing device config state - # ----------------------------- + # Before state: + # ------------- + # + # switch# show running-config | section interface # interface Ethernet1/1 # description outbound-intf # switchport @@ -488,8 +610,9 @@ Examples cisco.nxos.nxos_interfaces: state: gathered - # Task output (redacted) - # ----------------------- + # Task output + # ----------- + # # - name: Ethernet1/1 # description: outbound-intf # mode: layer2 @@ -500,8 +623,10 @@ Examples # Using purged - # Existing device config state - # ----------------------------- + # Before state: + # ------------- + # + # switch# show running-config | section interface # interface Vlan1 # interface Vlan42 # mtu 1800 @@ -522,6 +647,7 @@ Examples # Task output # ------------ + # # before: # - name: Vlan1 # - mtu: '1800' @@ -532,18 +658,25 @@ Examples # - name: Ethernet1/2 # - description: sub-intf # name: Ethernet1/2.100 - # # commands: # - no interface port-channel10 # - no interface Ethernet1/2.100 # - no interface Vlan42 - # # after: # - name: Vlan1 # - name: port-channel11 # - name: Ethernet1/1 # - name: Ethernet1/2 + # After state: + # ------------- + # + # switch# show running-config | section interface + # interface Vlan1 + # interface port-channel11 + # interface Ethernet1/1 + # interface Ethernet1/2 + Return Values diff --git a/docs/cisco.nxos.nxos_l2_interface_module.rst b/docs/cisco.nxos.nxos_l2_interface_module.rst deleted file mode 100644 index 947757fee..000000000 --- a/docs/cisco.nxos.nxos_l2_interface_module.rst +++ /dev/null @@ -1,640 +0,0 @@ -.. _cisco.nxos.nxos_l2_interface_module: - - -**************************** -cisco.nxos.nxos_l2_interface -**************************** - -**(deprecated, removed after 2022-06-01) Manage Layer-2 interface on Cisco NXOS devices.** - - -Version added: 1.0.0 - -.. contents:: - :local: - :depth: 1 - -DEPRECATED ----------- -:Removed in collection release after 2022-06-01 -:Why: Updated modules released with more functionality -:Alternative: nxos_l2_interfaces - - - -Synopsis --------- -- This module provides declarative management of Layer-2 interface on Cisco NXOS devices. - - - - -Parameters ----------- - -.. raw:: html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterChoices/DefaultsComments
-
- access_vlan - -
- string -
-
- -
Configure given VLAN in access port. If mode=access, used as the access VLAN ID.
-
-
- aggregate - -
- list - / elements=dictionary -
-
- -
List of Layer-2 interface definitions.
-
-
- access_vlan - -
- string -
-
- -
Configure given VLAN in access port. If mode=access, used as the access VLAN ID.
-
-
- mode - -
- string -
-
-
    Choices: -
  • access
  • -
  • trunk
  • -
-
-
Mode in which interface needs to be configured.
-
-
- name - -
- string -
-
- -
Full name of the interface excluding any logical unit number, i.e. Ethernet1/1.
-

aliases: interface
-
-
- native_vlan - -
- string -
-
- -
Native VLAN to be configured in trunk port. If mode=trunk, used as the trunk native VLAN ID.
-
-
- state - -
- string -
-
-
    Choices: -
  • present
  • -
  • absent
  • -
  • unconfigured
  • -
-
-
Manage the state of the Layer-2 Interface configuration.
-
-
- trunk_allowed_vlans - -
- string -
-
- -
List of allowed VLANs in a given trunk port. If mode=trunk, these are the only VLANs that will be configured on the trunk, i.e. "2-10,15".
-
-
- trunk_vlans - -
- string -
-
- -
List of VLANs to be configured in trunk port. If mode=trunk, used as the VLAN range to ADD or REMOVE from the trunk.
-

aliases: trunk_add_vlans
-
-
- mode - -
- string -
-
-
    Choices: -
  • access
  • -
  • trunk
  • -
-
-
Mode in which interface needs to be configured.
-
-
- name - -
- string -
-
- -
Full name of the interface excluding any logical unit number, i.e. Ethernet1/1.
-

aliases: interface
-
-
- native_vlan - -
- string -
-
- -
Native VLAN to be configured in trunk port. If mode=trunk, used as the trunk native VLAN ID.
-
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
-
- state - -
- string -
-
-
    Choices: -
  • present ←
  • -
  • absent
  • -
  • unconfigured
  • -
-
-
Manage the state of the Layer-2 Interface configuration.
-
-
- trunk_allowed_vlans - -
- string -
-
- -
List of allowed VLANs in a given trunk port. If mode=trunk, these are the only VLANs that will be configured on the trunk, i.e. "2-10,15".
-
-
- trunk_vlans - -
- string -
-
- -
List of VLANs to be configured in trunk port. If mode=trunk, used as the VLAN range to ADD or REMOVE from the trunk.
-

aliases: trunk_add_vlans
-
-
- - -Notes ------ - -.. note:: - - Tested against NXOSv 7.0(3)I5(1). - - Unsupported for Cisco MDS - - For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide ` - - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide ` - - For more information on using Ansible to manage Cisco devices see the `Cisco integration page `_. - - - -Examples --------- - -.. code-block:: yaml - - - name: Ensure Eth1/5 is in its default l2 interface state - cisco.nxos.nxos_l2_interface: - name: Ethernet1/5 - state: unconfigured - - - name: Ensure Eth1/5 is configured for access vlan 20 - cisco.nxos.nxos_l2_interface: - name: Ethernet1/5 - mode: access - access_vlan: 20 - - - name: Ensure Eth1/5 only has vlans 5-10 as trunk vlans - cisco.nxos.nxos_l2_interface: - name: Ethernet1/5 - mode: trunk - native_vlan: 10 - trunk_vlans: 5-10 - - - name: Ensure eth1/5 is a trunk port and ensure 2-50 are being tagged (doesn't mean - others aren't also being tagged) - cisco.nxos.nxos_l2_interface: - name: Ethernet1/5 - mode: trunk - native_vlan: 10 - trunk_vlans: 2-50 - - - name: Ensure these VLANs are not being tagged on the trunk - cisco.nxos.nxos_l2_interface: - name: Ethernet1/5 - mode: trunk - trunk_vlans: 51-4094 - state: absent - - - name: Aggregate Configure interfaces for access_vlan with aggregate - cisco.nxos.nxos_l2_interface: - aggregate: - - {name: Ethernet1/2, access_vlan: 6} - - {name: Ethernet1/7, access_vlan: 15} - mode: access - - - -Return Values -------------- -Common return values are documented `here `_, the following are the fields unique to this module: - -.. raw:: html - - - - - - - - - - - - -
KeyReturnedDescription
-
- commands - -
- list -
-
always, except for the platforms that use Netconf transport to manage the device. -
The list of configuration mode commands to send to the device
-
-
Sample:
-
['interface eth1/5', 'switchport access vlan 20']
-
-

- - -Status ------- - - -- This module will be removed in a release after 2022-06-01. *[deprecated]* -- For more information see `DEPRECATED`_. - - -Authors -~~~~~~~ - -- Trishna Guha (@trishnaguha) diff --git a/docs/cisco.nxos.nxos_l2_interfaces_module.rst b/docs/cisco.nxos.nxos_l2_interfaces_module.rst index 07bc67963..bfad0cf31 100644 --- a/docs/cisco.nxos.nxos_l2_interfaces_module.rst +++ b/docs/cisco.nxos.nxos_l2_interfaces_module.rst @@ -95,6 +95,7 @@ Parameters
    Choices: +
  • dot1q-tunnel
  • access
  • trunk
  • fex-fabric
  • @@ -239,29 +240,55 @@ Examples # Before state: # ------------- # + # switch# show running-config | section interface # interface Ethernet1/1 - # switchport access vlan 20 # interface Ethernet1/2 # switchport trunk native vlan 20 # interface mgmt0 # ip address dhcp # ipv6 address auto-config - - name: Merge provided configuration with device configuration. + - name: Merge provided configuration with device configuration cisco.nxos.nxos_l2_interfaces: config: - - name: Ethernet1/1 - trunk: - native_vlan: 10 - allowed_vlans: 2,4,15 - - name: Ethernet1/2 - access: - vlan: 30 + - name: Ethernet1/1 + trunk: + native_vlan: 10 + allowed_vlans: 2,4,15 + - name: Ethernet1/2 + access: + vlan: 30 state: merged + # Task Output + # ----------- + # + # before: + # - name: Loopback999 + # - name: Ethernet1/2 + # - name: mgmt0 + # - name: Ethernet1/1 + # commands: + # - interface Ethernet1/1 + # - switchport trunk allowed vlan 2,4,15 + # - switchport trunk native vlan 10 + # - interface Ethernet1/2 + # - switchport access vlan 30 + # after: + # - name: Ethernet1/1 + # trunk: + # allowed_vlans: 2,4,15 + # native_vlan: 10 + # - access: + # vlan: 30 + # name: Ethernet1/2 + # - name: mgmt0 + # - name: Loopback999 + # After state: # ------------ # + # switch# show running-config | section interface # interface Ethernet1/1 # switchport trunk native vlan 10 # switchport trunk allowed vlans 2,4,15 @@ -271,16 +298,17 @@ Examples # ip address dhcp # ipv6 address auto-config - # Using replaced # Before state: # ------------- # + # switch# show running-config | section interface # interface Ethernet1/1 - # switchport access vlan 20 + # switchport trunk native vlan 10 + # switchport trunk allowed vlans 2,4,15 # interface Ethernet1/2 - # switchport trunk native vlan 20 + # switchport access vlan 30 # interface mgmt0 # ip address dhcp # ipv6 address auto-config @@ -288,15 +316,43 @@ Examples - name: Replace device configuration of specified L2 interfaces with provided configuration. cisco.nxos.nxos_l2_interfaces: config: - - name: Ethernet1/1 - trunk: - native_vlan: 20 - allowed_vlans: 5-10, 15 + - name: Ethernet1/1 + trunk: + native_vlan: 20 + allowed_vlans: 5-10, 15 state: replaced + # Task Output + # ----------- + # + # before: + # - name: Ethernet1/1 + # trunk: + # allowed_vlans: 2,4,15 + # native_vlan: 10 + # - access: + # vlan: 30 + # name: Ethernet1/2 + # - name: mgmt0 + # commands: + # - interface Ethernet1/1 + # - no switchport trunk native vlan + # - switchport trunk allowed vlan 5-10,15 + # - switchport trunk native vlan 20 + # after: + # - name: Ethernet1/1 + # trunk: + # allowed_vlans: 5-10,15 + # native_vlan: 20 + # - access: + # vlan: 30 + # name: Ethernet1/2 + # - name: mgmt0 + # After state: # ------------ # + # switch# show running-config | section interface # interface Ethernet1/1 # switchport trunk native vlan 20 # switchport trunk allowed vlan 5-10,15 @@ -307,32 +363,57 @@ Examples # ip address dhcp # ipv6 address auto-config - # Using overridden # Before state: # ------------- # + # switch# show running-config | section interface # interface Ethernet1/1 - # switchport access vlan 20 + # switchport trunk native vlan 20 + # switchport trunk allowed vlan 5-10,15 # interface Ethernet1/2 # switchport trunk native vlan 20 + # switchport mode trunk # interface mgmt0 # ip address dhcp # ipv6 address auto-config - - name: Override device configuration of all L2 interfaces on device with provided - configuration. + - name: Override device configuration with provided configuration. cisco.nxos.nxos_l2_interfaces: config: - - name: Ethernet1/2 - access: - vlan: 30 + - name: Ethernet1/2 + access: + vlan: 30 state: overridden + # Task Output + # ----------- + # + # before: + # - name: Ethernet1/1 + # trunk: + # allowed_vlans: 5,6,7,8,9,10,15 + # native_vlan: 20 + # - access: + # vlan: 30 + # name: Ethernet1/2 + # - name: mgmt0 + # commands: + # - interface Ethernet1/1 + # - no switchport trunk allowed vlan + # - no switchport trunk native vlan + # after: + # - name: Ethernet1/1 + # - access: + # vlan: 30 + # name: Ethernet1/2 + # - name: mgmt0 + # After state: # ------------ # + # switch# show running-config | section interface # interface Ethernet1/1 # interface Ethernet1/2 # switchport access vlan 30 @@ -346,10 +427,12 @@ Examples # Before state: # ------------- # + # switch# show running-config | section interface # interface Ethernet1/1 - # switchport access vlan 20 + # switchport trunk native vlan 10 + # switchport trunk allowed vlan 2,4,15 # interface Ethernet1/2 - # switchport trunk native vlan 20 + # switchport access vlan 30 # interface mgmt0 # ip address dhcp # ipv6 address auto-config @@ -358,13 +441,37 @@ Examples itself). cisco.nxos.nxos_l2_interfaces: config: - - name: Ethernet1/1 - - name: Ethernet1/2 + - name: Ethernet1/1 + - name: Ethernet1/2 state: deleted + # Task Output + # ----------- + # + # before: + # - name: Ethernet1/1 + # trunk: + # allowed_vlans: 2,4,15 + # native_vlan: 10 + # - access: + # vlan: 30 + # name: Ethernet1/2 + # - name: mgmt0 + # commands: + # - interface Ethernet1/1 + # - no switchport trunk allowed vlan + # - no switchport trunk native vlan + # - interface Ethernet1/2 + # - no switchport access vlan + # after: + # - name: Ethernet1/1 + # - name: Ethernet1/2 + # - name: mgmt0 + # After state: # ------------ # + # switch# show running-config | section interface # interface Ethernet1/1 # interface Ethernet1/2 # interface mgmt0 @@ -376,36 +483,37 @@ Examples - name: Render platform specific configuration lines (without connecting to the device) cisco.nxos.nxos_l2_interfaces: config: - - name: Ethernet1/1 - trunk: - native_vlan: 10 - allowed_vlans: 2,4,15 - - name: Ethernet1/2 - access: - vlan: 30 - - name: Ethernet1/3 - trunk: - native_vlan: 20 - allowed_vlans: 5-10, 15 + - name: Ethernet1/1 + trunk: + native_vlan: 10 + allowed_vlans: 2,4,15 + - name: Ethernet1/2 + access: + vlan: 30 + - name: Ethernet1/3 + trunk: + native_vlan: 20 + allowed_vlans: 5-10, 15 state: rendered - # Task Output (redacted) - # ----------------------- - + # Task Output + # ----------- + # # rendered: - # - "interface Ethernet1/1" - # - "switchport trunk allowed vlan 2,4,15" - # - "switchport trunk native vlan 10" - # - "interface Ethernet1/2" - # - "switchport access vlan 30" - # - "interface Ethernet1/3" - # - "switchport trunk allowed vlan 5,6,7,8,9,10,15" - # - "switchport trunk native vlan 20" + # - interface Ethernet1/1 + # - switchport trunk allowed vlan 2,4,15 + # - switchport trunk native vlan 10 + # - interface Ethernet1/2 + # - switchport access vlan 30 + # - interface Ethernet1/3 + # - switchport trunk allowed vlan 5-10,15 + # - switchport trunk native vlan 20 # Using parsed # parsed.cfg # ------------ + # # interface Ethernet1/800 # switchport access vlan 18 # switchport trunk allowed vlan 210 @@ -417,8 +525,9 @@ Examples running_config: "{{ lookup('file', 'parsed.cfg') }}" state: parsed - # Task output (redacted) - # ----------------------- + # Task output + # ----------- + # # parsed: # - name: Ethernet1/800 # access: @@ -431,9 +540,10 @@ Examples # Using gathered - # Existing device config state - # ------------------------------- - # Nexus9kvI5# sh running-config | section ^interface + # Before state: + # ------------- + # + # switch# sh running-config | section ^interface # interface Ethernet1/1 # switchport access vlan 6 # switchport trunk allowed vlan 200 @@ -444,15 +554,15 @@ Examples cisco.nxos.nxos_l2_interfaces: state: gathered - # Task output (redacted) - # ----------------------- + # Task output + # ----------- + # # gathered: # - name: "Ethernet1/1" # access: # vlan: 6 # trunk: # allowed_vlans: "200" - # # - name: "Ethernet1/2" # trunk: # native_vlan: 10 diff --git a/docs/cisco.nxos.nxos_l3_interface_module.rst b/docs/cisco.nxos.nxos_l3_interface_module.rst deleted file mode 100644 index 32addf270..000000000 --- a/docs/cisco.nxos.nxos_l3_interface_module.rst +++ /dev/null @@ -1,516 +0,0 @@ -.. _cisco.nxos.nxos_l3_interface_module: - - -**************************** -cisco.nxos.nxos_l3_interface -**************************** - -**(deprecated, removed after 2022-06-01) Manage L3 interfaces on Cisco NXOS network devices** - - -Version added: 1.0.0 - -.. contents:: - :local: - :depth: 1 - -DEPRECATED ----------- -:Removed in collection release after 2022-06-01 -:Why: Updated modules released with more functionality -:Alternative: nxos_l3_interfaces - - - -Synopsis --------- -- This module provides declarative management of L3 interfaces on Cisco NXOS network devices. - - - - -Parameters ----------- - -.. raw:: html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    ParameterChoices/DefaultsComments
    -
    - aggregate - -
    - list - / elements=dictionary -
    -
    - -
    List of L3 interfaces definitions.
    -
    -
    - ipv4 - -
    - string -
    -
    - -
    IPv4 of the L3 interface.
    -
    -
    - ipv6 - -
    - string -
    -
    - -
    IPv6 of the L3 interface.
    -
    -
    - name - -
    - string -
    -
    - -
    Name of the L3 interface.
    -
    -
    - state - -
    - string -
    -
    -
      Choices: -
    • present
    • -
    • absent
    • -
    -
    -
    State of the L3 interface configuration.
    -
    -
    - ipv4 - -
    - string -
    -
    - -
    IPv4 of the L3 interface.
    -
    -
    - ipv6 - -
    - string -
    -
    - -
    IPv6 of the L3 interface.
    -
    -
    - name - -
    - string -
    -
    - -
    Name of the L3 interface.
    -
    -
    - provider - -
    - dictionary -
    -
    - -
    Deprecated
    -
    Starting with Ansible 2.5 we recommend using connection: network_cli.
    -
    Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
    -
    This option will be removed in a release after 2022-06-01.
    - -

    -
    A dict object containing connection details.
    -
    -
    - auth_pass - -
    - string -
    -
    - -
    Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
    -
    -
    - authorize - -
    - boolean -
    -
    -
      Choices: -
    • no ←
    • -
    • yes
    • -
    -
    -
    Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
    -
    -
    - host - -
    - string -
    -
    - -
    Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
    -
    -
    - password - -
    - string -
    -
    - -
    Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
    -
    -
    - port - -
    - integer -
    -
    - -
    Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
    -
    -
    - ssh_keyfile - -
    - string -
    -
    - -
    Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
    -
    -
    - timeout - -
    - integer -
    -
    - -
    Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
    -
    -
    - transport - -
    - string -
    -
    -
      Choices: -
    • cli ←
    • -
    • nxapi
    • -
    -
    -
    Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
    -
    -
    - use_proxy - -
    - boolean -
    -
    -
      Choices: -
    • no
    • -
    • yes ←
    • -
    -
    -
    If no, the environment variables http_proxy and https_proxy will be ignored.
    -
    -
    - use_ssl - -
    - boolean -
    -
    -
      Choices: -
    • no ←
    • -
    • yes
    • -
    -
    -
    Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
    -
    -
    - username - -
    - string -
    -
    - -
    Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
    -
    -
    - validate_certs - -
    - boolean -
    -
    -
      Choices: -
    • no ←
    • -
    • yes
    • -
    -
    -
    If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
    -
    -
    - state - -
    - string -
    -
    -
      Choices: -
    • present ←
    • -
    • absent
    • -
    -
    -
    State of the L3 interface configuration.
    -
    -
    - - -Notes ------ - -.. note:: - - Tested against NXOSv 7.0(3)I5(1). - - Unsupported for Cisco MDS - - For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide ` - - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide ` - - For more information on using Ansible to manage Cisco devices see the `Cisco integration page `_. - - - -Examples --------- - -.. code-block:: yaml - - - name: Set interface IPv4 address - cisco.nxos.nxos_l3_interface: - name: Ethernet2/3 - ipv4: 192.168.0.1/24 - - - name: Remove interface IPv4 address - cisco.nxos.nxos_l3_interface: - name: Ethernet2/3 - state: absent - - - name: Set IP addresses on aggregate - cisco.nxos.nxos_l3_interface: - aggregate: - - {name: "Ethernet2/1", ipv4: "192.168.2.10/24"} - - {name: "Ethernet2/5", ipv4: "192.168.3.10/24", ipv6: "fd5d:12c9:2201:1::1/64"} - - - name: Remove IP addresses on aggregate - cisco.nxos.nxos_l3_interface: - aggregate: - - {name: "Ethernet2/1", ipv4: "192.168.2.10/24"} - - {name: "Ethernet2/5", ipv4: "192.168.3.10/24", ipv6: "fd5d:12c9:2201:1::1/64"} - state: absent - - - -Return Values -------------- -Common return values are documented `here `_, the following are the fields unique to this module: - -.. raw:: html - - - - - - - - - - - - -
    KeyReturnedDescription
    -
    - commands - -
    - list -
    -
    always, except for the platforms that use Netconf transport to manage the device. -
    The list of configuration mode commands to send to the device
    -
    -
    Sample:
    -
    ['interface ethernet2/3', 'no switchport', 'ip address 192.168.22.1/24', 'ipv6 address "fd5d:12c9:2201:1::1/64"', 'no ip address 192.168.22.1/24']
    -
    -

    - - -Status ------- - - -- This module will be removed in a release after 2022-06-01. *[deprecated]* -- For more information see `DEPRECATED`_. - - -Authors -~~~~~~~ - -- Trishna Guha (@trishnaguha) diff --git a/docs/cisco.nxos.nxos_l3_interfaces_module.rst b/docs/cisco.nxos.nxos_l3_interfaces_module.rst index 236cf7bc1..28a56bdf8 100644 --- a/docs/cisco.nxos.nxos_l3_interfaces_module.rst +++ b/docs/cisco.nxos.nxos_l3_interfaces_module.rst @@ -211,6 +211,26 @@ Parameters
+
+ ipv6_redirects + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Enables/disables ipv6 redirects.
+
@@ -245,7 +265,7 @@ Parameters -
Enables/disables ip redirects
+
Enables/disables ipv4 redirects.
-
Enables/disables ip redirects
+
Enables/disables ip redirects.
The state of the configuration after module completion.
+
States replaced and overridden have the same behaviour for this module.
diff --git a/docs/cisco.nxos.nxos_lag_interfaces_module.rst b/docs/cisco.nxos.nxos_lag_interfaces_module.rst index cf2bd9102..7d570dbfc 100644 --- a/docs/cisco.nxos.nxos_lag_interfaces_module.rst +++ b/docs/cisco.nxos.nxos_lag_interfaces_module.rst @@ -215,9 +215,9 @@ Examples - name: Merge provided configuration with device configuration. cisco.nxos.nxos_lag_interfaces: config: - - name: port-channel99 - members: - - member: Ethernet1/4 + - name: port-channel99 + members: + - member: Ethernet1/4 state: merged # After state: @@ -239,9 +239,9 @@ Examples with provided configuration. cisco.nxos.nxos_lag_interfaces: config: - - name: port-channel10 - members: - - member: Ethernet1/4 + - name: port-channel10 + members: + - member: Ethernet1/4 state: replaced # After state: @@ -265,10 +265,10 @@ Examples device with provided configuration. cisco.nxos.nxos_lag_interfaces: config: - - name: port-channel20 - members: - - member: Ethernet1/6 - force: true + - name: port-channel20 + members: + - member: Ethernet1/6 + force: true state: overridden # After state: @@ -291,7 +291,7 @@ Examples itself). cisco.nxos.nxos_lag_interfaces: config: - - port-channel: port-channel99 + - port-channel: port-channel99 state: deleted - name: Delete LAG attributes of all the interfaces @@ -309,15 +309,15 @@ Examples - name: Use rendered state to convert task input to device specific commands cisco.nxos.nxos_lag_interfaces: config: - - name: port-channel10 - members: - - member: Ethernet1/800 - mode: active - - member: Ethernet1/801 - - name: port-channel11 - members: - - member: Ethernet1/802 - mode: passive + - name: port-channel10 + members: + - member: Ethernet1/800 + mode: active + - member: Ethernet1/801 + - name: port-channel11 + members: + - member: Ethernet1/802 + mode: passive state: rendered # Task Output (redacted) diff --git a/docs/cisco.nxos.nxos_linkagg_module.rst b/docs/cisco.nxos.nxos_linkagg_module.rst deleted file mode 100644 index 95c9d7645..000000000 --- a/docs/cisco.nxos.nxos_linkagg_module.rst +++ /dev/null @@ -1,638 +0,0 @@ -.. _cisco.nxos.nxos_linkagg_module: - - -*********************** -cisco.nxos.nxos_linkagg -*********************** - -**(deprecated, removed after 2022-06-01) Manage link aggregation groups on Cisco NXOS devices.** - - -Version added: 1.0.0 - -.. contents:: - :local: - :depth: 1 - -DEPRECATED ----------- -:Removed in collection release after 2022-06-01 -:Why: Updated modules released with more functionality. -:Alternative: nxos_lag_interfaces - - - -Synopsis --------- -- This module provides declarative management of link aggregation groups on Cisco NXOS devices. - - - - -Parameters ----------- - -.. raw:: html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterChoices/DefaultsComments
-
- aggregate - -
- list - / elements=dictionary -
-
- -
List of link aggregation definitions.
-
-
- force - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
When true it forces link aggregation group members to match what is declared in the members param. This can be used to remove members.
-
-
- group - -
- string - / required -
-
- -
Channel-group number for the port-channel Link aggregation group.
-
-
- members - -
- list - / elements=string -
-
- -
List of interfaces that will be managed in the link aggregation group.
-
-
- min_links - -
- integer -
-
- -
Minimum number of ports required up before bringing up the link aggregation group.
-
-
- mode - -
- string -
-
-
    Choices: -
  • active
  • -
  • on
  • -
  • passive
  • -
-
-
Mode for the link aggregation group.
-
-
- state - -
- string -
-
-
    Choices: -
  • present
  • -
  • absent
  • -
-
-
State of the link aggregation group.
-
-
- force - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
When true it forces link aggregation group members to match what is declared in the members param. This can be used to remove members.
-
-
- group - -
- string -
-
- -
Channel-group number for the port-channel Link aggregation group.
-
-
- members - -
- list - / elements=string -
-
- -
List of interfaces that will be managed in the link aggregation group.
-
-
- min_links - -
- integer -
-
- -
Minimum number of ports required up before bringing up the link aggregation group.
-
-
- mode - -
- string -
-
-
    Choices: -
  • active
  • -
  • on ←
  • -
  • passive
  • -
-
-
Mode for the link aggregation group.
-
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
-
- purge - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Purge links not defined in the aggregate parameter.
-
-
- state - -
- string -
-
-
    Choices: -
  • present ←
  • -
  • absent
  • -
-
-
State of the link aggregation group.
-
-
- - -Notes ------ - -.. note:: - - Tested against NXOSv 7.0(3)I5(1). - - Unsupported for Cisco MDS - - ``state=absent`` removes the portchannel config and interface if it already exists. If members to be removed are not explicitly passed, all existing members (if any), are removed. - - Members must be a list. - - LACP needs to be enabled first if active/passive modes are used. - - For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide ` - - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide ` - - For more information on using Ansible to manage Cisco devices see the `Cisco integration page `_. - - - -Examples --------- - -.. code-block:: yaml - - - name: create link aggregation group - cisco.nxos.nxos_linkagg: - group: 99 - state: present - - - name: delete link aggregation group - cisco.nxos.nxos_linkagg: - group: 99 - state: absent - - - name: set link aggregation group to members - cisco.nxos.nxos_linkagg: - group: 10 - min_links: 3 - mode: active - members: - - Ethernet1/2 - - Ethernet1/4 - - - name: remove link aggregation group from Ethernet1/2 - cisco.nxos.nxos_linkagg: - group: 10 - min_links: 3 - mode: active - members: - - Ethernet1/4 - - - name: Create aggregate of linkagg definitions - cisco.nxos.nxos_linkagg: - aggregate: - - {group: 3} - - {group: 100, min_links: 3} - - - name: Remove aggregate of linkagg definitions - cisco.nxos.nxos_linkagg: - aggregate: - - {group: 3} - - {group: 100, min_links: 3} - state: absent - - - -Return Values -------------- -Common return values are documented `here `_, the following are the fields unique to this module: - -.. raw:: html - - - - - - - - - - - - -
KeyReturnedDescription
-
- commands - -
- list -
-
always, except for the platforms that use Netconf transport to manage the device. -
The list of configuration mode commands to send to the device
-
-
Sample:
-
['interface port-channel 30', 'lacp min-links 5', 'interface Ethernet2/1', 'channel-group 30 mode active', 'no interface port-channel 30']
-
-

- - -Status ------- - - -- This module will be removed in a release after 2022-06-01. *[deprecated]* -- For more information see `DEPRECATED`_. - - -Authors -~~~~~~~ - -- Trishna Guha (@trishnaguha) diff --git a/docs/cisco.nxos.nxos_lldp_global_module.rst b/docs/cisco.nxos.nxos_lldp_global_module.rst index f5d90b856..57252cfe0 100644 --- a/docs/cisco.nxos.nxos_lldp_global_module.rst +++ b/docs/cisco.nxos.nxos_lldp_global_module.rst @@ -414,6 +414,7 @@ Parameters
    Choices:
  • merged ←
  • replaced
  • +
  • overridden
  • deleted
  • gathered
  • rendered
  • @@ -421,7 +422,8 @@ Parameters
-
The state of the configuration after module completion
+
The state of the configuration after module completion.
+
States replaced and overridden have the same behaviour for this module.
@@ -525,8 +527,8 @@ Examples port_id: 1 reinit: 5 tlv_select: - dcbxp: yes - power_management: yes + dcbxp: true + power_management: true state: rendered # Task Output (redacted) diff --git a/docs/cisco.nxos.nxos_lldp_interfaces_module.rst b/docs/cisco.nxos.nxos_lldp_interfaces_module.rst index cc83a3184..d634e9aa4 100644 --- a/docs/cisco.nxos.nxos_lldp_interfaces_module.rst +++ b/docs/cisco.nxos.nxos_lldp_interfaces_module.rst @@ -227,12 +227,12 @@ Examples - name: Merge provided configuration with device configuration cisco.nxos.nxos_lldp_interfaces: config: - - name: Ethernet1/4 - receive: false - transmit: true - tlv_set: - management_address: 192.168.122.64 - vlan: 12 + - name: Ethernet1/4 + receive: false + transmit: true + tlv_set: + management_address: 192.168.122.64 + vlan: 12 state: merged # After state: @@ -259,10 +259,10 @@ Examples - name: Replace LLDP configuration on interfaces with given configuration cisco.nxos.nxos_lldp_interfaces: config: - - name: Ethernet1/4 - transmit: no - tlv_set: - vlan: 2 + - name: Ethernet1/4 + transmit: false + tlv_set: + vlan: 2 state: replaced @@ -292,10 +292,10 @@ Examples - name: Override LLDP configuration on all interfaces with given configuration cisco.nxos.nxos_lldp_interfaces: config: - - name: Ethernet1/7 - receive: no - tlv_set: - vlan: 12 + - name: Ethernet1/7 + receive: false + tlv_set: + vlan: 12 state: overridden diff --git a/docs/cisco.nxos.nxos_lldp_module.rst b/docs/cisco.nxos.nxos_lldp_module.rst deleted file mode 100644 index 67434174d..000000000 --- a/docs/cisco.nxos.nxos_lldp_module.rst +++ /dev/null @@ -1,373 +0,0 @@ -.. _cisco.nxos.nxos_lldp_module: - - -******************** -cisco.nxos.nxos_lldp -******************** - -**(deprecated, removed after 2022-06-01) Manage LLDP configuration on Cisco NXOS network devices.** - - -Version added: 1.0.0 - -.. contents:: - :local: - :depth: 1 - -DEPRECATED ----------- -:Removed in collection release after 2022-06-01 -:Why: Updated modules released with more functionality -:Alternative: nxos_lldp_global - - - -Synopsis --------- -- This module provides declarative management of LLDP service on Cisco NXOS network devices. - - - - -Parameters ----------- - -.. raw:: html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterChoices/DefaultsComments
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
-
- state - -
- string -
-
-
    Choices: -
  • present ←
  • -
  • absent
  • -
  • enabled
  • -
  • disabled
  • -
-
-
State of the LLDP configuration. If value is present lldp will be enabled else if it is absent it will be disabled.
-
-
- - -Notes ------ - -.. note:: - - Tested against NXOSv 7.0(3)I5(1). - - Unsupported for Cisco MDS - - For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide ` - - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide ` - - For more information on using Ansible to manage Cisco devices see the `Cisco integration page `_. - - - -Examples --------- - -.. code-block:: yaml - - - name: Enable LLDP service - cisco.nxos.nxos_lldp: - state: present - - - name: Disable LLDP service - cisco.nxos.nxos_lldp: - state: absent - - - -Return Values -------------- -Common return values are documented `here `_, the following are the fields unique to this module: - -.. raw:: html - - - - - - - - - - - - -
KeyReturnedDescription
-
- commands - -
- list -
-
always, except for the platforms that use Netconf transport to manage the device. -
The list of configuration mode commands to send to the device
-
-
Sample:
-
['feature lldp']
-
-

- - -Status ------- - - -- This module will be removed in a release after 2022-06-01. *[deprecated]* -- For more information see `DEPRECATED`_. - - -Authors -~~~~~~~ - -- Ganesh Nalawade (@ganeshrn) diff --git a/docs/cisco.nxos.nxos_logging_global_module.rst b/docs/cisco.nxos.nxos_logging_global_module.rst index 4e2a90216..1cda59a35 100644 --- a/docs/cisco.nxos.nxos_logging_global_module.rst +++ b/docs/cisco.nxos.nxos_logging_global_module.rst @@ -544,6 +544,7 @@ Parameters
Display per-VRF information.
+
This option is unsupported on MDS switches.
IP configuration.
+
This option is unsupported on MDS switches.
Set persistent logging utilization alert threshold in percentage.
+
This option is unsupported on MDS switches.
Set RFC to which messages should compliant.
Syslogs will be compliant to RFC 5424.
+
This option is unsupported on MDS switches.
Enable Source-Interface for Remote Syslog Server.
+
This option is unsupported on MDS switches.
- + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
aggregate @@ -57,7 +57,7 @@ Parameters
+
dest @@ -79,7 +79,7 @@ Parameters
+
dest_level @@ -95,7 +95,7 @@ Parameters
+
event @@ -116,7 +116,7 @@ Parameters
+
facility @@ -131,7 +131,7 @@ Parameters
+
facility_level @@ -146,7 +146,7 @@ Parameters
+
facility_link_status @@ -167,7 +167,7 @@ Parameters
+
file_size @@ -182,7 +182,7 @@ Parameters
+
interface @@ -197,7 +197,7 @@ Parameters
+
interface_message @@ -215,7 +215,7 @@ Parameters
+
name @@ -230,241 +230,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
purge @@ -483,7 +249,7 @@ Parameters
+
remote_server @@ -498,7 +264,7 @@ Parameters
+
state @@ -517,7 +283,7 @@ Parameters
+
timestamp @@ -537,7 +303,7 @@ Parameters
+
use_vrf @@ -638,9 +404,9 @@ Examples - name: Configure logging using aggregate cisco.nxos.nxos_logging: aggregate: - - {dest: console, dest_level: 2} - - {dest: logfile, dest_level: 2, name: testfile} - - {facility: daemon, facility_level: 0} + - {dest: console, dest_level: 2} + - {dest: logfile, dest_level: 2, name: testfile} + - {facility: daemon, facility_level: 0} state: present diff --git a/docs/cisco.nxos.nxos_ntp_auth_module.rst b/docs/cisco.nxos.nxos_ntp_auth_module.rst index fd977ed3a..c825cd017 100644 --- a/docs/cisco.nxos.nxos_ntp_auth_module.rst +++ b/docs/cisco.nxos.nxos_ntp_auth_module.rst @@ -36,12 +36,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -432,6 +433,7 @@ Parameters @@ -470,6 +472,7 @@ Parameters @@ -595,6 +598,7 @@ Parameters @@ -722,6 +726,7 @@ Parameters @@ -740,6 +745,7 @@ Parameters @@ -845,8 +851,9 @@ Notes ----- .. note:: - - Tested against NX-OS 9.3.6. + - Tested against NX-OS 9.3.6 on Cisco Nexus Switches. - This module works with connection ``network_cli`` and ``httpapi``. + - Tested against Cisco MDS NX-OS 9.2(2) with connection ``network_cli``. @@ -870,7 +877,7 @@ Examples - access_list: PeerAcl1 serve: - access_list: ServeAcl1 - authenticate: True + authenticate: true authentication_keys: - id: 1001 key: vagwwtKfkv @@ -878,7 +885,7 @@ Examples - id: 1002 key: vagwwtKfkvgthz encryption: 7 - logging: True + logging: true master: stratum: 2 peers: @@ -889,7 +896,7 @@ Examples vrf: default - peer: 192.0.2.2 key_id: 2 - prefer: True + prefer: true vrf: siteA servers: - server: 198.51.100.1 @@ -922,7 +929,7 @@ Examples # - access_list: PeerAcl1 # serve: # - access_list: ServeAcl1 - # authenticate: True + # authenticate: true # authentication_keys: # - id: 1001 # key: vagwwtKfkv @@ -930,7 +937,7 @@ Examples # - id: 1002 # key: vagwwtKfkvgthz # encryption: 7 - # logging: True + # logging: true # master: # stratum: 2 # peers: @@ -941,7 +948,7 @@ Examples # vrf: default # - peer: 192.0.2.2 # key_id: 2 - # prefer: True + # prefer: true # vrf: siteA # servers: # - server: 198.51.100.1 @@ -991,7 +998,7 @@ Examples - access_list: PeerAcl2 serve: - access_list: ServeAcl2 - logging: True + logging: true master: stratum: 2 peers: @@ -1002,7 +1009,7 @@ Examples vrf: default - peer: 192.0.2.5 key_id: 2 - prefer: True + prefer: true vrf: siteA servers: - server: 198.51.100.1 @@ -1018,7 +1025,7 @@ Examples # - access_list: PeerAcl1 # serve: # - access_list: ServeAcl1 - # authenticate: True + # authenticate: true # authentication_keys: # - id: 1001 # key: vagwwtKfkv @@ -1026,7 +1033,7 @@ Examples # - id: 1002 # key: vagwwtKfkvgthz # encryption: 7 - # logging: True + # logging: true # master: # stratum: 2 # peers: @@ -1037,7 +1044,7 @@ Examples # vrf: default # - peer: 192.0.2.2 # key_id: 2 - # prefer: True + # prefer: true # vrf: siteA # servers: # - server: 198.51.100.1 @@ -1065,7 +1072,7 @@ Examples # - access_list: PeerAcl2 # serve: # - access_list: ServeAcl2 - # logging: True + # logging: true # master: # stratum: 2 # peers: @@ -1076,7 +1083,7 @@ Examples # vrf: default # - peer: 192.0.2.5 # key_id: 2 - # prefer: True + # prefer: true # vrf: siteA # servers: # - server: 198.51.100.1 @@ -1112,7 +1119,7 @@ Examples # - access_list: PeerAcl1 # serve: # - access_list: ServeAcl1 - # authenticate: True + # authenticate: true # authentication_keys: # - id: 1001 # key: vagwwtKfkv @@ -1120,7 +1127,7 @@ Examples # - id: 1002 # key: vagwwtKfkvgthz # encryption: 7 - # logging: True + # logging: true # master: # stratum: 2 # peers: @@ -1131,7 +1138,7 @@ Examples # vrf: default # - peer: 192.0.2.2 # key_id: 2 - # prefer: True + # prefer: true # vrf: siteA # servers: # - server: 198.51.100.1 @@ -1171,7 +1178,7 @@ Examples - access_list: PeerAcl1 serve: - access_list: ServeAcl1 - authenticate: True + authenticate: true authentication_keys: - id: 1001 key: vagwwtKfkv @@ -1179,7 +1186,7 @@ Examples - id: 1002 key: vagwwtKfkvgthz encryption: 7 - logging: True + logging: true master: stratum: 2 peers: @@ -1190,7 +1197,7 @@ Examples vrf: default - peer: 192.0.2.2 key_id: 2 - prefer: True + prefer: true vrf: siteA servers: - server: 198.51.100.1 @@ -1245,7 +1252,7 @@ Examples # - access_list: PeerAcl1 # serve: # - access_list: ServeAcl1 - # authenticate: True + # authenticate: true # authentication_keys: # - id: 1001 # key: vagwwtKfkv @@ -1253,7 +1260,7 @@ Examples # - id: 1002 # key: vagwwtKfkvgthz # encryption: 7 - # logging: True + # logging: true # master: # stratum: 2 # peers: @@ -1264,7 +1271,7 @@ Examples # vrf: default # - peer: 192.0.2.2 # key_id: 2 - # prefer: True + # prefer: true # vrf: siteA # servers: # - server: 198.51.100.1 diff --git a/docs/cisco.nxos.nxos_ntp_module.rst b/docs/cisco.nxos.nxos_ntp_module.rst index 0a5b0cd14..3fa835a96 100644 --- a/docs/cisco.nxos.nxos_ntp_module.rst +++ b/docs/cisco.nxos.nxos_ntp_module.rst @@ -36,12 +36,12 @@ Parameters
ParameterParameter Choices/Defaults Comments
+
auth_type @@ -60,7 +60,7 @@ Parameters
+
authentication @@ -79,7 +79,7 @@ Parameters
+
key_id @@ -94,7 +94,7 @@ Parameters
+
md5string @@ -109,241 +109,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
state @@ -362,7 +128,7 @@ Parameters
+
trusted_key diff --git a/docs/cisco.nxos.nxos_ntp_global_module.rst b/docs/cisco.nxos.nxos_ntp_global_module.rst index c6b54dea1..b77fc9440 100644 --- a/docs/cisco.nxos.nxos_ntp_global_module.rst +++ b/docs/cisco.nxos.nxos_ntp_global_module.rst @@ -62,6 +62,7 @@ Parameters
NTP access-group.
+
This option is unsupported on MDS switches.
Act as NTP master clock.
+
This option is unsupported on MDS switches.
NTP passive command.
+
This option is unsupported on MDS switches.
Display per-VRF information.
+
This option is unsupported on MDS switches.

aliases: use_vrf
Display per-VRF information.
+
This option is not applicable for MDS switches.

aliases: use_vrf
Source of NTP packets.
+
This option is unsupported on MDS switches.
- + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + +
ParameterParameter Choices/Defaults Comments
+
key_id @@ -56,7 +56,7 @@ Parameters
+
peer @@ -71,7 +71,7 @@ Parameters
+
prefer @@ -90,241 +90,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
server @@ -339,7 +105,7 @@ Parameters
+
source_addr @@ -354,7 +120,7 @@ Parameters
+
source_int @@ -369,7 +135,7 @@ Parameters
+
state @@ -388,7 +154,7 @@ Parameters
+
vrf_name diff --git a/docs/cisco.nxos.nxos_ntp_options_module.rst b/docs/cisco.nxos.nxos_ntp_options_module.rst index a54f80299..e99825641 100644 --- a/docs/cisco.nxos.nxos_ntp_options_module.rst +++ b/docs/cisco.nxos.nxos_ntp_options_module.rst @@ -36,12 +36,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + +
ParameterParameter Choices/Defaults Comments
+
logging @@ -60,7 +60,7 @@ Parameters
+
master @@ -79,241 +79,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
state @@ -332,7 +98,7 @@ Parameters
+
stratum diff --git a/docs/cisco.nxos.nxos_nxapi_module.rst b/docs/cisco.nxos.nxos_nxapi_module.rst index 27d48eecd..182fe1516 100644 --- a/docs/cisco.nxos.nxos_nxapi_module.rst +++ b/docs/cisco.nxos.nxos_nxapi_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + +
ParameterParameter Choices/Defaults Comments
+
http @@ -54,7 +54,7 @@ Parameters
+
http_port @@ -70,7 +70,7 @@ Parameters
+
https @@ -90,7 +90,7 @@ Parameters
+
https_port @@ -106,241 +106,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
sandbox @@ -360,7 +126,7 @@ Parameters
+
ssl_strong_ciphers @@ -379,7 +145,7 @@ Parameters
+
state @@ -398,7 +164,7 @@ Parameters
+
tlsv1_0 @@ -417,7 +183,7 @@ Parameters
+
tlsv1_1 @@ -436,7 +202,7 @@ Parameters
+
tlsv1_2 @@ -482,8 +248,8 @@ Examples cisco.nxos.nxos_nxapi: enable_http: false https_port: 9443 - https: yes - enable_sandbox: no + https: true + enable_sandbox: false - name: remove NXAPI configuration cisco.nxos.nxos_nxapi: diff --git a/docs/cisco.nxos.nxos_ospf_interfaces_module.rst b/docs/cisco.nxos.nxos_ospf_interfaces_module.rst index 19ba44ab1..ff69b6e71 100644 --- a/docs/cisco.nxos.nxos_ospf_interfaces_module.rst +++ b/docs/cisco.nxos.nxos_ospf_interfaces_module.rst @@ -784,164 +784,119 @@ Examples config: - name: Ethernet1/1 address_family: - - afi: ipv4 - processes: - - process_id: "100" - area: - area_id: 1.1.1.1 - secondaries: False - multi_areas: - - 11.11.11.11 - - afi: ipv6 - processes: - - process_id: "200" - area: - area_id: 2.2.2.2 + - afi: ipv4 + processes: + - process_id: '100' + area: + area_id: 1.1.1.1 + secondaries: false multi_areas: - - 21.0.0.0 - - process_id: "300" + - 11.11.11.11 + - afi: ipv6 + processes: + - process_id: '200' + area: + area_id: 2.2.2.2 + multi_areas: + - 21.0.0.0 + - process_id: '300' + multi_areas: + - 50.50.50.50 multi_areas: - - 50.50.50.50 - multi_areas: - - 16.10.10.10 + - 16.10.10.10 - name: Ethernet1/2 address_family: - - afi: ipv4 - authentication: - enable: True - key_chain: test-1 - message_digest_key: - key_id: 10 - encryption: 3 - key: abc01d272be25d29 - cost: 100 - - afi: ipv6 - network: broadcast - shutdown: True + - afi: ipv4 + authentication: + enable: true + key_chain: test-1 + message_digest_key: + key_id: 10 + encryption: 3 + key: abc01d272be25d29 + cost: 100 + - afi: ipv6 + network: broadcast + shutdown: true - name: Ethernet1/3 address_family: - - afi: ipv4 - authentication_key: - encryption: 7 - key: 12090404011C03162E + - afi: ipv4 + authentication_key: + encryption: 7 + key: 12090404011C03162E state: merged - # Task output - # ------------- - # "before": [ - # { - # "name": "Ethernet1/1" - # }, - # { - # "name": "Ethernet1/2" - # }, - # { - # "name": "Ethernet1/3" - # }, - # ] + # Task output: + # ------------ + # before: + # - name: Ethernet1/1 + # - name: Ethernet1/2 + # - name: Ethernet1/3 # - # "commands": [ - # "interface Ethernet1/1", - # "ip router ospf multi-area 11.11.11.11", - # "ip router ospf 100 area 1.1.1.1 secondaries none", - # "ipv6 router ospfv3 multi-area 16.10.10.10", - # "ipv6 router ospfv3 200 area 2.2.2.2", - # "ipv6 router ospfv3 200 multi-area 21.0.0.0", - # "ipv6 router ospfv3 300 multi-area 50.50.50.50", - # "interface Ethernet1/2", - # "ip ospf authentication key-chain test-1", - # "ip ospf authentication", - # "ip ospf message-digest-key 10 md5 3 abc01d272be25d29", - # "ip ospf cost 100", - # "ospfv3 network broadcast", - # "ospfv3 shutdown", - # "interface Ethernet1/3", - # "ip ospf authentication-key 7 12090404011C03162E" - # ] + # commands: + # - interface Ethernet1/1 + # - ip router ospf multi-area 11.11.11.11 + # - ip router ospf 100 area 1.1.1.1 secondaries none + # - ipv6 router ospfv3 multi-area 16.10.10.10 + # - ipv6 router ospfv3 200 area 2.2.2.2 + # - ipv6 router ospfv3 200 multi-area 21.0.0.0 + # - ipv6 router ospfv3 300 multi-area 50.50.50.50 + # - interface Ethernet1/2 + # - ip ospf authentication key-chain test-1 + # - ip ospf authentication + # - ip ospf message-digest-key 10 md5 3 abc01d272be25d29 + # - ip ospf cost 100 + # - ospfv3 network broadcast + # - ospfv3 shutdown + # - interface Ethernet1/3 + # - ip ospf authentication-key 7 12090404011C03162E # - # "after": [ - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "multi_areas": [ - # "11.11.11.11" - # ], - # "processes": [ - # { - # "area": { - # "area_id": "1.1.1.1", - # "secondaries": false - # }, - # "process_id": "100" - # } - # ] - # }, - # { - # "afi": "ipv6", - # "multi_areas": [ - # "16.10.10.10" - # ], - # "processes": [ - # { - # "area": { - # "area_id": "2.2.2.2" - # }, - # "multi_areas": [ - # "21.0.0.0" - # ], - # "process_id": "200" - # }, - # { - # "multi_areas": [ - # "50.50.50.50" - # ], - # "process_id": "300" - # } - # ] - # } - # ], - # "name": "Ethernet1/1" - # }, - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "authentication": { - # "enable": true, - # "key_chain": "test-1" - # }, - # "cost": 100, - # "message_digest_key": { - # "encryption": 3, - # "key": "abc01d272be25d29", - # "key_id": 10 - # } - # }, - # { - # "afi": "ipv6", - # "network": "broadcast", - # "shutdown": true - # } - # ], - # "name": "Ethernet1/2" - # }, - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "authentication_key": { - # "encryption": 7, - # "key": "12090404011C03162E" - # } - # } - # ], - # "name": "Ethernet1/3" - # }, - # ] + # after: + # - address_family: + # - afi: ipv4 + # multi_areas: + # - 11.11.11.11 + # processes: + # - area: + # area_id: 1.1.1.1 + # secondaries: false + # process_id: '100' + # - afi: ipv6 + # multi_areas: + # - 16.10.10.10 + # processes: + # - area: + # area_id: 2.2.2.2 + # multi_areas: + # - 21.0.0.0 + # process_id: '200' + # - multi_areas: + # - 50.50.50.50 + # process_id: '300' + # name: Ethernet1/1 + # - address_family: + # - afi: ipv4 + # authentication: + # enable: true + # key_chain: test-1 + # cost: 100 + # message_digest_key: + # encryption: 3 + # key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER + # key_id: 10 + # - afi: ipv6 + # network: broadcast + # shutdown: true + # name: Ethernet1/2 + # - address_family: + # - afi: ipv4 + # authentication_key: + # encryption: 7 + # key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER + # name: Ethernet1/3 # After state: - # ------------- + # ------------ # NXOS# show running-config | section ^interface # interface Ethernet1/1 # no switchport @@ -967,7 +922,7 @@ Examples # Using replaced # Before state: - # ------------ + # ------------- # NXOS# show running-config | section ^interface # interface Ethernet1/1 # no switchport @@ -992,164 +947,105 @@ Examples - name: Replace OSPF configurations of listed interfaces with provided configurations cisco.nxos.nxos_ospf_interfaces: config: - - name: Ethernet1/1 - address_family: - - afi: ipv4 - processes: - - process_id: "100" - area: - area_id: 1.1.1.1 - secondaries: False - multi_areas: - - 11.11.11.12 - - name: Ethernet1/3 + - name: Ethernet1/1 + address_family: + - afi: ipv4 + processes: + - process_id: "100" + area: + area_id: 1.1.1.1 + secondaries: false + multi_areas: + - 11.11.11.12 + - name: Ethernet1/3 state: replaced - # Task output - # ------------- - # "before": [ - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "multi_areas": [ - # "11.11.11.11" - # ], - # "processes": [ - # { - # "area": { - # "area_id": "1.1.1.1", - # "secondaries": false - # }, - # "process_id": "100" - # } - # ] - # }, - # { - # "afi": "ipv6", - # "multi_areas": [ - # "16.10.10.10" - # ], - # "processes": [ - # { - # "area": { - # "area_id": "2.2.2.2" - # }, - # "multi_areas": [ - # "21.0.0.0" - # ], - # "process_id": "200" - # }, - # { - # "multi_areas": [ - # "50.50.50.50" - # ], - # "process_id": "300" - # } - # ] - # } - # ], - # "name": "Ethernet1/1" - # }, - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "authentication": { - # "enable": true, - # "key_chain": "test-1" - # }, - # "cost": 100, - # "message_digest_key": { - # "encryption": 3, - # "key": "abc01d272be25d29", - # "key_id": 10 - # } - # }, - # { - # "afi": "ipv6", - # "network": "broadcast", - # "shutdown": true - # } - # ], - # "name": "Ethernet1/2" - # }, - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "authentication_key": { - # "encryption": 7, - # "key": "12090404011C03162E" - # } - # } - # ], - # "name": "Ethernet1/3" - # }, - # ] + # Task output: + # ------------ + # before: + # - address_family: + # - afi: ipv4 + # multi_areas: + # - 11.11.11.11 + # processes: + # - area: + # area_id: 1.1.1.1 + # secondaries: false + # process_id: '100' + # - afi: ipv6 + # multi_areas: + # - 16.10.10.10 + # processes: + # - area: + # area_id: 2.2.2.2 + # multi_areas: + # - 21.0.0.0 + # process_id: '200' + # - multi_areas: + # - 50.50.50.50 + # process_id: '300' + # name: Ethernet1/1 + # - address_family: + # - afi: ipv4 + # authentication: + # enable: true + # key_chain: test-1 + # cost: 100 + # message_digest_key: + # encryption: 3 + # key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER + # key_id: 10 + # - afi: ipv6 + # network: broadcast + # shutdown: true + # name: Ethernet1/2 + # - address_family: + # - afi: ipv4 + # authentication_key: + # encryption: 7 + # key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER + # name: Ethernet1/3 # - # "commands": [ - # "interface Ethernet1/1", - # "ip router ospf multi-area 11.11.11.12", - # "no ip router ospf multi-area 11.11.11.11", - # "no ipv6 router ospfv3 multi-area 16.10.10.10", - # "no ipv6 router ospfv3 200 area 2.2.2.2", - # "no ipv6 router ospfv3 200 multi-area 21.0.0.0", - # "no ipv6 router ospfv3 300 multi-area 50.50.50.50", - # "interface Ethernet1/3", - # "no ip ospf authentication-key 7 12090404011C03162E" - # ] + # commands: + # - interface Ethernet1/1 + # - ip router ospf multi-area 11.11.11.12 + # - no ip router ospf multi-area 11.11.11.11 + # - no ipv6 router ospfv3 multi-area 16.10.10.10 + # - no ipv6 router ospfv3 200 area 2.2.2.2 + # - no ipv6 router ospfv3 200 multi-area 21.0.0.0 + # - no ipv6 router ospfv3 300 multi-area 50.50.50.50 + # - interface Ethernet1/3 + # - no ip ospf authentication-key 7 12090404011C03162E # - # "after": [ - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "multi_areas": [ - # "11.11.11.12" - # ], - # "processes": [ - # { - # "area": { - # "area_id": "1.1.1.1", - # "secondaries": false - # }, - # "process_id": "100" - # } - # ] - # } - # ], - # "name": "Ethernet1/1" - # }, - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "authentication": { - # "enable": true, - # "key_chain": "test-1" - # }, - # "cost": 100, - # "message_digest_key": { - # "encryption": 3, - # "key": "abc01d272be25d29", - # "key_id": 10 - # } - # }, - # { - # "afi": "ipv6", - # "network": "broadcast", - # "shutdown": true - # } - # ], - # "name": "Ethernet1/2" - # }, - # { - # "name": "Ethernet1/3" - # }, + # after: + # - address_family: + # - afi: ipv4 + # multi_areas: + # - 11.11.11.12 + # processes: + # - area: + # area_id: 1.1.1.1 + # secondaries: false + # process_id: '100' + # name: Ethernet1/1 + # - address_family: + # - afi: ipv4 + # authentication: + # enable: true + # key_chain: test-1 + # cost: 100 + # message_digest_key: + # encryption: 3 + # key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER + # key_id: 10 + # - afi: ipv6 + # network: broadcast + # shutdown: true + # name: Ethernet1/2 + # - name: Ethernet1/3 # # After state: - # ------------- + # ------------ # NXOS# show running-config | section ^interface # interface Ethernet1/1 # no switchport @@ -1170,7 +1066,7 @@ Examples # Using overridden # Before state: - # ------------ + # ------------- # NXOS# show running-config | section ^interface # interface Ethernet1/1 # no switchport @@ -1195,148 +1091,95 @@ Examples - name: Override all OSPF interfaces configuration with provided configuration cisco.nxos.nxos_ospf_interfaces: config: - - name: Ethernet1/1 - address_family: - - afi: ipv4 - processes: - - process_id: "100" - area: - area_id: 1.1.1.1 - secondaries: False - multi_areas: - - 11.11.11.12 + - name: Ethernet1/1 + address_family: + - afi: ipv4 + processes: + - process_id: "100" + area: + area_id: 1.1.1.1 + secondaries: false + multi_areas: + - 11.11.11.12 state: overridden - # Task output - # ------------- - # "before": [ - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "multi_areas": [ - # "11.11.11.11" - # ], - # "processes": [ - # { - # "area": { - # "area_id": "1.1.1.1", - # "secondaries": false - # }, - # "process_id": "100" - # } - # ] - # }, - # { - # "afi": "ipv6", - # "multi_areas": [ - # "16.10.10.10" - # ], - # "processes": [ - # { - # "area": { - # "area_id": "2.2.2.2" - # }, - # "multi_areas": [ - # "21.0.0.0" - # ], - # "process_id": "200" - # }, - # { - # "multi_areas": [ - # "50.50.50.50" - # ], - # "process_id": "300" - # } - # ] - # } - # ], - # "name": "Ethernet1/1" - # }, - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "authentication": { - # "enable": true, - # "key_chain": "test-1" - # }, - # "cost": 100, - # "message_digest_key": { - # "encryption": 3, - # "key": "abc01d272be25d29", - # "key_id": 10 - # } - # }, - # { - # "afi": "ipv6", - # "network": "broadcast", - # "shutdown": true - # } - # ], - # "name": "Ethernet1/2" - # }, - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "authentication_key": { - # "encryption": 7, - # "key": "12090404011C03162E" - # } - # } - # ], - # "name": "Ethernet1/3" - # }, - # ] + # Task output: + # ------------ + # before: + # - address_family: + # - afi: ipv4 + # multi_areas: + # - 11.11.11.11 + # processes: + # - area: + # area_id: 1.1.1.1 + # secondaries: false + # process_id: '100' + # - afi: ipv6 + # multi_areas: + # - 16.10.10.10 + # processes: + # - area: + # area_id: 2.2.2.2 + # multi_areas: + # - 21.0.0.0 + # process_id: '200' + # - multi_areas: + # - 50.50.50.50 + # process_id: '300' + # name: Ethernet1/1 + # - address_family: + # - afi: ipv4 + # authentication: + # enable: true + # key_chain: test-1 + # cost: 100 + # message_digest_key: + # encryption: 3 + # key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER + # key_id: 10 + # - afi: ipv6 + # network: broadcast + # shutdown: true + # name: Ethernet1/2 + # - address_family: + # - afi: ipv4 + # authentication_key: + # encryption: 7 + # key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER + # name: Ethernet1/3 # - # "commands": [ - # "interface Ethernet1/2", - # "no ip ospf authentication key-chain test-1", - # "no ip ospf authentication", - # "no ip ospf message-digest-key 10 md5 3 abc01d272be25d29", - # "no ip ospf cost 100", - # "no ospfv3 network broadcast", - # "no ospfv3 shutdown", - # "interface Ethernet1/3", - # "no ip ospf authentication-key 7 12090404011C03162E", - # "interface Ethernet1/1", - # "ip router ospf multi-area 11.11.11.12", - # "no ip router ospf multi-area 11.11.11.11", - # "no ipv6 router ospfv3 multi-area 16.10.10.10", - # "no ipv6 router ospfv3 200 area 2.2.2.2", - # "no ipv6 router ospfv3 200 multi-area 21.0.0.0", - # "no ipv6 router ospfv3 300 multi-area 50.50.50.50" - # ] + # commands: + # - interface Ethernet1/2 + # - no ip ospf authentication key-chain test-1 + # - no ip ospf authentication + # - no ip ospf message-digest-key 10 md5 3 abc01d272be25d29 + # - no ip ospf cost 100 + # - no ospfv3 network broadcast + # - no ospfv3 shutdown + # - interface Ethernet1/3 + # - no ip ospf authentication-key 7 12090404011C03162E + # - interface Ethernet1/1 + # - ip router ospf multi-area 11.11.11.12 + # - no ip router ospf multi-area 11.11.11.11 + # - no ipv6 router ospfv3 multi-area 16.10.10.10 + # - no ipv6 router ospfv3 200 area 2.2.2.2 + # - no ipv6 router ospfv3 200 multi-area 21.0.0.0 + # - no ipv6 router ospfv3 300 multi-area 50.50.50.50 # - # "after": [ - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "multi_areas": [ - # "11.11.11.12" - # ], - # "processes": [ - # { - # "area": { - # "area_id": "1.1.1.1", - # "secondaries": false - # }, - # "process_id": "100" - # } - # ] - # } - # ], - # "name": "Ethernet1/1" - # }, - # { - # "name": "Ethernet1/2" - # }, - # { - # "name": "Ethernet1/3" - # }, - # ] + # after: + # - address_family: + # - afi: ipv4 + # multi_areas: + # - 11.11.11.12 + # processes: + # - area: + # area_id: 1.1.1.1 + # secondaries: false + # process_id: '100' + # name: Ethernet1/1 + # - name: Ethernet1/2 + # - name: Ethernet1/3 # After state: # ------------- @@ -1353,7 +1196,7 @@ Examples # Using deleted to delete OSPF config of a single interface # Before state: - # ------------ + # ------------- # NXOS# show running-config | section ^interface # interface Ethernet1/1 # no switchport @@ -1381,139 +1224,84 @@ Examples - name: Ethernet1/1 state: deleted - # Task output - # ------------- - # "before": [ - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "multi_areas": [ - # "11.11.11.11" - # ], - # "processes": [ - # { - # "area": { - # "area_id": "1.1.1.1", - # "secondaries": false - # }, - # "process_id": "100" - # } - # ] - # }, - # { - # "afi": "ipv6", - # "multi_areas": [ - # "16.10.10.10" - # ], - # "processes": [ - # { - # "area": { - # "area_id": "2.2.2.2" - # }, - # "multi_areas": [ - # "21.0.0.0" - # ], - # "process_id": "200" - # }, - # { - # "multi_areas": [ - # "50.50.50.50" - # ], - # "process_id": "300" - # } - # ] - # } - # ], - # "name": "Ethernet1/1" - # }, - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "authentication": { - # "enable": true, - # "key_chain": "test-1" - # }, - # "cost": 100, - # "message_digest_key": { - # "encryption": 3, - # "key": "abc01d272be25d29", - # "key_id": 10 - # } - # }, - # { - # "afi": "ipv6", - # "network": "broadcast", - # "shutdown": true - # } - # ], - # "name": "Ethernet1/2" - # }, - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "authentication_key": { - # "encryption": 7, - # "key": "12090404011C03162E" - # } - # } - # ], - # "name": "Ethernet1/3" - # }, - # ] + # Task output: + # ------------ + # before: + # - address_family: + # - afi: ipv4 + # multi_areas: + # - 11.11.11.11 + # processes: + # - area: + # area_id: 1.1.1.1 + # secondaries: false + # process_id: '100' + # - afi: ipv6 + # multi_areas: + # - 16.10.10.10 + # processes: + # - area: + # area_id: 2.2.2.2 + # multi_areas: + # - 21.0.0.0 + # process_id: '200' + # - multi_areas: + # - 50.50.50.50 + # process_id: '300' + # name: Ethernet1/1 + # - address_family: + # - afi: ipv4 + # authentication: + # enable: true + # key_chain: test-1 + # cost: 100 + # message_digest_key: + # encryption: 3 + # key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER + # key_id: 10 + # - afi: ipv6 + # network: broadcast + # shutdown: true + # name: Ethernet1/2 + # - address_family: + # - afi: ipv4 + # authentication_key: + # encryption: 7 + # key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER + # name: Ethernet1/3 # - # "commands": [ - # "interface Ethernet1/1", - # "no ip router ospf multi-area 11.11.11.11", - # "no ip router ospf 100 area 1.1.1.1 secondaries none", - # "no ipv6 router ospfv3 multi-area 16.10.10.10", - # "no ipv6 router ospfv3 200 area 2.2.2.2", - # "no ipv6 router ospfv3 200 multi-area 21.0.0.0", - # "no ipv6 router ospfv3 300 multi-area 50.50.50.50" - # ] + # commands: + # - interface Ethernet1/1 + # - no ip router ospf multi-area 11.11.11.11 + # - no ip router ospf 100 area 1.1.1.1 secondaries none + # - no ipv6 router ospfv3 multi-area 16.10.10.10 + # - no ipv6 router ospfv3 200 area 2.2.2.2 + # - no ipv6 router ospfv3 200 multi-area 21.0.0.0 + # - no ipv6 router ospfv3 300 multi-area 50.50.50.50 # - # "before": [ - # { - # "name": "Ethernet1/1" - # }, - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "authentication": { - # "enable": true, - # "key_chain": "test-1" - # }, - # "cost": 100, - # "message_digest_key": { - # "encryption": 3, - # "key": "abc01d272be25d29", - # "key_id": 10 - # } - # }, - # { - # "afi": "ipv6", - # "network": "broadcast", - # "shutdown": true - # } - # ], - # "name": "Ethernet1/2" - # }, - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "authentication_key": { - # "encryption": 7, - # "key": "12090404011C03162E" - # } - # } - # ], - # "name": "Ethernet1/3" - # }, - # ] + # after: + # - name: Ethernet1/1 + # - address_family: + # - afi: ipv4 + # authentication: + # enable: true + # key_chain: test-1 + # cost: 100 + # message_digest_key: + # encryption: 3 + # key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER + # key_id: 10 + # - afi: ipv6 + # network: broadcast + # shutdown: true + # name: Ethernet1/2 + # - address_family: + # - afi: ipv4 + # authentication_key: + # encryption: 7 + # key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER + # name: Ethernet1/3 + # After state: # ------------ @@ -1535,7 +1323,7 @@ Examples # Using deleted to delete OSPF config from all interfaces # Before state: - # ------------ + # ------------- # NXOS# show running-config | section ^interface # interface Ethernet1/1 # no switchport @@ -1561,119 +1349,53 @@ Examples cisco.nxos.nxos_ospf_interfaces: state: deleted - # Task output - # ------------- - # "before": [ - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "multi_areas": [ - # "11.11.11.11" - # ], - # "processes": [ - # { - # "area": { - # "area_id": "1.1.1.1", - # "secondaries": false - # }, - # "process_id": "100" - # } - # ] - # }, - # { - # "afi": "ipv6", - # "multi_areas": [ - # "16.10.10.10" - # ], - # "processes": [ - # { - # "area": { - # "area_id": "2.2.2.2" - # }, - # "multi_areas": [ - # "21.0.0.0" - # ], - # "process_id": "200" - # }, - # { - # "multi_areas": [ - # "50.50.50.50" - # ], - # "process_id": "300" - # } - # ] - # } - # ], - # "name": "Ethernet1/1" - # }, - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "authentication": { - # "enable": true, - # "key_chain": "test-1" - # }, - # "cost": 100, - # "message_digest_key": { - # "encryption": 3, - # "key": "abc01d272be25d29", - # "key_id": 10 - # } - # }, - # { - # "afi": "ipv6", - # "network": "broadcast", - # "shutdown": true - # } - # ], - # "name": "Ethernet1/2" - # }, - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "authentication_key": { - # "encryption": 7, - # "key": "12090404011C03162E" - # } - # } - # ], - # "name": "Ethernet1/3" - # }, - # ] + # Task output: + # ------------ + # before: + # - name: Ethernet1/1 + # - address_family: + # - afi: ipv4 + # authentication: + # enable: true + # key_chain: test-1 + # cost: 100 + # message_digest_key: + # encryption: 3 + # key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER + # key_id: 10 + # - afi: ipv6 + # network: broadcast + # shutdown: true + # name: Ethernet1/2 + # - address_family: + # - afi: ipv4 + # authentication_key: + # encryption: 7 + # key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER + # name: Ethernet1/3 # - # "commands": [ - # "interface Ethernet1/1", - # "no ip router ospf multi-area 11.11.11.11", - # "no ip router ospf 100 area 1.1.1.1 secondaries none", - # "no ipv6 router ospfv3 multi-area 16.10.10.10", - # "no ipv6 router ospfv3 200 area 2.2.2.2", - # "no ipv6 router ospfv3 200 multi-area 21.0.0.0", - # "no ipv6 router ospfv3 300 multi-area 50.50.50.50", - # "interface Ethernet1/2", - # "no ip ospf authentication key-chain test-1", - # "no ip ospf authentication", - # "no ip ospf message-digest-key 10 md5 3 abc01d272be25d29", - # "no ip ospf cost 100", - # "no ospfv3 network broadcast", - # "no ospfv3 shutdown", - # "interface Ethernet1/3", - # "no ip ospf authentication-key 7 12090404011C03162E" - # ] + # commands: + # - interface Ethernet1/1 + # - no ip router ospf multi-area 11.11.11.11 + # - no ip router ospf 100 area 1.1.1.1 secondaries none + # - no ipv6 router ospfv3 multi-area 16.10.10.10 + # - no ipv6 router ospfv3 200 area 2.2.2.2 + # - no ipv6 router ospfv3 200 multi-area 21.0.0.0 + # - no ipv6 router ospfv3 300 multi-area 50.50.50.50 + # - interface Ethernet1/2 + # - no ip ospf authentication key-chain test-1 + # - no ip ospf authentication + # - no ip ospf message-digest-key 10 md5 3 abc01d272be25d29 + # - no ip ospf cost 100 + # - no ospfv3 network broadcast + # - no ospfv3 shutdown + # - interface Ethernet1/3 + # - no ip ospf authentication-key 7 12090404011C03162E # - # "after": [ - # { - # "name": "Ethernet1/1" - # }, - # { - # "name": "Ethernet1/2" - # }, - # { - # "name": "Ethernet1/3" - # }, - # ] + # after: + # - name: Ethernet1/1 + # - name: Ethernet1/2 + # - name: Ethernet1/3 # After state: # ------------ @@ -1687,73 +1409,75 @@ Examples # Using rendered - - name: Render platform specific configuration lines with state rendered (without connecting to the device) + - name: >- + Render platform specific configuration lines with state rendered (without + connecting to the device) cisco.nxos.nxos_ospf_interfaces: config: - name: Ethernet1/1 address_family: - - afi: ipv4 - processes: - - process_id: "100" - area: - area_id: 1.1.1.1 - secondaries: False - multi_areas: - - 11.11.11.11 - - afi: ipv6 - processes: - - process_id: "200" - area: - area_id: 2.2.2.2 + - afi: ipv4 + processes: + - process_id: '100' + area: + area_id: 1.1.1.1 + secondaries: false multi_areas: - - 21.0.0.0 - - process_id: "300" + - 11.11.11.11 + - afi: ipv6 + processes: + - process_id: '200' + area: + area_id: 2.2.2.2 + multi_areas: + - 21.0.0.0 + - process_id: '300' + multi_areas: + - 50.50.50.50 multi_areas: - - 50.50.50.50 - multi_areas: - - 16.10.10.10 + - 16.10.10.10 - name: Ethernet1/2 address_family: - - afi: ipv4 - authentication: - enable: True - key_chain: test-1 - message_digest_key: - key_id: 10 - encryption: 3 - key: abc01d272be25d29 - cost: 100 - - afi: ipv6 - network: broadcast - shutdown: True + - afi: ipv4 + authentication: + enable: true + key_chain: test-1 + message_digest_key: + key_id: 10 + encryption: 3 + key: abc01d272be25d29 + cost: 100 + - afi: ipv6 + network: broadcast + shutdown: true - name: Ethernet1/3 address_family: - - afi: ipv4 - authentication_key: - encryption: 7 - key: 12090404011C03162E + - afi: ipv4 + authentication_key: + encryption: 7 + key: 12090404011C03162E state: rendered - # Task Output (redacted) - # ----------------------- - # "rendered": [ - # "interface Ethernet1/1", - # "ip router ospf multi-area 11.11.11.11", - # "ip router ospf 100 area 1.1.1.1 secondaries none", - # "ipv6 router ospfv3 multi-area 16.10.10.10", - # "ipv6 router ospfv3 200 area 2.2.2.2", - # "ipv6 router ospfv3 200 multi-area 21.0.0.0", - # "ipv6 router ospfv3 300 multi-area 50.50.50.50", - # "interface Ethernet1/2", - # "ip ospf authentication key-chain test-1", - # "ip ospf authentication", - # "ip ospf message-digest-key 10 md5 3 abc01d272be25d29", - # "ip ospf cost 100", - # "ospfv3 network broadcast", - # "ospfv3 shutdown", - # "interface Ethernet1/3", - # "ip ospf authentication-key 7 12090404011C03162E" - # ] + + # Task Output: + # ------------ + # rendered: + # - interface Ethernet1/1 + # - ip router ospf multi-area 11.11.11.11 + # - ip router ospf 100 area 1.1.1.1 secondaries none + # - ipv6 router ospfv3 multi-area 16.10.10.10 + # - ipv6 router ospfv3 200 area 2.2.2.2 + # - ipv6 router ospfv3 200 multi-area 21.0.0.0 + # - ipv6 router ospfv3 300 multi-area 50.50.50.50 + # - interface Ethernet1/2 + # - ip ospf authentication key-chain test-1 + # - ip ospf authentication + # - ip ospf message-digest-key 10 md5 3 abc01d272be25d29 + # - ip ospf cost 100 + # - ospfv3 network broadcast + # - ospfv3 shutdown + # - interface Ethernet1/3 + # - ip ospf authentication-key 7 12090404011C03162E # Using parsed @@ -1781,88 +1505,51 @@ Examples running_config: "{{ lookup('file', 'ospf_interfaces.cfg') }}" state: parsed - # Task output (redacted) - # ----------------------- - # "parsed": [ - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "multi_areas": [ - # "11.11.11.11" - # ], - # "processes": [ - # { - # "area": { - # "area_id": "1.1.1.1", - # "secondaries": false - # }, - # "process_id": "100" - # } - # ] - # }, - # { - # "afi": "ipv6", - # "multi_areas": [ - # "16.10.10.10" - # ], - # "processes": [ - # { - # "area": { - # "area_id": "2.2.2.2" - # }, - # "multi_areas": [ - # "21.0.0.0" - # ], - # "process_id": "200" - # }, - # { - # "multi_areas": [ - # "50.50.50.50" - # ], - # "process_id": "300" - # } - # ] - # } - # ], - # "name": "Ethernet1/1" - # }, - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "authentication": { - # "enable": true, - # "key_chain": "test-1" - # }, - # "cost": 100, - # "message_digest_key": { - # "encryption": 3, - # "key": "abc01d272be25d29", - # "key_id": 10 - # } - # }, - # { - # "afi": "ipv6", - # "network": "broadcast", - # "shutdown": true - # } - # ], - # "name": "Ethernet1/2" - # }, - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "authentication_key": { - # "encryption": 7, - # "key": "12090404011C03162E" - # } - # } - # ], - # "name": "Ethernet1/3" - # }, - # ] + # Task output: + # ------------ + # parsed: + # - address_family: + # - afi: ipv4 + # multi_areas: + # - 11.11.11.11 + # processes: + # - area: + # area_id: 1.1.1.1 + # secondaries: false + # process_id: '100' + # - afi: ipv6 + # multi_areas: + # - 16.10.10.10 + # processes: + # - area: + # area_id: 2.2.2.2 + # multi_areas: + # - 21.0.0.0 + # process_id: '200' + # - multi_areas: + # - 50.50.50.50 + # process_id: '300' + # name: Ethernet1/1 + # - address_family: + # - afi: ipv4 + # authentication: + # enable: true + # key_chain: test-1 + # cost: 100 + # message_digest_key: + # encryption: 3 + # key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER + # key_id: 10 + # - afi: ipv6 + # network: broadcast + # shutdown: true + # name: Ethernet1/2 + # - address_family: + # - afi: ipv4 + # authentication_key: + # encryption: 7 + # key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER + # name: Ethernet1/3 # Using gathered @@ -1884,55 +1571,34 @@ Examples # interface Ethernet1/3 # no switchport - # Task output (redacted) - # ----------------------- - # "gathered": [ - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "multi_areas": [ - # "11.11.11.12" - # ], - # "processes": [ - # { - # "area": { - # "area_id": "1.1.1.1", - # "secondaries": false - # }, - # "process_id": "100" - # } - # ] - # } - # ], - # "name": "Ethernet1/1" - # }, - # { - # "address_family": [ - # { - # "afi": "ipv4", - # "authentication": { - # "enable": true, - # "key_chain": "test-1" - # }, - # "cost": 100, - # "message_digest_key": { - # "encryption": 3, - # "key": "abc01d272be25d29", - # "key_id": 10 - # } - # }, - # { - # "afi": "ipv6", - # "network": "broadcast", - # "shutdown": true - # } - # ], - # "name": "Ethernet1/2" - # }, - # { - # "name": "Ethernet1/3" - # }, + # Task output: + # ------------ + # gathered: + # - address_family: + # - afi: ipv4 + # multi_areas: + # - 11.11.11.12 + # processes: + # - area: + # area_id: 1.1.1.1 + # secondaries: false + # process_id: '100' + # name: Ethernet1/1 + # - address_family: + # - afi: ipv4 + # authentication: + # enable: true + # key_chain: test-1 + # cost: 100 + # message_digest_key: + # encryption: 3 + # key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER + # key_id: 10 + # - afi: ipv6 + # network: broadcast + # shutdown: true + # name: Ethernet1/2 + # - name: Ethernet1/3 @@ -2001,6 +1667,57 @@ Common return values are documented `here ['interface Ethernet1/1', 'ip router ospf multi-area 11.11.11.11', 'ip router ospf 100 area 1.1.1.1 secondaries none', 'no ipv6 router ospfv3 multi-area 16.10.10.10', 'ipv6 router ospfv3 200 area 2.2.2.2', 'ipv6 router ospfv3 200 multi-area 21.0.0.0', 'ipv6 router ospfv3 300 multi-area 50.50.50.50', 'interface Ethernet1/2', 'no ip ospf authentication key-chain test-1', 'ip ospf authentication']
+
+ gathered + +
+ list +
+
when state is gathered +
Facts about the network resource gathered from the remote device as structured data.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ parsed + +
+ list +
+
when state is parsed +
The device native config provided in running_config option parsed into structured data as per module argspec.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ rendered + +
+ list +
+
when state is rendered +
The provided configuration in the task rendered in device-native format (offline).
+
+
Sample:
+
['interface Ethernet1/1', 'ip router ospf multi-area 11.11.11.11', 'ip router ospf 100 area 1.1.1.1 secondaries none']
+


diff --git a/docs/cisco.nxos.nxos_ospf_module.rst b/docs/cisco.nxos.nxos_ospf_module.rst deleted file mode 100644 index 2c4566a17..000000000 --- a/docs/cisco.nxos.nxos_ospf_module.rst +++ /dev/null @@ -1,382 +0,0 @@ -.. _cisco.nxos.nxos_ospf_module: - - -******************** -cisco.nxos.nxos_ospf -******************** - -**(deprecated, removed after 2022-06-01) Manages configuration of an ospf instance.** - - -Version added: 1.0.0 - -.. contents:: - :local: - :depth: 1 - -DEPRECATED ----------- -:Removed in collection release after 2022-06-01 -:Why: Updated modules released with more functionality. -:Alternative: nxos_ospfv2 and nxos_ospfv3 - - - -Synopsis --------- -- Manages configuration of an ospf instance. - - - - -Parameters ----------- - -.. raw:: html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterChoices/DefaultsComments
-
- ospf - -
- string - / required -
-
- -
Name of the ospf instance.
-
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
-
- state - -
- string -
-
-
    Choices: -
  • present ←
  • -
  • absent
  • -
-
-
Determines whether the config should be present or not on the device.
-
-
- - -Notes ------ - -.. note:: - - Unsupported for Cisco MDS - - For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide ` - - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide ` - - For more information on using Ansible to manage Cisco devices see the `Cisco integration page `_. - - - -Examples --------- - -.. code-block:: yaml - - - cisco.nxos.nxos_ospf: - ospf: 1 - state: present - - - -Return Values -------------- -Common return values are documented `here `_, the following are the fields unique to this module: - -.. raw:: html - - - - - - - - - - - - -
KeyReturnedDescription
-
- commands - -
- list -
-
always -
commands sent to the device
-
-
Sample:
-
['router ospf 1']
-
-

- - -Status ------- - - -- This module will be removed in a release after 2022-06-01. *[deprecated]* -- For more information see `DEPRECATED`_. - - -Authors -~~~~~~~ - -- Gabriele Gerbino (@GGabriele) diff --git a/docs/cisco.nxos.nxos_ospf_vrf_module.rst b/docs/cisco.nxos.nxos_ospf_vrf_module.rst deleted file mode 100644 index 00c969595..000000000 --- a/docs/cisco.nxos.nxos_ospf_vrf_module.rst +++ /dev/null @@ -1,602 +0,0 @@ -.. _cisco.nxos.nxos_ospf_vrf_module: - - -************************ -cisco.nxos.nxos_ospf_vrf -************************ - -**(deprecated, removed after 2022-10-01)Manages a VRF for an OSPF router.** - - -Version added: 1.0.0 - -.. contents:: - :local: - :depth: 1 - -DEPRECATED ----------- -:Removed in collection release after 2022-10-01 -:Why: Updated modules released with more functionality. -:Alternative: nxos_ospfv2 and nxos_ospfv3 - - - -Synopsis --------- -- Manages a VRF for an OSPF router. - - - - -Parameters ----------- - -.. raw:: html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterChoices/DefaultsComments
-
- auto_cost - -
- string -
-
- -
Specifies the reference bandwidth used to assign OSPF cost. Valid values are an integer, in Mbps, or the keyword 'default'.
-
-
- bfd - -
- string -
-
-
    Choices: -
  • enable
  • -
  • disable
  • -
-
-
Enables BFD on all OSPF interfaces.
-
Dependency: ''feature bfd''
-
-
- default_metric - -
- string -
-
- -
Specify the default Metric value. Valid values are an integer or the keyword 'default'.
-
-
- log_adjacency - -
- string -
-
-
    Choices: -
  • log
  • -
  • detail
  • -
  • default
  • -
-
-
Controls the level of log messages generated whenever a neighbor changes state. Valid values are 'log', 'detail', and 'default'.
-
-
- ospf - -
- string - / required -
-
- -
Name of the OSPF instance.
-
-
- passive_interface - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Setting to yes will suppress routing update on interface.
-
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
-
- router_id - -
- string -
-
- -
Router Identifier (ID) of the OSPF router VRF instance.
-
-
- state - -
- string -
-
-
    Choices: -
  • present ←
  • -
  • absent
  • -
-
-
State of ospf vrf configuration.
-
-
- timer_throttle_lsa_hold - -
- string -
-
- -
Specify the hold interval for rate-limiting Link-State Advertisement (LSA) generation. Valid values are an integer, in milliseconds, or the keyword 'default'.
-
-
- timer_throttle_lsa_max - -
- string -
-
- -
Specify the max interval for rate-limiting Link-State Advertisement (LSA) generation. Valid values are an integer, in milliseconds, or the keyword 'default'.
-
-
- timer_throttle_lsa_start - -
- string -
-
- -
Specify the start interval for rate-limiting Link-State Advertisement (LSA) generation. Valid values are an integer, in milliseconds, or the keyword 'default'.
-
-
- timer_throttle_spf_hold - -
- string -
-
- -
Specify minimum hold time between Shortest Path First (SPF) calculations. Valid values are an integer, in milliseconds, or the keyword 'default'.
-
-
- timer_throttle_spf_max - -
- string -
-
- -
Specify the maximum wait time between Shortest Path First (SPF) calculations. Valid values are an integer, in milliseconds, or the keyword 'default'.
-
-
- timer_throttle_spf_start - -
- string -
-
- -
Specify initial Shortest Path First (SPF) schedule delay. Valid values are an integer, in milliseconds, or the keyword 'default'.
-
-
- vrf - -
- string -
-
- Default:
"default"
-
-
Name of the resource instance. Valid value is a string. The name 'default' is a valid VRF representing the global OSPF.
-
-
- - -Notes ------ - -.. note:: - - Tested against NXOSv 7.3.(0)D1(1) on VIRL - - Unsupported for Cisco MDS - - Value *default* restores params default value, if any. Otherwise it removes the existing param configuration. - - For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide ` - - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide ` - - For more information on using Ansible to manage Cisco devices see the `Cisco integration page `_. - - - -Examples --------- - -.. code-block:: yaml - - - cisco.nxos.nxos_ospf_vrf: - ospf: 1 - timer_throttle_spf_start: 50 - timer_throttle_spf_hold: 1000 - timer_throttle_spf_max: 2000 - timer_throttle_lsa_start: 60 - timer_throttle_lsa_hold: 1100 - timer_throttle_lsa_max: 3000 - vrf: test - bfd: enable - state: present - - - -Return Values -------------- -Common return values are documented `here `_, the following are the fields unique to this module: - -.. raw:: html - - - - - - - - - - - - -
KeyReturnedDescription
-
- commands - -
- list -
-
always -
commands sent to the device
-
-
Sample:
-
['router ospf 1', 'vrf test', 'bfd', 'timers throttle lsa 60 1100 3000']
-
-

- - -Status ------- - - -- This module will be removed in a release after 2022-10-01. *[deprecated]* -- For more information see `DEPRECATED`_. - - -Authors -~~~~~~~ - -- Gabriele Gerbino (@GGabriele) diff --git a/docs/cisco.nxos.nxos_ospfv2_module.rst b/docs/cisco.nxos.nxos_ospfv2_module.rst index fabb4d7e4..2115d34f2 100644 --- a/docs/cisco.nxos.nxos_ospfv2_module.rst +++ b/docs/cisco.nxos.nxos_ospfv2_module.rst @@ -4432,60 +4432,60 @@ Examples cisco.nxos.nxos_ospfv2: config: processes: - - process_id: 100 - router_id: 203.0.113.20 - - process_id: 102 - router_id: 198.51.100.1 - areas: - - area_id: 0.0.0.100 - filter_list: - - route_map: rmap_1 - direction: in - - route_map: rmap_2 - direction: out - ranges: - - prefix: 198.51.100.64/27 - not_advertise: true - - prefix: 198.51.100.96/27 - cost: 120 - - area_id: 0.0.0.101 - authentication: - message_digest: true - redistribute: - - protocol: eigrp - id: 120 - route_map: rmap_1 - - protocol: direct - route_map: ospf102-direct-connect - vrfs: - - vrf: zone1 - router_id: 198.51.100.129 - redistribute: - - protocol: static - route_map: zone1-static-connect - summary_address: - - prefix: 198.51.100.128/27 - tag: 121 - - prefix: 198.51.100.160/27 + - process_id: 100 + router_id: 203.0.113.20 + - process_id: 102 + router_id: 198.51.100.1 areas: - - area_id: 0.0.0.102 - nssa: - default_information_originate: true - no_summary: true - - area_id: 0.0.0.103 - nssa: - no_summary: true - translate: - type7: - always: true - - vrf: zone2 - auto_cost: - reference_bandwidth: 45 - unit: Gbps + - area_id: 0.0.0.100 + filter_list: + - route_map: rmap_1 + direction: in + - route_map: rmap_2 + direction: out + ranges: + - prefix: 198.51.100.64/27 + not_advertise: true + - prefix: 198.51.100.96/27 + cost: 120 + - area_id: 0.0.0.101 + authentication: + message_digest: true + redistribute: + - protocol: eigrp + id: 120 + route_map: rmap_1 + - protocol: direct + route_map: ospf102-direct-connect + vrfs: + - vrf: zone1 + router_id: 198.51.100.129 + redistribute: + - protocol: static + route_map: zone1-static-connect + summary_address: + - prefix: 198.51.100.128/27 + tag: 121 + - prefix: 198.51.100.160/27 + areas: + - area_id: 0.0.0.102 + nssa: + default_information_originate: true + no_summary: true + - area_id: 0.0.0.103 + nssa: + no_summary: true + translate: + type7: + always: true + - vrf: zone2 + auto_cost: + reference_bandwidth: 45 + unit: Gbps state: merged - # Task output - # ------------- + # Task output: + # ------------ # before: {} # # commands: @@ -4613,45 +4613,48 @@ Examples # vrf zone2 # auto-cost reference-bandwidth 45 Gbps - - name: Replace device configurations of listed OSPF processes with provided configurations + - name: >- + Replace device configurations of listed OSPF processes with provided + configurations cisco.nxos.nxos_ospfv2: config: processes: - - process_id: 102 - router_id: 198.51.100.1 - areas: - - area_id: 0.0.0.100 - filter_list: - - route_map: rmap_8 - direction: in - ranges: - - prefix: 198.51.100.64/27 - not_advertise: true - - area_id: 0.0.0.101 - stub: - no_summary: true - redistribute: - - protocol: eigrp - id: 130 - route_map: rmap_1 - - protocol: direct - route_map: ospf102-direct-connect - vrfs: - - vrf: zone1 - router_id: 198.51.100.129 - redistribute: - - protocol: bgp - id: 65563 - route_map: zone1-bgp-connect + - process_id: 102 + router_id: 198.51.100.1 areas: - - area_id: 0.0.0.102 - nssa: - default_information_originate: true - no_summary: true + - area_id: 0.0.0.100 + filter_list: + - route_map: rmap_8 + direction: in + ranges: + - prefix: 198.51.100.64/27 + not_advertise: true + - area_id: 0.0.0.101 + stub: + no_summary: true + redistribute: + - protocol: eigrp + id: 130 + route_map: rmap_1 + - protocol: direct + route_map: ospf102-direct-connect + vrfs: + - vrf: zone1 + router_id: 198.51.100.129 + redistribute: + - protocol: bgp + id: 65563 + route_map: zone1-bgp-connect + areas: + - area_id: 0.0.0.102 + nssa: + default_information_originate: true + no_summary: true state: replaced - # Task output - # ------------- + + # Task output: + # ------------ # before: # processes: # - process_id: "100" @@ -4803,15 +4806,15 @@ Examples cisco.nxos.nxos_ospfv2: config: processes: - - process_id: 104 - router_id: 203.0.113.20 - - process_id: 102 - router_id: 198.51.100.1 - shutdown: true + - process_id: 104 + router_id: 203.0.113.20 + - process_id: 102 + router_id: 198.51.100.1 + shutdown: true state: overridden - # Task output - # ------------- + # Task output: + # ------------ # before: # processes: # - process_id: "100" @@ -4925,11 +4928,11 @@ Examples cisco.nxos.nxos_ospfv2: config: processes: - - process_id: 102 + - process_id: 102 state: deleted - # Task output - # ------------- + # Task output: + # ------------ # before: # processes: # - process_id: "100" @@ -5024,8 +5027,8 @@ Examples cisco.nxos.nxos_ospfv2: state: deleted - # Task output - # ------------- + # Task output: + # ------------ # before: # processes: # - process_id: "100" @@ -5088,64 +5091,67 @@ Examples # Using rendered - - name: Render platform specific configuration lines (without connecting to the device) + - name: >- + Render platform specific configuration lines (without connecting to the + device) cisco.nxos.nxos_ospfv2: config: processes: - - process_id: 100 - router_id: 203.0.113.20 - - process_id: 102 - router_id: 198.51.100.1 - areas: - - area_id: 0.0.0.100 - filter_list: - - route_map: rmap_1 - direction: in - - route_map: rmap_2 - direction: out - ranges: - - prefix: 198.51.100.64/27 - not_advertise: true - - prefix: 198.51.100.96/27 - cost: 120 - - area_id: 0.0.0.101 - authentication: - message_digest: true - redistribute: - - protocol: eigrp - id: 120 - route_map: rmap_1 - - protocol: direct - route_map: ospf102-direct-connect - vrfs: - - vrf: zone1 - router_id: 198.51.100.129 - redistribute: - - protocol: static - route_map: zone1-static-connect - summary_address: - - prefix: 198.51.100.128/27 - tag: 121 - - prefix: 198.51.100.160/27 + - process_id: 100 + router_id: 203.0.113.20 + - process_id: 102 + router_id: 198.51.100.1 areas: - - area_id: 0.0.0.102 - nssa: - default_information_originate: true - no_summary: true - - area_id: 0.0.0.103 - nssa: - no_summary: true - translate: - type7: - always: true - - vrf: zone2 - auto_cost: - reference_bandwidth: 45 - unit: Gbps + - area_id: 0.0.0.100 + filter_list: + - route_map: rmap_1 + direction: in + - route_map: rmap_2 + direction: out + ranges: + - prefix: 198.51.100.64/27 + not_advertise: true + - prefix: 198.51.100.96/27 + cost: 120 + - area_id: 0.0.0.101 + authentication: + message_digest: true + redistribute: + - protocol: eigrp + id: 120 + route_map: rmap_1 + - protocol: direct + route_map: ospf102-direct-connect + vrfs: + - vrf: zone1 + router_id: 198.51.100.129 + redistribute: + - protocol: static + route_map: zone1-static-connect + summary_address: + - prefix: 198.51.100.128/27 + tag: 121 + - prefix: 198.51.100.160/27 + areas: + - area_id: 0.0.0.102 + nssa: + default_information_originate: true + no_summary: true + - area_id: 0.0.0.103 + nssa: + no_summary: true + translate: + type7: + always: true + - vrf: zone2 + auto_cost: + reference_bandwidth: 45 + unit: Gbps state: rendered - # Task Output (redacted) - # ----------------------- + + # Task output: + # ------------ # rendered: # - router ospf 100 # - router-id 203.0.113.20 @@ -5208,8 +5214,8 @@ Examples running_config: "{{ lookup('file', 'ospfv2.cfg') }}" state: parsed - # Task output (redacted) - # ----------------------- + # Task output: + # ------------ # parsed: # processes: # - process_id: "100" @@ -5283,8 +5289,8 @@ Examples cisco.nxos.nxos_ospfv2: state: gathered - # Task output (redacted) - # ----------------------- + # Task output: + # ------------ # gathered: # processes: # - process_id: "102" @@ -5387,6 +5393,57 @@ Common return values are documented `here ['router ospf 102', 'router-id 198.54.100.1', 'router ospf 100', 'router-id 192.0.100.1', 'redistribute eigrp 120 route-map rmap_1', 'redistribute direct route-map ospf-direct-connect', 'area 0.0.0.100 filter-list route-map rmap_1 in', 'area 0.0.0.100 filter-list route-map rmap_2 out', 'area 0.0.0.100 range 192.0.2.0/24 not-advertise', 'area 0.0.0.100 range 192.0.3.0/24 cost 120', 'vrf zone1', 'router-id 192.0.100.2', 'summary-address 10.0.0.0/24 tag 121', 'summary-address 11.0.0.0/24', 'redistribute static route-map zone1-direct-connect', 'vrf zone2', 'auto-cost reference-bandwidth 45 Gbps', 'capability vrf-lite evpn']
+
+ gathered + +
+ dictionary +
+
when state is gathered +
Facts about the network resource gathered from the remote device as structured data.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ parsed + +
+ dictionary +
+
when state is parsed +
The device native config provided in running_config option parsed into structured data as per module argspec.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ rendered + +
+ list +
+
when state is rendered +
The provided configuration in the task rendered in device-native format (offline).
+
+
Sample:
+
['router ospf 102', 'router-id 198.54.100.1', 'router ospf 100']
+


diff --git a/docs/cisco.nxos.nxos_ospfv3_module.rst b/docs/cisco.nxos.nxos_ospfv3_module.rst index 0fa5710ed..8e7c46ef6 100644 --- a/docs/cisco.nxos.nxos_ospfv3_module.rst +++ b/docs/cisco.nxos.nxos_ospfv3_module.rst @@ -3570,53 +3570,53 @@ Examples cisco.nxos.nxos_ospfv3: config: processes: - - process_id: 100 - router_id: 203.0.113.20 - - process_id: 102 - router_id: 198.51.100.1 - address_family: - afi: ipv6 - safi: unicast - areas: - - area_id: 0.0.0.100 - filter_list: - - route_map: rmap_1 - direction: in - - route_map: rmap_2 - direction: out - ranges: - - prefix: 2001:db2::/32 - not_advertise: true - - prefix: 2001:db3::/32 - cost: 120 - redistribute: - - protocol: eigrp - id: 120 - route_map: rmap_1 - - protocol: direct - route_map: ospf102-direct-connect - vrfs: - - vrf: zone1 - router_id: 198.51.100.129 - areas: - - area_id: 0.0.0.102 - nssa: - default_information_originate: true - no_summary: true - - area_id: 0.0.0.103 - nssa: - no_summary: true - translate: - type7: - always: true - - vrf: zone2 - auto_cost: - reference_bandwidth: 45 - unit: Gbps + - process_id: 100 + router_id: 203.0.113.20 + - process_id: 102 + router_id: 198.51.100.1 + address_family: + afi: ipv6 + safi: unicast + areas: + - area_id: 0.0.0.100 + filter_list: + - route_map: rmap_1 + direction: in + - route_map: rmap_2 + direction: out + ranges: + - prefix: '2001:db2::/32' + not_advertise: true + - prefix: '2001:db3::/32' + cost: 120 + redistribute: + - protocol: eigrp + id: 120 + route_map: rmap_1 + - protocol: direct + route_map: ospf102-direct-connect + vrfs: + - vrf: zone1 + router_id: 198.51.100.129 + areas: + - area_id: 0.0.0.102 + nssa: + default_information_originate: true + no_summary: true + - area_id: 0.0.0.103 + nssa: + no_summary: true + translate: + type7: + always: true + - vrf: zone2 + auto_cost: + reference_bandwidth: 45 + unit: Gbps state: merged - # Task output - # ------------- + # Task output: + # ------------ # before: {} # # commands: @@ -3711,7 +3711,7 @@ Examples # Using replaced # Before state: - # ------------ + # ------------- # nxos-9k-rdo# sh running-config | section "^router ospfv3" # router ospfv3 100 # router-id 203.0.113.20 @@ -3736,37 +3736,37 @@ Examples cisco.nxos.nxos_ospfv3: config: processes: - - process_id: 102 - router_id: 198.51.100.1 - address_family: - afi: ipv6 - safi: unicast - areas: - - area_id: 0.0.0.100 - filter_list: - - route_map: rmap_8 - direction: in - ranges: - - not_advertise: true - prefix: 2001:db2::/32 - redistribute: - - protocol: eigrp - id: 130 - route_map: rmap_1 - - protocol: direct - route_map: ospf102-direct-connect - vrfs: - - vrf: zone1 - router_id: 198.51.100.129 - areas: - - area_id: 0.0.0.102 - nssa: - default_information_originate: True - no_summary: True + - process_id: 102 + router_id: 198.51.100.1 + address_family: + afi: ipv6 + safi: unicast + areas: + - area_id: 0.0.0.100 + filter_list: + - route_map: rmap_8 + direction: in + ranges: + - not_advertise: true + prefix: 2001:db2::/32 + redistribute: + - protocol: eigrp + id: 130 + route_map: rmap_1 + - protocol: direct + route_map: ospf102-direct-connect + vrfs: + - vrf: zone1 + router_id: 198.51.100.129 + areas: + - area_id: 0.0.0.102 + nssa: + default_information_originate: true + no_summary: true state: replaced - # Task output - # ------------- + # Task output: + # ------------ # before: # processes: # - process_id: "100" @@ -3877,7 +3877,7 @@ Examples # Using overridden # Before state: - # ------------ + # ------------- # nxos-9k-rdo# sh running-config | section "^router ospfv3" # router ospfv3 100 # router-id 203.0.113.20 @@ -3902,15 +3902,15 @@ Examples cisco.nxos.nxos_ospfv3: config: processes: - - process_id: 104 - router_id: 203.0.113.20 - - process_id: 102 - router_id: 198.51.100.1 - shutdown: true + - process_id: 104 + router_id: 203.0.113.20 + - process_id: 102 + router_id: 198.51.100.1 + shutdown: true state: overridden - # Task output - # ------------- + # Task output: + # ------------ # before: # processes: # - process_id: "100" @@ -3997,7 +3997,7 @@ Examples # Using deleted to delete a single OSPF process # Before state: - # ------------ + # ------------- # nxos-9k-rdo# sh running-config | section "^router ospf .*" # router ospfv3 100 # router-id 203.0.113.20 @@ -4022,11 +4022,11 @@ Examples cisco.nxos.nxos_ospfv3: config: processes: - - process_id: 102 + - process_id: 102 state: deleted - # Task output - # ------------- + # Task output: + # ------------ # before: # processes: # - process_id: "100" @@ -4074,7 +4074,7 @@ Examples # vrf: zone2 # # commands: - # - no router ospfv3 102 + # - no router ospfv3 102 # # after: # processes: @@ -4090,7 +4090,7 @@ Examples # Using deleted all OSPFv3 processes from the device # Before state: - # ------------ + # ------------- # nxos-9k-rdo# sh running-config | section "^router ospfv3" # router ospfv3 100 # router-id 203.0.113.20 @@ -4115,8 +4115,8 @@ Examples cisco.nxos.nxos_ospfv3: state: deleted - # Task output - # ------------- + # Task output: + # ------------ # before: # processes: # - process_id: "100" @@ -4180,53 +4180,53 @@ Examples cisco.nxos.nxos_ospfv3: config: processes: - - process_id: 100 - router_id: 203.0.113.20 - - process_id: 102 - router_id: 198.51.100.1 - address_family: - afi: ipv6 - safi: unicast - areas: - - area_id: 0.0.0.100 - filter_list: - - route_map: rmap_1 - direction: in - - route_map: rmap_2 - direction: out - ranges: - - prefix: 2001:db2::/32 - not_advertise: true - - prefix: 2001:db3::/32 - cost: 120 - redistribute: - - protocol: eigrp - id: 120 - route_map: rmap_1 - - protocol: direct - route_map: ospf102-direct-connect - vrfs: - - vrf: zone1 - router_id: 198.51.100.129 - areas: - - area_id: 0.0.0.102 - nssa: - default_information_originate: true - no_summary: true - - area_id: 0.0.0.103 - nssa: - no_summary: true - translate: - type7: - always: true - - vrf: zone2 - auto_cost: - reference_bandwidth: 45 - unit: Gbps + - process_id: 100 + router_id: 203.0.113.20 + - process_id: 102 + router_id: 198.51.100.1 + address_family: + afi: ipv6 + safi: unicast + areas: + - area_id: 0.0.0.100 + filter_list: + - route_map: rmap_1 + direction: in + - route_map: rmap_2 + direction: out + ranges: + - prefix: 2001:db2::/32 + not_advertise: true + - prefix: 2001:db3::/32 + cost: 120 + redistribute: + - protocol: eigrp + id: 120 + route_map: rmap_1 + - protocol: direct + route_map: ospf102-direct-connect + vrfs: + - vrf: zone1 + router_id: 198.51.100.129 + areas: + - area_id: 0.0.0.102 + nssa: + default_information_originate: true + no_summary: true + - area_id: 0.0.0.103 + nssa: + no_summary: true + translate: + type7: + always: true + - vrf: zone2 + auto_cost: + reference_bandwidth: 45 + unit: Gbps state: rendered - # Task Output (redacted) - # ----------------------- + # Task output: + # ------------ # rendered: # - router ospfv3 100 # - router-id 203.0.113.20 @@ -4272,8 +4272,8 @@ Examples running_config: "{{ lookup('file', 'ospfv2.cfg') }}" state: parsed - # Task output (redacted) - # ----------------------- + # Task output: + # ------------ # parsed: # processes: # - process_id: "100" @@ -4315,7 +4315,7 @@ Examples # router_id: 192.0.100.2 # - process_id: "102" # router_id: 198.54.100.1 - # shutdown: True + # shutdown: true # Using gathered @@ -4323,8 +4323,8 @@ Examples cisco.nxos.nxos_ospfv3: state: gathered - # Task output (redacted) - # ----------------------- + # Task output: + # ------------ # gathered: # processes: # - process_id: "100" @@ -4439,6 +4439,57 @@ Common return values are documented `here ['router ospfv3 102', 'router-id 198.54.100.1', 'router ospfv3 100', 'router-id 192.0.100.1', 'address-family ipv6 unicast', 'redistribute eigrp 120 route-map rmap_1', 'redistribute direct route-map ospf-direct-connect', 'area 0.0.0.100 filter-list route-map rmap_1 in', 'area 0.0.0.100 filter-list route-map rmap_2 out', 'area 0.0.0.100 range 2001:db2::/32 not-advertise', 'area 0.0.0.100 range 2001:db3::/32 cost 120', 'vrf zone1', 'router-id 192.0.100.2', 'vrf zone2', 'auto-cost reference-bandwidth 45 Gbps']
+
+ gathered + +
+ dictionary +
+
when state is gathered +
Facts about the network resource gathered from the remote device as structured data.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ parsed + +
+ dictionary +
+
when state is parsed +
The device native config provided in running_config option parsed into structured data as per module argspec.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ rendered + +
+ list +
+
when state is rendered +
The provided configuration in the task rendered in device-native format (offline).
+
+
Sample:
+
['router ospfv3 102', 'router-id 198.54.100.1', 'router ospfv3 100']
+


diff --git a/docs/cisco.nxos.nxos_overlay_global_module.rst b/docs/cisco.nxos.nxos_overlay_global_module.rst index c17a8de2f..1a1b8d975 100644 --- a/docs/cisco.nxos.nxos_overlay_global_module.rst +++ b/docs/cisco.nxos.nxos_overlay_global_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
anycast_gateway_mac @@ -49,240 +49,6 @@ Parameters
Anycast gateway mac of the switch.
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-

diff --git a/docs/cisco.nxos.nxos_pim_interface_module.rst b/docs/cisco.nxos.nxos_pim_interface_module.rst index f8c02af0f..d238a7ce3 100644 --- a/docs/cisco.nxos.nxos_pim_interface_module.rst +++ b/docs/cisco.nxos.nxos_pim_interface_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
bfd @@ -56,7 +56,7 @@ Parameters
+
border @@ -75,7 +75,7 @@ Parameters
+
dr_prio @@ -90,7 +90,7 @@ Parameters
+
hello_auth_key @@ -105,7 +105,7 @@ Parameters
+
hello_interval @@ -121,7 +121,7 @@ Parameters
+
hello_interval_ms @@ -142,7 +142,7 @@ Parameters
+
interface @@ -158,7 +158,7 @@ Parameters
+
jp_policy_in @@ -173,7 +173,7 @@ Parameters
+
jp_policy_out @@ -188,7 +188,7 @@ Parameters
+
jp_type_in @@ -207,7 +207,7 @@ Parameters
+
jp_type_out @@ -226,7 +226,7 @@ Parameters
+
neighbor_policy @@ -241,7 +241,7 @@ Parameters
+
neighbor_type @@ -260,241 +260,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
sparse @@ -513,7 +279,7 @@ Parameters
+
state diff --git a/docs/cisco.nxos.nxos_pim_module.rst b/docs/cisco.nxos.nxos_pim_module.rst index 876dc2cdf..e19eee567 100644 --- a/docs/cisco.nxos.nxos_pim_module.rst +++ b/docs/cisco.nxos.nxos_pim_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
bfd @@ -54,241 +54,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
ssm_range @@ -298,6 +64,7 @@ Parameters
+ Default:
[]
Configure group ranges for Source Specific Multicast (SSM). Valid values are multicast addresses or the keyword none or keyword default. none removes all SSM group ranges. default will set ssm_range to the default multicast address. If you set multicast address, please ensure that it is not the same as the default, otherwise use the default option.
diff --git a/docs/cisco.nxos.nxos_pim_rp_address_module.rst b/docs/cisco.nxos.nxos_pim_rp_address_module.rst index 7c43ad41a..29246e4df 100644 --- a/docs/cisco.nxos.nxos_pim_rp_address_module.rst +++ b/docs/cisco.nxos.nxos_pim_rp_address_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
bidir @@ -53,7 +53,7 @@ Parameters
+
group_list @@ -68,7 +68,7 @@ Parameters
+
prefix_list @@ -83,241 +83,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
route_map @@ -332,7 +98,7 @@ Parameters
+
rp_address @@ -348,7 +114,7 @@ Parameters
+
state diff --git a/docs/cisco.nxos.nxos_ping_module.rst b/docs/cisco.nxos.nxos_ping_module.rst index d24913b6e..d0d805868 100644 --- a/docs/cisco.nxos.nxos_ping_module.rst +++ b/docs/cisco.nxos.nxos_ping_module.rst @@ -32,12 +32,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
count @@ -53,7 +53,7 @@ Parameters
+
dest @@ -69,7 +69,7 @@ Parameters
+
df_bit @@ -88,241 +88,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
size @@ -337,7 +103,7 @@ Parameters
+
source @@ -352,7 +118,7 @@ Parameters
+
state @@ -371,7 +137,7 @@ Parameters
+
vrf diff --git a/docs/cisco.nxos.nxos_reboot_module.rst b/docs/cisco.nxos.nxos_reboot_module.rst index 8e3593f85..cc94a6762 100644 --- a/docs/cisco.nxos.nxos_reboot_module.rst +++ b/docs/cisco.nxos.nxos_reboot_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
confirm @@ -52,240 +52,6 @@ Parameters
Safeguard boolean. Set to true if you're sure you want to reboot.
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-

diff --git a/docs/cisco.nxos.nxos_rollback_module.rst b/docs/cisco.nxos.nxos_rollback_module.rst index ba7d3e520..c948e093a 100644 --- a/docs/cisco.nxos.nxos_rollback_module.rst +++ b/docs/cisco.nxos.nxos_rollback_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1962,6 +2047,333 @@ Parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2542,6 +2954,47 @@ Examples group_range: first: 239.0.0.1 last: 239.255.255.255 + + - route_map: rmap3 + entries: + - sequence: 10 + description: "*** first stanza ***" + action: permit + set: + ip: + next_hop: + verify_availability: + - address: 3.3.3.3 + track: 1 + - address: 4.4.4.4 + track: 3 + + - sequence: 20 + description: "*** second stanza ***" + action: permit + set: + ip: + next_hop: + address: 6.6.6.6 2.2.2.2 + load_share: true + drop_on_fail: true + + - sequence: 30 + description: "*** third stanza ***" + action: permit + set: + ip: + next_hop: + peer_address: true + + - sequence: 40 + description: "*** fourth stanza ***" + action: permit + set: + ip: + next_hop: + unchanged: true + redist_unchanged: true state: merged # Task output @@ -2571,6 +3024,20 @@ Examples # - "match route-type level-1 level-2" # - "match tag 2" # - "description rmap2-40-deny" + # - "route-map rmap3 permit 10" + # - "description *** first stanza ***" + # - "set ip next-hop verify-availability 3.3.3.3 track 1" + # - "set ip next-hop verify-availability 4.4.4.4 track 3" + # - "route-map rmap3 permit 20" + # - "description *** second stanza ***" + # - "set ip next-hop 6.6.6.6 2.2.2.2 load-share drop-on-fail" + # - "route-map rmap3 permit 30" + # - "description *** third stanza ***" + # - "set ip next-hop peer-address" + # - "route-map rmap3 permit 40" + # - "description *** fourth stanza ***" + # - "set ip next-hop unchanged" + # - "set ip next-hop redist-unchanged" # # after: # - route_map: rmap1 @@ -2648,6 +3115,47 @@ Examples # tags: # - 2 # sequence: 40 + # + # - route_map: rmap3 + # entries: + # - sequence: 10 + # description: "*** first stanza ***" + # action: permit + # set: + # ip: + # next_hop: + # verify_availability: + # - address: 3.3.3.3 + # track: 1 + # - address: 4.4.4.4 + # track: 3 + # + # - sequence: 20 + # description: "*** second stanza ***" + # action: permit + # set: + # ip: + # next_hop: + # address: 6.6.6.6 2.2.2.2 + # load_share: true + # drop_on_fail: true + # + # - sequence: 30 + # description: "*** third stanza ***" + # action: permit + # set: + # ip: + # next_hop: + # peer_address: true + # + # - sequence: 40 + # description: "*** fourth stanza ***" + # action: permit + # set: + # ip: + # next_hop: + # unchanged: true + # redist_unchanged: true # After state: # ------------ @@ -2674,7 +3182,21 @@ Examples # match route-type level-1 level-2 # match tag 2 # description rmap2-40-deny - + # route-map rmap3 permit 10 + # description *** first stanza *** + # set ip next-hop verify-availability 3.3.3.3 track 1 + # set ip next-hop verify-availability 4.4.4.4 track 3 + # route-map rmap3 permit 20 + # description *** second stanza *** + # set ip next-hop 6.6.6.6 2.2.2.2 load-share drop-on-fail + # route-map rmap3 permit 30 + # description *** third stanza *** + # set ip next-hop peer-address + # route-map rmap3 permit 40 + # description *** fourth stanza *** + # set ip next-hop unchanged + # set ip next-hop redist-unchanged + # # Using replaced # (for the listed route-map(s), sequences that are in running-config but not in the task are negated) @@ -2703,7 +3225,21 @@ Examples # match route-type level-1 level-2 # match tag 2 # description rmap2-40-deny - + # route-map rmap3 permit 10 + # description *** first stanza *** + # set ip next-hop verify-availability 3.3.3.3 track 1 + # set ip next-hop verify-availability 4.4.4.4 track 3 + # route-map rmap3 permit 20 + # description *** second stanza *** + # set ip next-hop 6.6.6.6 2.2.2.2 load-share drop-on-fail + # route-map rmap3 permit 30 + # description *** third stanza *** + # set ip next-hop peer-address + # route-map rmap3 permit 40 + # description *** fourth stanza *** + # set ip next-hop unchanged + # set ip next-hop redist-unchanged + # - name: Replace route-maps configurations of listed route-maps with provided configurations cisco.nxos.nxos_route_maps: config: @@ -2723,7 +3259,35 @@ Examples - AllowPrefix1 set: community: - local_as: True + local_as: true + + - route_map: rmap3 + entries: + - sequence: 10 + description: "*** first stanza ***" + action: permit + set: + ip: + next_hop: + verify_availability: + - address: 3.3.3.3 + track: 1 + - sequence: 20 + description: "*** second stanza ***" + action: permit + set: + ip: + next_hop: + peer_address: true + - sequence: 30 + description: "*** third stanza ***" + action: permit + set: + ip: + next_hop: + address: 6.6.6.6 2.2.2.2 + load_share: true + drop_on_fail: true state: replaced # Task output @@ -2805,6 +3369,47 @@ Examples # - 2 # sequence: 40 # + # - route_map: rmap3 + # entries: + # - sequence: 10 + # description: "*** first stanza ***" + # action: permit + # set: + # ip: + # next_hop: + # verify_availability: + # - address: 3.3.3.3 + # track: 1 + # - address: 4.4.4.4 + # track: 3 + # + # - sequence: 20 + # description: "*** second stanza ***" + # action: permit + # set: + # ip: + # next_hop: + # address: 6.6.6.6 2.2.2.2 + # load_share: true + # drop_on_fail: true + # + # - sequence: 30 + # description: "*** third stanza ***" + # action: permit + # set: + # ip: + # next_hop: + # peer_address: true + # + # - sequence: 40 + # description: "*** fourth stanza ***" + # action: permit + # set: + # ip: + # next_hop: + # unchanged: true + # redist_unchanged: true + # # commands: # - no route-map rmap1 permit 10 # - route-map rmap1 deny 20 @@ -2814,6 +3419,15 @@ Examples # - match ip address prefix-list AllowPrefix1 # - no set dampening 30 1500 10000 120 # - set community local-AS + # - route-map rmap3 permit 10 + # - no set ip next-hop verify-availability 4.4.4.4 track 3 + # - route-map rmap3 permit 20 + # - no set ip next-hop 6.6.6.6 2.2.2.2 load-share drop-on-fail + # - set ip next-hop peer-address + # - route-map rmap3 permit 30 + # - no set ip next-hop peer-address + # - set ip next-hop 6.6.6.6 2.2.2.2 load-share drop-on-fail + # - no route-map rmap3 permit 40 # # after: # - route_map: rmap1 @@ -2832,7 +3446,7 @@ Examples # - AllowPrefix1 # set: # community: - # local_as: True + # local_as: true # # - route_map: rmap2 # entries: @@ -2875,6 +3489,33 @@ Examples # - 2 # sequence: 40 # + # - route_map: rmap3 + # entries: + # - sequence: 10 + # description: "*** first stanza ***" + # action: permit + # set: + # ip: + # next_hop: + # verify_availability: + # - address: 3.3.3.3 + # track: 1 + # - sequence: 20 + # description: "*** second stanza ***" + # action: permit + # set: + # ip: + # next_hop: + # peer_address: true + # - sequence: 30 + # description: "*** third stanza ***" + # action: permit + # set: + # ip: + # next_hop: + # address: 6.6.6.6 2.2.2.2 + # load_share: true + # drop_on_fail: true # After state: # ------------ @@ -2896,6 +3537,15 @@ Examples # match route-type level-1 level-2 # match tag 2 # description rmap2-40-deny + # route-map rmap3 permit 10 + # description *** first stanza *** + # set ip next-hop verify-availability 3.3.3.3 track 1 + # route-map rmap3 permit 20 + # description *** second stanza *** + # set ip next-hop peer-address + # route-map rmap3 permit 30 + # description *** third stanza *** + # set ip next-hop 6.6.6.6 2.2.2.2 load-share drop-on-fail # Using overridden @@ -2944,7 +3594,7 @@ Examples - AllowPrefix1 set: community: - local_as: True + local_as: true state: overridden # Task output @@ -3055,7 +3705,7 @@ Examples # - AllowPrefix1 # set: # community: - # local_as: True + # local_as: true # # After state: # ------------ diff --git a/docs/cisco.nxos.nxos_rpm_module.rst b/docs/cisco.nxos.nxos_rpm_module.rst index 28ff6f269..79d616a59 100644 --- a/docs/cisco.nxos.nxos_rpm_module.rst +++ b/docs/cisco.nxos.nxos_rpm_module.rst @@ -134,240 +134,6 @@ Parameters
Name of the RPM package.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
checkpoint_file @@ -49,241 +49,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
rollback_to diff --git a/docs/cisco.nxos.nxos_route_maps_module.rst b/docs/cisco.nxos.nxos_route_maps_module.rst index 9b2da5a5c..bcdf6a426 100644 --- a/docs/cisco.nxos.nxos_route_maps_module.rst +++ b/docs/cisco.nxos.nxos_route_maps_module.rst @@ -1882,6 +1882,91 @@ Parameters
Set BGP extcommunity list (for deletion).
+
+ extcommunity + +
+ dictionary +
+
+ +
Set BGP extcommunity attribute.
+
+
+ rt + +
+ dictionary +
+
+ +
Route-Target.
+
+
+ additive + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Add to existing rt extcommunity.
+
+
+ extcommunity_numbers + +
+ list + / elements=string +
+
+ +
Extcommunity number.
+
Supported formats are ASN2:NN, ASN4:NN, IPV4:NN.
+
+
+ next_hop + +
+ dictionary +
+
+ +
Set next-hop IP address (for policy-based routing)
+
+
+ address + +
+ string +
+
+ +
Set space-separated list of next-hop IP addresses. Address ordering is important. Also don`t use unnecessary spaces.
+
+
+ drop_on_fail + +
+ boolean +
+
+
    Choices: +
  • no ←
  • +
  • yes
  • +
+
+
Drop packets instead of using default routing when the configured next hop becomes unreachable
+
+
+ force_order + +
+ boolean +
+
+
    Choices: +
  • no ←
  • +
  • yes
  • +
+
+
Enable next-hop ordering as specified in the address parameter.
+
+
+ load_share + +
+ boolean +
+
+
    Choices: +
  • no ←
  • +
  • yes
  • +
+
+
Enable traffic load balancing across a maximum of 32 next-hop addresses
+
+
+ peer_address + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
BGP prefix next hop is set to the local address of the peer.
+
If no next hop is set in the route map, the next hop is set to the one stored in the path.
+
+
+ redist_unchanged + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Set for next-hop address conservation for non-local generated routes.
+
Used with redistribute command. Available to maintain BGP routing compliant with RFC 4271 on Nexus OS.
+
+
+ unchanged + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Set for next-hop address conservation in eBGP outgoing updates
+
+
+ verify_availability + +
+ list + / elements=dictionary +
+
+ +
Set next-hop ip address tracking with IP SLA
+
+
+ address + +
+ string + / required +
+
+ +
Set one next-hop address
+
+
+ drop_on_fail + +
+ boolean +
+
+
    Choices: +
  • no ←
  • +
  • yes
  • +
+
+
Drop packets instead of using default routing when the configured next hop becomes unreachable
+
+
+ force_order + +
+ boolean +
+
+
    Choices: +
  • no ←
  • +
  • yes
  • +
+
+
Enable next-hop ordering as specified in the address parameter.
+
+
+ load_share + +
+ boolean +
+
+
    Choices: +
  • no ←
  • +
  • yes
  • +
+
+
Enable traffic load balancing across a maximum of 32 next-hop addresses
+
+
+ track + +
+ integer + / required +
+
+ +
Set track number
+
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
diff --git a/docs/cisco.nxos.nxos_smu_module.rst b/docs/cisco.nxos.nxos_smu_module.rst deleted file mode 100644 index 76afa1a8e..000000000 --- a/docs/cisco.nxos.nxos_smu_module.rst +++ /dev/null @@ -1,381 +0,0 @@ -.. _cisco.nxos.nxos_smu_module: - - -******************* -cisco.nxos.nxos_smu -******************* - -**(deprecated, removed after 2022-10-01) Perform SMUs on Cisco NX-OS devices.** - - -Version added: 1.0.0 - -.. contents:: - :local: - :depth: 1 - -DEPRECATED ----------- -:Removed in collection release after 2022-10-01 -:Why: Updated modules released with more functionality. -:Alternative: nxos_rpm - - - -Synopsis --------- -- Perform software maintenance upgrades (SMUs) on Cisco NX-OS devices. - - - - -Parameters ----------- - -.. raw:: html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterChoices/DefaultsComments
-
- file_system - -
- string -
-
- Default:
"bootflash:"
-
-
The remote file system of the device. If omitted, devices that support a file_system parameter will use their default values.
-
-
- pkg - -
- string - / required -
-
- -
Name of the remote package.
-
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
-
- - -Notes ------ - -.. note:: - - Tested against NXOSv 7.3.(0)D1(1) on VIRL - - Unsupported for Cisco MDS - - The module can only activate and commit a package, not remove or deactivate it. - - Use ``transport=nxapi`` to avoid connection timeout - - For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide ` - - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide ` - - For more information on using Ansible to manage Cisco devices see the `Cisco integration page `_. - - - -Examples --------- - -.. code-block:: yaml - - - cisco.nxos.nxos_smu: - pkg: nxos.CSCuz65185-n9k_EOR-1.0.0-7.0.3.I2.2d.lib32_n9000.rpm - - - -Return Values -------------- -Common return values are documented `here `_, the following are the fields unique to this module: - -.. raw:: html - - - - - - - - - - - - -
KeyReturnedDescription
-
- commands - -
- list -
-
always -
commands sent to the device
-
-
Sample:
-
['install add bootflash:nxos.CSCuz65185-n9k_EOR-1.0.0-7.0.3.I2.2d.lib32_n9000.rpm', 'install activate bootflash:nxos.CSCuz65185-n9k_EOR-1.0.0-7.0.3.I2.2d.lib32_n9000.rpm force', 'install commit bootflash:nxos.CSCuz65185-n9k_EOR-1.0.0-7.0.3.I2.2d.lib32_n9000.rpm']
-
-

- - -Status ------- - - -- This module will be removed in a release after 2022-10-01. *[deprecated]* -- For more information see `DEPRECATED`_. - - -Authors -~~~~~~~ - -- Gabriele Gerbino (@GGabriele) diff --git a/docs/cisco.nxos.nxos_snapshot_module.rst b/docs/cisco.nxos.nxos_snapshot_module.rst index b90b123a3..fe89b5b7b 100644 --- a/docs/cisco.nxos.nxos_snapshot_module.rst +++ b/docs/cisco.nxos.nxos_snapshot_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
action @@ -57,7 +57,7 @@ Parameters
+
compare_option @@ -77,7 +77,7 @@ Parameters
+
comparison_results_file @@ -92,7 +92,7 @@ Parameters
+
description @@ -107,7 +107,7 @@ Parameters
+
element_key1 @@ -122,7 +122,7 @@ Parameters
+
element_key2 @@ -137,7 +137,7 @@ Parameters
+
path @@ -153,241 +153,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
row_id @@ -402,7 +168,7 @@ Parameters
+
save_snapshot_locally @@ -421,7 +187,7 @@ Parameters
+
section @@ -436,7 +202,7 @@ Parameters
+
show_command @@ -451,7 +217,7 @@ Parameters
+
snapshot1 @@ -466,7 +232,7 @@ Parameters
+
snapshot2 @@ -481,7 +247,7 @@ Parameters
+
snapshot_name diff --git a/docs/cisco.nxos.nxos_snmp_community_module.rst b/docs/cisco.nxos.nxos_snmp_community_module.rst index 931a6f500..584d2d772 100644 --- a/docs/cisco.nxos.nxos_snmp_community_module.rst +++ b/docs/cisco.nxos.nxos_snmp_community_module.rst @@ -36,12 +36,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
access @@ -60,7 +60,7 @@ Parameters
+
acl @@ -75,7 +75,7 @@ Parameters
+
community @@ -91,7 +91,7 @@ Parameters
+
group @@ -106,241 +106,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
state diff --git a/docs/cisco.nxos.nxos_snmp_contact_module.rst b/docs/cisco.nxos.nxos_snmp_contact_module.rst index f4fc5f21f..86dcba5a3 100644 --- a/docs/cisco.nxos.nxos_snmp_contact_module.rst +++ b/docs/cisco.nxos.nxos_snmp_contact_module.rst @@ -36,12 +36,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
contact @@ -57,241 +57,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
state diff --git a/docs/cisco.nxos.nxos_snmp_host_module.rst b/docs/cisco.nxos.nxos_snmp_host_module.rst index 0a898f0a3..8aef0b21d 100644 --- a/docs/cisco.nxos.nxos_snmp_host_module.rst +++ b/docs/cisco.nxos.nxos_snmp_host_module.rst @@ -36,12 +36,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
community @@ -56,241 +56,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
snmp_host @@ -306,7 +72,7 @@ Parameters
+
snmp_type @@ -325,7 +91,7 @@ Parameters
+
src_intf @@ -340,7 +106,7 @@ Parameters
+
state @@ -359,7 +125,7 @@ Parameters
+
udp @@ -375,7 +141,7 @@ Parameters
+
v3 @@ -395,7 +161,7 @@ Parameters
+
version @@ -415,7 +181,7 @@ Parameters
+
vrf @@ -430,7 +196,7 @@ Parameters
+
vrf_filter diff --git a/docs/cisco.nxos.nxos_snmp_location_module.rst b/docs/cisco.nxos.nxos_snmp_location_module.rst index 25e8eaa61..06f564693 100644 --- a/docs/cisco.nxos.nxos_snmp_location_module.rst +++ b/docs/cisco.nxos.nxos_snmp_location_module.rst @@ -36,12 +36,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -208,6 +209,7 @@ Parameters @@ -309,6 +311,7 @@ Parameters @@ -326,6 +329,7 @@ Parameters @@ -401,6 +405,7 @@ Parameters @@ -460,6 +465,7 @@ Parameters @@ -567,6 +573,7 @@ Parameters @@ -694,6 +701,7 @@ Parameters @@ -874,6 +882,7 @@ Parameters @@ -987,6 +996,7 @@ Parameters @@ -1123,6 +1133,7 @@ Parameters @@ -1229,6 +1240,7 @@ Parameters @@ -1313,6 +1325,7 @@ Parameters @@ -1419,6 +1432,7 @@ Parameters @@ -1741,6 +1755,7 @@ Parameters @@ -1825,6 +1840,7 @@ Parameters @@ -1887,6 +1903,7 @@ Parameters @@ -2015,6 +2032,7 @@ Parameters @@ -2103,6 +2121,7 @@ Parameters @@ -2147,6 +2166,7 @@ Parameters @@ -2253,6 +2273,7 @@ Parameters @@ -2439,6 +2460,7 @@ Parameters @@ -2501,6 +2523,7 @@ Parameters @@ -2651,6 +2674,7 @@ Parameters @@ -2691,6 +2715,7 @@ Parameters @@ -2713,6 +2738,7 @@ Parameters @@ -2753,6 +2779,7 @@ Parameters @@ -2881,6 +2908,7 @@ Parameters @@ -2965,6 +2993,7 @@ Parameters @@ -3027,6 +3056,7 @@ Parameters @@ -3067,6 +3097,7 @@ Parameters @@ -3129,6 +3160,7 @@ Parameters @@ -3290,6 +3322,7 @@ Parameters
    Choices:
  • md5
  • sha
  • +
  • sha-256
+ + + + + + + + + @@ -3588,8 +3644,9 @@ Notes ----- .. note:: - - Tested against NX-OS 9.3.6. + - Tested against NX-OS 9.3.6 on Cisco Nexus Switches. - This module works with connection ``network_cli`` and ``httpapi``. + - Tested against Cisco MDS NX-OS 9.2(2) with connection ``network_cli``. @@ -3619,18 +3676,18 @@ Examples location: serverroom-1 traps: aaa: - server_state_change: True + server_state_change: true system: - clock_change_notification: True + clock_change_notification: true hosts: - host: 192.0.2.1 - traps: True + traps: true version: '1' community: public - host: 192.0.2.1 source_interface: Ethernet1/1 - host: 192.0.2.2 - informs: True + informs: true version: '3' auth: NMS users: @@ -3640,16 +3697,16 @@ Examples authentication: algorithm: md5 password: '0x5632724fb8ac3699296af26281e1d0f1' - localized_key: True + localized_key: true - user: snmp_user_2 group: network-operator authentication: algorithm: md5 password: '0x5632724fb8ac3699296af26281e1d0f1' - localized_key: True + localized_key: true priv: privacy_password: '0x5632724fb8ac3699296af26281e1d0f1' - aes_128: True + aes_128: true use_acls: - user: snmp_user_1 ipv4: acl1 @@ -3668,7 +3725,7 @@ Examples # authentication: # algorithm: md5 # password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" - # localized_key: True + # localized_key: true # priv: # privacy_password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" # @@ -3700,9 +3757,9 @@ Examples # location: serverroom-1 # traps: # aaa: - # server_state_change: True + # server_state_change: true # system: - # clock_change_notification: True + # clock_change_notification: true # hosts: # - host: 192.0.2.1 # traps: true @@ -3723,7 +3780,7 @@ Examples # authentication: # algorithm: md5 # password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" - # localized_key: True + # localized_key: true # priv: # privacy_password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" # @@ -3732,7 +3789,7 @@ Examples # authentication: # algorithm: md5 # password: "0x5632724fb8ac3699296af26281e1d0f1" - # localized_key: True + # localized_key: true # # - authentication: # algorithm: md5 @@ -3806,16 +3863,16 @@ Examples location: serverroom-2 traps: aaa: - server_state_change: True + server_state_change: true hosts: - host: 192.0.2.1 - traps: True + traps: true version: '1' community: public - host: 192.0.2.1 source_interface: Ethernet1/1 - host: 192.0.3.2 - informs: True + informs: true version: '3' auth: NMS users: @@ -3825,7 +3882,7 @@ Examples authentication: algorithm: md5 password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" - localized_key: True + localized_key: true priv: privacy_password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" @@ -3834,17 +3891,17 @@ Examples authentication: algorithm: md5 password: '0x5632724fb8ac3699296af26281e1d0f1' - localized_key: True + localized_key: true - user: snmp_user_2 group: network-operator authentication: algorithm: md5 password: '0x5632724fb8ac3699296af26281e1d0f1' - localized_key: True + localized_key: true priv: privacy_password: '0x5632724fb8ac3699296af26281e1d0f1' - aes_128: True + aes_128: true use_acls: - user: snmp_user_1 ipv4: acl1 @@ -3865,9 +3922,9 @@ Examples # location: serverroom-1 # traps: # aaa: - # server_state_change: True + # server_state_change: true # system: - # clock_change_notification: True + # clock_change_notification: true # hosts: # - host: 192.0.2.1 # traps: true @@ -3888,7 +3945,7 @@ Examples # authentication: # algorithm: md5 # password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" - # localized_key: True + # localized_key: true # priv: # privacy_password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" # @@ -3897,7 +3954,7 @@ Examples # authentication: # algorithm: md5 # password: "0x5632724fb8ac3699296af26281e1d0f1" - # localized_key: True + # localized_key: true # # - authentication: # algorithm: md5 @@ -3939,16 +3996,16 @@ Examples # location: serverroom-2 # traps: # aaa: - # server_state_change: True + # server_state_change: true # hosts: # - host: 192.0.2.1 - # traps: True + # traps: true # version: '1' # community: public # - host: 192.0.2.1 # source_interface: Ethernet1/1 # - host: 192.0.3.2 - # informs: True + # informs: true # version: '3' # auth: NMS # users: @@ -3958,7 +4015,7 @@ Examples # authentication: # algorithm: md5 # password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" - # localized_key: True + # localized_key: true # priv: # privacy_password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" # @@ -3967,17 +4024,17 @@ Examples # authentication: # algorithm: md5 # password: '0x5632724fb8ac3699296af26281e1d0f1' - # localized_key: True + # localized_key: true # # - user: snmp_user_2 # group: network-operator # authentication: # algorithm: md5 # password: '0x5632724fb8ac3699296af26281e1d0f1' - # localized_key: True + # localized_key: true # priv: # privacy_password: '0x5632724fb8ac3699296af26281e1d0f1' - # aes_128: True + # aes_128: true # # use_acls: # - user: snmp_user_1 @@ -4043,9 +4100,9 @@ Examples # location: serverroom-1 # traps: # aaa: - # server_state_change: True + # server_state_change: true # system: - # clock_change_notification: True + # clock_change_notification: true # hosts: # - host: 192.0.2.1 # traps: true @@ -4066,7 +4123,7 @@ Examples # authentication: # algorithm: md5 # password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" - # localized_key: True + # localized_key: true # priv: # privacy_password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" # @@ -4075,7 +4132,7 @@ Examples # authentication: # algorithm: md5 # password: "0x5632724fb8ac3699296af26281e1d0f1" - # localized_key: True + # localized_key: true # # - authentication: # algorithm: md5 @@ -4120,7 +4177,7 @@ Examples # authentication: # algorithm: md5 # password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" - # localized_key: True + # localized_key: true # priv: # privacy_password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" @@ -4146,18 +4203,18 @@ Examples location: serverroom-1 traps: aaa: - server_state_change: True + server_state_change: true system: - clock_change_notification: True + clock_change_notification: true hosts: - host: 192.0.2.1 - traps: True + traps: true version: '1' community: public - host: 192.0.2.1 source_interface: Ethernet1/1 - host: 192.0.2.2 - informs: True + informs: true version: '3' auth: NMS users: @@ -4167,16 +4224,16 @@ Examples authentication: algorithm: md5 password: '0x5632724fb8ac3699296af26281e1d0f1' - localized_key: True + localized_key: true - user: snmp_user_2 group: network-operator authentication: algorithm: md5 password: '0x5632724fb8ac3699296af26281e1d0f1' - localized_key: True + localized_key: true priv: privacy_password: '0x5632724fb8ac3699296af26281e1d0f1' - aes_128: True + aes_128: true use_acls: - user: snmp_user_1 ipv4: acl1 @@ -4243,9 +4300,9 @@ Examples # location: serverroom-1 # traps: # aaa: - # server_state_change: True + # server_state_change: true # system: - # clock_change_notification: True + # clock_change_notification: true # hosts: # - host: 192.0.2.1 # traps: true @@ -4266,7 +4323,7 @@ Examples # authentication: # algorithm: md5 # password: "0x5632724fb8ac3699296af26281e1d0f1" - # localized_key: True + # localized_key: true # # - authentication: # algorithm: md5 diff --git a/docs/cisco.nxos.nxos_snmp_traps_module.rst b/docs/cisco.nxos.nxos_snmp_traps_module.rst index 26d2a68bc..726a4d5fe 100644 --- a/docs/cisco.nxos.nxos_snmp_traps_module.rst +++ b/docs/cisco.nxos.nxos_snmp_traps_module.rst @@ -36,12 +36,12 @@ Parameters
ParameterParameter Choices/Defaults Comments
+
location @@ -57,241 +57,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
state diff --git a/docs/cisco.nxos.nxos_snmp_server_module.rst b/docs/cisco.nxos.nxos_snmp_server_module.rst index b4bad7e15..126e16341 100644 --- a/docs/cisco.nxos.nxos_snmp_server_module.rst +++ b/docs/cisco.nxos.nxos_snmp_server_module.rst @@ -191,6 +191,7 @@ Parameters
Specify IPv4 ACL, the ACL name specified must be IPv4 ACL.
+
This option is unsupported on MDS switches.
Specify IPv6 ACL, the ACL name specified after must be IPv6 ACL.
+
This option is unsupported on MDS switches.
VRF associated with the SNMP context.
+
This option is unsupported on MDS switches.
Configure port counter configuration.
+
This option is unsupported on MDS switches.
Silently drop unknown v3 user packets.
+
This option is unsupported on MDS switches.
Configure a local SNMPv3 engineID.
+
This option is unsupported on MDS switches.
Filters notifications to the notification host receiver based on the configured VRF.
+
This option is unsupported on MDS switches.
Configures SNMP to use the selected VRF to communicate with the host receiver.
+
This option is unsupported on MDS switches.
Source interface to be used for sending out SNMP notifications.
+
This option is unsupported on MDS switches.
Enable tcp-session.
+
This option is unsupported on MDS switches.
Bridge traps.
+
This option is unsupported on MDS switches.
Enable callhome traps.
+
This option is unsupported on MDS switches.
Enable cfs traps.
+
This option is unsupported on MDS switches.
Enable config traps.
+
This option is unsupported on MDS switches.
Enable feature-control traps.
+
This option is unsupported on MDS switches.
Enable generic traps.
+
This option is unsupported on MDS switches.
Enable license traps.
+
This option is unsupported on MDS switches.
Err-disable state notification.
+
This option is unsupported on MDS switches.
Mac addr move trap.
+
This option is unsupported on MDS switches.
Enable link traps.
+
This option is unsupported on MDS switches.
MMode traps.
+
This option is unsupported on MDS switches.
Enable rf traps.
+
This option is unsupported on MDS switches.
Enable rmon traps.
+
This option is unsupported on MDS switches.
Enable snmp traps.
+
This option is unsupported on MDS switches.
Port-Storm-Control-Event.
+
This option is unsupported on MDS switches.
Enable storm-control traps.
+
This option is unsupported on MDS switches.
Stpx traps.
+
This option is unsupported on MDS switches.
Enable syslog traps.
+
This option is unsupported on MDS switches.
Enable sysmgr traps.
+
This option is unsupported on MDS switches.
Enable system traps.
+
This option is unsupported on MDS switches.
Enable upgrade traps.
+
This option is unsupported on MDS switches.
VTP traps.
+
This option is unsupported on MDS switches.
@@ -3339,6 +3372,29 @@ Parameters
Specifies whether the passwords are in localized key format.
+
+ localizedv2_key + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
Specifies whether the passwords are in localized V2 key format.
+
- + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
group @@ -89,241 +89,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
state diff --git a/docs/cisco.nxos.nxos_snmp_user_module.rst b/docs/cisco.nxos.nxos_snmp_user_module.rst index 67139fceb..2d3f6f26c 100644 --- a/docs/cisco.nxos.nxos_snmp_user_module.rst +++ b/docs/cisco.nxos.nxos_snmp_user_module.rst @@ -36,12 +36,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -683,13 +975,12 @@ Common return values are documented `here list - + @@ -701,12 +992,63 @@ Common return values are documented `here list - + + + + + + + + + + + + + + + +
ParameterParameter Choices/Defaults Comments
+
authentication @@ -60,7 +60,7 @@ Parameters
+
encrypt @@ -79,7 +79,7 @@ Parameters
+
group @@ -94,7 +94,7 @@ Parameters
+
privacy @@ -109,241 +109,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
pwd @@ -358,7 +124,7 @@ Parameters
+
state @@ -377,7 +143,7 @@ Parameters
+
user diff --git a/docs/cisco.nxos.nxos_static_route_module.rst b/docs/cisco.nxos.nxos_static_route_module.rst deleted file mode 100644 index bf522ad05..000000000 --- a/docs/cisco.nxos.nxos_static_route_module.rst +++ /dev/null @@ -1,631 +0,0 @@ -.. _cisco.nxos.nxos_static_route_module: - - -**************************** -cisco.nxos.nxos_static_route -**************************** - -**(deprecated, removed after 2022-06-01) Manages static route configuration** - - -Version added: 1.0.0 - -.. contents:: - :local: - :depth: 1 - -DEPRECATED ----------- -:Removed in collection release after 2022-06-01 -:Why: Updated modules released with more functionality -:Alternative: nxos_static_routes - - - -Synopsis --------- -- Manages static route configuration - - - - -Parameters ----------- - -.. raw:: html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterChoices/DefaultsComments
-
- aggregate - -
- list - / elements=dictionary -
-
- -
List of static route definitions
-
-
- next_hop - -
- string - / required -
-
- -
Next hop address or interface of static route. If interface, it must be the fully-qualified interface name.
-
-
- pref - -
- string -
-
- -
Preference or administrative difference of route (range 1-255) or keyword 'default'.
-

aliases: admin_distance
-
-
- prefix - -
- string - / required -
-
- -
Destination prefix of static route.
-
-
- route_name - -
- string -
-
- -
Name of the route or keyword 'default'. Used with the name parameter on the CLI.
-
-
- state - -
- string -
-
-
    Choices: -
  • present
  • -
  • absent
  • -
-
-
Manage the state of the resource.
-
-
- tag - -
- string -
-
- -
Route tag value (numeric) or keyword 'default'.
-
-
- track - -
- integer -
-
- -
Track value (range 1 - 512). Track must already be configured on the device before adding the route.
-
-
- vrf - -
- string -
-
- -
VRF for static route.
-
-
- next_hop - -
- string -
-
- -
Next hop address or interface of static route. If interface, it must be the fully-qualified interface name.
-
-
- pref - -
- string -
-
- -
Preference or administrative difference of route (range 1-255) or keyword 'default'.
-

aliases: admin_distance
-
-
- prefix - -
- string -
-
- -
Destination prefix of static route.
-

aliases: address
-
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
-
- route_name - -
- string -
-
- -
Name of the route or keyword 'default'. Used with the name parameter on the CLI.
-
-
- state - -
- string -
-
-
    Choices: -
  • present ←
  • -
  • absent
  • -
-
-
Manage the state of the resource.
-
-
- tag - -
- string -
-
- -
Route tag value (numeric) or keyword 'default'.
-
-
- track - -
- integer -
-
- -
Track value (range 1 - 512). Track must already be configured on the device before adding the route.
-
-
- vrf - -
- string -
-
- Default:
"default"
-
-
VRF for static route.
-
-
- - -Notes ------ - -.. note:: - - Tested against NXOSv 7.3.(0)D1(1) on VIRL - - Unsupported for Cisco MDS - - If no vrf is supplied, vrf is set to default. - - If ``state=absent``, the route will be removed, regardless of the non-required parameters. - - For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide ` - - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide ` - - For more information on using Ansible to manage Cisco devices see the `Cisco integration page `_. - - - -Examples --------- - -.. code-block:: yaml - - - cisco.nxos.nxos_static_route: - prefix: 192.168.20.64/24 - next_hop: 192.0.2.3 - route_name: testing - pref: 100 - - - -Return Values -------------- -Common return values are documented `here `_, the following are the fields unique to this module: - -.. raw:: html - - - - - - - - - - - - -
KeyReturnedDescription
-
- commands - -
- list -
-
always -
commands sent to the device
-
-
Sample:
-
['ip route 192.168.20.0/24 192.0.2.3 name testing 100']
-
-

- - -Status ------- - - -- This module will be removed in a release after 2022-06-01. *[deprecated]* -- For more information see `DEPRECATED`_. - - -Authors -~~~~~~~ - -- Gabriele Gerbino (@GGabriele) diff --git a/docs/cisco.nxos.nxos_static_routes_module.rst b/docs/cisco.nxos.nxos_static_routes_module.rst index f490bf282..0ce8ef2ed 100644 --- a/docs/cisco.nxos.nxos_static_routes_module.rst +++ b/docs/cisco.nxos.nxos_static_routes_module.rst @@ -348,7 +348,7 @@ Notes ----- .. note:: - - Tested against NX-OS 7.3.(0)D1(1) on VIRL + - Tested against Nexus 9300v running NX-OS 9.3.6 on CML. - Unsupported for Cisco MDS - When a route is configured for a non-existent VRF, the VRF is created and the route is added to it. - When deleting routes for a VRF, all routes inside the VRF are deleted, but the VRF is not deleted. @@ -360,28 +360,54 @@ Examples .. code-block:: yaml - # Using deleted: + # Using deleted - delete all # Before state: # ------------- # + # switch# show running-config | include '^ip(v6)* route' # ip route 192.0.2.32/28 192.0.2.12 name new_route # ip route 192.0.2.26/24 192.0.2.13 tag 12 + # switch# show running-config | section '^vrf context' - name: Delete all routes cisco.nxos.nxos_static_routes: state: deleted + # Task Output + # ----------- + # + # before: + # - address_families: + # - afi: ipv4 + # routes: + # - dest: 192.0.2.0/24 + # next_hops: + # - forward_router_address: 192.0.2.13 + # tag: 12 + # - dest: 192.0.2.32/28 + # next_hops: + # - forward_router_address: 192.0.2.12 + # route_name: new_route + # commands: + # - no ip route 192.0.2.0/24 192.0.2.13 tag 12 + # - no ip route 192.0.2.32/28 192.0.2.12 name new_route + # after: [] + # After state: # ------------ - # + # switch# show running-config | include '^ip(v6)* route' + # switch# show running-config | section '^vrf context' + # Using deleted - vrf based # Before state: # ------------ # + # switch# show running-config | include '^ip(v6)* route' # ip route 192.0.2.16/28 192.0.2.24 name new_route # ip route 192.0.2.80/28 192.0.2.26 tag 12 + # switch# show running-config | section '^vrf context' # vrf context trial_vrf # ip route 192.0.2.64/28 192.0.2.22 tag 4 # ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 @@ -390,21 +416,78 @@ Examples - name: Delete routes based on VRF cisco.nxos.nxos_static_routes: config: - - vrf: trial_vrf + - vrf: trial_vrf state: deleted + # Task Output + # ----------- + # + # before: + # - address_families: + # - afi: ipv4 + # routes: + # - dest: 192.0.2.64/28 + # next_hops: + # - forward_router_address: 192.0.2.22 + # tag: 4 + # - admin_distance: 1 + # forward_router_address: 192.0.2.23 + # route_name: merged_route + # - afi: ipv6 + # routes: + # - dest: '2200:10::/36' + # next_hops: + # - admin_distance: 5 + # dest_vrf: dest + # forward_router_address: '2048:ae12::1' + # vrf: trial_vrf + # - address_families: + # - afi: ipv4 + # routes: + # - dest: 192.0.2.16/28 + # next_hops: + # - forward_router_address: 192.0.2.24 + # route_name: new_route + # - dest: 192.0.2.80/28 + # next_hops: + # - forward_router_address: 192.0.2.26 + # tag: 12 + # commands: + # - vrf context trial_vrf + # - no ip route 192.0.2.64/28 192.0.2.22 tag 4 + # - no ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 + # - no ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5 + # after: + # - address_families: + # - afi: ipv4 + # routes: + # - dest: 192.0.2.16/28 + # next_hops: + # - forward_router_address: 192.0.2.24 + # route_name: new_route + # - dest: 192.0.2.80/28 + # next_hops: + # - forward_router_address: 192.0.2.26 + # tag: 12 + # After state: # ----------- + # + # switch# show running-config | include '^ip(v6)* route' # ip route 192.0.2.16/28 192.0.2.24 name new_route # ip route 192.0.2.80/28 192.0.2.26 tag 12 + # switch# show running-config | section '^vrf context' # vrf context trial_vrf + # Using deleted - afi based # Before state: # ------------ # + # switch# show running-config | include '^ip(v6)* route' # ip route 192.0.2.16/28 192.0.2.24 name new_route # ip route 192.0.2.80/28 192.0.2.26 tag 12 + # switch# show running-config | section '^vrf context' # vrf context trial_vrf # ip route 192.0.2.64/28 192.0.2.22 tag 4 # ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 @@ -413,112 +496,255 @@ Examples - name: Delete routes based on AFI in a VRF cisco.nxos.nxos_static_routes: config: - - vrf: trial_vrf - address_families: - - afi: ipv4 + - vrf: trial_vrf + address_families: + - afi: ipv4 state: deleted - # After state: + # Task Output # ----------- - # ip route 192.0.2.16/28 192.0.2.24 name new_route - # ip route 192.0.2.80/28 192.0.2.26 tag 12 - # vrf context trial_vrf - # ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5 - + # + # before: + # - address_families: + # - afi: ipv4 + # routes: + # - dest: 192.0.2.64/28 + # next_hops: + # - forward_router_address: 192.0.2.22 + # tag: 4 + # - admin_distance: 1 + # forward_router_address: 192.0.2.23 + # route_name: merged_route + # - afi: ipv6 + # routes: + # - dest: '2200:10::/36' + # next_hops: + # - admin_distance: 5 + # dest_vrf: dest + # forward_router_address: '2048:ae12::1' + # vrf: trial_vrf + # - address_families: + # - afi: ipv4 + # routes: + # - dest: 192.0.2.16/28 + # next_hops: + # - forward_router_address: 192.0.2.24 + # route_name: new_route + # - dest: 192.0.2.80/28 + # next_hops: + # - forward_router_address: 192.0.2.26 + # tag: 12 + # commands: + # - vrf context trial_vrf + # - no ip route 192.0.2.64/28 192.0.2.22 tag 4 + # - no ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 + # after: + # - address_families: + # - afi: ipv6 + # routes: + # - dest: '2200:10::/36' + # next_hops: + # - admin_distance: 5 + # dest_vrf: dest + # forward_router_address: '2048:ae12::1' + # vrf: trial_vrf + # - address_families: + # - afi: ipv4 + # routes: + # - dest: 192.0.2.16/28 + # next_hops: + # - forward_router_address: 192.0.2.24 + # route_name: new_route + # - dest: 192.0.2.80/28 + # next_hops: + # - forward_router_address: 192.0.2.26 + # tag: 12 - # Before state: + # After state: # ----------- + # + # switch# show running-config | include '^ip(v6)* route' # ip route 192.0.2.16/28 192.0.2.24 name new_route + # ip route 192.0.2.80/28 192.0.2.26 tag 12 + # switch# show running-config | section '^vrf context' # vrf context trial_vrf # ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5 - # Using merged # Before state: # ------------- - # + # switch# show running-config | include '^ip(v6)* route' + # switch# show running-config | section '^vrf context' - name: Merge new static route configuration cisco.nxos.nxos_static_routes: config: - - vrf: trial_vrf - address_families: - - afi: ipv4 - routes: - - dest: 192.0.2.64/24 - next_hops: - - forward_router_address: 192.0.2.22 - tag: 4 - admin_distance: 2 - - - address_families: - - afi: ipv4 - routes: - - dest: 192.0.2.16/24 - next_hops: - - forward_router_address: 192.0.2.24 - route_name: new_route - - afi: ipv6 - routes: - - dest: 2001:db8::/64 - next_hops: - - interface: eth1/3 - forward_router_address: 2001:db8::12 + - vrf: trial_vrf + address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.64/24 + next_hops: + - forward_router_address: 192.0.2.22 + tag: 4 + admin_distance: 2 + - address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.16/24 + next_hops: + - forward_router_address: 192.0.2.24 + route_name: new_route + - afi: ipv6 + routes: + - dest: '2001:db8::/64' + next_hops: + - interface: eth1/3 + forward_router_address: '2001:db8::12' state: merged + # Task Output + # ----------- + # + # before:[] + # commands: + # - vrf context trial_vrf + # - ip route 192.0.2.64/24 192.0.2.22 tag 4 2 + # - ip route 192.0.2.16/24 192.0.2.24 name new_route + # - ipv6 route 2001:db8::/64 Ethernet1/3 2001:db8::12 + # after: + # - vrf: trial_vrf + # address_families: + # - afi: ipv4 + # routes: + # - dest: 192.0.2.64/24 + # next_hops: + # - forward_router_address: 192.0.2.22 + # tag: 4 + # admin_distance: 2 + # - address_families: + # - afi: ipv4 + # routes: + # - dest: 192.0.2.16/24 + # next_hops: + # - forward_router_address: 192.0.2.24 + # route_name: new_route + # - afi: ipv6 + # routes: + # - dest: 2001:db8::/64 + # next_hops: + # - interface: eth1/3 + # forward_router_address: 2 + # After state: # ------------ # + # switch# show running-config | include '^ip(v6)* route' # ip route 192.0.2.16/24 192.0.2.24 name new_route # ipv6 route 2001:db8::/64 Ethernet1/3 2001:db8::12 + # switch# show running-config | section '^vrf context' # vrf context trial_vrf # ip route 192.0.2.0/24 192.0.2.22 tag 4 2 - - # Using overridden: + # Using overridden # Before state: # ------------- # + # switch# show running-config | include '^ip(v6)* route' # ip route 192.0.2.16/28 192.0.2.24 name new_route # ip route 192.0.2.80/28 192.0.2.26 tag 12 + # switch# show running-config | section '^vrf context' # vrf context trial_vrf # ip route 192.0.2.64/28 192.0.2.22 tag 4 # ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 - - name: Overriden existing static route configuration with new configuration + - name: Overridden existing static route configuration with new configuration cisco.nxos.nxos_static_routes: config: - - vrf: trial_vrf - address_families: - - afi: ipv4 - routes: - - dest: 192.0.2.16/28 - next_hops: - - forward_router_address: 192.0.2.23 - route_name: overridden_route1 - admin_distance: 3 - - - forward_router_address: 192.0.2.45 - route_name: overridden_route2 - dest_vrf: destinationVRF - interface: Ethernet1/2 + - vrf: trial_vrf + address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.16/28 + next_hops: + - forward_router_address: 192.0.2.23 + route_name: overridden_route1 + admin_distance: 3 + - forward_router_address: 192.0.2.45 + route_name: overridden_route2 + dest_vrf: destinationVRF + interface: Ethernet1/2 state: overridden + # Task Output + # ----------- + # + # before: + # - address_families: + # - afi: ipv4 + # routes: + # - dest: 192.0.2.64/28 + # next_hops: + # - forward_router_address: 192.0.2.22 + # tag: 4 + # - admin_distance: 1 + # forward_router_address: 192.0.2.23 + # route_name: merged_route + # vrf: trial_vrf + # - address_families: + # - afi: ipv4 + # routes: + # - dest: 192.0.2.16/28 + # next_hops: + # - forward_router_address: 192.0.2.24 + # route_name: new_route + # - dest: 192.0.2.80/28 + # next_hops: + # - forward_router_address: 192.0.2.26 + # tag: 12 + # commands: + # - no ip route 192.0.2.16/28 192.0.2.24 name new_route + # - no ip route 192.0.2.80/28 192.0.2.26 tag 12 + # - vrf context trial_vrf + # - no ip route 192.0.2.64/28 192.0.2.22 tag 4 + # - no ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 + # - ip route 192.0.2.16/28 192.0.2.23 name overridden_route1 3 + # - ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name overridden_route2 + # after: + # - address_families: + # - afi: ipv4 + # routes: + # - dest: 192.0.2.16/28 + # next_hops: + # - admin_distance: 3 + # forward_router_address: 192.0.2.23 + # route_name: overridden_route1 + # - dest_vrf: destinationVRF + # forward_router_address: 192.0.2.45 + # interface: Ethernet1/2 + # route_name: overridden_route2 + # vrf: trial_vrf + # After state: # ------------ # - # ip route 192.0.2.16/28 192.0.2.23 name replaced_route1 3 - # ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2 - + # switch# show running-config | include '^ip(v6)* route' + # switch# show running-config | section '^vrf context' + # vrf context trial_vrf + # ip route 192.0.2.16/28 192.0.2.23 name overridden_route1 3 + # ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name overridden_route2 - # Using replaced: + # Using replaced # Before state: # ------------ + # + # switch# show running-config | include '^ip(v6)* route' # ip route 192.0.2.16/28 192.0.2.24 name new_route # ip route 192.0.2.80/28 192.0.2.26 tag 12 + # switch# show running-config | section '^vrf context' # vrf context trial_vrf # ip route 192.0.2.64/28 192.0.2.22 tag 4 # ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 @@ -526,45 +752,111 @@ Examples - name: Replaced the existing static configuration of a prefix with new configuration cisco.nxos.nxos_static_routes: config: - - address_families: - - afi: ipv4 - routes: - - dest: 192.0.2.16/28 - next_hops: - - forward_router_address: 192.0.2.23 - route_name: replaced_route1 - admin_distance: 3 - - - forward_router_address: 192.0.2.45 - route_name: replaced_route2 - dest_vrf: destinationVRF - interface: Ethernet1/2 + - address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.16/28 + next_hops: + - forward_router_address: 192.0.2.23 + route_name: replaced_route1 + admin_distance: 3 + - forward_router_address: 192.0.2.45 + route_name: replaced_route2 + dest_vrf: destinationVRF + interface: Ethernet1/2 state: replaced - # After state: + # Task Output # ----------- + # + # before: + # - address_families: + # - afi: ipv4 + # routes: + # - dest: 192.0.2.64/28 + # next_hops: + # - forward_router_address: 192.0.2.22 + # tag: 4 + # - admin_distance: 1 + # forward_router_address: 192.0.2.23 + # route_name: merged_route + # vrf: trial_vrf + # - address_families: + # - afi: ipv4 + # routes: + # - dest: 192.0.2.16/28 + # next_hops: + # - forward_router_address: 192.0.2.24 + # route_name: new_route + # - dest: 192.0.2.80/28 + # next_hops: + # - forward_router_address: 192.0.2.26 + # tag: 12 + # commands: + # - no ip route 192.0.2.16/28 192.0.2.24 name new_route + # - ip route 192.0.2.16/28 192.0.2.23 name replaced_route1 3 + # - ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2 + # after: + # - address_families: + # - afi: ipv4 + # routes: + # - dest: 192.0.2.64/28 + # next_hops: + # - forward_router_address: 192.0.2.22 + # tag: 4 + # - admin_distance: 1 + # forward_router_address: 192.0.2.23 + # route_name: merged_route + # vrf: trial_vrf + # - address_families: + # - afi: ipv4 + # routes: + # - dest: 192.0.2.16/28 + # next_hops: + # - admin_distance: 3 + # forward_router_address: 192.0.2.23 + # route_name: replaced_route1 + # - dest_vrf: destinationVRF + # forward_router_address: 192.0.2.45 + # interface: Ethernet1/2 + # route_name: replaced_route2 + # - dest: 192.0.2.80/28 + # next_hops: + # - forward_router_address: 192.0.2.26 + # tag: 12 + + # After state: + # ------------ + # + # switch# show running-config | include '^ip(v6)* route' # ip route 192.0.2.16/28 192.0.2.23 name replaced_route1 3 # ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2 # ip route 192.0.2.80/28 192.0.2.26 tag 12 + # switch# show running-config | section '^vrf context' # vrf context trial_vrf # ip route 192.0.2.64/28 192.0.2.22 tag 4 # ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 - # Using gathered: + # Using gathered # Before state: # ------------- + # + # switch# show running-config | include '^ip(v6)* route' # ipv6 route 2001:db8:12::/32 2001:db8::12 + # switch# show running-config | section '^vrf context' # vrf context Test # ip route 192.0.2.48/28 192.0.2.13 # ip route 192.0.2.48/28 192.0.2.14 5 - - name: Gather the exisitng condiguration + - name: Gather the existing configuration cisco.nxos.nxos_static_routes: state: gathered - # returns: + # Task Output + # ----------- + # # gathered: # - vrf: Test # address_families: @@ -585,44 +877,47 @@ Examples # - forward_router_address: 2001:db8::12 - # Using rendered: + # Using rendered - name: Render required configuration to be pushed to the device cisco.nxos.nxos_static_routes: config: - - address_families: - - afi: ipv4 - routes: - - dest: 192.0.2.48/28 - next_hops: - - forward_router_address: 192.0.2.13 - - - afi: ipv6 - routes: - - dest: 2001:db8::/64 - next_hops: - - interface: eth1/3 - forward_router_address: 2001:db8::12 + - address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.48/28 + next_hops: + - forward_router_address: 192.0.2.13 + - afi: ipv6 + routes: + - dest: 2001:db8::/64 + next_hops: + - interface: eth1/3 + forward_router_address: 2001:db8::12 state: rendered - # returns + # Task Output + # ----------- + # # rendered: # vrf context default # ip route 192.0.2.48/28 192.0.2.13 # ipv6 route 2001:db8::/64 Ethernet1/3 2001:db8::12 - # Using parsed - name: Parse the config to structured data cisco.nxos.nxos_static_routes: + state: parsed running_config: | ipv6 route 2002:db8:12::/32 2002:db8:12::1 vrf context Test ip route 192.0.2.48/28 192.0.2.13 ip route 192.0.2.48/28 192.0.2.14 5 - # returns: + # Task Output + # ----------- + # # parsed: # - vrf: Test # address_families: @@ -631,10 +926,8 @@ Examples # - dest: 192.0.2.48/28 # next_hops: # - forward_router_address: 192.0.2.13 - # # - forward_router_address: 192.0.2.14 # admin_distance: 5 - # # - address_families: # - afi: ipv6 # routes: @@ -667,11 +960,10 @@ Common return values are documented `here
when changed -
The resulting configuration model invocation.
+
The resulting configuration after module execution.

Sample:
-
The configuration returned will always be in the same format - of the parameters above.
+
This output will always be in the same format as the module argspec.
alwayswhen state is merged, replaced, overridden, deleted or purged -
The configuration prior to the model invocation.
+
The configuration prior to the module execution.

Sample:
-
The configuration returned will always be in the same format - of the parameters above.
+
This output will always be in the same format as the module argspec.
alwayswhen state is merged, replaced, overridden, deleted or purged
The set of commands pushed to the remote device.

Sample:
-
['ip route 192.0.2.48/28 192.0.2.12 Ethernet1/2 name sample_route', 'ipv6 route 2001:db8:3000::/36 2001:db8:200:2::2', 'vrf context test', 'ip route 192.0.2.48/28 192.0.2.121']
+
['ip route 192.0.2.16/28 192.0.2.24 name new_route', 'vrf context trial_vrf', 'ip route 192.0.2.16/28 192.0.2.23 name overridden_route1 3']
+
+
+ gathered + +
+ list +
+
when state is gathered +
Facts about the network resource gathered from the remote device as structured data.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ parsed + +
+ list +
+
when state is parsed +
The device native config provided in running_config option parsed into structured data as per module argspec.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ rendered + +
+ list +
+
when state is rendered +
The provided configuration in the task rendered in device-native format (offline).
+
+
Sample:
+
['ip route 192.0.2.16/28 192.0.2.24 name new_route', 'vrf context trial_vrf', 'ip route 192.0.2.16/28 192.0.2.23 name overridden_route1 3']
@@ -721,3 +1063,4 @@ Authors ~~~~~~~ - Adharsh Srivats Rangarajan (@adharshsrivatsr) +- Sagar Paul (@KB-perByte) diff --git a/docs/cisco.nxos.nxos_system_module.rst b/docs/cisco.nxos.nxos_system_module.rst index b114aeed7..630ebbaad 100644 --- a/docs/cisco.nxos.nxos_system_module.rst +++ b/docs/cisco.nxos.nxos_system_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -303,14 +303,14 @@ Parameters id
- integer + string
@@ -449,7 +449,7 @@ Parameters destination_group
- integer + string
@@ -503,7 +503,7 @@ Parameters id
- integer + string
ParameterParameter Choices/Defaults Comments
+
domain_lookup @@ -53,7 +53,7 @@ Parameters
+
domain_name @@ -69,7 +69,7 @@ Parameters
+
domain_search @@ -85,7 +85,7 @@ Parameters
+
hostname @@ -100,7 +100,7 @@ Parameters
+
name_servers @@ -116,241 +116,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
state @@ -369,7 +135,7 @@ Parameters
+
system_mtu @@ -415,14 +181,14 @@ Examples - name: configure name servers cisco.nxos.nxos_system: name_servers: - - 8.8.8.8 - - 8.8.4.4 + - 8.8.8.8 + - 8.8.4.4 - name: configure name servers with VRF support cisco.nxos.nxos_system: name_servers: - - {server: 8.8.8.8, vrf: mgmt} - - {server: 8.8.4.4, vrf: mgmt} + - {server: 8.8.8.8, vrf: mgmt} + - {server: 8.8.4.4, vrf: mgmt} diff --git a/docs/cisco.nxos.nxos_telemetry_module.rst b/docs/cisco.nxos.nxos_telemetry_module.rst index 742d0960b..d1394ccf0 100644 --- a/docs/cisco.nxos.nxos_telemetry_module.rst +++ b/docs/cisco.nxos.nxos_telemetry_module.rst @@ -245,14 +245,14 @@ Parameters id
- integer + string
Destination group identifier.
-
Value must be a int representing the destination group identifier.
+
Value must be an integer or string representing the destination group identifier.
Sensor group identifier.
-
Value must be a int representing the sensor group identifier.
+
Value must be a integer or a string representing the sensor group identifier.
@@ -466,14 +466,14 @@ Parameters id
- integer + string
Subscription identifier.
-
Value must be a int representing the subscription identifier.
+
Value must be an integer or string representing the subscription identifier.
@@ -611,41 +611,41 @@ Examples source_interface: Ethernet1/1 vrf: management destination_groups: - - id: 2 - destination: - ip: 192.168.0.2 - port: 50001 - protocol: gPRC - encoding: GPB - - id: 55 - destination: - ip: 192.168.0.55 - port: 60001 - protocol: gPRC - encoding: GPB + - id: 2 + destination: + ip: 192.168.0.2 + port: 50001 + protocol: gRPC + encoding: GPB + - id: 55 + destination: + ip: 192.168.0.55 + port: 60001 + protocol: gRPC + encoding: GPB sensor_groups: - - id: 1 - data_source: NX-API - path: - name: '"show lldp neighbors detail"' - depth: 0 - - id: 55 - data_source: DME - path: - name: sys/ch - depth: unbounded - filter_condition: ne(eqptFt.operSt,"ok") + - id: 1 + data_source: NX-API + path: + name: '"show lldp neighbors detail"' + depth: 0 + - id: 55 + data_source: DME + path: + name: sys/ch + depth: unbounded + filter_condition: ne(eqptFt.operSt,"ok") subscriptions: - - id: 5 - destination_group: 55 - sensor_group: - id: 1 - sample_interval: 1000 - - id: 6 - destination_group: 2 - sensor_group: - id: 55 - sample_interval: 2000 + - id: 5 + destination_group: 55 + sensor_group: + id: 1 + sample_interval: 1000 + - id: 6 + destination_group: 2 + sensor_group: + id: 55 + sample_interval: 2000 state: merged @@ -663,15 +663,15 @@ Examples source_interface: Ethernet1/1 vrf: management destination_groups: - - id: 2 - destination: - ip: 192.168.0.2 - port: 50001 - protocol: gPRC - encoding: GPB + - id: 2 + destination: + ip: 192.168.0.2 + port: 50001 + protocol: gRPC + encoding: GPB subscriptions: - - id: 5 - destination_group: 55 + - id: 5 + destination_group: 55 state: replaced diff --git a/docs/cisco.nxos.nxos_udld_interface_module.rst b/docs/cisco.nxos.nxos_udld_interface_module.rst index 67f4c5bed..cba2733c0 100644 --- a/docs/cisco.nxos.nxos_udld_interface_module.rst +++ b/docs/cisco.nxos.nxos_udld_interface_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
interface @@ -50,7 +50,7 @@ Parameters
+
mode @@ -71,241 +71,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
state diff --git a/docs/cisco.nxos.nxos_udld_module.rst b/docs/cisco.nxos.nxos_udld_module.rst index 6a271c05e..dc461bc89 100644 --- a/docs/cisco.nxos.nxos_udld_module.rst +++ b/docs/cisco.nxos.nxos_udld_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + @@ -169,13 +185,13 @@ Parameters - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
aggressive @@ -53,7 +53,7 @@ Parameters
+
msg_time @@ -68,241 +68,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
reset @@ -321,7 +87,7 @@ Parameters
+
state diff --git a/docs/cisco.nxos.nxos_user_module.rst b/docs/cisco.nxos.nxos_user_module.rst index bf2dce378..a03a23a03 100644 --- a/docs/cisco.nxos.nxos_user_module.rst +++ b/docs/cisco.nxos.nxos_user_module.rst @@ -63,7 +63,23 @@ Parameters
-
The password to be configured on the network device. The password needs to be provided in cleartext and it will be encrypted on the device. Please note that this option is not same as provider password.
+
The password to be configured on the network device. The password needs to be provided in cleartext and it will be encrypted on the device.
+
+
+ hashed_password + +
+ string +
+
+ +
The hashed password to be configured on the network device. The password needs to already be encrypted.
-
The password to be configured on the network device. The password needs to be provided in cleartext and it will be encrypted on the device. Please note that this option is not same as provider password.
+
The password to be configured on the network device. The password needs to be provided in cleartext and it will be encrypted on the device.
- name + hashed_password
string @@ -184,211 +200,13 @@ Parameters
-
The username to be configured on the remote Cisco Nexus device. This argument accepts a string value and is mutually exclusive with the aggregate argument.
+
The hashed password to be configured on the network device. The password needs to already be encrypted.
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username + name
string @@ -397,30 +215,9 @@ Parameters
-
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
+
The username to be configured on the remote Cisco Nexus device. This argument accepts a string value and is mutually exclusive with the aggregate argument.
@@ -538,13 +335,13 @@ Examples - name: remove all users except admin cisco.nxos.nxos_user: - purge: yes + purge: true - name: set multiple users role cisco.nxos.nxos_user: aggregate: - - name: netop - - name: netend + - name: netop + - name: netend role: network-operator state: present diff --git a/docs/cisco.nxos.nxos_vlan_module.rst b/docs/cisco.nxos.nxos_vlan_module.rst deleted file mode 100644 index 0be685165..000000000 --- a/docs/cisco.nxos.nxos_vlan_module.rst +++ /dev/null @@ -1,804 +0,0 @@ -.. _cisco.nxos.nxos_vlan_module: - - -******************** -cisco.nxos.nxos_vlan -******************** - -**(deprecated, removed after 2022-06-01) Manages VLAN resources and attributes.** - - -Version added: 1.0.0 - -.. contents:: - :local: - :depth: 1 - -DEPRECATED ----------- -:Removed in collection release after 2022-06-01 -:Why: Updated modules released with more functionality -:Alternative: nxos_vlans - - - -Synopsis --------- -- Manages VLAN configurations on NX-OS switches. - - - - -Parameters ----------- - -.. raw:: html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterChoices/DefaultsComments
-
- admin_state - -
- string -
-
-
    Choices: -
  • up ←
  • -
  • down
  • -
-
-
Manage the VLAN administrative state of the VLAN equivalent to shut/no shut in VLAN config mode.
-
-
- aggregate - -
- list - / elements=dictionary -
-
- -
List of VLANs definitions.
-
-
- admin_state - -
- string -
-
-
    Choices: -
  • up
  • -
  • down
  • -
-
-
Manage the VLAN administrative state of the VLAN equivalent to shut/no shut in VLAN config mode.
-
-
- associated_interfaces - -
- list - / elements=string -
-
- -
This is a intent option and checks the operational state of the for given vlan name for associated interfaces. If the value in the associated_interfaces does not match with the operational state of vlan interfaces on device it will result in failure.
-
-
- delay - -
- integer -
-
- -
Time in seconds to wait before checking for the operational state on remote device. This wait is applicable for operational state arguments.
-
-
- interfaces - -
- list - / elements=string -
-
- -
List of interfaces that should be associated to the VLAN or keyword 'default'.
-
-
- mapped_vni - -
- string -
-
- -
The Virtual Network Identifier (VNI) ID that is mapped to the VLAN. Valid values are integer and keyword 'default'. Range 4096-16773119.
-
-
- mode - -
- string -
-
-
    Choices: -
  • ce
  • -
  • fabricpath
  • -
-
-
Set VLAN mode to classical ethernet or fabricpath. This is a valid option for Nexus 5000 and 7000 series.
-
-
- name - -
- string -
-
- -
Name of VLAN or keyword 'default'.
-
-
- state - -
- string -
-
-
    Choices: -
  • present
  • -
  • absent
  • -
-
-
Manage the state of the resource.
-
-
- vlan_id - -
- integer - / required -
-
- -
Single VLAN ID.
-
-
- vlan_range - -
- string -
-
- -
Range of VLANs such as 2-10 or 2,5,10-15, etc.
-
-
- vlan_state - -
- string -
-
-
    Choices: -
  • active
  • -
  • suspend
  • -
-
-
Manage the vlan operational state of the VLAN
-
-
- associated_interfaces - -
- list - / elements=string -
-
- -
This is a intent option and checks the operational state of the for given vlan name for associated interfaces. If the value in the associated_interfaces does not match with the operational state of vlan interfaces on device it will result in failure.
-
-
- delay - -
- integer -
-
- Default:
10
-
-
Time in seconds to wait before checking for the operational state on remote device. This wait is applicable for operational state arguments.
-
-
- interfaces - -
- list - / elements=string -
-
- -
List of interfaces that should be associated to the VLAN or keyword 'default'.
-
-
- mapped_vni - -
- string -
-
- -
The Virtual Network Identifier (VNI) ID that is mapped to the VLAN. Valid values are integer and keyword 'default'. Range 4096-16773119.
-
-
- mode - -
- string -
-
-
    Choices: -
  • ce ←
  • -
  • fabricpath
  • -
-
-
Set VLAN mode to classical ethernet or fabricpath. This is a valid option for Nexus 5000 and 7000 series.
-
-
- name - -
- string -
-
- -
Name of VLAN or keyword 'default'.
-
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
-
- purge - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Purge VLANs not defined in the aggregate parameter. This parameter can be used without aggregate as well.
-
Removal of Vlan 1 is not allowed and will be ignored by purge.
-
-
- state - -
- string -
-
-
    Choices: -
  • present ←
  • -
  • absent
  • -
-
-
Manage the state of the resource.
-
-
- vlan_id - -
- integer -
-
- -
Single VLAN ID.
-
-
- vlan_range - -
- string -
-
- -
Range of VLANs such as 2-10 or 2,5,10-15, etc.
-
-
- vlan_state - -
- string -
-
-
    Choices: -
  • active ←
  • -
  • suspend
  • -
-
-
Manage the vlan operational state of the VLAN
-
-
- - -Notes ------ - -.. note:: - - For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide ` - - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide ` - - For more information on using Ansible to manage Cisco devices see the `Cisco integration page `_. - - - -Examples --------- - -.. code-block:: yaml - - - name: Ensure a range of VLANs are not present on the switch - cisco.nxos.nxos_vlan: - vlan_range: 2-10,20,50,55-60,100-150 - state: absent - - - name: Ensure VLAN 50 exists with the name WEB and is in the shutdown state - cisco.nxos.nxos_vlan: - vlan_id: 50 - admin_state: down - name: WEB - - - name: Ensure VLAN is NOT on the device - cisco.nxos.nxos_vlan: - vlan_id: 50 - state: absent - - - name: Add interfaces to VLAN and check intent (config + intent) - cisco.nxos.nxos_vlan: - vlan_id: 100 - interfaces: - - Ethernet2/1 - - Ethernet2/5 - associated_interfaces: - - Ethernet2/1 - - Ethernet2/5 - - - name: Check interfaces assigned to VLAN - cisco.nxos.nxos_vlan: - vlan_id: 100 - associated_interfaces: - - Ethernet2/1 - - Ethernet2/5 - - - name: Create aggregate of vlans - cisco.nxos.nxos_vlan: - aggregate: - - {vlan_id: 4000, mode: ce} - - {vlan_id: 4001, name: vlan-4001} - - - name: purge vlans - removes all other vlans except the ones mentioned in aggregate) - cisco.nxos.nxos_vlan: - aggregate: - - vlan_id: 1 - - vlan_id: 4001 - purge: yes - - - -Return Values -------------- -Common return values are documented `here `_, the following are the fields unique to this module: - -.. raw:: html - - - - - - - - - - - - -
KeyReturnedDescription
-
- commands - -
- list -
-
always -
Set of command strings to send to the remote device
-
-
Sample:
-
['vlan 20', 'vlan 55', 'vn-segment 5000']
-
-

- - -Status ------- - - -- This module will be removed in a release after 2022-06-01. *[deprecated]* -- For more information see `DEPRECATED`_. - - -Authors -~~~~~~~ - -- Jason Edelman (@jedelman8) diff --git a/docs/cisco.nxos.nxos_vlans_module.rst b/docs/cisco.nxos.nxos_vlans_module.rst index 1da6615e6..a9dc3f41d 100644 --- a/docs/cisco.nxos.nxos_vlans_module.rst +++ b/docs/cisco.nxos.nxos_vlans_module.rst @@ -228,10 +228,10 @@ Examples - name: Merge provided configuration with device configuration. cisco.nxos.nxos_vlans: config: - - vlan_id: 5 - name: test-vlan5 - - vlan_id: 10 - enabled: false + - vlan_id: 5 + name: test-vlan5 + - vlan_id: 10 + enabled: false state: merged # After state: @@ -258,11 +258,11 @@ Examples - name: Replace device configuration of specified vlan with provided configuration. cisco.nxos.nxos_vlans: config: - - vlan_id: 5 - name: test-vlan - enabled: false - - vlan_id: 10 - enabled: false + - vlan_id: 5 + name: test-vlan + enabled: false + - vlan_id: 10 + enabled: false state: replaced # After state: @@ -293,10 +293,10 @@ Examples - name: Override device configuration of all vlans with provided configuration. cisco.nxos.nxos_vlans: config: - - vlan_id: 5 - name: test-vlan - - vlan_id: 10 - state: active + - vlan_id: 5 + name: test-vlan + - vlan_id: 10 + state: active state: overridden # After state: @@ -321,8 +321,8 @@ Examples - name: Delete vlans. cisco.nxos.nxos_vlans: config: - - vlan_id: 5 - - vlan_id: 10 + - vlan_id: 5 + - vlan_id: 10 state: deleted # After state: @@ -334,13 +334,13 @@ Examples - name: Use rendered state to convert task input to device specific commands cisco.nxos.nxos_vlans: config: - - vlan_id: 5 - name: vlan5 - mapped_vni: 100 + - vlan_id: 5 + name: vlan5 + mapped_vni: 100 - - vlan_id: 6 - name: vlan6 - state: suspend + - vlan_id: 6 + name: vlan6 + state: suspend state: rendered # Task Output (redacted) diff --git a/docs/cisco.nxos.nxos_vpc_interface_module.rst b/docs/cisco.nxos.nxos_vpc_interface_module.rst index 0f874ff88..01138d606 100644 --- a/docs/cisco.nxos.nxos_vpc_interface_module.rst +++ b/docs/cisco.nxos.nxos_vpc_interface_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
peer_link @@ -53,7 +53,7 @@ Parameters
+
portchannel @@ -69,241 +69,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
state @@ -322,7 +88,7 @@ Parameters
+
vpc diff --git a/docs/cisco.nxos.nxos_vpc_module.rst b/docs/cisco.nxos.nxos_vpc_module.rst index 904a59300..9e0ca3c29 100644 --- a/docs/cisco.nxos.nxos_vpc_module.rst +++ b/docs/cisco.nxos.nxos_vpc_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
auto_recovery @@ -55,7 +55,7 @@ Parameters
+
auto_recovery_reload_delay @@ -71,7 +71,7 @@ Parameters
+
delay_restore @@ -86,7 +86,7 @@ Parameters
+
delay_restore_interface_vlan @@ -102,7 +102,7 @@ Parameters
+
delay_restore_orphan_port @@ -118,7 +118,7 @@ Parameters
+
domain @@ -134,7 +134,7 @@ Parameters
+
peer_gw @@ -153,7 +153,7 @@ Parameters
+
pkl_dest @@ -169,7 +169,7 @@ Parameters
+
pkl_src @@ -184,7 +184,7 @@ Parameters
+
pkl_vrf @@ -201,241 +201,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
role_priority @@ -450,7 +216,7 @@ Parameters
+
state @@ -469,7 +235,7 @@ Parameters
+
system_priority diff --git a/docs/cisco.nxos.nxos_vrf_af_module.rst b/docs/cisco.nxos.nxos_vrf_af_module.rst index b2274781d..236991587 100644 --- a/docs/cisco.nxos.nxos_vrf_af_module.rst +++ b/docs/cisco.nxos.nxos_vrf_af_module.rst @@ -53,240 +53,6 @@ Parameters
Address-Family Identifier (AFI).
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
@@ -444,55 +210,50 @@ Examples afi: ipv4 route_target_both_auto_evpn: true state: present - - cisco.nxos.nxos_vrf_af: vrf: ntc afi: ipv4 route_targets: - - rt: 65000:1000 - direction: import - - rt: 65001:1000 - direction: import - + - rt: '65000:1000' + direction: import + - rt: '65001:1000' + direction: import - cisco.nxos.nxos_vrf_af: vrf: ntc afi: ipv4 route_targets: - - rt: 65000:1000 - direction: import - - rt: 65001:1000 - state: absent - + - rt: '65000:1000' + direction: import + - rt: '65001:1000' + state: absent - cisco.nxos.nxos_vrf_af: vrf: ntc afi: ipv4 route_targets: - - rt: 65000:1000 - direction: export - - rt: 65001:1000 - direction: export - + - rt: '65000:1000' + direction: export + - rt: '65001:1000' + direction: export - cisco.nxos.nxos_vrf_af: vrf: ntc afi: ipv4 route_targets: - - rt: 65000:1000 - direction: export - state: absent - + - rt: '65000:1000' + direction: export + state: absent - cisco.nxos.nxos_vrf_af: vrf: ntc afi: ipv4 route_targets: - - rt: 65000:1000 - direction: both - state: present - - rt: 65001:1000 - direction: import - state: present - - rt: 65002:1000 - direction: both - state: absent + - rt: '65000:1000' + direction: both + state: present + - rt: '65001:1000' + direction: import + state: present + - rt: '65002:1000' + direction: both + state: absent diff --git a/docs/cisco.nxos.nxos_vrf_interface_module.rst b/docs/cisco.nxos.nxos_vrf_interface_module.rst index 7f7fb2a25..156ded21c 100644 --- a/docs/cisco.nxos.nxos_vrf_interface_module.rst +++ b/docs/cisco.nxos.nxos_vrf_interface_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
interface @@ -50,241 +50,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
state @@ -303,7 +69,7 @@ Parameters
+
vrf diff --git a/docs/cisco.nxos.nxos_vrf_module.rst b/docs/cisco.nxos.nxos_vrf_module.rst index 20576c8b0..6765f78b5 100644 --- a/docs/cisco.nxos.nxos_vrf_module.rst +++ b/docs/cisco.nxos.nxos_vrf_module.rst @@ -303,240 +303,6 @@ Parameters

aliases: vrf
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
@@ -634,48 +400,48 @@ Examples name: ntc description: testing state: present - - name: Aggregate definition of VRFs cisco.nxos.nxos_vrf: aggregate: - - {name: test1, description: Testing, admin_state: down} - - {name: test2, interfaces: Ethernet1/2} - + - name: test1 + description: Testing + admin_state: down + - name: test2 + interfaces: Ethernet1/2 - name: Aggregate definitions of VRFs with Purge cisco.nxos.nxos_vrf: aggregate: - - {name: ntc1, description: purge test1} - - {name: ntc2, description: purge test2} + - name: ntc1 + description: purge test1 + - name: ntc2 + description: purge test2 state: present - purge: yes - + purge: true - name: Delete VRFs exist on switch cisco.nxos.nxos_vrf: aggregate: - - {name: ntc1} - - {name: ntc2} + - name: ntc1 + - name: ntc2 state: absent - - name: Assign interfaces to VRF declaratively cisco.nxos.nxos_vrf: name: test1 interfaces: - - Ethernet2/3 - - Ethernet2/5 - + - Ethernet2/3 + - Ethernet2/5 - name: Check interfaces assigned to VRF cisco.nxos.nxos_vrf: name: test1 associated_interfaces: - - Ethernet2/3 - - Ethernet2/5 - - - name: Ensure VRF is tagged with interface Ethernet2/5 only (Removes from Ethernet2/3) + - Ethernet2/3 + - Ethernet2/5 + - name: >- + Ensure VRF is tagged with interface Ethernet2/5 only (Removes from + Ethernet2/3) cisco.nxos.nxos_vrf: name: test1 interfaces: - - Ethernet2/5 - + - Ethernet2/5 - name: Delete VRF cisco.nxos.nxos_vrf: name: ntc diff --git a/docs/cisco.nxos.nxos_vrrp_module.rst b/docs/cisco.nxos.nxos_vrrp_module.rst index 392e5c54c..88183c5af 100644 --- a/docs/cisco.nxos.nxos_vrrp_module.rst +++ b/docs/cisco.nxos.nxos_vrrp_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
admin_state @@ -54,7 +54,7 @@ Parameters
+
authentication @@ -69,7 +69,7 @@ Parameters
+
group @@ -85,7 +85,7 @@ Parameters
+
interface @@ -101,7 +101,7 @@ Parameters
+
interval @@ -116,7 +116,7 @@ Parameters
+
preempt @@ -135,7 +135,7 @@ Parameters
+
priority @@ -150,241 +150,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
state @@ -403,7 +169,7 @@ Parameters
+
vip diff --git a/docs/cisco.nxos.nxos_vsan_module.rst b/docs/cisco.nxos.nxos_vsan_module.rst index c161f11d8..9baa64c68 100644 --- a/docs/cisco.nxos.nxos_vsan_module.rst +++ b/docs/cisco.nxos.nxos_vsan_module.rst @@ -160,25 +160,25 @@ Examples - name: Test that vsan module works cisco.nxos.nxos_vsan: vsan: - - id: 922 - interface: - - fc1/1 - - fc1/2 - - port-channel 1 - name: vsan-SAN-A - remove: false - suspend: false - - id: 923 - interface: - - fc1/11 - - fc1/21 - - port-channel 2 - name: vsan-SAN-B - remove: false - suspend: true - - id: 1923 - name: vsan-SAN-Old - remove: true + - id: 922 + interface: + - fc1/1 + - fc1/2 + - port-channel 1 + name: vsan-SAN-A + remove: false + suspend: false + - id: 923 + interface: + - fc1/11 + - fc1/21 + - port-channel 2 + name: vsan-SAN-B + remove: false + suspend: true + - id: 1923 + name: vsan-SAN-Old + remove: true diff --git a/docs/cisco.nxos.nxos_vtp_domain_module.rst b/docs/cisco.nxos.nxos_vtp_domain_module.rst index c2c3ad6b5..db2e8bd89 100644 --- a/docs/cisco.nxos.nxos_vtp_domain_module.rst +++ b/docs/cisco.nxos.nxos_vtp_domain_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
domain @@ -49,240 +49,6 @@ Parameters
VTP domain name.
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-

diff --git a/docs/cisco.nxos.nxos_vtp_password_module.rst b/docs/cisco.nxos.nxos_vtp_password_module.rst index d6f7616c6..084e62b8a 100644 --- a/docs/cisco.nxos.nxos_vtp_password_module.rst +++ b/docs/cisco.nxos.nxos_vtp_password_module.rst @@ -29,246 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
state @@ -287,7 +53,7 @@ Parameters
+
vtp_password diff --git a/docs/cisco.nxos.nxos_vtp_version_module.rst b/docs/cisco.nxos.nxos_vtp_version_module.rst index 35fefd9de..996e950ff 100644 --- a/docs/cisco.nxos.nxos_vtp_version_module.rst +++ b/docs/cisco.nxos.nxos_vtp_version_module.rst @@ -29,246 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
version @@ -281,6 +47,7 @@ Parameters
    Choices:
  • 1
  • 2
  • +
  • 3
@@ -314,9 +81,6 @@ Examples # ENSURE VTP VERSION IS 2 - cisco.nxos.nxos_vtp_version: version: 2 - host: '{{ inventory_hostname }}' - username: '{{ un }}' - password: '{{ pwd }}' diff --git a/docs/cisco.nxos.nxos_vxlan_vtep_module.rst b/docs/cisco.nxos.nxos_vxlan_vtep_module.rst index ee68c43a8..57fdc14a3 100644 --- a/docs/cisco.nxos.nxos_vxlan_vtep_module.rst +++ b/docs/cisco.nxos.nxos_vxlan_vtep_module.rst @@ -29,97 +29,14 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
-
- description - -
- string -
-
- -
Description of the NVE interface.
-
-
- global_ingress_replication_bgp - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Configures ingress replication protocol as bgp for all VNIs. This is available on Nexus 9000 series switches running NX-OS software release 9.2(x) or higher.
-
-
- global_mcast_group_L2 - -
- string -
-
- -
Global multicast IP prefix for L2 VNIs or the keyword 'default'. This is available on Nexus 9000 series switches running NX-OS software release 9.2(x) or higher.
-
-
- global_mcast_group_L3 - -
- string -
-
- -
Global multicast IP prefix for L3 VNIs or the keyword 'default'. This is available on Nexus 9000 series switches running NX-OS software release 9.2(x) or higher.
-
-
- global_suppress_arp - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Enables ARP suppression for all VNIs. This is available on NX-OS 9K series running 9.2.x or higher.
-
+
- host_reachability + advertise_virtual_rmac
boolean @@ -132,67 +49,13 @@ Parameters
-
Specify mechanism for host reachability advertisement. A Boolean value of 'true' indicates that BGP will be used for host reachability advertisement. A Boolean value of 'false' indicates that no protocol is used for host reachability advertisement. Other host reachability advertisement protocols (e.g. OpenFlow, controller, etc.) are not supported.
-
-
- interface - -
- string - / required -
-
- -
Interface name for the VXLAN Network Virtualization Endpoint.
-
-
- multisite_border_gateway_interface - -
- string -
-
added in 1.1.0
-
- -
Specify the loopback interface whose IP address should be used for the NVE Multisite Border-gateway Interface. This is available on specific Nexus 9000 series switches running NX-OS 7.0(3)I7(x) or higher. Specify "default" to remove an existing gateway config.
+
The advertise_virtual_rmac parameter lets BGP to use the VMAC with VIP as next-hop when advertising type-2 routes. Should be used together with advertise_pip parameter from cisco.nxos.nxos_bgp_address_family module.
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
- auth_pass + description
string @@ -201,14 +64,13 @@ Parameters
-
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
+
Description of the NVE interface.
- authorize + global_ingress_replication_bgp
boolean @@ -216,67 +78,18 @@ Parameters
    Choices: -
  • no ←
  • +
  • no
  • yes
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
+
Configures ingress replication protocol as bgp for all VNIs. This is available on Nexus 9000 series switches running NX-OS software release 9.2(x) or higher.
- ssh_keyfile + global_mcast_group_L2
string @@ -285,50 +98,28 @@ Parameters
-
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
+
Global multicast IP prefix for L2 VNIs or the keyword 'default'. This is available on Nexus 9000 series switches running NX-OS software release 9.2(x) or higher.
- transport + global_mcast_group_L3
string
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
+
Global multicast IP prefix for L3 VNIs or the keyword 'default'. This is available on Nexus 9000 series switches running NX-OS software release 9.2(x) or higher.
- use_proxy + global_suppress_arp
boolean @@ -337,18 +128,17 @@ Parameters
    Choices:
  • no
  • -
  • yes ←
  • +
  • yes
-
If no, the environment variables http_proxy and https_proxy will be ignored.
+
Enables ARP suppression for all VNIs. This is available on NX-OS 9K series running 9.2.x or higher.
- use_ssl + host_reachability
boolean @@ -356,53 +146,48 @@ Parameters
    Choices: -
  • no ←
  • +
  • no
  • yes
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
+
Specify mechanism for host reachability advertisement. A Boolean value of 'true' indicates that BGP will be used for host reachability advertisement. A Boolean value of 'false' indicates that no protocol is used for host reachability advertisement. Other host reachability advertisement protocols (e.g. OpenFlow, controller, etc.) are not supported.
- username + interface
string + / required
-
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
+
Interface name for the VXLAN Network Virtualization Endpoint.
- validate_certs + multisite_border_gateway_interface
- boolean + string
+
added in 1.1.0
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
+
Specify the loopback interface whose IP address should be used for the NVE Multisite Border-gateway Interface. This is available on specific Nexus 9000 series switches running NX-OS 7.0(3)I7(x) or higher. Specify "default" to remove an existing gateway config.
+
shutdown @@ -421,7 +206,7 @@ Parameters
+
source_interface @@ -436,7 +221,7 @@ Parameters
+
source_interface_hold_down_time @@ -451,7 +236,7 @@ Parameters
+
state @@ -479,7 +264,7 @@ Notes .. note:: - Tested against NXOSv 7.3.(0)D1(1) on VIRL - Unsupported for Cisco MDS - - The module is used to manage NVE properties, not to create NVE interfaces. Use :ref:`cisco.nxos.nxos_interface ` if you wish to do so. + - The module is used to manage NVE properties, not to create NVE interfaces. Use :ref:`cisco.nxos.nxos_interfaces ` if you wish to do so. - ``state=absent`` removes the interface. - Default, where supported, restores params default value. - For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide ` diff --git a/docs/cisco.nxos.nxos_vxlan_vtep_vni_module.rst b/docs/cisco.nxos.nxos_vxlan_vtep_vni_module.rst index e27325e0d..d000c9959 100644 --- a/docs/cisco.nxos.nxos_vxlan_vtep_vni_module.rst +++ b/docs/cisco.nxos.nxos_vxlan_vtep_vni_module.rst @@ -29,12 +29,12 @@ Parameters - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterParameter Choices/Defaults Comments
+
assoc_vrf @@ -53,7 +53,7 @@ Parameters
+
ingress_replication @@ -73,7 +73,7 @@ Parameters
+
interface @@ -89,7 +89,7 @@ Parameters
+
multicast_group @@ -104,7 +104,7 @@ Parameters
+
multisite_ingress_replication @@ -125,7 +125,7 @@ Parameters
+
peer_list @@ -141,241 +141,7 @@ Parameters
-
- provider - -
- dictionary -
-
- -
Deprecated
-
Starting with Ansible 2.5 we recommend using connection: network_cli.
-
Starting with Ansible 2.6 we recommend using connection: httpapi for NX-API.
-
This option will be removed in a release after 2022-06-01.
- -

-
A dict object containing connection details.
-
-
- auth_pass - -
- string -
-
- -
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
-
-
- authorize - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
-
-
- host - -
- string -
-
- -
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
-
-
- password - -
- string -
-
- -
Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for either cli or nxapi transports. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
-
-
- port - -
- integer -
-
- -
Specifies the port to use when building the connection to the remote device. This value applies to either cli or nxapi. The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, http=80, https=443).
-
-
- ssh_keyfile - -
- string -
-
- -
Specifies the SSH key to use to authenticate the connection to the remote device. This argument is only used for the cli transport. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
-
-
- timeout - -
- integer -
-
- -
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. NX-API can be slow to return on long-running commands (sh mac, sh bgp, etc).
-
-
- transport - -
- string -
-
-
    Choices: -
  • cli ←
  • -
  • nxapi
  • -
-
-
Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh) or nxapi.
-
-
- use_proxy - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
If no, the environment variables http_proxy and https_proxy will be ignored.
-
-
- use_ssl - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Configures the transport to use SSL if set to yes only when the transport=nxapi, otherwise this value is ignored.
-
-
- username - -
- string -
-
- -
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate either the CLI login or the nxapi authentication depending on which transport is used. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If the transport argument is not nxapi, this value is ignored.
-
state @@ -394,7 +160,7 @@ Parameters
+
suppress_arp @@ -413,7 +179,7 @@ Parameters
+
suppress_arp_disable @@ -432,7 +198,7 @@ Parameters
+
vni diff --git a/docs/cisco.nxos.nxos_zone_zoneset_module.rst b/docs/cisco.nxos.nxos_zone_zoneset_module.rst index 4d0c320b7..95ef4972a 100644 --- a/docs/cisco.nxos.nxos_zone_zoneset_module.rst +++ b/docs/cisco.nxos.nxos_zone_zoneset_module.rst @@ -426,54 +426,54 @@ Examples - name: Test that zone/zoneset module works cisco.nxos.nxos_zone_zoneset: zone_zoneset_details: - - mode: enhanced - vsan: 22 - zone: - - members: - - pwwn: 11:11:11:11:11:11:11:11 - - device_alias: test123 - - pwwn: 61:61:62:62:12:12:12:12 - remove: true - name: zoneA - - members: - - pwwn: 10:11:11:11:11:11:11:11 - - pwwn: 62:62:62:62:21:21:21:21 - name: zoneB - - name: zoneC - remove: true - zoneset: - - action: activate - members: - - name: zoneA - - name: zoneB - - name: zoneC - remove: true - name: zsetname1 - - action: deactivate - name: zsetTestExtra - remove: true - - mode: basic - smart_zoning: true - vsan: 21 - zone: - - members: - - devtype: both - pwwn: 11:11:11:11:11:11:11:11 - - pwwn: 62:62:62:62:12:12:12:12 - - devtype: both - pwwn: 92:62:62:62:12:12:1a:1a - remove: true - name: zone21A - - members: - - pwwn: 10:11:11:11:11:11:11:11 - - pwwn: 62:62:62:62:21:21:21:21 - name: zone21B - zoneset: - - action: activate - members: - - name: zone21A - - name: zone21B - name: zsetname212 + - mode: enhanced + vsan: 22 + zone: + - members: + - pwwn: 31314874576271 + - device_alias: test123 + - pwwn: '61:61:62:62:12:12:12:12' + remove: true + name: zoneA + - members: + - pwwn: 28515514576271 + - pwwn: '62:62:62:62:21:21:21:21' + name: zoneB + - name: zoneC + remove: true + zoneset: + - action: activate + members: + - name: zoneA + - name: zoneB + - name: zoneC + remove: true + name: zsetname1 + - action: deactivate + name: zsetTestExtra + remove: true + - mode: basic + smart_zoning: true + vsan: 21 + zone: + - members: + - devtype: both + pwwn: 31314874576271 + - pwwn: '62:62:62:62:12:12:12:12' + - devtype: both + pwwn: '92:62:62:62:12:12:1a:1a' + remove: true + name: zone21A + - members: + - pwwn: 28515514576271 + - pwwn: '62:62:62:62:21:21:21:21' + name: zone21B + zoneset: + - action: activate + members: + - name: zone21A + - name: zone21B + name: zsetname212 diff --git a/galaxy.yml b/galaxy.yml index 76aec2b24..be9792ba9 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,8 +1,7 @@ ---- authors: - Ansible Network Community (ansible-network) dependencies: - "ansible.netcommon": ">=2.6.1" + "ansible.netcommon": ">=6.0.0" license_file: LICENSE name: nxos namespace: cisco @@ -11,6 +10,4 @@ readme: README.md repository: https://github.com/ansible-collections/cisco.nxos issues: https://github.com/ansible-collections/cisco.nxos/issues tags: [cisco, nxos, networking, nxapi, netconf] -# NOTE(pabelanger): We create an empty version key to keep ansible-galaxy -# happy. We dynamically inject version info based on git information. -version: null +version: 6.0.2 diff --git a/tests/unit/modules/network/nxos/storage/__init__.py b/meta/__init__.py similarity index 100% rename from tests/unit/modules/network/nxos/storage/__init__.py rename to meta/__init__.py diff --git a/meta/runtime.yml b/meta/runtime.yml index 87a44f8fc..ae5586276 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -1,422 +1,11 @@ --- -requires_ansible: ">=2.9.10" +requires_ansible: ">=2.14.0" plugin_routing: - action: - nxos_aaa_server: - redirect: cisco.nxos.nxos - aaa_server: - redirect: cisco.nxos.nxos - nxos_aaa_server_host: - redirect: cisco.nxos.nxos - aaa_server_host: - redirect: cisco.nxos.nxos - nxos_acl: - redirect: cisco.nxos.nxos - acl: - redirect: cisco.nxos.nxos - nxos_acl_interface: - redirect: cisco.nxos.nxos - acl_interface: - redirect: cisco.nxos.nxos - nxos_acl_interfaces: - redirect: cisco.nxos.nxos - acl_interfaces: - redirect: cisco.nxos.nxos - nxos_acls: - redirect: cisco.nxos.nxos - acls: - redirect: cisco.nxos.nxos - nxos_banner: - redirect: cisco.nxos.nxos - banner: - redirect: cisco.nxos.nxos - nxos_bfd_global: - redirect: cisco.nxos.nxos - bfd_global: - redirect: cisco.nxos.nxos - nxos_bfd_interfaces: - redirect: cisco.nxos.nxos - bfd_interfaces: - redirect: cisco.nxos.nxos - nxos_bgp: - redirect: cisco.nxos.nxos - bgp: - redirect: cisco.nxos.nxos - nxos_bgp_af: - redirect: cisco.nxos.nxos - bgp_af: - redirect: cisco.nxos.nxos - nxos_bgp_neighbor: - redirect: cisco.nxos.nxos - bgp_neighbor: - redirect: cisco.nxos.nxos - nxos_bgp_neighbor_af: - redirect: cisco.nxos.nxos - bgp_neighbor_af: - redirect: cisco.nxos.nxos - nxos_command: - redirect: cisco.nxos.nxos - command: - redirect: cisco.nxos.nxos - nxos_config: - redirect: cisco.nxos.nxos - config: - redirect: cisco.nxos.nxos - nxos_devicealias: - redirect: cisco.nxos.nxos - devicealias: - redirect: cisco.nxos.nxos - nxos_evpn_global: - redirect: cisco.nxos.nxos - evpn_global: - redirect: cisco.nxos.nxos - nxos_evpn_vni: - redirect: cisco.nxos.nxos - evpn_vni: - redirect: cisco.nxos.nxos - nxos_facts: - redirect: cisco.nxos.nxos - facts: - redirect: cisco.nxos.nxos - nxos_feature: - redirect: cisco.nxos.nxos - feature: - redirect: cisco.nxos.nxos - nxos_gir: - redirect: cisco.nxos.nxos - gir: - redirect: cisco.nxos.nxos - nxos_gir_profile_management: - redirect: cisco.nxos.nxos - gir_profile_management: - redirect: cisco.nxos.nxos - nxos_hostname: - redirect: cisco.nxos.nxos - hostname: - redirect: cisco.nxos.nxos - nxos_hsrp: - redirect: cisco.nxos.nxos - hsrp: - redirect: cisco.nxos.nxos - nxos_hsrp_interfaces: - redirect: cisco.nxos.nxos - hsrp_interfaces: - redirect: cisco.nxos.nxos - nxos_igmp: - redirect: cisco.nxos.nxos - igmp: - redirect: cisco.nxos.nxos - nxos_igmp_interface: - redirect: cisco.nxos.nxos - igmp_interface: - redirect: cisco.nxos.nxos - nxos_igmp_snooping: - redirect: cisco.nxos.nxos - igmp_snooping: - redirect: cisco.nxos.nxos - nxos_install_os: - redirect: cisco.nxos.nxos - install_os: - redirect: cisco.nxos.nxos - nxos_interface: - redirect: cisco.nxos.nxos - interface: - redirect: cisco.nxos.nxos - nxos_interface_ospf: - redirect: cisco.nxos.nxos - interface_ospf: - redirect: cisco.nxos.nxos - nxos_interfaces: - redirect: cisco.nxos.nxos - interfaces: - redirect: cisco.nxos.nxos - nxos_l2_interface: - redirect: cisco.nxos.nxos - l2_interface: - redirect: cisco.nxos.nxos - nxos_l2_interfaces: - redirect: cisco.nxos.nxos - l2_interfaces: - redirect: cisco.nxos.nxos - nxos_l3_interface: - redirect: cisco.nxos.nxos - l3_interface: - redirect: cisco.nxos.nxos - nxos_l3_interfaces: - redirect: cisco.nxos.nxos - l3_interfaces: - redirect: cisco.nxos.nxos - nxos_lacp: - redirect: cisco.nxos.nxos - lacp: - redirect: cisco.nxos.nxos - nxos_lacp_interfaces: - redirect: cisco.nxos.nxos - lacp_interfaces: - redirect: cisco.nxos.nxos - nxos_lag_interfaces: - redirect: cisco.nxos.nxos - lag_interfaces: - redirect: cisco.nxos.nxos - nxos_linkagg: - redirect: cisco.nxos.nxos - linkagg: - redirect: cisco.nxos.nxos - nxos_lldp: - redirect: cisco.nxos.nxos - lldp: - redirect: cisco.nxos.nxos - nxos_lldp_global: - redirect: cisco.nxos.nxos - lldp_global: - redirect: cisco.nxos.nxos - nxos_lldp_interfaces: - redirect: cisco.nxos.nxos - lldp_interfaces: - redirect: cisco.nxos.nxos - nxos_logging: - redirect: cisco.nxos.nxos - logging: - redirect: cisco.nxos.nxos - nxos_logging_global: - redirect: cisco.nxos.nxos - logging_global: - redirect: cisco.nxos.nxos - nxos_ntp_global: - redirect: cisco.nxos.nxos - ntp_global: - redirect: cisco.nxos.nxos - nxos_ntp: - redirect: cisco.nxos.nxos - ntp: - redirect: cisco.nxos.nxos - nxos_ntp_auth: - redirect: cisco.nxos.nxos - ntp_auth: - redirect: cisco.nxos.nxos - nxos_ntp_options: - redirect: cisco.nxos.nxos - ntp_options: - redirect: cisco.nxos.nxos - nxos_nxapi: - redirect: cisco.nxos.nxos - nxapi: - redirect: cisco.nxos.nxos - nxos_ospf_interfaces: - redirect: cisco.nxos.nxos - ospf_interfaces: - redirect: cisco.nxos.nxos - nxos_ospf: - redirect: cisco.nxos.nxos - ospf: - redirect: cisco.nxos.nxos - nxos_ospf_vrf: - redirect: cisco.nxos.nxos - ospf_vrf: - redirect: cisco.nxos.nxos - nxos_bgp_global: - redirect: cisco.nxos.nxos - bgp_global: - redirect: cisco.nxos.nxos - nxos_bgp_address_family: - redirect: cisco.nxos.nxos - bgp_address_family: - redirect: cisco.nxos.nxos - nxos_ospfv2: - redirect: cisco.nxos.nxos - ospfv2: - redirect: cisco.nxos.nxos - nxos_ospfv3: - redirect: cisco.nxos.nxos - ospfv3: - redirect: cisco.nxos.nxos - nxos_overlay_global: - redirect: cisco.nxos.nxos - overlay_global: - redirect: cisco.nxos.nxos - nxos_pim: - redirect: cisco.nxos.nxos - pim: - redirect: cisco.nxos.nxos - nxos_pim_interface: - redirect: cisco.nxos.nxos - pim_interface: - redirect: cisco.nxos.nxos - nxos_pim_rp_address: - redirect: cisco.nxos.nxos - pim_rp_address: - redirect: cisco.nxos.nxos - nxos_ping: - redirect: cisco.nxos.nxos - ping: - redirect: cisco.nxos.nxos - nxos_prefix_lists: - redirect: cisco.nxos.nxos - prefix_lists: - redirect: cisco.nxos.nxos - nxos_reboot: - redirect: cisco.nxos.nxos - reboot: - redirect: cisco.nxos.nxos - nxos_rollback: - redirect: cisco.nxos.nxos - rollback: - redirect: cisco.nxos.nxos - nxos_route_maps: - redirect: cisco.nxos.nxos - route_maps: - redirect: cisco.nxos.nxos - nxos_rpm: - redirect: cisco.nxos.nxos - rpm: - redirect: cisco.nxos.nxos - nxos_smu: - redirect: cisco.nxos.nxos - smu: - redirect: cisco.nxos.nxos - nxos_snapshot: - redirect: cisco.nxos.nxos - snapshot: - redirect: cisco.nxos.nxos - nxos_snmp_community: - redirect: cisco.nxos.nxos - snmp_community: - redirect: cisco.nxos.nxos - nxos_snmp_contact: - redirect: cisco.nxos.nxos - snmp_contact: - redirect: cisco.nxos.nxos - nxos_snmp_host: - redirect: cisco.nxos.nxos - snmp_host: - redirect: cisco.nxos.nxos - nxos_snmp_location: - redirect: cisco.nxos.nxos - snmp_location: - redirect: cisco.nxos.nxos - nxos_snmp_server: - redirect: cisco.nxos.nxos - snmp_server: - redirect: cisco.nxos.nxos - nxos_snmp_traps: - redirect: cisco.nxos.nxos - snmp_traps: - redirect: cisco.nxos.nxos - nxos_snmp_user: - redirect: cisco.nxos.nxos - snmp_user: - redirect: cisco.nxos.nxos - nxos_static_route: - redirect: cisco.nxos.nxos - static_route: - redirect: cisco.nxos.nxos - nxos_static_routes: - redirect: cisco.nxos.nxos - static_routes: - redirect: cisco.nxos.nxos - nxos_system: - redirect: cisco.nxos.nxos - system: - redirect: cisco.nxos.nxos - nxos_telemetry: - redirect: cisco.nxos.nxos - telemetry: - redirect: cisco.nxos.nxos - nxos_udld: - redirect: cisco.nxos.nxos - udld: - redirect: cisco.nxos.nxos - nxos_udld_interface: - redirect: cisco.nxos.nxos - udld_interface: - redirect: cisco.nxos.nxos - nxos_user: - redirect: cisco.nxos.nxos - user: - redirect: cisco.nxos.nxos - nxos_vlan: - redirect: cisco.nxos.nxos - vlan: - redirect: cisco.nxos.nxos - nxos_vlans: - redirect: cisco.nxos.nxos - vlans: - redirect: cisco.nxos.nxos - nxos_vpc: - redirect: cisco.nxos.nxos - vpc: - redirect: cisco.nxos.nxos - nxos_vpc_interface: - redirect: cisco.nxos.nxos - vpc_interface: - redirect: cisco.nxos.nxos - nxos_vrf: - redirect: cisco.nxos.nxos - vrf: - redirect: cisco.nxos.nxos - nxos_vrf_af: - redirect: cisco.nxos.nxos - vrf_af: - redirect: cisco.nxos.nxos - nxos_vrf_interface: - redirect: cisco.nxos.nxos - vrf_interface: - redirect: cisco.nxos.nxos - nxos_vrrp: - redirect: cisco.nxos.nxos - vrrp: - redirect: cisco.nxos.nxos - nxos_vsan: - redirect: cisco.nxos.nxos - vsan: - redirect: cisco.nxos.nxos - nxos_vtp_domain: - redirect: cisco.nxos.nxos - vtp_domain: - redirect: cisco.nxos.nxos - nxos_vtp_password: - redirect: cisco.nxos.nxos - vtp_password: - redirect: cisco.nxos.nxos - nxos_vtp_version: - redirect: cisco.nxos.nxos - vtp_version: - redirect: cisco.nxos.nxos - nxos_vxlan_vtep: - redirect: cisco.nxos.nxos - vxlan_vtep: - redirect: cisco.nxos.nxos - nxos_vxlan_vtep_vni: - redirect: cisco.nxos.nxos - vxlan_vtep_vni: - redirect: cisco.nxos.nxos - nxos_zone_zoneset: - redirect: cisco.nxos.nxos - zone_zoneset: - redirect: cisco.nxos.nxos modules: aaa_server: redirect: cisco.nxos.nxos_aaa_server aaa_server_host: redirect: cisco.nxos.nxos_aaa_server_host - acl: - redirect: cisco.nxos.nxos_acl - deprecation: - removal_date: "2022-06-01" - warning_text: See the plugin documentation for more details - nxos_acl: - deprecation: - removal_date: "2022-06-01" - warning_text: See the plugin documentation for more details - acl_interface: - redirect: cisco.nxos.nxos_acl_interface - deprecation: - removal_date: "2022-06-01" - warning_text: See the plugin documentation for more details - nxos_acl_interface: - deprecation: - removal_date: "2022-06-01" - warning_text: See the plugin documentation for more details acl_interfaces: redirect: cisco.nxos.nxos_acl_interfaces acls: @@ -427,42 +16,6 @@ plugin_routing: redirect: cisco.nxos.nxos_bfd_global bfd_interfaces: redirect: cisco.nxos.nxos_bfd_interfaces - bgp: - redirect: cisco.nxos.nxos_bgp - deprecation: - removal_date: "2023-01-27" - warning_text: See the plugin documentation for more details - nxos_bgp: - deprecation: - removal_date: "2023-01-27" - warning_text: See the plugin documentation for more details - bgp_af: - redirect: cisco.nxos.nxos_bgp_af - deprecation: - removal_date: "2023-02-24" - warning_text: See the plugin documentation for more details - nxos_bgp_af: - deprecation: - removal_date: "2023-02-24" - warning_text: See the plugin documentation for more details - bgp_neighbor: - redirect: cisco.nxos.nxos_bgp_neighbor - deprecation: - removal_date: "2023-01-27" - warning_text: See the plugin documentation for more details - nxos_bgp_neighbor: - deprecation: - removal_date: "2023-01-27" - warning_text: See the plugin documentation for more details - bgp_neighbor_af: - redirect: cisco.nxos.nxos_bgp_neighbor_af - deprecation: - removal_date: "2023-02-24" - warning_text: See the plugin documentation for more details - nxos_bgp_neighbor_af: - deprecation: - removal_date: "2023-02-24" - warning_text: See the plugin documentation for more details command: redirect: cisco.nxos.nxos_command config: @@ -497,46 +50,10 @@ plugin_routing: redirect: cisco.nxos.nxos_igmp_snooping install_os: redirect: cisco.nxos.nxos_install_os - interface: - redirect: cisco.nxos.nxos_interface - deprecation: - removal_date: "2022-06-01" - warning_text: See the plugin documentation for more details - nxos_interface: - deprecation: - removal_date: "2022-06-01" - warning_text: See the plugin documentation for more details - interface_ospf: - redirect: cisco.nxos.nxos_interface_ospf - deprecation: - removal_date: "2022-10-26" - warning_text: See the plugin documentation for more details - nxos_interface_ospf: - deprecation: - removal_date: "2022-10-26" - warning_text: See the plugin documentation for more details interfaces: redirect: cisco.nxos.nxos_interfaces - l2_interface: - redirect: cisco.nxos.nxos_l2_interface - deprecation: - removal_date: "2022-06-01" - warning_text: See the plugin documentation for more details - nxos_l2_interface: - deprecation: - removal_date: "2022-06-01" - warning_text: See the plugin documentation for more details l2_interfaces: redirect: cisco.nxos.nxos_l2_interfaces - l3_interface: - redirect: cisco.nxos.nxos_l3_interface - deprecation: - removal_date: "2022-06-01" - warning_text: See the plugin documentation for more details - nxos_l3_interface: - deprecation: - removal_date: "2022-06-01" - warning_text: See the plugin documentation for more details l3_interfaces: redirect: cisco.nxos.nxos_l3_interfaces lacp: @@ -545,24 +62,6 @@ plugin_routing: redirect: cisco.nxos.nxos_lacp_interfaces lag_interfaces: redirect: cisco.nxos.nxos_lag_interfaces - linkagg: - redirect: cisco.nxos.nxos_linkagg - deprecation: - removal_date: "2022-06-01" - warning_text: See the plugin documentation for more details - nxos_linkagg: - deprecation: - removal_date: "2022-06-01" - warning_text: See the plugin documentation for more details - lldp: - redirect: cisco.nxos.nxos_lldp - deprecation: - removal_date: "2022-06-01" - warning_text: See the plugin documentation for more details - nxos_lldp: - deprecation: - removal_date: "2022-06-01" - warning_text: See the plugin documentation for more details lldp_global: redirect: cisco.nxos.nxos_lldp_global lldp_interfaces: @@ -611,24 +110,6 @@ plugin_routing: redirect: cisco.nxos.nxos_nxapi ospf_interfaces: redirect: cisco.nxos.nxos_ospf_interfaces - ospf: - redirect: cisco.nxos.nxos_ospf - deprecation: - removal_date: "2022-06-01" - warning_text: See the plugin documentation for more details - nxos_ospf: - deprecation: - removal_date: "2022-06-01" - warning_text: See the plugin documentation for more details - ospf_vrf: - redirect: cisco.nxos.nxos_ospf_vrf - deprecation: - removal_date: "2022-10-01" - warning_text: See the plugin documentation for more details - nxos_ospf_vrf: - deprecation: - removal_date: "2022-10-01" - warning_text: See the plugin documentation for more details bgp_global: redirect: cisco.nxos.nxos_bgp_global bgp_address_family: @@ -657,15 +138,6 @@ plugin_routing: redirect: cisco.nxos.nxos_route_maps rpm: redirect: cisco.nxos.nxos_rpm - smu: - redirect: cisco.nxos.nxos_smu - deprecation: - removal_date: "2022-10-01" - warning_text: See the plugin documentation for more details - nxos_smu: - deprecation: - removal_date: "2022-10-01" - warning_text: See the plugin documentation for more details snapshot: redirect: cisco.nxos.nxos_snapshot snmp_community: @@ -724,15 +196,6 @@ plugin_routing: deprecation: removal_date: "2024-01-01" warning_text: See the plugin documentation for more details - static_route: - redirect: cisco.nxos.nxos_static_route - deprecation: - removal_date: "2022-06-01" - warning_text: See the plugin documentation for more details - nxos_static_route: - deprecation: - removal_date: "2022-06-01" - warning_text: See the plugin documentation for more details static_routes: redirect: cisco.nxos.nxos_static_routes system: @@ -745,15 +208,6 @@ plugin_routing: redirect: cisco.nxos.nxos_udld_interface user: redirect: cisco.nxos.nxos_user - vlan: - redirect: cisco.nxos.nxos_vlan - deprecation: - removal_date: "2022-06-01" - warning_text: See the plugin documentation for more details - nxos_vlan: - deprecation: - removal_date: "2022-06-01" - warning_text: See the plugin documentation for more details vlans: redirect: cisco.nxos.nxos_vlans vpc: diff --git a/platform_guide.rst b/platform_guide.rst new file mode 100644 index 000000000..250854561 --- /dev/null +++ b/platform_guide.rst @@ -0,0 +1,167 @@ +.. _nxos_platform_options: + +*************************************** +NXOS Platform Options +*************************************** + +The `Cisco NXOS `_ supports multiple connections. This page offers details on how each connection works in Ansible and how to use it. + +.. contents:: + :local: + +Connections available +================================================================================ + +.. table:: + :class: documentation-table + + ==================== ========================================== ========================= + .. CLI NX-API + ==================== ========================================== ========================= + Protocol SSH HTTP(S) + + Credentials uses SSH keys / SSH-agent if present uses HTTPS certificates if + present + accepts ``-u myuser -k`` if using password + + Indirect Access by a bastion (jump host) by a web proxy + + Connection Settings ``ansible_connection:`` ``ansible_connection:`` + ``ansible.netcommon.network_cli`` ``ansible.netcommon.httpapi`` + + Enable Mode supported: use ``ansible_become: true`` not supported by NX-API + with ``ansible_become_method: enable`` + and ``ansible_become_password:`` + + Returned Data Format ``stdout[0].`` ``stdout[0].messages[0].`` + ==================== ========================================== ========================= + + +The ``ansible_connection: local`` has been deprecated. Please use ``ansible_connection: ansible.netcommon.network_cli`` or ``ansible_connection: ansible.netcommon.httpapi`` instead. + +Using CLI in Ansible +==================== + +Example CLI ``group_vars/nxos.yml`` +----------------------------------- + +.. code-block:: yaml + + ansible_connection: ansible.netcommon.network_cli + ansible_network_os: cisco.nxos.nxos + ansible_user: myuser + ansible_password: !vault... + ansible_become: true + ansible_become_method: enable + ansible_become_password: !vault... + ansible_ssh_common_args: '-o ProxyCommand="ssh -W %h:%p -q bastion01"' + + +- If you are using SSH keys (including an ssh-agent) you can remove the ``ansible_password`` configuration. +- If you are accessing your host directly (not through a bastion/jump host) you can remove the ``ansible_ssh_common_args`` configuration. +- If you are accessing your host through a bastion/jump host, you cannot include your SSH password in the ``ProxyCommand`` directive. To prevent secrets from leaking out (for example in ``ps`` output), SSH does not support providing passwords through environment variables. + +Example CLI task +---------------- + +.. code-block:: yaml + + - name: Backup current switch config (nxos) + cisco.nxos.nxos_config: + backup: yes + register: backup_nxos_location + when: ansible_network_os == 'cisco.nxos.nxos' + + + +Using NX-API in Ansible +======================= + +Enabling NX-API +--------------- + +Before you can use NX-API to connect to a switch, you must enable NX-API. To enable NX-API on a new switch through Ansible, use the ``nxos_nxapi`` module through the CLI connection. Set up group_vars/nxos.yml just like in the CLI example above, then run a playbook task like this: + +.. code-block:: yaml + + - name: Enable NX-API + cisco.nxos.nxos_nxapi: + enable_http: yes + enable_https: yes + when: ansible_network_os == 'cisco.nxos.nxos' + +To find out more about the options for enabling HTTP/HTTPS and local http see the :ref:`nxos_nxapi ` module documentation. + +Once NX-API is enabled, change your ``group_vars/nxos.yml`` to use the NX-API connection. + +Example NX-API ``group_vars/nxos.yml`` +-------------------------------------- + +.. code-block:: yaml + + ansible_connection: ansible.netcommon.httpapi + ansible_network_os: cisco.nxos.nxos + ansible_user: myuser + ansible_password: !vault... + proxy_env: + http_proxy: http://proxy.example.com:8080 + +- If you are accessing your host directly (not through a web proxy) you can remove the ``proxy_env`` configuration. +- If you are accessing your host through a web proxy using ``https``, change ``http_proxy`` to ``https_proxy``. + + +Example NX-API task +------------------- + +.. code-block:: yaml + + - name: Backup current switch config (nxos) + cisco.nxos.nxos_config: + backup: yes + register: backup_nxos_location + environment: "{{ proxy_env }}" + when: ansible_network_os == 'cisco.nxos.nxos' + +In this example the ``proxy_env`` variable defined in ``group_vars`` gets passed to the ``environment`` option of the module used in the task. + +Warning +-------- +Never store passwords in plain text. We recommend using SSH keys to authenticate SSH connections. Ansible supports ssh-agent to manage your SSH keys. If you must use passwords to authenticate SSH connections, we recommend encrypting them with Ansible Vault. + +Cisco Nexus platform support matrix +=================================== + +The following platforms and software versions have been certified by Cisco to work with this version of Ansible. + +.. table:: Platform / Software Minimum Requirements + :align: center + + =================== ===================== + Supported Platforms Minimum NX-OS Version + =================== ===================== + Cisco Nexus N3k 7.0(3)I2(5) and later + Cisco Nexus N9k 7.0(3)I2(5) and later + Cisco Nexus N5k 7.3(0)N1(1) and later + Cisco Nexus N6k 7.3(0)N1(1) and later + Cisco Nexus N7k 7.3(0)D1(1) and later + Cisco Nexus MDS 8.4(1) and later (Please see individual module documentation for compatibility) + =================== ===================== + +.. table:: Platform Models + :align: center + + ======== ============================================== + Platform Description + ======== ============================================== + N3k Support includes N30xx, N31xx and N35xx models + N5k Support includes all N5xxx models + N6k Support includes all N6xxx models + N7k Support includes all N7xxx models + N9k Support includes all N9xxx models + MDS Support includes all MDS 9xxx models + ======== ============================================== + +Notes +----- + +`Setting Timeout Option `_ diff --git a/plugins/action/nxos.py b/plugins/action/nxos.py index d113c75c9..e57c08aeb 100644 --- a/plugins/action/nxos.py +++ b/plugins/action/nxos.py @@ -18,24 +18,15 @@ # from __future__ import absolute_import, division, print_function -__metaclass__ = type -import copy -import re -import sys +__metaclass__ = type -from ansible import constants as C +from ansible.module_utils.connection import Connection +from ansible.utils.display import Display from ansible_collections.ansible.netcommon.plugins.action.network import ( ActionModule as ActionNetworkModule, ) -from ansible.module_utils.connection import Connection -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - load_provider, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_provider_spec, -) -from ansible.utils.display import Display + display = Display() @@ -45,21 +36,18 @@ def run(self, tmp=None, task_vars=None): del tmp # tmp no longer has any effect module_name = self._task.action.split(".")[-1] - self._config_module = ( - True if module_name in ["nxos_config", "config"] else False - ) + self._config_module = True if module_name in ["nxos_config", "config"] else False persistent_connection = self._play_context.connection.split(".")[-1] warnings = [] - if ( - self._play_context.connection in ("httpapi", "local") - or self._task.args.get("provider", {}).get("transport") == "nxapi" - ) and module_name in ("nxos_file_copy", "nxos_nxapi"): + if (self._play_context.connection == "httpapi") and module_name in ( + "nxos_file_copy", + "nxos_nxapi", + ): return { "failed": True, - "msg": "Transport type 'nxapi' is not valid for '%s' module." - % (module_name), + "msg": f"Connection httpapi is not valid for {module_name} module.", } if module_name == "nxos_file_copy": @@ -69,174 +57,72 @@ def run(self, tmp=None, task_vars=None): if persistent_connection != "network_cli": return { "failed": True, - "msg": "Connection type must be fully qualified name for network_cli connection type, got %s" + "msg": ( + f"Connection type must be fully qualified name for " + f"network_cli connection type, got {self._play_context.connection}" + ) % self._play_context.connection, } conn = Connection(self._connection.socket_path) + persistent_command_timeout = conn.get_option("persistent_command_timeout") file_pull = self._task.args.get("file_pull", False) - file_pull_timeout = self._task.args.get("file_pull_timeout", 300) + file_pull_timeout = self._task.args.get("file_pull_timeout") connect_ssh_port = self._task.args.get("connect_ssh_port", 22) if file_pull: - conn.set_option( - "persistent_command_timeout", file_pull_timeout - ) + # if file_pull_timeout is explicitly set, use that + if file_pull_timeout: + conn.set_option("persistent_command_timeout", file_pull_timeout) + # if file_pull_timeout is not set and command_timeout < 300s, bump to 300s. + elif persistent_command_timeout < 300: + conn.set_option("persistent_command_timeout", 300) conn.set_option("port", connect_ssh_port) if module_name == "nxos_install_os": connection = self._connection - if connection.transport == "local": - persistent_command_timeout = C.PERSISTENT_COMMAND_TIMEOUT - persistent_connect_timeout = C.PERSISTENT_CONNECT_TIMEOUT - else: - persistent_command_timeout = connection.get_option( - "persistent_command_timeout" - ) - persistent_connect_timeout = connection.get_option( - "persistent_connect_timeout" - ) + persistent_command_timeout = connection.get_option( + "persistent_command_timeout", + ) + persistent_connect_timeout = connection.get_option( + "persistent_connect_timeout", + ) display.vvvv( - "PERSISTENT_COMMAND_TIMEOUT is %s" - % str(persistent_command_timeout), + f"PERSISTENT_COMMAND_TIMEOUT is {persistent_command_timeout}", self._play_context.remote_addr, ) display.vvvv( - "PERSISTENT_CONNECT_TIMEOUT is %s" - % str(persistent_connect_timeout), + f"PERSISTENT_CONNECT_TIMEOUT is %s {persistent_connect_timeout}", self._play_context.remote_addr, ) - if ( - persistent_command_timeout < 600 - or persistent_connect_timeout < 600 - ): - msg = ( - "PERSISTENT_COMMAND_TIMEOUT and PERSISTENT_CONNECT_TIMEOUT" - ) + if persistent_command_timeout < 600 or persistent_connect_timeout < 600: + msg = "PERSISTENT_COMMAND_TIMEOUT and PERSISTENT_CONNECT_TIMEOUT" msg += " must be set to 600 seconds or higher when using nxos_install_os module." msg += " Current persistent_command_timeout setting:" + str( - persistent_command_timeout + persistent_command_timeout, ) msg += " Current persistent_connect_timeout setting:" + str( - persistent_connect_timeout + persistent_connect_timeout, ) return {"failed": True, "msg": msg} if persistent_connection in ("network_cli", "httpapi"): - provider = self._task.args.get("provider", {}) - if any(provider.values()): - display.warning( - "provider is unnecessary when using %s and will be ignored" - % self._play_context.connection - ) - del self._task.args["provider"] - if module_name == "nxos_gir": conn = Connection(self._connection.socket_path) persistent_command_timeout = conn.get_option( - "persistent_command_timeout" + "persistent_command_timeout", ) gir_timeout = 200 if persistent_command_timeout < gir_timeout: conn.set_option("persistent_command_timeout", gir_timeout) - msg = ( - "timeout value extended to %ss for nxos_gir" - % gir_timeout - ) + msg = f"timeout value extended to %ss for nxos_gir {gir_timeout}" display.warning(msg) - elif self._play_context.connection == "local": - provider = load_provider(nxos_provider_spec, self._task.args) - transport = provider["transport"] or "cli" - - display.vvvv( - "connection transport is %s" % transport, - self._play_context.remote_addr, - ) - - if transport == "cli": - pc = copy.deepcopy(self._play_context) - pc.connection = "ansible.netcommon.network_cli" - pc.network_os = "cisco.nxos.nxos" - pc.remote_addr = ( - provider["host"] or self._play_context.remote_addr - ) - pc.port = int( - provider["port"] or self._play_context.port or 22 - ) - pc.remote_user = ( - provider["username"] or self._play_context.connection_user - ) - pc.password = ( - provider["password"] or self._play_context.password - ) - pc.private_key_file = ( - provider["ssh_keyfile"] - or self._play_context.private_key_file - ) - pc.become = provider["authorize"] or False - if pc.become: - pc.become_method = "enable" - pc.become_pass = provider["auth_pass"] - - connection = self._shared_loader_obj.connection_loader.get( - "ansible.netcommon.persistent", - pc, - sys.stdin, - task_uuid=self._task._uuid, - ) - - # TODO: Remove below code after ansible minimal is cut out - if connection is None: - pc.connection = "network_cli" - pc.network_os = "nxos" - connection = self._shared_loader_obj.connection_loader.get( - "persistent", pc, sys.stdin, task_uuid=self._task._uuid - ) - - display.vvv( - "using connection plugin %s (was local)" % pc.connection, - pc.remote_addr, - ) - - command_timeout = ( - int(provider["timeout"]) - if provider["timeout"] - else connection.get_option("persistent_command_timeout") - ) - connection.set_options( - direct={"persistent_command_timeout": command_timeout} - ) - - socket_path = connection.run() - display.vvvv("socket_path: %s" % socket_path, pc.remote_addr) - if not socket_path: - return { - "failed": True, - "msg": "unable to open shell. Please see: " - + "https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell", - } - - task_vars["ansible_socket"] = socket_path - - else: - self._task.args[ - "provider" - ] = ActionModule.nxapi_implementation( - provider, self._play_context - ) - warnings.append( - [ - "connection local support for this module is deprecated and will be removed in version 2.14," - " use connection either httpapi or ansible.netcommon.httpapi (whichever is applicable)" - ] - ) else: return { "failed": True, - "msg": "Connection type %s is not valid for this module" - % self._play_context.connection, + "msg": f"Connection type {self._play_context.connection} is not valid for this module", } result = super(ActionModule, self).run(task_vars=task_vars) @@ -246,32 +132,3 @@ def run(self, tmp=None, task_vars=None): else: result["warnings"] = warnings return result - - @staticmethod - def nxapi_implementation(provider, play_context): - provider["transport"] = "nxapi" - if provider.get("host") is None: - provider["host"] = play_context.remote_addr - - if provider.get("port") is None: - if provider.get("use_ssl"): - provider["port"] = 443 - else: - provider["port"] = 80 - - if provider.get("timeout") is None: - provider["timeout"] = C.PERSISTENT_COMMAND_TIMEOUT - - if provider.get("username") is None: - provider["username"] = play_context.connection_user - - if provider.get("password") is None: - provider["password"] = play_context.password - - if provider.get("use_ssl") is None: - provider["use_ssl"] = False - - if provider.get("validate_certs") is None: - provider["validate_certs"] = True - - return provider diff --git a/plugins/cliconf/nxos.py b/plugins/cliconf/nxos.py index ace8267fc..4f6393858 100644 --- a/plugins/cliconf/nxos.py +++ b/plugins/cliconf/nxos.py @@ -18,6 +18,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type DOCUMENTATION = """ @@ -54,13 +55,8 @@ NetworkConfig, dumps, ) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, -) -from ansible_collections.ansible.netcommon.plugins.plugin_utils.cliconf_base import ( - CliconfBase, - enable_mode, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import to_list +from ansible_collections.ansible.netcommon.plugins.plugin_utils.cliconf_base import CliconfBase class Cliconf(CliconfBase): @@ -88,64 +84,46 @@ def get_device_info(self): reply = self.get("show version") platform_reply = self.get("show inventory") - match_sys_ver = re.search( - r"\s+system:\s+version\s*(\S+)", reply, re.M - ) + match_sys_ver = re.search(r"\s+system:\s+version\s*(\S+)", reply, re.M) if match_sys_ver: device_info["network_os_version"] = match_sys_ver.group(1) else: - match_kick_ver = re.search( - r"\s+kickstart:\s+version\s*(\S+)", reply, re.M - ) + match_kick_ver = re.search(r"\s+kickstart:\s+version\s*(\S+)", reply, re.M) if match_kick_ver: device_info["network_os_version"] = match_kick_ver.group(1) if "network_os_version" not in device_info: - match_sys_ver = re.search( - r"\s+NXOS:\s+version\s*(\S+)", reply, re.M - ) + match_sys_ver = re.search(r"\s+NXOS:\s+version\s*(\S+)", reply, re.M) if match_sys_ver: device_info["network_os_version"] = match_sys_ver.group(1) - match_chassis_id = re.search( - r"Hardware\n\s+cisco(.+)$", reply, re.M - ) + match_chassis_id = re.search(r"Hardware\n\s+cisco(.+)$", reply, re.M) if match_chassis_id: - device_info["network_os_model"] = match_chassis_id.group( - 1 - ).strip() + device_info["network_os_model"] = match_chassis_id.group(1).strip() - match_host_name = re.search( - r"\s+Device name:\s*(\S+)", reply, re.M - ) + match_host_name = re.search(r"\s+Device name:\s*(\S+)", reply, re.M) if match_host_name: device_info["network_os_hostname"] = match_host_name.group(1) - match_isan_file_name = re.search( - r"\s+system image file is:\s*(\S+)", reply, re.M - ) + match_isan_file_name = re.search(r"\s+system image file is:\s*(\S+)", reply, re.M) if match_isan_file_name: device_info["network_os_image"] = match_isan_file_name.group(1) else: match_kick_file_name = re.search( - r"\s+kickstart image file is:\s*(\S+)", reply, re.M + r"\s+kickstart image file is:\s*(\S+)", + reply, + re.M, ) if match_kick_file_name: - device_info[ - "network_os_image" - ] = match_kick_file_name.group(1) + device_info["network_os_image"] = match_kick_file_name.group(1) if "network_os_image" not in device_info: - match_isan_file_name = re.search( - r"\s+NXOS image file is:\s*(\S+)", reply, re.M - ) + match_isan_file_name = re.search(r"\s+NXOS image file is:\s*(\S+)", reply, re.M) if match_isan_file_name: - device_info[ - "network_os_image" - ] = match_isan_file_name.group(1) + device_info["network_os_image"] = match_isan_file_name.group(1) match_os_platform = re.search( - r'NAME: "Chassis",\s*DESCR:.*\n' r"PID:\s*(\S+)", + r'NAME: "Chassis",\s*DESCR:.*\nPID:\s*(\S+)', platform_reply, re.M, ) @@ -170,20 +148,18 @@ def get_diff( option_values = self.get_option_values() if candidate is None and device_operations["supports_generate_diff"]: - raise ValueError( - "candidate configuration is required to generate diff" - ) + raise ValueError("candidate configuration is required to generate diff") if diff_match not in option_values["diff_match"]: raise ValueError( "'match' value %s in invalid, valid values are %s" - % (diff_match, ", ".join(option_values["diff_match"])) + % (diff_match, ", ".join(option_values["diff_match"])), ) if diff_replace not in option_values["diff_replace"]: raise ValueError( "'replace' value %s in invalid, valid values are %s" - % (diff_replace, ", ".join(option_values["diff_replace"])) + % (diff_replace, ", ".join(option_values["diff_replace"])), ) # prepare candidate configuration @@ -192,34 +168,31 @@ def get_diff( if running and diff_match != "none" and diff_replace != "config": # running configuration - running_obj = NetworkConfig( - indent=2, contents=running, ignore_lines=diff_ignore_lines - ) + running_obj = NetworkConfig(indent=2, contents=running, ignore_lines=diff_ignore_lines) configdiffobjs = candidate_obj.difference( - running_obj, path=path, match=diff_match, replace=diff_replace + running_obj, + path=path, + match=diff_match, + replace=diff_replace, ) else: configdiffobjs = candidate_obj.items - diff["config_diff"] = ( - dumps(configdiffobjs, "commands") if configdiffobjs else "" - ) + diff["config_diff"] = dumps(configdiffobjs, "commands") if configdiffobjs else "" return diff - def get_config(self, source="running", format="text", flags=None): + def get_config(self, source="running", flags=None, format="text"): options_values = self.get_option_values() if format not in options_values["format"]: raise ValueError( "'format' value %s is invalid. Valid values are %s" - % (format, ",".join(options_values["format"])) + % (format, ",".join(options_values["format"])), ) lookup = {"running": "running-config", "startup": "startup-config"} if source not in lookup: - raise ValueError( - "fetching configuration from %s is not supported" % source - ) + raise ValueError("fetching configuration from %s is not supported" % source) cmd = "show {0} ".format(lookup[source]) if format and format != "text": @@ -231,14 +204,10 @@ def get_config(self, source="running", format="text", flags=None): return self.send_command(cmd) - def edit_config( - self, candidate=None, commit=True, replace=None, comment=None - ): + def edit_config(self, candidate=None, commit=True, replace=None, comment=None): resp = {} operations = self.get_device_operations() - self.check_edit_config_capability( - operations, candidate, commit, replace, comment - ) + self.check_edit_config_capability(operations, candidate, commit, replace, comment) results = [] requests = [] @@ -274,8 +243,8 @@ def get( prompt=None, answer=None, sendonly=False, - output=None, newline=True, + output=None, check_all=False, ): if output: @@ -300,9 +269,7 @@ def run_commands(self, commands=None, check_rc=True): output = cmd.pop("output", None) if output: - cmd["command"] = self._get_command_with_output( - cmd["command"], output - ) + cmd["command"] = self._get_command_with_output(cmd["command"], output) try: out = self.send_command(**cmd) @@ -316,8 +283,7 @@ def run_commands(self, commands=None, check_rc=True): out = to_text(out, errors="surrogate_or_strict").strip() except UnicodeError: raise ConnectionError( - message="Failed to decode output from %s: %s" - % (cmd, to_text(out)) + message="Failed to decode output from %s: %s" % (cmd, to_text(out)), ) try: @@ -348,7 +314,7 @@ def get_option_values(self): "format": ["text", "json"], "diff_match": ["line", "strict", "exact", "none"], "diff_replace": ["line", "block", "config"], - "output": ["text", "json"], + "output": ["text", "json", "json-pretty"], } def get_capabilities(self): @@ -370,15 +336,11 @@ def pull_file(self, command, remotepassword=None): re.compile(rb"(?i)Could not resolve hostname"), re.compile(rb"(?i)Too many authentication failures"), re.compile(rb"Access Denied"), - re.compile( - rb"(?i)Copying to\/from this server name is not permitted" - ), + re.compile(rb"(?i)Copying to\/from this server name is not permitted"), ] # set error regex for copy command - current_stderr_re = self._connection._get_terminal_std_re( - "terminal_stderr_re" - ) + current_stderr_re = self._connection._get_terminal_std_re("terminal_stderr_re") current_stderr_re.extend(possible_errors_re) # do not change the ordering of this list @@ -390,9 +352,7 @@ def pull_file(self, command, remotepassword=None): # set stdout regex for copy command to handle optional user prompts # based on different match conditions - current_stdout_re = self._connection._get_terminal_std_re( - "terminal_stdout_re" - ) + current_stdout_re = self._connection._get_terminal_std_re("terminal_stdout_re") current_stdout_re.extend(possible_prompts_re) retry = 1 @@ -407,14 +367,10 @@ def pull_file(self, command, remotepassword=None): output = self.send_command(command="y", strip_prompt=False) if possible_prompts_re[1].search(to_bytes(output)): - output = self.send_command( - command="yes", strip_prompt=False - ) + output = self.send_command(command="yes", strip_prompt=False) if possible_prompts_re[2].search(to_bytes(output)): - output = self.send_command( - command=remotepassword, strip_prompt=False - ) + output = self.send_command(command=remotepassword, strip_prompt=False) if "Copy complete" in output: file_pulled = True return file_pulled @@ -435,37 +391,34 @@ def set_cli_prompt_context(self): if out is None: raise AnsibleConnectionFailure( message="cli prompt is not identified from the last received" - " response window: %s" % self._connection._last_recv_window + " response window: %s" % self._connection._last_recv_window, ) # Match prompts ending in )# except those with (maint-mode)# config_prompt = re.compile(r"^.*\((?!maint-mode).*\)#$") - while config_prompt.match( - to_text(out, errors="surrogate_then_replace").strip() - ): - self._connection.queue_message( - "vvvv", "wrong context, sending exit to device" - ) + while config_prompt.match(to_text(out, errors="surrogate_then_replace").strip()): + self._connection.queue_message("vvvv", "wrong context, sending exit to device") self._connection.send_command("exit") out = self._connection.get_prompt() def _get_command_with_output(self, command, output): + output_re = r".+\|\s*json(?:-pretty)?$" options_values = self.get_option_values() if output not in options_values["output"]: raise ValueError( "'output' value %s is invalid. Valid values are %s" - % (output, ",".join(options_values["output"])) + % (output, ",".join(options_values["output"])), ) - if output == "json" and not command.endswith("| json"): + if output in ["json", "json-pretty"] and not re.search(output_re, command): device_info = self.get_device_info() model = device_info.get("network_os_model", "") platform = device_info.get("network_os_platform", "") if platform.startswith("DS-") and "MDS" in model: cmd = "%s | json native" % command else: - cmd = "%s | json" % command - elif output == "text" and command.endswith("| json"): + cmd = "%s | %s" % (command, output) + elif output == "text" and re.search(output_re, command): cmd = command.rsplit("|", 1)[0] else: cmd = command diff --git a/plugins/doc_fragments/nxos.py b/plugins/doc_fragments/nxos.py index 1cda905da..d3c6afe5d 100644 --- a/plugins/doc_fragments/nxos.py +++ b/plugins/doc_fragments/nxos.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import, division, print_function + __metaclass__ = type # Copyright: (c) 2015, Peter Sprygada @@ -8,112 +9,13 @@ class ModuleDocFragment(object): - # Standard files documentation fragment - DOCUMENTATION = r"""options: - provider: - description: - - B(Deprecated) - - 'Starting with Ansible 2.5 we recommend using C(connection: network_cli).' - - 'Starting with Ansible 2.6 we recommend using C(connection: httpapi) for NX-API.' - - This option will be removed in a release after 2022-06-01. - - For more information please see the U(https://docs.ansible.com/ansible/latest/network/user_guide/platform_nxos.html). - - HORIZONTALLINE - - A dict object containing connection details. - type: dict - suboptions: - host: - description: - - Specifies the DNS host name or address for connecting to the remote device - over the specified transport. The value of host is used as the destination - address for the transport. - type: str - port: - description: - - Specifies the port to use when building the connection to the remote device. This - value applies to either I(cli) or I(nxapi). The port value will default - to the appropriate transport common port if none is provided in the task. (cli=22, - http=80, https=443). - type: int - username: - description: - - Configures the username to use to authenticate the connection to the remote - device. This value is used to authenticate either the CLI login or the - nxapi authentication depending on which transport is used. If the value - is not specified in the task, the value of environment variable C(ANSIBLE_NET_USERNAME) - will be used instead. - type: str - password: - description: - - Specifies the password to use to authenticate the connection to the remote - device. This is a common argument used for either I(cli) or I(nxapi) transports. - If the value is not specified in the task, the value of environment variable - C(ANSIBLE_NET_PASSWORD) will be used instead. - type: str - authorize: - description: - - Instructs the module to enter privileged mode on the remote device before - sending any commands. If not specified, the device will attempt to execute - all commands in non-privileged mode. If the value is not specified in the - task, the value of environment variable C(ANSIBLE_NET_AUTHORIZE) will be - used instead. - type: bool - default: false - auth_pass: - description: - - Specifies the password to use if required to enter privileged mode on the - remote device. If I(authorize) is false, then this argument does nothing. - If the value is not specified in the task, the value of environment variable - C(ANSIBLE_NET_AUTH_PASS) will be used instead. - type: str - timeout: - description: - - Specifies the timeout in seconds for communicating with the network device - for either connecting or sending commands. If the timeout is exceeded before - the operation is completed, the module will error. NX-API can be slow to - return on long-running commands (sh mac, sh bgp, etc). - type: int - ssh_keyfile: - description: - - Specifies the SSH key to use to authenticate the connection to the remote - device. This argument is only used for the I(cli) transport. If the value - is not specified in the task, the value of environment variable C(ANSIBLE_NET_SSH_KEYFILE) - will be used instead. - type: str - transport: - description: - - Configures the transport connection to use when connecting to the remote - device. The transport argument supports connectivity to the device over - cli (ssh) or nxapi. - type: str - choices: - - cli - - nxapi - default: cli - use_ssl: - description: - - Configures the I(transport) to use SSL if set to C(yes) only when the C(transport=nxapi), - otherwise this value is ignored. - type: bool - default: false - validate_certs: - description: - - If C(no), SSL certificates will not be validated. This should only be used - on personally controlled sites using self-signed certificates. If the transport - argument is not nxapi, this value is ignored. - type: bool - default: False - use_proxy: - description: - - If C(no), the environment variables C(http_proxy) and C(https_proxy) will - be ignored. - type: bool - default: true + DOCUMENTATION = r"""options: {} notes: -- For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide - ` -- For more information on using Ansible to manage network devices see the :ref:`Ansible - Network Guide ` -- For more information on using Ansible to manage Cisco devices see the `Cisco integration - page `_. + - For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide + ` + - For more information on using Ansible to manage network devices see the :ref:`Ansible + Network Guide ` + - For more information on using Ansible to manage Cisco devices see the `Cisco integration + page `_. """ diff --git a/plugins/httpapi/nxos.py b/plugins/httpapi/nxos.py index be56a80ea..57421e835 100644 --- a/plugins/httpapi/nxos.py +++ b/plugins/httpapi/nxos.py @@ -3,6 +3,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type DOCUMENTATION = """ @@ -15,18 +16,14 @@ version_added: 1.0.0 """ +import collections import json import re -import collections from ansible.module_utils._text import to_text 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.plugin_utils.httpapi_base import ( - HttpApiBase, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import to_list +from ansible_collections.ansible.netcommon.plugins.plugin_utils.httpapi_base import HttpApiBase OPTIONS = { @@ -98,16 +95,17 @@ def _run_queue(self, queue, output): headers = {"Content-Type": "application/json"} response, response_data = self.connection.send( - "/ins", request, headers=headers, method="POST" + "/ins", + request, + headers=headers, + method="POST", ) try: response_data = json.loads(to_text(response_data.getvalue())) except ValueError: raise ConnectionError( - "Response was not valid JSON, got {0}".format( - to_text(response_data.getvalue()) - ) + "Response was not valid JSON, got {0}".format(to_text(response_data.getvalue())), ) results = handle_response(response_data) @@ -120,9 +118,7 @@ def get_device_info(self): device_info = {} device_info["network_os"] = "nxos" - reply, platform_reply = self.send_request( - ["show version", "show inventory"] - ) + reply, platform_reply = self.send_request(["show version", "show inventory"]) find_os_version = [ r"\s+system:\s+version\s*(\S+)", @@ -135,9 +131,7 @@ def get_device_info(self): device_info["network_os_version"] = match_ver.group(1) break - match_chassis_id = re.search( - r"Hardware\n\s+cisco\s*(\S+\s+\S+)", reply, re.M - ) + match_chassis_id = re.search(r"Hardware\n\s+cisco\s*(\S+\s+\S+)", reply, re.M) if match_chassis_id: device_info["network_os_model"] = match_chassis_id.group(1) diff --git a/plugins/module_utils/network/nxos/argspec/acl_interfaces/acl_interfaces.py b/plugins/module_utils/network/nxos/argspec/acl_interfaces/acl_interfaces.py index 64a9e7aa6..ad2d59d33 100644 --- a/plugins/module_utils/network/nxos/argspec/acl_interfaces/acl_interfaces.py +++ b/plugins/module_utils/network/nxos/argspec/acl_interfaces/acl_interfaces.py @@ -26,6 +26,7 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type diff --git a/plugins/module_utils/network/nxos/argspec/acls/acls.py b/plugins/module_utils/network/nxos/argspec/acls/acls.py index 28dfa6b0e..3618248b7 100644 --- a/plugins/module_utils/network/nxos/argspec/acls/acls.py +++ b/plugins/module_utils/network/nxos/argspec/acls/acls.py @@ -26,6 +26,7 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -65,7 +66,7 @@ class AclsArgs(object): # pylint: disable=R0903 "neq", "gt", "range", - ] + ], ], "options": { "eq": {"type": "str"}, @@ -75,13 +76,9 @@ class AclsArgs(object): # pylint: disable=R0903 "range": { "options": { "end": {"type": "str"}, - "start": { - "type": "str" - }, + "start": {"type": "str"}, }, - "required_together": [ - ["start", "end"] - ], + "required_together": [["start", "end"]], "type": "dict", }, }, @@ -90,9 +87,7 @@ class AclsArgs(object): # pylint: disable=R0903 "prefix": {"type": "str"}, "wildcard_bits": {"type": "str"}, }, - "required_together": [ - ["address", "wildcard_bits"] - ], + "required_together": [["address", "wildcard_bits"]], "type": "dict", }, "dscp": {"type": "str"}, @@ -105,145 +100,115 @@ class AclsArgs(object): # pylint: disable=R0903 "precedence": {"type": "str"}, "protocol": {"type": "str"}, "protocol_options": { - "mutually_exclusive": [ - ["icmp", "igmp", "tcp"] - ], + "mutually_exclusive": [["icmp", "igmp", "tcp"]], "options": { "icmp": { "options": { - "administratively_prohibited": { - "type": "bool" - }, - "alternate_address": { - "type": "bool" - }, - "conversion_error": { - "type": "bool" - }, - "dod_host_prohibited": { - "type": "bool" - }, - "dod_net_prohibited": { - "type": "bool" - }, + "administratively_prohibited": {"type": "bool"}, + "alternate_address": {"type": "bool"}, + "conversion_error": {"type": "bool"}, + "dod_host_prohibited": {"type": "bool"}, + "dod_net_prohibited": {"type": "bool"}, "echo": {"type": "bool"}, "echo_reply": {"type": "bool"}, - "echo_request": { - "type": "bool" - }, - "general_parameter_problem": { - "type": "bool" - }, - "host_isolated": { - "type": "bool" - }, - "host_precedence_unreachable": { - "type": "bool" - }, - "host_redirect": { - "type": "bool" - }, - "host_tos_redirect": { - "type": "bool" - }, - "host_tos_unreachable": { - "type": "bool" - }, - "host_unknown": { - "type": "bool" - }, - "host_unreachable": { - "type": "bool" - }, - "information_reply": { - "type": "bool" - }, - "information_request": { - "type": "bool" - }, + "echo_request": {"type": "bool"}, + "general_parameter_problem": {"type": "bool"}, + "host_isolated": {"type": "bool"}, + "host_precedence_unreachable": {"type": "bool"}, + "host_redirect": {"type": "bool"}, + "host_tos_redirect": {"type": "bool"}, + "host_tos_unreachable": {"type": "bool"}, + "host_unknown": {"type": "bool"}, + "host_unreachable": {"type": "bool"}, + "information_reply": {"type": "bool"}, + "information_request": {"type": "bool"}, "mask_reply": {"type": "bool"}, - "mask_request": { - "type": "bool" - }, - "message_code": { - "type": "int" - }, - "message_type": { - "type": "int" - }, - "mobile_redirect": { - "type": "bool" - }, - "net_redirect": { - "type": "bool" - }, - "net_tos_redirect": { - "type": "bool" - }, - "net_tos_unreachable": { - "type": "bool" - }, - "net_unreachable": { - "type": "bool" - }, - "network_unknown": { - "type": "bool" - }, - "no_room_for_option": { - "type": "bool" - }, - "option_missing": { - "type": "bool" + "mask_request": {"type": "bool"}, + "message_code": {"type": "int"}, + "message_type": {"type": "int"}, + "mobile_redirect": {"type": "bool"}, + "net_redirect": {"type": "bool"}, + "net_tos_redirect": {"type": "bool"}, + "net_tos_unreachable": {"type": "bool"}, + "net_unreachable": {"type": "bool"}, + "network_unknown": {"type": "bool"}, + "no_room_for_option": {"type": "bool"}, + "option_missing": {"type": "bool"}, + "packet_too_big": {"type": "bool"}, + "parameter_problem": {"type": "bool"}, + "port_unreachable": {"type": "bool"}, + "precedence_unreachable": {"type": "bool"}, + "protocol_unreachable": {"type": "bool"}, + "reassembly_timeout": {"type": "bool"}, + "redirect": {"type": "bool"}, + "router_advertisement": {"type": "bool"}, + "router_solicitation": {"type": "bool"}, + "source_quench": {"type": "bool"}, + "source_route_failed": {"type": "bool"}, + "time_exceeded": {"type": "bool"}, + "timestamp_reply": {"type": "bool"}, + "timestamp_request": {"type": "bool"}, + "traceroute": {"type": "bool"}, + "ttl_exceeded": {"type": "bool"}, + "unreachable": {"type": "bool"}, + }, + "type": "dict", + }, + "icmpv6": { + "type": "dict", + "options": { + "beyond_scope": {"type": "bool"}, + "destination_unreachable": { + "type": "bool", }, - "packet_too_big": { - "type": "bool" + "echo_reply": {"type": "bool"}, + "echo_request": {"type": "bool"}, + "fragments": {"type": "bool"}, + "header": {"type": "bool"}, + "hop_limit": {"type": "bool"}, + "mld_query": {"type": "bool"}, + "mld_reduction": {"type": "bool"}, + "mld_report": {"type": "bool"}, + "mldv2": {"type": "bool"}, + "nd_na": {"type": "bool"}, + "nd_ns": {"type": "bool"}, + "next_header": {"type": "bool"}, + "no_admin": {"type": "bool"}, + "no_route": {"type": "bool"}, + "packet_too_big": {"type": "bool"}, + "parameter_option": { + "type": "bool", }, "parameter_problem": { - "type": "bool" + "type": "bool", }, "port_unreachable": { - "type": "bool" - }, - "precedence_unreachable": { - "type": "bool" - }, - "protocol_unreachable": { - "type": "bool" + "type": "bool", }, "reassembly_timeout": { - "type": "bool" + "type": "bool", }, - "redirect": {"type": "bool"}, - "router_advertisement": { - "type": "bool" - }, - "router_solicitation": { - "type": "bool" - }, - "source_quench": { - "type": "bool" + "renum_command": {"type": "bool"}, + "renum_result": {"type": "bool"}, + "renum_seq_number": { + "type": "bool", }, - "source_route_failed": { - "type": "bool" - }, - "time_exceeded": { - "type": "bool" - }, - "timestamp_reply": { - "type": "bool" + "router_advertisement": { + "type": "bool", }, - "timestamp_request": { - "type": "bool" + "router_renumbering": { + "type": "bool", }, - "traceroute": {"type": "bool"}, - "ttl_exceeded": { - "type": "bool" + "router_solicitation": { + "type": "bool", }, - "unreachable": { - "type": "bool" + "time_exceeded": {"type": "bool"}, + "unreachable": {"type": "bool"}, + "telemetry_path": {"type": "bool"}, + "telemetry_queue": { + "type": "bool", }, }, - "type": "dict", }, "igmp": { "mutually_exclusive": [ @@ -251,23 +216,19 @@ class AclsArgs(object): # pylint: disable=R0903 "dvmrp", "host_query", "host_report", - ] + ], ], "options": { "dvmrp": {"type": "bool"}, "host_query": {"type": "bool"}, - "host_report": { - "type": "bool" - }, + "host_report": {"type": "bool"}, }, "type": "dict", }, "tcp": { "options": { "ack": {"type": "bool"}, - "established": { - "type": "bool" - }, + "established": {"type": "bool"}, "fin": {"type": "bool"}, "psh": {"type": "bool"}, "rst": {"type": "bool"}, @@ -308,9 +269,7 @@ class AclsArgs(object): # pylint: disable=R0903 "range": { "options": { "end": {"type": "str"}, - "start": { - "type": "str" - }, + "start": {"type": "str"}, }, "type": "dict", }, @@ -320,9 +279,7 @@ class AclsArgs(object): # pylint: disable=R0903 "prefix": {"type": "str"}, "wildcard_bits": {"type": "str"}, }, - "required_together": [ - ["address", "wildcard_bits"] - ], + "required_together": [["address", "wildcard_bits"]], "type": "dict", }, }, diff --git a/plugins/module_utils/network/nxos/argspec/bfd_interfaces/bfd_interfaces.py b/plugins/module_utils/network/nxos/argspec/bfd_interfaces/bfd_interfaces.py index dcc0b2dbe..6c47d2e57 100644 --- a/plugins/module_utils/network/nxos/argspec/bfd_interfaces/bfd_interfaces.py +++ b/plugins/module_utils/network/nxos/argspec/bfd_interfaces/bfd_interfaces.py @@ -23,6 +23,7 @@ ############################################# from __future__ import absolute_import, division, print_function + __metaclass__ = type """ diff --git a/plugins/module_utils/network/nxos/argspec/bgp_address_family/bgp_address_family.py b/plugins/module_utils/network/nxos/argspec/bgp_address_family/bgp_address_family.py index f5feb90a1..f77843d79 100644 --- a/plugins/module_utils/network/nxos/argspec/bgp_address_family/bgp_address_family.py +++ b/plugins/module_utils/network/nxos/argspec/bgp_address_family/bgp_address_family.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type ############################################# @@ -134,27 +135,19 @@ class Bgp_address_familyArgs(object): # pylint: disable=R0903 "parallel_paths": {"type": "int"}, "ibgp": { "type": "dict", - "options": { - "parallel_paths": {"type": "int"} - }, + "options": {"parallel_paths": {"type": "int"}}, }, "eibgp": { "type": "dict", - "options": { - "parallel_paths": {"type": "int"} - }, + "options": {"parallel_paths": {"type": "int"}}, }, "local": { "type": "dict", - "options": { - "parallel_paths": {"type": "int"} - }, + "options": {"parallel_paths": {"type": "int"}}, }, "mixed": { "type": "dict", - "options": { - "parallel_paths": {"type": "int"} - }, + "options": {"parallel_paths": {"type": "int"}}, }, }, }, @@ -212,7 +205,7 @@ class Bgp_address_familyArgs(object): # pylint: disable=R0903 "retain_all": {"type": "bool"}, "route_map": {"type": "str"}, }, - } + }, }, }, "suppress_inactive": {"type": "bool"}, @@ -232,7 +225,7 @@ class Bgp_address_familyArgs(object): # pylint: disable=R0903 "defer_time": {"type": "int"}, "maximum_defer_time": {"type": "int"}, }, - } + }, }, }, "wait_igp_convergence": {"type": "bool"}, diff --git a/plugins/module_utils/network/nxos/argspec/bgp_global/bgp_global.py b/plugins/module_utils/network/nxos/argspec/bgp_global/bgp_global.py index c3519a2be..3f17ccebc 100644 --- a/plugins/module_utils/network/nxos/argspec/bgp_global/bgp_global.py +++ b/plugins/module_utils/network/nxos/argspec/bgp_global/bgp_global.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type ############################################# @@ -143,9 +144,7 @@ class Bgp_globalArgs(object): # pylint: disable=R0903 "type": "dict", "options": { "tx_interval": {"type": "int"}, - "min_rx_interval": { - "type": "int" - }, + "min_rx_interval": {"type": "int"}, "multiplier": {"type": "int"}, }, }, @@ -160,9 +159,7 @@ class Bgp_globalArgs(object): # pylint: disable=R0903 "bmp_activate_server": {"type": "int"}, "capability": { "type": "dict", - "options": { - "suppress_4_byte_as": {"type": "bool"} - }, + "options": {"suppress_4_byte_as": {"type": "bool"}}, }, "description": {"type": "str"}, "disable_connected_check": {"type": "bool"}, @@ -179,7 +176,7 @@ class Bgp_globalArgs(object): # pylint: disable=R0903 "set": {"type": "bool"}, "route_map": {"type": "str"}, }, - } + }, }, }, "inherit": { @@ -238,6 +235,7 @@ class Bgp_globalArgs(object): # pylint: disable=R0903 ], }, "remote_as": {"type": "str"}, + "remote_as_route_map": {"type": "str"}, "remove_private_as": { "type": "dict", "options": { @@ -260,7 +258,7 @@ class Bgp_globalArgs(object): # pylint: disable=R0903 "connection_mode": { "type": "dict", "options": {"passive": {"type": "bool"}}, - } + }, }, }, "ttl_security": { @@ -276,9 +274,7 @@ class Bgp_globalArgs(object): # pylint: disable=R0903 }, "nexthop": { "type": "dict", - "options": { - "suppress_default_resolution": {"type": "bool"} - }, + "options": {"suppress_default_resolution": {"type": "bool"}}, }, "rd": { "type": "dict", @@ -383,15 +379,9 @@ class Bgp_globalArgs(object): # pylint: disable=R0903 "interval": { "type": "dict", "options": { - "tx_interval": { - "type": "int" - }, - "min_rx_interval": { - "type": "int" - }, - "multiplier": { - "type": "int" - }, + "tx_interval": {"type": "int"}, + "min_rx_interval": {"type": "int"}, + "multiplier": {"type": "int"}, }, }, }, @@ -405,9 +395,7 @@ class Bgp_globalArgs(object): # pylint: disable=R0903 "bmp_activate_server": {"type": "int"}, "capability": { "type": "dict", - "options": { - "suppress_4_byte_as": {"type": "bool"} - }, + "options": {"suppress_4_byte_as": {"type": "bool"}}, }, "description": {"type": "str"}, "disable_connected_check": {"type": "bool"}, @@ -424,7 +412,7 @@ class Bgp_globalArgs(object): # pylint: disable=R0903 "set": {"type": "bool"}, "route_map": {"type": "str"}, }, - } + }, }, }, "inherit": { @@ -483,6 +471,7 @@ class Bgp_globalArgs(object): # pylint: disable=R0903 ], }, "remote_as": {"type": "str"}, + "remote_as_route_map": {"type": "str"}, "remove_private_as": { "type": "dict", "options": { @@ -504,10 +493,8 @@ class Bgp_globalArgs(object): # pylint: disable=R0903 "options": { "connection_mode": { "type": "dict", - "options": { - "passive": {"type": "bool"} - }, - } + "options": {"passive": {"type": "bool"}}, + }, }, }, "ttl_security": { @@ -553,6 +540,7 @@ class Bgp_globalArgs(object): # pylint: disable=R0903 "choices": [ "merged", "replaced", + "overridden", "deleted", "purged", "parsed", diff --git a/plugins/module_utils/network/nxos/argspec/bgp_neighbor_address_family/bgp_neighbor_address_family.py b/plugins/module_utils/network/nxos/argspec/bgp_neighbor_address_family/bgp_neighbor_address_family.py index 48515536a..397acb1f4 100644 --- a/plugins/module_utils/network/nxos/argspec/bgp_neighbor_address_family/bgp_neighbor_address_family.py +++ b/plugins/module_utils/network/nxos/argspec/bgp_neighbor_address_family/bgp_neighbor_address_family.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type ############################################# @@ -107,7 +108,7 @@ class Bgp_neighbor_address_familyArgs(object): # pylint: disable=R0903 ], }, }, - } + }, }, }, "default_originate": { @@ -136,9 +137,7 @@ class Bgp_neighbor_address_familyArgs(object): # pylint: disable=R0903 "type": "dict", "options": { "max_prefix_limit": {"type": "int"}, - "generate_warning_threshold": { - "type": "int" - }, + "generate_warning_threshold": {"type": "int"}, "restart_interval": {"type": "int"}, "warning_only": {"type": "bool"}, }, @@ -159,6 +158,7 @@ class Bgp_neighbor_address_familyArgs(object): # pylint: disable=R0903 }, }, "rewrite_evpn_rt_asn": {"type": "bool"}, + "rewrite_rt_asn": {"type": "bool"}, "route_map": { "type": "dict", "options": { @@ -243,21 +243,15 @@ class Bgp_neighbor_address_familyArgs(object): # pylint: disable=R0903 "required": True, }, "exist_map": {"type": "str"}, - "non_exist_map": { - "type": "str" - }, + "non_exist_map": {"type": "str"}, }, }, - "advertisement_interval": { - "type": "int" - }, + "advertisement_interval": {"type": "int"}, "allowas_in": { "type": "dict", "options": { "set": {"type": "bool"}, - "max_occurences": { - "type": "int" - }, + "max_occurences": {"type": "int"}, }, }, "as_override": {"type": "bool"}, @@ -282,7 +276,7 @@ class Bgp_neighbor_address_familyArgs(object): # pylint: disable=R0903 ], }, }, - } + }, }, }, "default_originate": { @@ -292,9 +286,7 @@ class Bgp_neighbor_address_familyArgs(object): # pylint: disable=R0903 "route_map": {"type": "str"}, }, }, - "disable_peer_as_check": { - "type": "bool" - }, + "disable_peer_as_check": {"type": "bool"}, "filter_list": { "type": "dict", "options": { @@ -312,18 +304,10 @@ class Bgp_neighbor_address_familyArgs(object): # pylint: disable=R0903 "maximum_prefix": { "type": "dict", "options": { - "max_prefix_limit": { - "type": "int" - }, - "generate_warning_threshold": { - "type": "int" - }, - "restart_interval": { - "type": "int" - }, - "warning_only": { - "type": "bool" - }, + "max_prefix_limit": {"type": "int"}, + "generate_warning_threshold": {"type": "int"}, + "restart_interval": {"type": "int"}, + "warning_only": {"type": "bool"}, }, }, "next_hop_self": { @@ -333,9 +317,7 @@ class Bgp_neighbor_address_familyArgs(object): # pylint: disable=R0903 "all_routes": {"type": "bool"}, }, }, - "next_hop_third_party": { - "type": "bool" - }, + "next_hop_third_party": {"type": "bool"}, "prefix_list": { "type": "dict", "options": { @@ -343,9 +325,8 @@ class Bgp_neighbor_address_familyArgs(object): # pylint: disable=R0903 "outbound": {"type": "str"}, }, }, - "rewrite_evpn_rt_asn": { - "type": "bool" - }, + "rewrite_evpn_rt_asn": {"type": "bool"}, + "rewrite_rt_asn": {"type": "bool"}, "route_map": { "type": "dict", "options": { @@ -353,9 +334,7 @@ class Bgp_neighbor_address_familyArgs(object): # pylint: disable=R0903 "outbound": {"type": "str"}, }, }, - "route_reflector_client": { - "type": "bool" - }, + "route_reflector_client": {"type": "bool"}, "send_community": { "type": "dict", "options": { diff --git a/plugins/module_utils/network/nxos/argspec/bgp_templates/__init__.py b/plugins/module_utils/network/nxos/argspec/bgp_templates/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/module_utils/network/nxos/argspec/bgp_templates/bgp_templates.py b/plugins/module_utils/network/nxos/argspec/bgp_templates/bgp_templates.py new file mode 100644 index 000000000..22a6666e5 --- /dev/null +++ b/plugins/module_utils/network/nxos/argspec/bgp_templates/bgp_templates.py @@ -0,0 +1,314 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 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 + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the +# ansible.content_builder. +# +# Manually editing this file is not advised. +# +# To update the argspec make the desired changes +# in the module docstring and re-run +# ansible.content_builder. +# +############################################# + +""" +The arg spec for the nxos_bgp_templates module +""" + + +class Bgp_templatesArgs(object): # pylint: disable=R0903 + """The arg spec for the nxos_bgp_templates module""" + + argument_spec = { + "running_config": {"type": "str"}, + "config": { + "type": "dict", + "options": { + "as_number": {"type": "str"}, + "neighbor": { + "type": "list", + "elements": "dict", + "options": { + "name": {"type": "str"}, + "address_family": { + "type": "list", + "elements": "dict", + "options": { + "afi": { + "type": "str", + "choices": [ + "ipv4", + "ipv6", + "link-state", + "l2vpn", + ], + "required": True, + }, + "safi": { + "type": "str", + "choices": ["unicast", "multicast", "mvpn", "evpn"], + }, + "advertise_map": { + "type": "dict", + "options": { + "route_map": { + "type": "str", + "required": True, + }, + "exist_map": {"type": "str"}, + "non_exist_map": {"type": "str"}, + }, + }, + "advertisement_interval": {"type": "int"}, + "allowas_in": { + "type": "dict", + "options": { + "set": {"type": "bool"}, + "max_occurences": {"type": "int"}, + }, + }, + "as_override": {"type": "bool"}, + "capability": { + "type": "dict", + "options": { + "additional_paths": { + "type": "dict", + "options": { + "receive": { + "type": "str", + "choices": [ + "enable", + "disable", + ], + }, + "send": { + "type": "str", + "choices": [ + "enable", + "disable", + ], + }, + }, + }, + }, + }, + "default_originate": { + "type": "dict", + "options": { + "set": {"type": "bool"}, + "route_map": {"type": "str"}, + }, + }, + "disable_peer_as_check": {"type": "bool"}, + "filter_list": { + "type": "dict", + "options": { + "inbound": {"type": "str"}, + "outbound": {"type": "str"}, + }, + }, + "inherit": { + "type": "dict", + "options": {"peer_policy": {"type": "str"}}, + }, + "maximum_prefix": { + "type": "dict", + "options": { + "max_prefix_limit": {"type": "int"}, + "generate_warning_threshold": { + "type": "int", + }, + "restart_interval": {"type": "int"}, + "warning_only": {"type": "bool"}, + }, + }, + "next_hop_self": { + "type": "dict", + "options": { + "set": {"type": "bool"}, + "all_routes": {"type": "bool"}, + }, + }, + "next_hop_third_party": {"type": "bool"}, + "prefix_list": { + "type": "dict", + "options": { + "inbound": {"type": "str"}, + "outbound": {"type": "str"}, + }, + }, + "route_map": { + "type": "dict", + "options": { + "inbound": {"type": "str"}, + "outbound": {"type": "str"}, + }, + }, + "route_reflector_client": {"type": "bool"}, + "send_community": { + "type": "str", + "choices": ["standard", "extended", "both"], + }, + "soft_reconfiguration_inbound": { + "type": "dict", + "options": { + "set": {"type": "bool"}, + "always": {"type": "bool"}, + }, + }, + "soo": {"type": "str"}, + "suppress_inactive": {"type": "bool"}, + "unsuppress_map": {"type": "str"}, + "weight": {"type": "int"}, + }, + }, + "bfd": { + "type": "dict", + "options": { + "set": {"type": "bool"}, + "singlehop": {"type": "bool"}, + "multihop": { + "type": "dict", + "options": { + "set": {"type": "bool"}, + "interval": { + "type": "dict", + "options": { + "tx_interval": {"type": "int", "required": True}, + "min_rx_interval": { + "type": "int", + "required": True, + }, + "multiplier": {"type": "int", "required": True}, + }, + }, + }, + }, + }, + }, + "bmp_activate_server": {"type": "int"}, + "capability": { + "type": "dict", + "options": {"suppress_4_byte_as": {"type": "bool"}}, + }, + "description": {"type": "str"}, + "disable_connected_check": {"type": "bool"}, + "dont_capability_negotiate": {"type": "bool"}, + "dscp": {"type": "str"}, + "dynamic_capability": {"type": "bool"}, + "ebgp_multihop": {"type": "int"}, + "graceful_shutdown": { + "type": "dict", + "options": { + "activate": { + "type": "dict", + "options": { + "set": {"type": "bool"}, + "route_map": {"type": "str"}, + }, + }, + }, + }, + "inherit": { + "type": "dict", + "options": {"peer_session": {"type": "str"}}, + }, + "local_as": {"type": "str"}, + "log_neighbor_changes": { + "type": "dict", + "options": { + "set": {"type": "bool"}, + "disable": {"type": "bool"}, + }, + }, + "low_memory": { + "type": "dict", + "options": {"exempt": {"type": "bool"}}, + }, + "password": { + "type": "dict", + "no_log": False, + "options": { + "encryption": {"type": "int"}, + "key": {"type": "str", "no_log": True}, + }, + }, + "path_attribute": { + "type": "list", + "elements": "dict", + "options": { + "action": { + "type": "str", + "choices": ["discard", "treat-as-withdraw"], + }, + "type": {"type": "int"}, + "range": { + "type": "dict", + "options": { + "start": {"type": "int"}, + "end": {"type": "int"}, + }, + }, + }, + }, + "remote_as": {"type": "str"}, + "remove_private_as": { + "type": "dict", + "options": { + "set": {"type": "bool"}, + "replace_as": {"type": "bool"}, + "all": {"type": "bool"}, + }, + }, + "shutdown": {"type": "bool"}, + "timers": { + "type": "dict", + "options": { + "keepalive": {"type": "int"}, + "holdtime": {"type": "int"}, + }, + }, + "transport": { + "type": "dict", + "options": { + "connection_mode": { + "type": "dict", + "options": {"passive": {"type": "bool"}}, + }, + }, + }, + "ttl_security": { + "type": "dict", + "options": {"hops": {"type": "int"}}, + }, + "update_source": {"type": "str"}, + }, + }, + }, + }, + "state": { + "type": "str", + "choices": [ + "merged", + "replaced", + "overridden", + "deleted", + "parsed", + "gathered", + "rendered", + ], + "default": "merged", + }, + } # pylint: disable=C0301 diff --git a/plugins/module_utils/network/nxos/argspec/facts/facts.py b/plugins/module_utils/network/nxos/argspec/facts/facts.py index f2b716c40..ae12a8d60 100644 --- a/plugins/module_utils/network/nxos/argspec/facts/facts.py +++ b/plugins/module_utils/network/nxos/argspec/facts/facts.py @@ -5,6 +5,7 @@ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type """ The arg spec for the nxos facts module. diff --git a/plugins/module_utils/network/nxos/argspec/fc_interfaces/__init__.py b/plugins/module_utils/network/nxos/argspec/fc_interfaces/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/module_utils/network/nxos/argspec/fc_interfaces/fc_interfaces.py b/plugins/module_utils/network/nxos/argspec/fc_interfaces/fc_interfaces.py new file mode 100644 index 000000000..5a58d99e0 --- /dev/null +++ b/plugins/module_utils/network/nxos/argspec/fc_interfaces/fc_interfaces.py @@ -0,0 +1,76 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 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 + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the +# ansible.content_builder. +# +# Manually editing this file is not advised. +# +# To update the argspec make the desired changes +# in the documentation in the module file and re-run +# ansible.content_builder commenting out +# the path to external 'docstring' in build.yaml. +# +############################################## + +""" +The arg spec for the nxos_fc_interfaces module +""" +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.fc_interfaces import ( + allowed_port_modes, + allowed_speed_values, +) + + +class Fc_interfacesArgs(object): # pylint: disable=R0903 + """The arg spec for the nxos_fc_interfaces module""" + + argument_spec = { + "running_config": {"type": "str"}, + "config": { + "type": "list", + "elements": "dict", + "options": { + "name": {"type": "str", "required": True}, + "description": {"type": "str"}, + "enabled": {"type": "bool"}, + "speed": { + "choices": allowed_speed_values, + "type": "str", + }, + "mode": { + "choices": allowed_port_modes, + "type": "str", + }, + "trunk_mode": {"choices": ["auto", "on", "off"], "type": "str"}, + "analytics": { + "choices": ["fc-scsi", "fc-nvme", "fc-all"], + "type": "str", + }, + }, + }, + "state": { + "type": "str", + "choices": [ + "merged", + "replaced", + "overridden", + "deleted", + "gathered", + "rendered", + "parsed", + ], + "default": "merged", + }, + } # pylint: disable=C0301 diff --git a/plugins/module_utils/network/nxos/argspec/hostname/hostname.py b/plugins/module_utils/network/nxos/argspec/hostname/hostname.py index 9327e0471..3a7120719 100644 --- a/plugins/module_utils/network/nxos/argspec/hostname/hostname.py +++ b/plugins/module_utils/network/nxos/argspec/hostname/hostname.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type ############################################# diff --git a/plugins/module_utils/network/nxos/argspec/hsrp_interfaces/hsrp_interfaces.py b/plugins/module_utils/network/nxos/argspec/hsrp_interfaces/hsrp_interfaces.py index 436348ed0..ac3026367 100644 --- a/plugins/module_utils/network/nxos/argspec/hsrp_interfaces/hsrp_interfaces.py +++ b/plugins/module_utils/network/nxos/argspec/hsrp_interfaces/hsrp_interfaces.py @@ -23,6 +23,7 @@ ############################################# from __future__ import absolute_import, division, print_function + __metaclass__ = type """ diff --git a/plugins/module_utils/network/nxos/argspec/interfaces/interfaces.py b/plugins/module_utils/network/nxos/argspec/interfaces/interfaces.py index d7104c922..ba8d7923d 100644 --- a/plugins/module_utils/network/nxos/argspec/interfaces/interfaces.py +++ b/plugins/module_utils/network/nxos/argspec/interfaces/interfaces.py @@ -26,6 +26,7 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type diff --git a/plugins/module_utils/network/nxos/argspec/l2_interfaces/l2_interfaces.py b/plugins/module_utils/network/nxos/argspec/l2_interfaces/l2_interfaces.py index 81f9b8214..046511c72 100644 --- a/plugins/module_utils/network/nxos/argspec/l2_interfaces/l2_interfaces.py +++ b/plugins/module_utils/network/nxos/argspec/l2_interfaces/l2_interfaces.py @@ -26,6 +26,7 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -43,7 +44,7 @@ class L2_interfacesArgs(object): # pylint: disable=R0903 }, "mode": { "type": "str", - "choices": ["access", "trunk", "fex-fabric", "fabricpath"], + "choices": ["access", "dot1q-tunnel", "trunk", "fex-fabric", "fabricpath"], }, "name": {"required": True, "type": "str"}, "trunk": { diff --git a/plugins/module_utils/network/nxos/argspec/l3_interfaces/l3_interfaces.py b/plugins/module_utils/network/nxos/argspec/l3_interfaces/l3_interfaces.py index cccc0b748..7a5163e0f 100644 --- a/plugins/module_utils/network/nxos/argspec/l3_interfaces/l3_interfaces.py +++ b/plugins/module_utils/network/nxos/argspec/l3_interfaces/l3_interfaces.py @@ -26,6 +26,7 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -57,6 +58,7 @@ class L3_interfacesArgs(object): # pylint: disable=R0903 }, "name": {"required": True, "type": "str"}, "redirects": {"type": "bool"}, + "ipv6_redirects": {"type": "bool"}, "unreachables": {"type": "bool"}, "evpn_multisite_tracking": { "type": "str", diff --git a/plugins/module_utils/network/nxos/argspec/lacp/lacp.py b/plugins/module_utils/network/nxos/argspec/lacp/lacp.py index 48e6b9ce3..6eddf5893 100644 --- a/plugins/module_utils/network/nxos/argspec/lacp/lacp.py +++ b/plugins/module_utils/network/nxos/argspec/lacp/lacp.py @@ -26,6 +26,7 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -51,7 +52,7 @@ class LacpArgs(object): "priority": {"type": "int"}, }, "type": "dict", - } + }, }, "type": "dict", }, @@ -59,6 +60,7 @@ class LacpArgs(object): "choices": [ "merged", "replaced", + "overridden", "deleted", "gathered", "rendered", diff --git a/plugins/module_utils/network/nxos/argspec/lacp_interfaces/lacp_interfaces.py b/plugins/module_utils/network/nxos/argspec/lacp_interfaces/lacp_interfaces.py index cc74faaa5..119432bf7 100644 --- a/plugins/module_utils/network/nxos/argspec/lacp_interfaces/lacp_interfaces.py +++ b/plugins/module_utils/network/nxos/argspec/lacp_interfaces/lacp_interfaces.py @@ -26,6 +26,7 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type diff --git a/plugins/module_utils/network/nxos/argspec/lag_interfaces/lag_interfaces.py b/plugins/module_utils/network/nxos/argspec/lag_interfaces/lag_interfaces.py index 8a2f86618..12330b84f 100644 --- a/plugins/module_utils/network/nxos/argspec/lag_interfaces/lag_interfaces.py +++ b/plugins/module_utils/network/nxos/argspec/lag_interfaces/lag_interfaces.py @@ -26,6 +26,7 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type diff --git a/plugins/module_utils/network/nxos/argspec/lldp_global/lldp_global.py b/plugins/module_utils/network/nxos/argspec/lldp_global/lldp_global.py index f2e885855..abcbc08fa 100644 --- a/plugins/module_utils/network/nxos/argspec/lldp_global/lldp_global.py +++ b/plugins/module_utils/network/nxos/argspec/lldp_global/lldp_global.py @@ -26,6 +26,7 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -76,6 +77,7 @@ class Lldp_globalArgs(object): # pylint: disable=R0903 "choices": [ "merged", "replaced", + "overridden", "deleted", "gathered", "parsed", diff --git a/plugins/module_utils/network/nxos/argspec/lldp_interfaces/lldp_interfaces.py b/plugins/module_utils/network/nxos/argspec/lldp_interfaces/lldp_interfaces.py index 7f4db6d30..0552901ef 100644 --- a/plugins/module_utils/network/nxos/argspec/lldp_interfaces/lldp_interfaces.py +++ b/plugins/module_utils/network/nxos/argspec/lldp_interfaces/lldp_interfaces.py @@ -26,6 +26,7 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type diff --git a/plugins/module_utils/network/nxos/argspec/logging_global/logging_global.py b/plugins/module_utils/network/nxos/argspec/logging_global/logging_global.py index 2c8cd71e4..58a9052f1 100644 --- a/plugins/module_utils/network/nxos/argspec/logging_global/logging_global.py +++ b/plugins/module_utils/network/nxos/argspec/logging_global/logging_global.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type ############################################# @@ -115,7 +116,7 @@ class Logging_globalArgs(object): # pylint: disable=R0903 "options": {"sgt": {"type": "bool"}}, }, }, - } + }, }, }, "facilities": { @@ -245,10 +246,8 @@ class Logging_globalArgs(object): # pylint: disable=R0903 "options": { "trustpoint": { "type": "dict", - "options": { - "client_identity": {"type": "str"} - }, - } + "options": {"client_identity": {"type": "str"}}, + }, }, }, "use_vrf": {"type": "str"}, diff --git a/plugins/module_utils/network/nxos/argspec/ntp_global/ntp_global.py b/plugins/module_utils/network/nxos/argspec/ntp_global/ntp_global.py index 89f160625..a680e58d6 100644 --- a/plugins/module_utils/network/nxos/argspec/ntp_global/ntp_global.py +++ b/plugins/module_utils/network/nxos/argspec/ntp_global/ntp_global.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type ############################################# diff --git a/plugins/module_utils/network/nxos/argspec/ospf_interfaces/ospf_interfaces.py b/plugins/module_utils/network/nxos/argspec/ospf_interfaces/ospf_interfaces.py index 1be1c77b7..30d65035f 100644 --- a/plugins/module_utils/network/nxos/argspec/ospf_interfaces/ospf_interfaces.py +++ b/plugins/module_utils/network/nxos/argspec/ospf_interfaces/ospf_interfaces.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type ############################################# @@ -40,9 +41,7 @@ class Ospf_interfacesArgs(object): # pylint: disable=R0903 "address_family": { "type": "list", "elements": "dict", - "mutually_exclusive": [ - ["passive_interface", "default_passive_interface"] - ], + "mutually_exclusive": [["passive_interface", "default_passive_interface"]], "options": { "afi": { "type": "str", diff --git a/plugins/module_utils/network/nxos/argspec/ospfv2/ospfv2.py b/plugins/module_utils/network/nxos/argspec/ospfv2/ospfv2.py index ae34b122f..2e5e62f12 100644 --- a/plugins/module_utils/network/nxos/argspec/ospfv2/ospfv2.py +++ b/plugins/module_utils/network/nxos/argspec/ospfv2/ospfv2.py @@ -24,6 +24,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -50,7 +51,7 @@ class Ospfv2Args(object): # pylint: disable=R0903 "nssa", "ranges", "stub", - ] + ], ], "elements": "dict", "options": { @@ -80,31 +81,21 @@ class Ospfv2Args(object): # pylint: disable=R0903 }, "nssa": { "options": { - "default_information_originate": { - "type": "bool" - }, + "default_information_originate": {"type": "bool"}, "no_redistribution": {"type": "bool"}, "no_summary": {"type": "bool"}, "set": {"type": "bool"}, "translate": { "options": { "type7": { - "mutually_exclusive": [ - ["always", "never"] - ], + "mutually_exclusive": [["always", "never"]], "options": { - "always": { - "type": "bool" - }, - "never": { - "type": "bool" - }, - "supress_fa": { - "type": "bool" - }, + "always": {"type": "bool"}, + "never": {"type": "bool"}, + "supress_fa": {"type": "bool"}, }, "type": "dict", - } + }, }, "type": "dict", }, @@ -157,7 +148,7 @@ class Ospfv2Args(object): # pylint: disable=R0903 "set": {"type": "bool"}, }, "type": "dict", - } + }, }, "type": "dict", }, @@ -200,9 +191,7 @@ class Ospfv2Args(object): # pylint: disable=R0903 "options": { "external_lsa": { "options": { - "max_metric_value": { - "type": "int" - }, + "max_metric_value": {"type": "int"}, "set": {"type": "bool"}, }, "type": "dict", @@ -211,9 +200,7 @@ class Ospfv2Args(object): # pylint: disable=R0903 "on_startup": { "options": { "set": {"type": "bool"}, - "wait_for_bgp_asn": { - "type": "int" - }, + "wait_for_bgp_asn": {"type": "int"}, "wait_period": {"type": "int"}, }, "type": "dict", @@ -221,16 +208,14 @@ class Ospfv2Args(object): # pylint: disable=R0903 "set": {"type": "bool"}, "summary_lsa": { "options": { - "max_metric_value": { - "type": "int" - }, + "max_metric_value": {"type": "int"}, "set": {"type": "bool"}, }, "type": "dict", }, }, "type": "dict", - } + }, }, "type": "dict", }, @@ -242,15 +227,13 @@ class Ospfv2Args(object): # pylint: disable=R0903 "areas": { "type": "list", "elements": "dict", - "options": { - "area_id": {"type": "str"} - }, + "options": {"area_id": {"type": "str"}}, }, "multicast_intact": {"type": "bool"}, "router_id": {"type": "str"}, }, "type": "dict", - } + }, }, "type": "dict", }, @@ -310,29 +293,17 @@ class Ospfv2Args(object): # pylint: disable=R0903 "options": { "lsa": { "options": { - "hold_interval": { - "type": "int" - }, - "max_interval": { - "type": "int" - }, - "start_interval": { - "type": "int" - }, + "hold_interval": {"type": "int"}, + "max_interval": {"type": "int"}, + "start_interval": {"type": "int"}, }, "type": "dict", }, "spf": { "options": { - "initial_spf_delay": { - "type": "int" - }, - "max_wait_time": { - "type": "int" - }, - "min_hold_time": { - "type": "int" - }, + "initial_spf_delay": {"type": "int"}, + "max_wait_time": {"type": "int"}, + "min_hold_time": {"type": "int"}, }, "type": "dict", }, @@ -354,7 +325,7 @@ class Ospfv2Args(object): # pylint: disable=R0903 "nssa", "ranges", "stub", - ] + ], ], "elements": "dict", "options": { @@ -365,9 +336,7 @@ class Ospfv2Args(object): # pylint: disable=R0903 "authentication": { "options": { "set": {"type": "bool"}, - "message_digest": { - "type": "bool" - }, + "message_digest": {"type": "bool"}, }, "type": "dict", }, @@ -389,12 +358,8 @@ class Ospfv2Args(object): # pylint: disable=R0903 }, "nssa": { "options": { - "default_information_originate": { - "type": "bool" - }, - "no_redistribution": { - "type": "bool" - }, + "default_information_originate": {"type": "bool"}, + "no_redistribution": {"type": "bool"}, "no_summary": {"type": "bool"}, "set": {"type": "bool"}, "translate": { @@ -404,21 +369,15 @@ class Ospfv2Args(object): # pylint: disable=R0903 [ "always", "never", - ] + ], ], "options": { - "always": { - "type": "bool" - }, - "never": { - "type": "bool" - }, - "supress_fa": { - "type": "bool" - }, + "always": {"type": "bool"}, + "never": {"type": "bool"}, + "supress_fa": {"type": "bool"}, }, "type": "dict", - } + }, }, "type": "dict", }, @@ -429,9 +388,7 @@ class Ospfv2Args(object): # pylint: disable=R0903 "elements": "dict", "options": { "cost": {"type": "int"}, - "not_advertise": { - "type": "bool" - }, + "not_advertise": {"type": "bool"}, "prefix": { "type": "str", "required": True, @@ -473,7 +430,7 @@ class Ospfv2Args(object): # pylint: disable=R0903 "set": {"type": "bool"}, "evpn": {"type": "bool"}, }, - } + }, }, }, "default_information": { @@ -485,7 +442,7 @@ class Ospfv2Args(object): # pylint: disable=R0903 "set": {"type": "bool"}, }, "type": "dict", - } + }, }, "type": "dict", }, @@ -527,47 +484,31 @@ class Ospfv2Args(object): # pylint: disable=R0903 "options": { "external_lsa": { "options": { - "max_metric_value": { - "type": "int" - }, - "set": { - "type": "bool" - }, + "max_metric_value": {"type": "int"}, + "set": {"type": "bool"}, }, "type": "dict", }, - "include_stub": { - "type": "bool" - }, + "include_stub": {"type": "bool"}, "on_startup": { "options": { - "set": { - "type": "bool" - }, - "wait_for_bgp_asn": { - "type": "int" - }, - "wait_period": { - "type": "int" - }, + "set": {"type": "bool"}, + "wait_for_bgp_asn": {"type": "int"}, + "wait_period": {"type": "int"}, }, "type": "dict", }, "set": {"type": "bool"}, "summary_lsa": { "options": { - "max_metric_value": { - "type": "int" - }, - "set": { - "type": "bool" - }, + "max_metric_value": {"type": "int"}, + "set": {"type": "bool"}, }, "type": "dict", }, }, "type": "dict", - } + }, }, "type": "dict", }, @@ -635,29 +576,17 @@ class Ospfv2Args(object): # pylint: disable=R0903 "options": { "lsa": { "options": { - "hold_interval": { - "type": "int" - }, - "max_interval": { - "type": "int" - }, - "start_interval": { - "type": "int" - }, + "hold_interval": {"type": "int"}, + "max_interval": {"type": "int"}, + "start_interval": {"type": "int"}, }, "type": "dict", }, "spf": { "options": { - "initial_spf_delay": { - "type": "int" - }, - "max_wait_time": { - "type": "int" - }, - "min_hold_time": { - "type": "int" - }, + "initial_spf_delay": {"type": "int"}, + "max_wait_time": {"type": "int"}, + "min_hold_time": {"type": "int"}, }, "type": "dict", }, @@ -673,7 +602,7 @@ class Ospfv2Args(object): # pylint: disable=R0903 }, }, "type": "list", - } + }, }, "type": "dict", }, diff --git a/plugins/module_utils/network/nxos/argspec/ospfv3/ospfv3.py b/plugins/module_utils/network/nxos/argspec/ospfv3/ospfv3.py index 1dcc07829..601bb618f 100644 --- a/plugins/module_utils/network/nxos/argspec/ospfv3/ospfv3.py +++ b/plugins/module_utils/network/nxos/argspec/ospfv3/ospfv3.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type ############################################# @@ -83,9 +84,7 @@ class Ospfv3Args(object): # pylint: disable=R0903 "required": True, }, "cost": {"type": "int"}, - "not_advertise": { - "type": "bool" - }, + "not_advertise": {"type": "bool"}, }, }, }, @@ -100,7 +99,7 @@ class Ospfv3Args(object): # pylint: disable=R0903 "always": {"type": "bool"}, "route_map": {"type": "str"}, }, - } + }, }, }, "distance": {"type": "int"}, @@ -161,19 +160,13 @@ class Ospfv3Args(object): # pylint: disable=R0903 "spf": { "type": "dict", "options": { - "initial_spf_delay": { - "type": "int" - }, - "min_hold_time": { - "type": "int" - }, - "max_wait_time": { - "type": "int" - }, + "initial_spf_delay": {"type": "int"}, + "min_hold_time": {"type": "int"}, + "max_wait_time": {"type": "int"}, }, - } + }, }, - } + }, }, }, }, @@ -187,9 +180,7 @@ class Ospfv3Args(object): # pylint: disable=R0903 "type": "dict", "options": { "set": {"type": "bool"}, - "default_information_originate": { - "type": "bool" - }, + "default_information_originate": {"type": "bool"}, "no_redistribution": {"type": "bool"}, "no_summary": {"type": "bool"}, "route_map": {"type": "str"}, @@ -199,17 +190,11 @@ class Ospfv3Args(object): # pylint: disable=R0903 "type7": { "type": "dict", "options": { - "always": { - "type": "bool" - }, - "never": { - "type": "bool" - }, - "supress_fa": { - "type": "bool" - }, + "always": {"type": "bool"}, + "never": {"type": "bool"}, + "supress_fa": {"type": "bool"}, }, - } + }, }, }, }, @@ -280,9 +265,7 @@ class Ospfv3Args(object): # pylint: disable=R0903 "type": "dict", "options": { "set": {"type": "bool"}, - "max_metric_value": { - "type": "int" - }, + "max_metric_value": {"type": "int"}, }, }, "stub_prefix_lsa": {"type": "bool"}, @@ -291,22 +274,18 @@ class Ospfv3Args(object): # pylint: disable=R0903 "options": { "set": {"type": "bool"}, "wait_period": {"type": "int"}, - "wait_for_bgp_asn": { - "type": "int" - }, + "wait_for_bgp_asn": {"type": "int"}, }, }, "inter_area_prefix_lsa": { "type": "dict", "options": { "set": {"type": "bool"}, - "max_metric_value": { - "type": "int" - }, + "max_metric_value": {"type": "int"}, }, }, }, - } + }, }, }, "name_lookup": {"type": "bool"}, @@ -328,17 +307,11 @@ class Ospfv3Args(object): # pylint: disable=R0903 "lsa": { "type": "dict", "options": { - "start_interval": { - "type": "int" - }, - "hold_interval": { - "type": "int" - }, - "max_interval": { - "type": "int" - }, + "start_interval": {"type": "int"}, + "hold_interval": {"type": "int"}, + "max_interval": {"type": "int"}, }, - } + }, }, }, }, @@ -359,12 +332,8 @@ class Ospfv3Args(object): # pylint: disable=R0903 "type": "dict", "options": { "set": {"type": "bool"}, - "default_information_originate": { - "type": "bool" - }, - "no_redistribution": { - "type": "bool" - }, + "default_information_originate": {"type": "bool"}, + "no_redistribution": {"type": "bool"}, "no_summary": {"type": "bool"}, "route_map": {"type": "str"}, "translate": { @@ -373,17 +342,11 @@ class Ospfv3Args(object): # pylint: disable=R0903 "type7": { "type": "dict", "options": { - "always": { - "type": "bool" - }, - "never": { - "type": "bool" - }, - "supress_fa": { - "type": "bool" - }, + "always": {"type": "bool"}, + "never": {"type": "bool"}, + "supress_fa": {"type": "bool"}, }, - } + }, }, }, }, @@ -451,44 +414,28 @@ class Ospfv3Args(object): # pylint: disable=R0903 "external_lsa": { "type": "dict", "options": { - "set": { - "type": "bool" - }, - "max_metric_value": { - "type": "int" - }, + "set": {"type": "bool"}, + "max_metric_value": {"type": "int"}, }, }, - "stub_prefix_lsa": { - "type": "bool" - }, + "stub_prefix_lsa": {"type": "bool"}, "on_startup": { "type": "dict", "options": { - "set": { - "type": "bool" - }, - "wait_period": { - "type": "int" - }, - "wait_for_bgp_asn": { - "type": "int" - }, + "set": {"type": "bool"}, + "wait_period": {"type": "int"}, + "wait_for_bgp_asn": {"type": "int"}, }, }, "inter_area_prefix_lsa": { "type": "dict", "options": { - "set": { - "type": "bool" - }, - "max_metric_value": { - "type": "int" - }, + "set": {"type": "bool"}, + "max_metric_value": {"type": "int"}, }, }, }, - } + }, }, }, "name_lookup": {"type": "bool"}, @@ -509,17 +456,11 @@ class Ospfv3Args(object): # pylint: disable=R0903 "lsa": { "type": "dict", "options": { - "start_interval": { - "type": "int" - }, - "hold_interval": { - "type": "int" - }, - "max_interval": { - "type": "int" - }, + "start_interval": {"type": "int"}, + "hold_interval": {"type": "int"}, + "max_interval": {"type": "int"}, }, - } + }, }, }, }, @@ -528,7 +469,7 @@ class Ospfv3Args(object): # pylint: disable=R0903 }, }, }, - } + }, }, }, "state": { diff --git a/plugins/module_utils/network/nxos/argspec/prefix_lists/prefix_lists.py b/plugins/module_utils/network/nxos/argspec/prefix_lists/prefix_lists.py index 396f38616..c29e03757 100644 --- a/plugins/module_utils/network/nxos/argspec/prefix_lists/prefix_lists.py +++ b/plugins/module_utils/network/nxos/argspec/prefix_lists/prefix_lists.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type ############################################# diff --git a/plugins/module_utils/network/nxos/argspec/route_maps/route_maps.py b/plugins/module_utils/network/nxos/argspec/route_maps/route_maps.py index 0602a9897..14dfa5b05 100644 --- a/plugins/module_utils/network/nxos/argspec/route_maps/route_maps.py +++ b/plugins/module_utils/network/nxos/argspec/route_maps/route_maps.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type ############################################# @@ -81,7 +82,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "route_types": { "type": "list", "elements": "str", - } + }, }, }, "extcommunity": { @@ -117,29 +118,19 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "source": {"type": "str"}, "group": { "type": "dict", - "options": { - "prefix": { - "type": "str" - } - }, + "options": {"prefix": {"type": "str"}}, }, "group_range": { "type": "dict", "options": { - "first": { - "type": "str" - }, - "last": { - "type": "str" - }, + "first": {"type": "str"}, + "last": {"type": "str"}, }, }, "rp": { "type": "dict", "options": { - "prefix": { - "type": "str" - }, + "prefix": {"type": "str"}, "rp_type": { "type": "str", "choices": [ @@ -157,7 +148,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "prefix_lists": { "type": "list", "elements": "str", - } + }, }, }, "route_source": { @@ -166,7 +157,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "prefix_lists": { "type": "list", "elements": "str", - } + }, }, }, }, @@ -190,29 +181,19 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "source": {"type": "str"}, "group": { "type": "dict", - "options": { - "prefix": { - "type": "str" - } - }, + "options": {"prefix": {"type": "str"}}, }, "group_range": { "type": "dict", "options": { - "first": { - "type": "str" - }, - "last": { - "type": "str" - }, + "first": {"type": "str"}, + "last": {"type": "str"}, }, }, "rp": { "type": "dict", "options": { - "prefix": { - "type": "str" - }, + "prefix": {"type": "str"}, "rp_type": { "type": "str", "choices": [ @@ -230,7 +211,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "prefix_lists": { "type": "list", "elements": "str", - } + }, }, }, "route_source": { @@ -239,7 +220,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "prefix_lists": { "type": "list", "elements": "str", - } + }, }, }, }, @@ -316,9 +297,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "options": { "half_life": {"type": "int"}, "start_reuse_route": {"type": "int"}, - "start_suppress_route": { - "type": "int" - }, + "start_suppress_route": {"type": "int"}, "max_suppress_time": {"type": "int"}, }, }, @@ -335,19 +314,30 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "options": { "gateway_ip": { "type": "dict", - "mutually_exclusive": [ - ["ip", "use_nexthop"] - ], + "mutually_exclusive": [["ip", "use_nexthop"]], "options": { "ip": {"type": "str"}, - "use_nexthop": { - "type": "bool" - }, + "use_nexthop": {"type": "bool"}, }, - } + }, }, }, "extcomm_list": {"type": "str"}, + "extcommunity": { + "type": "dict", + "options": { + "rt": { + "type": "dict", + "options": { + "additive": {"type": "bool"}, + "extcommunity_numbers": { + "type": "list", + "elements": "str", + }, + }, + }, + }, + }, "forwarding_address": {"type": "bool"}, "null_interface": {"type": "str"}, "ip": { @@ -355,11 +345,58 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "options": { "address": { "type": "dict", + "options": {"prefix_list": {"type": "str"}}, + }, + "precedence": {"type": "str"}, + "next_hop": { + "type": "dict", + "mutually_exclusive": [ + [ + "address", + "peer_address", + "redist_unchanged", + "verify_availability", + ], + [ + "address", + "peer_address", + "unchanged", + "verify_availability", + ], + ], "options": { - "prefix_list": {"type": "str"} + "address": {"type": "str"}, + "drop_on_fail": {"type": "bool", "default": False}, + "force_order": {"type": "bool", "default": False}, + "load_share": {"type": "bool", "default": False}, + "peer_address": {"type": "bool"}, + "redist_unchanged": {"type": "bool"}, + "unchanged": {"type": "bool"}, + "verify_availability": { + "type": "list", + "elements": "dict", + "options": { + "address": { + "type": "str", + "required": True, + }, + "track": {"type": "int", "required": True}, + "drop_on_fail": { + "type": "bool", + "default": False, + }, + "force_order": { + "type": "bool", + "default": False, + }, + "load_share": { + "type": "bool", + "default": False, + }, + }, + }, }, }, - "precedence": {"type": "str"}, }, }, "ipv6": { @@ -367,9 +404,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "options": { "address": { "type": "dict", - "options": { - "prefix_list": {"type": "str"} - }, + "options": {"prefix_list": {"type": "str"}}, }, "precedence": {"type": "str"}, }, @@ -389,12 +424,8 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "options": { "bandwidth": {"type": "int"}, "igrp_delay_metric": {"type": "int"}, - "igrp_reliability_metric": { - "type": "int" - }, - "igrp_effective_bandwidth_metric": { - "type": "int" - }, + "igrp_reliability_metric": {"type": "int"}, + "igrp_effective_bandwidth_metric": {"type": "int"}, "igrp_mtu": {"type": "int"}, }, }, diff --git a/plugins/module_utils/network/nxos/argspec/snmp_server/snmp_server.py b/plugins/module_utils/network/nxos/argspec/snmp_server/snmp_server.py index 73a48e287..a6b3d4201 100644 --- a/plugins/module_utils/network/nxos/argspec/snmp_server/snmp_server.py +++ b/plugins/module_utils/network/nxos/argspec/snmp_server/snmp_server.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type ############################################# @@ -70,7 +71,7 @@ class Snmp_serverArgs(object): # pylint: disable=R0903 "enable": {"type": "bool"}, "timeout": {"type": "int"}, }, - } + }, }, }, "drop": { @@ -131,16 +132,12 @@ class Snmp_serverArgs(object): # pylint: disable=R0903 "type": "dict", "options": { "enable": {"type": "bool"}, - "cefcMIBEnableStatusNotification": { - "type": "bool" - }, + "cefcMIBEnableStatusNotification": {"type": "bool"}, "entity_fan_status_change": {"type": "bool"}, "entity_mib_change": {"type": "bool"}, "entity_module_inserted": {"type": "bool"}, "entity_module_removed": {"type": "bool"}, - "entity_module_status_change": { - "type": "bool" - }, + "entity_module_status_change": {"type": "bool"}, "entity_power_out_change": {"type": "bool"}, "entity_power_status_change": {"type": "bool"}, "entity_sensor": {"type": "bool"}, @@ -168,22 +165,16 @@ class Snmp_serverArgs(object): # pylint: disable=R0903 "options": { "enable": {"type": "bool"}, "notify_license_expiry": {"type": "bool"}, - "notify_license_expiry_warning": { - "type": "bool" - }, + "notify_license_expiry_warning": {"type": "bool"}, "notify_licensefile_missing": {"type": "bool"}, - "notify_no_license_for_feature": { - "type": "bool" - }, + "notify_no_license_for_feature": {"type": "bool"}, }, }, "link": { "type": "dict", "options": { "enable": {"type": "bool"}, - "cErrDisableInterfaceEventRev1": { - "type": "bool" - }, + "cErrDisableInterfaceEventRev1": {"type": "bool"}, "cieLinkDown": {"type": "bool"}, "cieLinkUp": {"type": "bool"}, "cisco_xcvr_mon_status_chg": {"type": "bool"}, @@ -263,9 +254,7 @@ class Snmp_serverArgs(object): # pylint: disable=R0903 "type": "dict", "options": { "enable": {"type": "bool"}, - "cseFailSwCoreNotifyExtended": { - "type": "bool" - }, + "cseFailSwCoreNotifyExtended": {"type": "bool"}, }, }, "system": { @@ -280,9 +269,7 @@ class Snmp_serverArgs(object): # pylint: disable=R0903 "options": { "enable": {"type": "bool"}, "upgradeJobStatusNotify": {"type": "bool"}, - "upgradeOpNotifyOnCompletion": { - "type": "bool" - }, + "upgradeOpNotifyOnCompletion": {"type": "bool"}, }, }, "vtp": { @@ -331,7 +318,7 @@ class Snmp_serverArgs(object): # pylint: disable=R0903 "community": {"type": "str"}, "context": {"type": "str"}, }, - } + }, }, }, "packetsize": {"type": "int"}, @@ -368,7 +355,11 @@ class Snmp_serverArgs(object): # pylint: disable=R0903 "options": { "algorithm": { "type": "str", - "choices": ["md5", "sha"], + "choices": [ + "md5", + "sha", + "sha-256", + ], }, "password": { "type": "str", @@ -376,6 +367,7 @@ class Snmp_serverArgs(object): # pylint: disable=R0903 }, "engine_id": {"type": "str"}, "localized_key": {"type": "bool"}, + "localizedv2_key": {"type": "bool"}, "priv": { "type": "dict", "options": { diff --git a/plugins/module_utils/network/nxos/argspec/static_routes/static_routes.py b/plugins/module_utils/network/nxos/argspec/static_routes/static_routes.py index d0e32819a..25b78da1b 100644 --- a/plugins/module_utils/network/nxos/argspec/static_routes/static_routes.py +++ b/plugins/module_utils/network/nxos/argspec/static_routes/static_routes.py @@ -1,80 +1,79 @@ -# # -*- coding: utf-8 -*- -# Copyright 2019 Red Hat +# Copyright 2023 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 + ############################################# # WARNING # ############################################# # -# This file is auto generated by the resource -# module builder playbook. +# This file is auto generated by the +# ansible.content_builder. # -# Do not edit this file manually. +# Manually editing this file is not advised. # -# Changes to this file will be over written -# by the resource module builder. +# To update the argspec make the desired changes +# in the documentation in the module file and re-run +# ansible.content_builder commenting out +# the path to external 'docstring' in build.yaml. # -# Changes should be made in the model used to -# generate this file or in the resource module -# builder template. -# -############################################# +############################################## + """ The arg spec for the nxos_static_routes module """ -from __future__ import absolute_import, division, print_function - -__metaclass__ = type class Static_routesArgs(object): # pylint: disable=R0903 """The arg spec for the nxos_static_routes module""" argument_spec = { + "running_config": {"type": "str"}, "config": { + "type": "list", "elements": "dict", "options": { + "vrf": {"type": "str"}, "address_families": { + "type": "list", "elements": "dict", "options": { "afi": { + "type": "str", "choices": ["ipv4", "ipv6"], "required": True, - "type": "str", }, "routes": { "elements": "dict", + "type": "list", "options": { - "dest": {"required": True, "type": "str"}, + "dest": {"type": "str", "required": True}, "next_hops": { + "type": "list", "elements": "dict", "options": { - "admin_distance": {"type": "int"}, - "dest_vrf": {"type": "str"}, - "forward_router_address": { - "type": "str" - }, + "forward_router_address": {"type": "str"}, "interface": {"type": "str"}, + "admin_distance": {"type": "int"}, "route_name": {"type": "str"}, "tag": {"type": "int"}, "track": {"type": "int"}, + "dest_vrf": {"type": "str"}, }, - "type": "list", }, }, - "type": "list", }, }, - "type": "list", }, - "vrf": {"type": "str"}, }, - "type": "list", }, - "running_config": {"type": "str"}, "state": { + "type": "str", "choices": [ "deleted", "merged", @@ -85,6 +84,5 @@ class Static_routesArgs(object): # pylint: disable=R0903 "parsed", ], "default": "merged", - "type": "str", }, } # pylint: disable=C0301 diff --git a/plugins/module_utils/network/nxos/argspec/telemetry/telemetry.py b/plugins/module_utils/network/nxos/argspec/telemetry/telemetry.py index f376f4f70..7da72979b 100644 --- a/plugins/module_utils/network/nxos/argspec/telemetry/telemetry.py +++ b/plugins/module_utils/network/nxos/argspec/telemetry/telemetry.py @@ -27,6 +27,7 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -63,7 +64,7 @@ class TelemetryArgs(object): # pylint: disable=R0903 }, "type": "dict", }, - "id": {"type": "int"}, + "id": {"type": "str"}, }, "type": "list", "elements": "raw", @@ -74,7 +75,7 @@ class TelemetryArgs(object): # pylint: disable=R0903 "choices": ["NX-API", "DME", "YANG"], "type": "str", }, - "id": {"type": "int"}, + "id": {"type": "str"}, "path": { "options": { "depth": {"type": "str"}, @@ -90,11 +91,11 @@ class TelemetryArgs(object): # pylint: disable=R0903 }, "subscriptions": { "options": { - "destination_group": {"type": "int"}, - "id": {"type": "int"}, + "destination_group": {"type": "str"}, + "id": {"type": "str"}, "sensor_group": { "options": { - "id": {"type": "int"}, + "id": {"type": "str"}, "sample_interval": {"type": "int"}, }, "type": "dict", diff --git a/plugins/module_utils/network/nxos/argspec/vlans/vlans.py b/plugins/module_utils/network/nxos/argspec/vlans/vlans.py index dcdd3b592..4f915f092 100644 --- a/plugins/module_utils/network/nxos/argspec/vlans/vlans.py +++ b/plugins/module_utils/network/nxos/argspec/vlans/vlans.py @@ -27,6 +27,7 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type diff --git a/plugins/module_utils/network/nxos/cmdref/telemetry/telemetry.py b/plugins/module_utils/network/nxos/cmdref/telemetry/telemetry.py index 187a2c42f..f5844538f 100644 --- a/plugins/module_utils/network/nxos/cmdref/telemetry/telemetry.py +++ b/plugins/module_utils/network/nxos/cmdref/telemetry/telemetry.py @@ -8,6 +8,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type TMS_GLOBAL = """ @@ -130,7 +131,7 @@ destination_group: _exclude: ['N3K', 'N5K', 'N6k', 'N7k'] multiple: true - kind: int + kind: str getval: dst-grp (\\S+)$ setval: 'dst-grp {0}' default: ~ diff --git a/plugins/module_utils/network/nxos/config/acl_interfaces/acl_interfaces.py b/plugins/module_utils/network/nxos/config/acl_interfaces/acl_interfaces.py index aa97b3304..5bd15062e 100644 --- a/plugins/module_utils/network/nxos/config/acl_interfaces/acl_interfaces.py +++ b/plugins/module_utils/network/nxos/config/acl_interfaces/acl_interfaces.py @@ -12,24 +12,22 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, remove_empties, - dict_diff, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, + to_list, ) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( - flatten_dict, - search_obj_in_list, get_interface_type, normalize_interface, + search_obj_in_list, ) @@ -52,11 +50,11 @@ def get_acl_interfaces_facts(self, data=None): :returns: The current configuration as a dictionary """ facts, _warnings = Facts(self._module).get_facts( - self.gather_subset, self.gather_network_resources, data=data - ) - acl_interfaces_facts = facts["ansible_network_resources"].get( - "acl_interfaces" + self.gather_subset, + self.gather_network_resources, + data=data, ) + acl_interfaces_facts = facts["ansible_network_resources"].get("acl_interfaces") if not acl_interfaces_facts: return [] return acl_interfaces_facts @@ -88,7 +86,7 @@ def execute_module(self): running_config = self._module.params["running_config"] if not running_config: self._module.fail_json( - msg="value of running_config parameter must not be empty for state parsed" + msg="value of running_config parameter must not be empty for state parsed", ) result["parsed"] = self.set_config({}) # no need to fetch facts for parsed @@ -122,7 +120,7 @@ def set_config(self, existing_acl_interfaces_facts): for w in config: if get_interface_type(w["name"]) == "loopback": self._module.fail_json( - msg="This module works with ethernet, management or port-channe" + msg="This module works with ethernet, management or port-channe", ) w.update({"name": normalize_interface(w["name"])}) want.append(remove_empties(w)) @@ -139,14 +137,9 @@ def set_state(self, want, have): :returns: the commands necessary to migrate the current configuration to the desired configuration """ - if ( - self.state in ("overridden", "merged", "replaced", "rendered") - and not want - ): + if self.state in ("overridden", "merged", "replaced", "rendered") and not want: self._module.fail_json( - msg="value of config parameter must not be empty for state {0}".format( - self.state - ) + msg="value of config parameter must not be empty for state {0}".format(self.state), ) commands = [] @@ -192,9 +185,7 @@ def _state_replaced(self, want, have): for ag in obj_in_have["access_groups"]: want_afi = [] if want.get("access_groups"): - want_afi = search_obj_in_list( - ag["afi"], want["access_groups"], "afi" - ) + want_afi = search_obj_in_list(ag["afi"], want["access_groups"], "afi") if not want_afi: # whatever in have is not in want del_dict["access_groups"].append(ag) @@ -207,18 +198,12 @@ def _state_replaced(self, want, have): else: del_acl.append(acl) afi = want_afi["afi"] - del_dict["access_groups"].append( - {"afi": afi, "acls": del_acl} - ) + del_dict["access_groups"].append({"afi": afi, "acls": del_acl}) commands.extend(self._state_deleted([del_dict], have)) commands.extend(self._state_merged(want, have)) new_commands.append(commands[0]) - commands = [ - commands[i] - for i in range(1, len(commands)) - if commands[i] != commands[0] - ] + commands = [commands[i] for i in range(1, len(commands)) if commands[i] != commands[0]] new_commands.extend(commands) return new_commands @@ -256,36 +241,26 @@ def set_commands(self, want, have, deleted=False): ip = "ipv6" if w_afi["afi"] == "ipv4": ip = "ip" - have_afi = search_obj_in_list( - w_afi["afi"], have_name["access_groups"], "afi" - ) + have_afi = search_obj_in_list(w_afi["afi"], have_name["access_groups"], "afi") if have_afi: new_acls = [] if deleted: if w_afi.get("acls") and have_afi.get("acls"): new_acls = [ - acl - for acl in w_afi.get("acls") - if acl in have_afi.get("acls") + acl for acl in w_afi.get("acls") if acl in have_afi.get("acls") ] elif "acls" not in w_afi.keys(): new_acls = have_afi.get("acls") else: if w_afi.get("acls"): new_acls = [ - acl - for acl in w_afi["acls"] - if acl not in have_afi["acls"] + acl for acl in w_afi["acls"] if acl not in have_afi["acls"] ] - commands.extend( - self.process_acl(new_acls, ip, deleted) - ) + commands.extend(self.process_acl(new_acls, ip, deleted)) else: if not deleted: if w_afi.get("acls"): - commands.extend( - self.process_acl(w_afi["acls"], ip) - ) + commands.extend(self.process_acl(w_afi["acls"], ip)) else: # only name is given to delete if deleted and "access_groups" in have_name.keys(): @@ -320,9 +295,7 @@ def process_acl(self, acls, ip, deleted=False): ag = " access-group " if ip == "ipv6": ag = " traffic-filter " - commands.append( - no + ip + port + ag + acl["name"] + " " + acl["direction"] - ) + commands.append(no + ip + port + ag + acl["name"] + " " + acl["direction"]) return commands def _state_deleted(self, main_want, have): @@ -340,9 +313,7 @@ def _state_deleted(self, main_want, have): commands.extend(self.set_commands(h, have, deleted=True)) else: for want in main_want: - commands.extend( - self.set_commands(want, have, deleted=True) - ) + commands.extend(self.set_commands(want, have, deleted=True)) else: for h in have: commands.extend(self.set_commands(h, have, deleted=True)) diff --git a/plugins/module_utils/network/nxos/config/acls/acls.py b/plugins/module_utils/network/nxos/config/acls/acls.py index 0e983b446..5e6f3c34a 100644 --- a/plugins/module_utils/network/nxos/config/acls/acls.py +++ b/plugins/module_utils/network/nxos/config/acls/acls.py @@ -12,26 +12,24 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type import re -from copy import deepcopy + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, remove_empties, + to_list, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, -) + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.acls.acls import ( AclsArgs, ) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( search_obj_in_list, ) @@ -57,7 +55,9 @@ def get_acls_facts(self, data=None): :returns: The current configuration as a dictionary """ facts, _warnings = Facts(self._module).get_facts( - self.gather_subset, self.gather_network_resources, data=data + self.gather_subset, + self.gather_network_resources, + data=data, ) acls_facts = facts["ansible_network_resources"].get("acls") if not acls_facts: @@ -91,11 +91,11 @@ def execute_module(self): else: existing_acls_facts = self.get_acls_facts() commands.extend(self.set_config(existing_acls_facts)) + result["before"] = existing_acls_facts if commands and state in action_states: if not self._module.check_mode: self._connection.edit_config(commands) result["changed"] = True - result["before"] = existing_acls_facts result["commands"] = commands changed_acls_facts = self.get_acls_facts() @@ -222,57 +222,37 @@ def convert_values(self, want): ace["dscp"] = ace["dscp"].lower() if "precedence" in ace.keys(): if ace["precedence"].isdigit(): - ace["precedence"] = precedence[ - int(ace["precedence"]) - ] + ace["precedence"] = precedence[int(ace["precedence"])] if ( "protocol" in ace.keys() and ace["protocol"].isdigit() and int(ace["protocol"]) in protocol.keys() ): - ace["protocol"] = protocol[ - int(ace["protocol"]) - ] + ace["protocol"] = protocol[int(ace["protocol"])] # convert number to name - if "protocol" in ace.keys() and ace[ - "protocol" - ] in ["tcp", "udp"]: + if "protocol" in ace.keys() and ace["protocol"] in ["tcp", "udp"]: for x in ["source", "destination"]: if "port_protocol" in ace[x].keys(): - key = list( - ace[x]["port_protocol"].keys() - )[0] + key = list(ace[x]["port_protocol"].keys())[0] # key could be eq,gt,lt,neq or range if key != "range": val = ace[x]["port_protocol"][key] - if ( - val.isdigit() - and int(val) - in port_protocol.keys() - ): - ace[x]["port_protocol"][ - key - ] = port_protocol[int(val)] + if val.isdigit() and int(val) in port_protocol.keys(): + ace[x]["port_protocol"][key] = port_protocol[ + int(val) + ] else: - st = int( - ace[x]["port_protocol"][ - "range" - ]["start"] - ) - end = int( - ace[x]["port_protocol"][ - "range" - ]["end"] - ) + st = int(ace[x]["port_protocol"]["range"]["start"]) + end = int(ace[x]["port_protocol"]["range"]["end"]) if st in port_protocol.keys(): - ace[x]["port_protocol"][ - "range" - ]["start"] = port_protocol[st] + ace[x]["port_protocol"]["range"][ + "start" + ] = port_protocol[st] if end in port_protocol.keys(): - ace[x]["port_protocol"][ - "range" - ]["end"] = port_protocol[end] + ace[x]["port_protocol"]["range"][ + "end" + ] = port_protocol[end] return want def set_state(self, want, have): @@ -337,19 +317,11 @@ def _state_replaced(self, want, have): if w["name"] not in have_names: # creates new ACL in replaced state merge_dict = {"afi": want["afi"], "acls": [w]} - commands.extend( - self._state_merged(merge_dict, have) - ) + commands.extend(self._state_merged(merge_dict, have)) else: # acl in want exists in have - have_name = search_obj_in_list( - w["name"], have_afi["acls"], "name" - ) - have_aces = ( - have_name.get("aces") - if have_name.get("aces") - else [] - ) + have_name = search_obj_in_list(w["name"], have_afi["acls"], "name") + have_aces = have_name.get("aces") if have_name.get("aces") else [] merge_aces = [] del_aces = [] w_aces = w.get("aces") if w.get("aces") else [] @@ -362,23 +334,15 @@ def _state_replaced(self, want, have): merge_aces.append(ace) merge_dict = { "afi": want["afi"], - "acls": [ - {"name": w["name"], "aces": merge_aces} - ], + "acls": [{"name": w["name"], "aces": merge_aces}], } del_dict = { "afi": want["afi"], - "acls": [ - {"name": w["name"], "aces": del_aces} - ], + "acls": [{"name": w["name"], "aces": del_aces}], } if del_dict["acls"]: - acl_commands.extend( - self._state_deleted([del_dict], have) - ) - acl_commands.extend( - self._state_merged(merge_dict, have) - ) + acl_commands.extend(self._state_deleted([del_dict], have)) + acl_commands.extend(self._state_merged(merge_dict, have)) for i in range(1, len(acl_commands)): if acl_commands[i] == acl_commands[0]: @@ -413,9 +377,7 @@ def _state_overridden(self, want, have): if h["afi"] in want_afi: w = search_obj_in_list(h["afi"], want, "afi") for h_acl in h["acls"]: - w_acl = search_obj_in_list( - h_acl["name"], w["acls"], "name" - ) + w_acl = search_obj_in_list(h_acl["name"], w["acls"], "name") if not w_acl: del_dict = { "afi": h["afi"], @@ -455,12 +417,11 @@ def _state_deleted(self, want, have): if have_afi: if w.get("acls"): for acl in w["acls"]: - if ( - "aces" in acl.keys() - and self.state != "deleted" - ): + if "aces" in acl.keys() and self.state != "deleted": have_name = search_obj_in_list( - acl["name"], have_afi["acls"], "name" + acl["name"], + have_afi["acls"], + "name", ) if have_name: ace_commands = [] @@ -470,32 +431,20 @@ def _state_deleted(self, want, have): # only sequence number is specified to be deleted if "aces" in have_name.keys(): for h_ace in have_name["aces"]: - if ( - h_ace["sequence"] - == ace["sequence"] - ): + if h_ace["sequence"] == ace["sequence"]: ace_commands.append( - "no " - + str( - ace["sequence"] - ) + "no " + str(ace["sequence"]), ) flag = 1 else: if "aces" in have_name.keys(): for h_ace in have_name["aces"]: # when want['ace'] does not have seq number - if ( - "sequence" - not in ace.keys() - ): + if "sequence" not in ace.keys(): del h_ace["sequence"] if ace == h_ace: ace_commands.append( - "no " - + self.process_ace( - ace - ) + "no " + self.process_ace(ace), ) flag = 1 if flag: @@ -510,9 +459,7 @@ def _state_deleted(self, want, have): if h["name"] == acl["name"]: acl_names.append(acl["name"]) for name in acl_names: - commands.append( - "no " + ip + " access-list " + name - ) + commands.append("no " + ip + " access-list " + name) else: # 'only afi is given' @@ -520,9 +467,7 @@ def _state_deleted(self, want, have): for h in have_afi["acls"]: acl_names.append(h["name"]) for name in acl_names: - commands.append( - "no " + ip + " access-list " + name - ) + commands.append("no " + ip + " access-list " + name) else: v6 = [] v4 = [] @@ -565,9 +510,7 @@ def set_commands(self, want, have): if have_afi: if want.get("acls"): for w_acl in want["acls"]: - have_acl = search_obj_in_list( - w_acl["name"], have_afi["acls"], "name" - ) + have_acl = search_obj_in_list(w_acl["name"], have_afi["acls"], "name") name = w_acl["name"] flag = 0 ace_commands = [] @@ -581,9 +524,7 @@ def set_commands(self, want, have): # For replaced and overridden, rule is deleted in the state's config) ace_list = [ - item - for item in w_acl["aces"] - if "sequence" not in item.keys() + item for item in w_acl["aces"] if "sequence" not in item.keys() ] # case 1 want_seq = [ @@ -592,21 +533,15 @@ def set_commands(self, want, have): if "sequence" in item.keys() ] - have_seq = [ - item["sequence"] - for item in have_acl["aces"] - ] + have_seq = [item["sequence"] for item in have_acl["aces"]] new_seq = list(set(want_seq) - set(have_seq)) - common_seq = list( - set(want_seq).intersection(set(have_seq)) - ) + common_seq = list(set(want_seq).intersection(set(have_seq))) temp_list = [ item for item in w_acl["aces"] - if "sequence" in item.keys() - and item["sequence"] in new_seq + if "sequence" in item.keys() and item["sequence"] in new_seq ] # case 2 ace_list.extend(temp_list) for w in w_acl["aces"]: @@ -621,16 +556,13 @@ def set_commands(self, want, have): { "name": name, "aces": ace_list, - } + }, ], - } - ] + }, + ], }, ) - if ( - "sequence" in w.keys() - and w["sequence"] in common_seq - ): + if "sequence" in w.keys() and w["sequence"] in common_seq: temp_obj = search_obj_in_list( w["sequence"], have_acl["aces"], @@ -643,30 +575,25 @@ def set_commands(self, want, have): self._module.fail_json( msg="Cannot update existing ACE {0} of ACL {1} with state merged." " Please use state replaced or overridden.".format( - name, w["sequence"] - ) + name, + w["sequence"], + ), ) elif w_acl.get("aces"): # 'have' has ACL defined without any ACE ace_list = list(w_acl["aces"]) for w_ace in ace_list: - ace_commands.append( - self.process_ace(w_ace).strip() - ) + ace_commands.append(self.process_ace(w_ace).strip()) flag = 1 if flag: - ace_commands.insert( - 0, ip + "access-list " + name - ) + ace_commands.insert(0, ip + "access-list " + name) else: commands.append(ip + "access-list " + name) if "aces" in w_acl.keys(): for w_ace in w_acl["aces"]: - commands.append( - self.process_ace(w_ace).strip() - ) + commands.append(self.process_ace(w_ace).strip()) commands.extend(ace_commands) else: if want.get("acls"): @@ -687,21 +614,21 @@ def process_ace(self, w_ace): else: command += w_ace["grant"] + " " if "protocol" in ace_keys: - command += w_ace["protocol"] + " " + if w_ace["protocol"] == "icmpv6": + command += "icmp" + " " + else: + command += w_ace["protocol"] + " " src = self.get_address(w_ace["source"], w_ace["protocol"]) - dest = self.get_address( - w_ace["destination"], w_ace["protocol"] - ) + dest = self.get_address(w_ace["destination"], w_ace["protocol"]) command += src + dest if "protocol_options" in ace_keys: pro = list(w_ace["protocol_options"].keys())[0] if pro != w_ace["protocol"]: - self._module.fail_json( - msg="protocol and protocol_options mismatch" - ) + self._module.fail_json(msg="protocol and protocol_options mismatch") flags = "" for k in w_ace["protocol_options"][pro].keys(): - k = re.sub("_", "-", k) + if k not in ["telemetry_queue", "telemetry_path"]: + k = re.sub("_", "-", k) flags += k + " " command += flags if "dscp" in ace_keys: @@ -721,13 +648,9 @@ def get_address(self, endpoint, pro=""): keys = list(endpoint.keys()) if "address" in keys: if "wildcard_bits" not in keys: - self._module.fail_json( - msg="wildcard bits not specified for address" - ) + self._module.fail_json(msg="wildcard bits not specified for address") else: - ret_addr = ( - endpoint["address"] + " " + endpoint["wildcard_bits"] + " " - ) + ret_addr = endpoint["address"] + " " + endpoint["wildcard_bits"] + " " elif "any" in keys: ret_addr = "any " elif "host" in keys: @@ -745,13 +668,7 @@ def get_options(self, item): com = "" subkey = list(item.keys()) if "range" in subkey: - com = ( - "range " - + item["range"]["start"] - + " " - + item["range"]["end"] - + " " - ) + com = "range " + item["range"]["start"] + " " + item["range"]["end"] + " " else: com = subkey[0] + " " + item[subkey[0]] + " " return com diff --git a/plugins/module_utils/network/nxos/config/bfd_interfaces/bfd_interfaces.py b/plugins/module_utils/network/nxos/config/bfd_interfaces/bfd_interfaces.py index d167b0c2f..a9dc51fd9 100644 --- a/plugins/module_utils/network/nxos/config/bfd_interfaces/bfd_interfaces.py +++ b/plugins/module_utils/network/nxos/config/bfd_interfaces/bfd_interfaces.py @@ -11,9 +11,11 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type import re + from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) @@ -21,9 +23,8 @@ dict_diff, to_list, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, -) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( flatten_dict, search_obj_in_list, @@ -50,11 +51,11 @@ def get_bfd_interfaces_facts(self, data=None): if self.state not in self.ACTION_STATES: self.gather_subset = ["!all", "!min"] facts, _warnings = Facts(self._module).get_facts( - self.gather_subset, self.gather_network_resources, data=data - ) - bfd_interfaces_facts = facts["ansible_network_resources"].get( - "bfd_interfaces", [] + self.gather_subset, + self.gather_network_resources, + data=data, ) + bfd_interfaces_facts = facts["ansible_network_resources"].get("bfd_interfaces", []) platform = facts.get("ansible_net_platform", "") return bfd_interfaces_facts, platform @@ -81,9 +82,7 @@ def execute_module(self): existing_bfd_interfaces_facts, platform = [], "" if self.state in self.ACTION_STATES or self.state == "rendered": - commands.extend( - self.set_config(existing_bfd_interfaces_facts, platform) - ) + commands.extend(self.set_config(existing_bfd_interfaces_facts, platform)) if commands and self.state in self.ACTION_STATES: if not self._module.check_mode: @@ -106,11 +105,9 @@ def execute_module(self): running_config = self._module.params["running_config"] if not running_config: self._module.fail_json( - msg="value of running_config parameter must not be empty for state parsed" + msg="value of running_config parameter must not be empty for state parsed", ) - result["parsed"], platform = self.get_bfd_interfaces_facts( - data=running_config - ) + result["parsed"], platform = self.get_bfd_interfaces_facts(data=running_config) if self.state in self.ACTION_STATES: result["before"] = existing_bfd_interfaces_facts @@ -161,14 +158,9 @@ def set_state(self, want, have): to the desired configuration """ state = self._module.params["state"] - if ( - state in ("overridden", "merged", "replaced", "rendered") - and not want - ): + if state in ("overridden", "merged", "replaced", "rendered") and not want: self._module.fail_json( - msg="value of config parameter must not be empty for state {0}".format( - state - ) + msg="value of config parameter must not be empty for state {0}".format(state), ) cmds = list() @@ -222,9 +214,7 @@ def _state_overridden(self, want, have): for h in have: # Clean up bfd attrs for any interfaces not listed in the play h = flatten_dict(h) - obj_in_want = flatten_dict( - search_obj_in_list(h["name"], want, "name") - ) + obj_in_want = flatten_dict(search_obj_in_list(h["name"], want, "name")) if obj_in_want: # Let the 'want' loop handle all vals for this interface continue @@ -258,9 +248,7 @@ def _state_deleted(self, want, have): cmds = [] if want: for w in want: - obj_in_have = flatten_dict( - search_obj_in_list(w["name"], have, "name") - ) + obj_in_have = flatten_dict(search_obj_in_list(w["name"], have, "name")) cmds.extend(self.del_attribs(obj_in_have)) else: for h in have: @@ -314,9 +302,7 @@ def add_commands(self, want): def set_commands(self, want, have): cmds = [] - obj_in_have = flatten_dict( - search_obj_in_list(want["name"], have, "name") - ) + obj_in_have = flatten_dict(search_obj_in_list(want["name"], have, "name")) if not obj_in_have: cmds = self.add_commands(want) else: diff --git a/plugins/module_utils/network/nxos/config/bgp_address_family/bgp_address_family.py b/plugins/module_utils/network/nxos/config/bgp_address_family/bgp_address_family.py index 96751926e..4443039c3 100644 --- a/plugins/module_utils/network/nxos/config/bgp_address_family/bgp_address_family.py +++ b/plugins/module_utils/network/nxos/config/bgp_address_family/bgp_address_family.py @@ -7,6 +7,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -19,23 +20,19 @@ from copy import deepcopy -import re from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - dict_merge, -) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.resource_module import ( +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, + remove_empties, ) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.bgp_address_family import ( Bgp_address_familyTemplate, ) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - remove_empties, -) class Bgp_address_family(ResourceModule): @@ -117,18 +114,14 @@ def generate_commands(self): # if state is overridden or deleted, remove superfluos config if self.state in ["deleted", "overridden"]: - if ( - haved and haved["as_number"] == wantd.get("as_number") - ) or not wantd: + if (haved and haved["as_number"] == wantd.get("as_number")) or not wantd: remove = True if self.state == "deleted" else False purge = True if not wantd else False self._remove_af(want_af, have_af, remove=remove, purge=purge) for k, hvrf in iteritems(hvrfs): wvrf = wvrfs.get(k, {}) - self._remove_af( - wvrf, hvrf, vrf=k, remove=remove, purge=purge - ) + self._remove_af(wvrf, hvrf, vrf=k, remove=remove, purge=purge) if self.state in ["merged", "replaced", "overridden", "rendered"]: for k, want in iteritems(want_af): @@ -147,9 +140,7 @@ def generate_commands(self): self.commands.insert(cur_ptr, "vrf {0}".format(wk)) if self.commands: - self.commands.insert( - 0, "router bgp {as_number}".format(**haved or wantd) - ) + self.commands.insert(0, "router bgp {as_number}".format(**haved or wantd)) def _compare(self, want, have): """Leverages the base class `compare()` method and @@ -205,19 +196,13 @@ def _build_key(data): # transform parameters which are # list of dicts to dict of dicts for item in entry.get("address_family", []): - item["aggregate_address"] = { - x["prefix"]: x for x in item.get("aggregate_address", []) - } + item["aggregate_address"] = {x["prefix"]: x for x in item.get("aggregate_address", [])} item["inject_map"] = { - (x["route_map"], x["exist_map"]): x - for x in item.get("inject_map", []) - } - item["networks"] = { - x["prefix"]: x for x in item.get("networks", []) + (x["route_map"], x["exist_map"]): x for x in item.get("inject_map", []) } + item["networks"] = {x["prefix"]: x for x in item.get("networks", [])} item["redistribute"] = { - (x.get("id"), x["protocol"]): x - for x in item.get("redistribute", []) + (x.get("id"), x["protocol"]): x for x in item.get("redistribute", []) } # transform all entries under @@ -249,9 +234,7 @@ def _build_key(data): # final structure: https://gist.github.com/NilashishC/628dae5fe39a4908e87c9e833bfbe57d - def _remove_af( - self, want_af, have_af, vrf=None, remove=False, purge=False - ): + def _remove_af(self, want_af, have_af, vrf=None, remove=False, purge=False): cur_ptr = len(self.commands) for k, v in iteritems(have_af): # first conditional is for deleted with config provided @@ -262,7 +245,7 @@ def _remove_af( (remove and k in want_af), (not remove and k not in want_af), purge, - ) + ), ): self.addcmd(v, "address_family", True) if cur_ptr < len(self.commands) and vrf: diff --git a/plugins/module_utils/network/nxos/config/bgp_global/bgp_global.py b/plugins/module_utils/network/nxos/config/bgp_global/bgp_global.py index 09ca1ddee..fe738d1af 100644 --- a/plugins/module_utils/network/nxos/config/bgp_global/bgp_global.py +++ b/plugins/module_utils/network/nxos/config/bgp_global/bgp_global.py @@ -7,6 +7,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -17,18 +18,15 @@ created. """ -from copy import deepcopy - from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - dict_merge, -) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.resource_module import ( +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, ) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.bgp_global import ( Bgp_globalTemplate, ) @@ -123,7 +121,7 @@ def generate_commands(self): self._module.fail_json( msg="BGP is already configured with ASN {0}. " "Please remove it with state purged before " - "configuring new ASN".format(h_asn) + "configuring new ASN".format(h_asn), ) if self.state in ["deleted", "replaced"]: @@ -134,15 +132,11 @@ def generate_commands(self): # if state is deleted, clean up global params if self.state == "deleted": - if not self.want or ( - self.have.get("as_number") == self.want.get("as_number") - ): + if not self.want or (self.have.get("as_number") == self.want.get("as_number")): self._compare(want={}, have=self.have) elif self.state == "purged": - if not self.want or ( - self.have.get("as_number") == self.want.get("as_number") - ): + if not self.want or (self.have.get("as_number") == self.want.get("as_number")): self.addcmd(self.have or {}, "as_number", True) else: @@ -170,9 +164,7 @@ def _compare(self, want, have, vrf=None): begin, self._tmplt.render( want or have, - "vrf" - if "vrf" in (want.keys() or have.keys()) - else "as_number", + "vrf" if "vrf" in (want.keys() or have.keys()) else "as_number", False, ), ) @@ -242,10 +234,8 @@ def _compare_neighbors(self, want, have, vrf=None): self.compare(parsers=nbr_parsers, want=entry, have=have_nbr) self._compare_path_attribute(entry, have_nbr) - if len(self.commands) != begin: - self.commands.insert( - begin, self._tmplt.render(entry, "neighbor_address", False) - ) + if len(self.commands) != begin or (entry and not have_nbr): + self.commands.insert(begin, self._tmplt.render(entry, "neighbor_address", False)) # cleanup remaining neighbors # but do not negate it entirely @@ -256,8 +246,8 @@ def _compare_neighbors(self, want, have, vrf=None): self._module.fail_json( msg="Neighbor {0} has address-family configurations. " "Please use the nxos_bgp_neighbor_af module to remove those first.".format( - name - ) + name, + ), ) else: self.addcmd(entry, "neighbor_address", True) @@ -298,9 +288,7 @@ def _vrfs_compare(self, want, have): if self._has_af(vrf=name): self._module.fail_json( msg="VRF {0} has address-family configurations. " - "Please use the nxos_bgp_af module to remove those first.".format( - name - ) + "Please use the nxos_bgp_af module to remove those first.".format(name), ) else: self.addcmd(entry, "vrf", True) @@ -329,13 +317,10 @@ def _build_key(x): for x in entry["neighbors"]: if "path_attribute" in x: x["path_attribute"] = { - _build_key(item): item - for item in x.get("path_attribute", []) + _build_key(item): item for item in x.get("path_attribute", []) } - entry["neighbors"] = { - x["neighbor_address"]: x for x in entry.get("neighbors", []) - } + entry["neighbors"] = {x["neighbor_address"]: x for x in entry.get("neighbors", [])} if "vrfs" in entry: entry["vrfs"] = {x["vrf"]: x for x in entry.get("vrfs", [])} @@ -343,9 +328,7 @@ def _build_key(x): self._bgp_list_to_dict(vrf) def _get_config(self): - return self._connection.get( - "show running-config | section '^router bgp'" - ) + return self._connection.get("show running-config | section '^router bgp'") def _build_af_data(self): """Build a dictionary with AF related information diff --git a/plugins/module_utils/network/nxos/config/bgp_neighbor_address_family/bgp_neighbor_address_family.py b/plugins/module_utils/network/nxos/config/bgp_neighbor_address_family/bgp_neighbor_address_family.py index 5e436a987..0ab282a6c 100644 --- a/plugins/module_utils/network/nxos/config/bgp_neighbor_address_family/bgp_neighbor_address_family.py +++ b/plugins/module_utils/network/nxos/config/bgp_neighbor_address_family/bgp_neighbor_address_family.py @@ -7,6 +7,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -19,15 +20,14 @@ from copy import deepcopy from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - dict_merge, -) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.resource_module import ( +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, ) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.bgp_neighbor_address_family import ( Bgp_neighbor_address_familyTemplate, ) @@ -65,6 +65,7 @@ def __init__(self, module): "prefix_list.inbound", "prefix_list.outbound", "rewrite_evpn_rt_asn", + "rewrite_rt_asn", "route_map.inbound", "route_map.outbound", "route_reflector_client", @@ -123,9 +124,7 @@ def generate_commands(self): self._compare(want=wantd, have=haved) if self.commands: - self.commands.insert( - 0, "router bgp {as_number}".format(**haved or wantd) - ) + self.commands.insert(0, "router bgp {as_number}".format(**haved or wantd)) def _compare(self, want, have, vrf=""): """Leverages the base class `compare()` method and @@ -172,9 +171,7 @@ def _compare(self, want, have, vrf=""): self.addcmd(have_af, "address_family", True) if len(self.commands) != begin: - self.commands.insert( - begin, "neighbor {0}".format(w_nbr["neighbor_address"]) - ) + self.commands.insert(begin, "neighbor {0}".format(w_nbr["neighbor_address"])) if self.state in ["overridden", "deleted"]: for k, h_nbr in iteritems(h_nbrs): @@ -184,9 +181,7 @@ def _compare(self, want, have, vrf=""): for k, have_af in iteritems(have_afs): self.addcmd(have_af, "address_family", True) if len(self.commands) != begin: - self.commands.insert( - begin, "neighbor {0}".format(h_nbr["neighbor_address"]) - ) + self.commands.insert(begin, "neighbor {0}".format(h_nbr["neighbor_address"])) if vrf: if len(self.commands) != begin_vrf: @@ -209,12 +204,9 @@ def _bgp_list_to_dict(self, data): for nbr in data["neighbors"]: if "address_family" in nbr: nbr["address_family"] = { - (x["afi"], x.get("safi")): x - for x in nbr["address_family"] + (x["afi"], x.get("safi")): x for x in nbr["address_family"] } - data["neighbors"] = { - x["neighbor_address"]: x for x in data["neighbors"] - } + data["neighbors"] = {x["neighbor_address"]: x for x in data["neighbors"]} if "vrfs" in data: for vrf in data["vrfs"]: diff --git a/plugins/module_utils/network/nxos/config/bgp_templates/__init__.py b/plugins/module_utils/network/nxos/config/bgp_templates/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/module_utils/network/nxos/config/bgp_templates/bgp_templates.py b/plugins/module_utils/network/nxos/config/bgp_templates/bgp_templates.py new file mode 100644 index 000000000..648db72e6 --- /dev/null +++ b/plugins/module_utils/network/nxos/config/bgp_templates/bgp_templates.py @@ -0,0 +1,238 @@ +# +# -*- coding: utf-8 -*- +# Copyright 2023 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 + +""" +The nxos_bgp_templates config file. +It is in this file where the current configuration (as dict) +is compared to the provided configuration (as dict) and the command set +necessary to bring the current configuration to its desired end-state is +created. +""" +from copy import deepcopy + +from ansible.module_utils.six import iteritems +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( + ResourceModule, +) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, +) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.bgp_templates import ( + Bgp_templatesTemplate, +) + + +class Bgp_templates(ResourceModule): + """ + The nxos_bgp_templates config class + """ + + def __init__(self, module): + super(Bgp_templates, self).__init__( + empty_fact_val={}, + facts_module=Facts(module), + module=module, + resource="bgp_templates", + tmplt=Bgp_templatesTemplate(), + ) + self.parsers = [ + "bfd", + "bfd.multihop.interval", + "bmp_activate_server", + "capability", + "description", + "disable_connected_check", + "dont_capability_negotiate", + "dscp", + "dynamic_capability", + "ebgp_multihop", + "graceful_shutdown", + "inherit.peer_session", + "local_as", + "log_neighbor_changes", + "low_memory", + "password", + "remote_as", + "remove_private_as", + "shutdown", + "timers", + "transport", + "ttl_security", + "update_source", + ] + self.af_parsers = [ + "advertise_map.exist_map", + "advertise_map.non_exist_map", + "advertisement_interval", + "allowas_in", + "as_override", + "capability.additional_paths.receive", + "capability.additional_paths.send", + "default_originate", + "disable_peer_as_check", + "filter_list.inbound", + "inherit.peer_policy", + "filter_list.outbound", + "maximum_prefix", + "next_hop_self", + "next_hop_third_party", + "prefix_list.inbound", + "prefix_list.outbound", + "route_map.inbound", + "route_map.outbound", + "send_community_standard", + "send_community_extended", + "route_reflector_client", + "soft_reconfiguration_inbound", + "soo", + "suppress_inactive", + "unsuppress_map", + "weight", + ] + + def execute_module(self): + """Execute the module + + :rtype: A dictionary + :returns: The result from module execution + """ + if self.state not in ["parsed", "gathered"]: + self.generate_commands() + self.run_commands() + return self.result + + def generate_commands(self): + """Generate configuration commands to send based on + want, have and desired state. + """ + wantd = self._list_to_dict(deepcopy(self.want)) + haved = self._list_to_dict(deepcopy(self.have)) + + # if state is merged, merge want onto have and then compare + if self.state == "merged": + wantd = dict_merge(haved, wantd) + + w_asn = wantd.pop("as_number", "") + h_asn = haved.pop("as_number", "") + + asn = w_asn or h_asn + + # if state is deleted, empty out wantd and set haved to wantd + if self.state == "deleted": + haved = {k: v for k, v in iteritems(haved) if k in wantd or not wantd} + wantd = {} + + # remove superfluous config for overridden and deleted + if self.state in ["overridden", "deleted"]: + cmds = [] + for k, have in iteritems(haved): + if k not in wantd: + cmds.append("no template peer {0}".format(have["name"])) + self.commands.extend(cmds) + + for k, want in iteritems(wantd): + begin = len(self.commands) + self._compare(want=want, have=haved.pop(k, {})) + if len(self.commands) != begin: + self.commands.insert(begin, "template peer {0}".format(want["name"])) + + if self.commands: + self.commands.insert(0, "router bgp {0}".format(asn)) + + def _compare(self, want, have): + """Leverages the base class `compare()` method and + populates the list of commands to be run by comparing + the `want` and `have` data with the `parsers` defined + for the Bgp_templates network resource. + """ + self.compare(parsers=self.parsers, want=want, have=have) + self._compare_path_attribute(want=want, have=have) + + w_af = want.get("address_family", {}) + h_af = have.get("address_family", {}) + self._afs_compare(want=w_af, have=h_af) + + def _compare_path_attribute(self, want, have): + """Custom handling of neighbor path_attribute + option. + + :params want: the want neighbor dictionary + :params have: the have neighbor dictionary + """ + w_p_attr = want.get("path_attribute", {}) + h_p_attr = have.get("path_attribute", {}) + + for wkey, wentry in iteritems(w_p_attr): + if wentry != h_p_attr.pop(wkey, {}): + self.addcmd(wentry, "path_attribute", False) + + # remove remaining items in have for replaced + for hkey, hentry in iteritems(h_p_attr): + self.addcmd(hentry, "path_attribute", True) + + def _afs_compare(self, want, have): + for name, wentry in iteritems(want): + begin = len(self.commands) + self._af_compare(want=wentry, have=have.pop(name, {})) + if begin != len(self.commands): + self.commands.insert(begin, self._tmplt.render(wentry, "address_family", False)) + for name, hentry in iteritems(have): + self.commands.append(self._tmplt.render(hentry, "address_family", True)) + + def _af_compare(self, want, have): + # "unpack" send_community + for item in [want, have]: + send_comm_val = item.get("send_community", "") + if send_comm_val: + if send_comm_val == "both": + item["send_community_extended"] = True + item["send_community_standard"] = True + else: + key = "send_community_%s" % send_comm_val + item[key] = True + self.compare(parsers=self.af_parsers, want=want, have=have) + + def _list_to_dict(self, data): + def _build_key(x): + """Build primary key for path_attribute + option. + :params x: path_attribute dictionary + :returns: primary key as tuple + """ + key_1 = "start_{0}".format(x.get("range", {}).get("start", "")) + key_2 = "end_{0}".format(x.get("range", {}).get("end", "")) + key_3 = "type_{0}".format(x.get("type", "")) + key_4 = x["action"] + + return (key_1, key_2, key_3, key_4) + + new_data = {} + new_data["as_number"] = data.pop("as_number", None) + + for k, v in iteritems(data): + for entry in v: + if "address_family" in entry: + entry["address_family"] = { + (x["afi"], x.get("safi")): x for x in entry["address_family"] + } + if "path_attribute" in entry: + entry["path_attribute"] = { + _build_key(x): x for x in entry.get("path_attribute", []) + } + + # attach top-level keys with their values + tmp = {(k + "_" + x["name"]): x for x in v} + new_data.update(tmp) + + return new_data diff --git a/plugins/module_utils/network/nxos/config/fc_interfaces/__init__.py b/plugins/module_utils/network/nxos/config/fc_interfaces/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/module_utils/network/nxos/config/fc_interfaces/fc_interfaces.py b/plugins/module_utils/network/nxos/config/fc_interfaces/fc_interfaces.py new file mode 100644 index 000000000..e08a9ce1b --- /dev/null +++ b/plugins/module_utils/network/nxos/config/fc_interfaces/fc_interfaces.py @@ -0,0 +1,202 @@ +# +# -*- coding: utf-8 -*- +# Copyright 2023 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 + +""" +The nxos_fc_interfaces config file. +It is in this file where the current configuration (as dict) +is compared to the provided configuration (as dict) and the command set +necessary to bring the current configuration to its desired end-state is +created. +""" + + +from ansible.module_utils.six import iteritems +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( + ResourceModule, +) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, +) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.fc_interfaces import ( + Fc_interfacesTemplate, +) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( + normalize_interface, +) + + +class Fc_interfaces(ResourceModule): + """ + The nxos_fc_interfaces config class + """ + + def __init__(self, module): + super(Fc_interfaces, self).__init__( + empty_fact_val={}, + facts_module=Facts(module, chassis_type="mds"), + module=module, + resource="fc_interfaces", + tmplt=Fc_interfacesTemplate(), + ) + self.parsers = ["description", "speed", "mode", "trunk_mode", "analytics"] + + def execute_module(self): + """Execute the module + + :rtype: A dictionary + :returns: The result from module execution + """ + if self.state not in ["parsed", "gathered"]: + self.generate_commands() + self.run_commands() + return self.result + + def generate_commands(self): + """Generate configuration commands to send based on + want, have and desired state. + """ + + wantd = {entry["name"]: entry for entry in self.want} + haved = {entry["name"]: entry for entry in self.have} + + for each in wantd, haved: + self.normalize_interface_names(each) + + # if state is merged, merge want onto have and then compare + if self.state == "merged": + wantd = dict_merge(haved, wantd) + + # if state is deleted, empty out wantd and set haved to wantd + if self.state == "deleted": + haved = {k: v for k, v in iteritems(haved) if k in wantd or not wantd} + wantd = {} + + # remove superfluous config for overridden and deleted + if self.state in ["overridden", "deleted"]: + for k, have in iteritems(haved): + if k not in wantd: + self._compare(want={}, have=have) + + for k, want in iteritems(wantd): + self._compare(want=want, have=haved.pop(k, {})) + + modified_list = [ + "switchport trunk mode on" if item.startswith("no switchport trunk mode") else item + for item in self.commands + ] + self.commands = modified_list + + def _calculate_ana_config(self, want_ana, have_ana): + """ + get the cmds based on want_ana and have_ana and the state + + Args: + want_ana (str): analytics type which you want + have_ana (str): analytics type which you have + + +----------+----------+---------+ + | MERGED | + |----------+----------+---------+ + | want_ana | have_ana | outcome | + +----------+----------+---------+ + | "" | * | no op | + | fc-scsi | * | fc-scsi | + | fc-scsi | fc-all | no op | + | fc-nvme | * | fc-nvme | + | fc-nvme | fc-all | no op | + +----------+----------+---------+ + + + +----------+----------+-----------+ + | DELETED | + |----------+----------+-----------+ + | want_ana | have_ana | outcome | + +----------+----------+-----------+ + | * | fc-scsi | no fc-all | + | * | fc-nvme | no fc-all | + | * | fc-all | no fc-all | + | * | "" | no op | + +----------+----------+-----------+ + + + +----------+----------+---------------------+ + | REPLACED/OVERRIDEN | + |----------+----------+---------------------+ + | want_ana | have_ana | outcome | + +----------+----------+---------------------+ + | "" | * | no fc-all | + | fc-scsi | "" | fc-scsi | + | fc-nvme | "" | fc-nvme | + | fc-all | "" | fc-all | + | fc-scsi | * | no fc-all ; fc-scsi | + | fc-nvme | * | no fc-all ; fc-nvme | + | fc-all | * | fc-all | + +----------+----------+---------------------+ + + + """ + + if want_ana == have_ana: + return [] + val = [] + if self.state in ["overridden", "replaced"]: + if want_ana == "": + val = ["no analytics type fc-all"] + elif want_ana == "fc-all": + val = ["analytics type fc-all"] + elif have_ana == "": + val = [f"analytics type {want_ana}"] + else: + val = ["no analytics type fc-all", f"analytics type {want_ana}"] + elif self.state in ["deleted"]: + if have_ana: + val = ["no analytics type fc-all"] + elif self.state in ["merged"]: + if want_ana: + if have_ana != "fc-all": + val = [f"analytics type {want_ana}"] + return val + + def _compare(self, want, have): + """Leverages the base class `compare()` method and + populates the list of commands to be run by comparing + the `want` and `have` data with the `parsers` defined + for the Fc_interfaces network resource. + """ + + begin = len(self.commands) + self.compare(parsers=self.parsers, want=want, have=have) + if want.get("enabled") != have.get("enabled"): + if want.get("enabled"): + self.addcmd(want, "enabled", True) + else: + if want: + self.addcmd(want, "enabled", False) + elif have.get("enabled"): + # handles deleted as want be blank and only + # negates if no shutdown + self.addcmd(have, "enabled", False) + + ana_cmds = self._calculate_ana_config(want.get("analytics", ""), have.get("analytics", "")) + + self.commands.extend(ana_cmds) + + if len(self.commands) != begin: + self.commands.insert(begin, self._tmplt.render(want or have, "interface", False)) + + def normalize_interface_names(self, param): + if param: + for _k, val in iteritems(param): + val["name"] = normalize_interface(val["name"]) + return param diff --git a/plugins/module_utils/network/nxos/config/hostname/hostname.py b/plugins/module_utils/network/nxos/config/hostname/hostname.py index d7305dd2d..42ed06946 100644 --- a/plugins/module_utils/network/nxos/config/hostname/hostname.py +++ b/plugins/module_utils/network/nxos/config/hostname/hostname.py @@ -7,6 +7,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -20,9 +21,8 @@ from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, -) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.hostname import ( HostnameTemplate, ) diff --git a/plugins/module_utils/network/nxos/config/hsrp_interfaces/hsrp_interfaces.py b/plugins/module_utils/network/nxos/config/hsrp_interfaces/hsrp_interfaces.py index 9c4adce56..757505e71 100644 --- a/plugins/module_utils/network/nxos/config/hsrp_interfaces/hsrp_interfaces.py +++ b/plugins/module_utils/network/nxos/config/hsrp_interfaces/hsrp_interfaces.py @@ -11,6 +11,7 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( @@ -19,17 +20,13 @@ from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( dict_diff, to_list, - remove_empties, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, ) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( flatten_dict, - get_interface_type, normalize_interface, search_obj_in_list, - vlan_range_to_list, ) @@ -52,11 +49,11 @@ def get_hsrp_interfaces_facts(self, data=None): :returns: The current configuration as a dictionary """ facts, _warnings = Facts(self._module).get_facts( - self.gather_subset, self.gather_network_resources, data=data - ) - hsrp_interfaces_facts = facts["ansible_network_resources"].get( - "hsrp_interfaces", [] + self.gather_subset, + self.gather_network_resources, + data=data, ) + hsrp_interfaces_facts = facts["ansible_network_resources"].get("hsrp_interfaces", []) return hsrp_interfaces_facts def edit_config(self, commands): @@ -98,11 +95,9 @@ def execute_module(self): running_config = self._module.params["running_config"] if not running_config: self._module.fail_json( - msg="value of running_config parameter must not be empty for state parsed" + msg="value of running_config parameter must not be empty for state parsed", ) - result["parsed"] = self.get_hsrp_interfaces_facts( - data=running_config - ) + result["parsed"] = self.get_hsrp_interfaces_facts(data=running_config) if self.state in self.ACTION_STATES: result["before"] = existing_hsrp_interfaces_facts @@ -144,14 +139,9 @@ def set_state(self, want, have): """ state = self._module.params["state"] # check for 'config' keyword in play - if ( - state in ("overridden", "merged", "replaced", "rendered") - and not want - ): + if state in ("overridden", "merged", "replaced", "rendered") and not want: self._module.fail_json( - msg="value of config parameter must not be empty for state {0}".format( - state - ) + msg="value of config parameter must not be empty for state {0}".format(state), ) cmds = list() @@ -239,9 +229,7 @@ def _state_deleted(self, want, have): cmds = [] if want: for w in want: - obj_in_have = flatten_dict( - search_obj_in_list(w["name"], have, "name") - ) + obj_in_have = flatten_dict(search_obj_in_list(w["name"], have, "name")) cmds.extend(self.del_attribs(obj_in_have)) else: for h in have: @@ -279,11 +267,7 @@ def add_commands(self, want, obj_in_have): if want["bfd"] == "enable": cmd = "hsrp bfd" cmds.append(cmd) - elif ( - want["bfd"] == "disable" - and obj_in_have - and obj_in_have.get("bfd") == "enable" - ): + elif want["bfd"] == "disable" and obj_in_have and obj_in_have.get("bfd") == "enable": cmd = "no hsrp bfd" cmds.append(cmd) diff --git a/plugins/module_utils/network/nxos/config/interfaces/interfaces.py b/plugins/module_utils/network/nxos/config/interfaces/interfaces.py index 2ab550401..400f0432f 100644 --- a/plugins/module_utils/network/nxos/config/interfaces/interfaces.py +++ b/plugins/module_utils/network/nxos/config/interfaces/interfaces.py @@ -13,32 +13,30 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from copy import deepcopy import re +from copy import deepcopy + from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( dict_diff, - to_list, remove_empties, + to_list, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + default_intf_enabled, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( normalize_interface, search_obj_in_list, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( - remove_rsvd_interfaces, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - default_intf_enabled, -) class Interfaces(ConfigBase): @@ -63,11 +61,11 @@ def get_interfaces_facts(self, data=None): :returns: The current configuration as a dictionary """ self.facts, _warnings = Facts(self._module).get_facts( - self.gather_subset, self.gather_network_resources, data=data - ) - interfaces_facts = self.facts["ansible_network_resources"].get( - "interfaces" + self.gather_subset, + self.gather_network_resources, + data=data, ) + interfaces_facts = self.facts["ansible_network_resources"].get("interfaces") return interfaces_facts @@ -82,12 +80,12 @@ def get_system_defaults(self): This method exists solely to allow the unit test framework to mock device connection calls. """ return self._connection.get( - "show running-config all | incl 'system default switchport'" + "show running-config all | incl 'system default switchport'", ) def edit_config(self, commands): """Wrapper method for `_connection.edit_config()` - This method exists solely to allow the unit test framework to mock device connection calls. + This method exists solely to allow the unit test framework to mcdock device connection calls. """ return self._connection.edit_config(commands) @@ -108,7 +106,8 @@ def execute_module(self): if self.state in self.ACTION_STATES: self.intf_defs = self.render_interface_defaults( - self.get_system_defaults(), existing_interfaces_facts + self.get_system_defaults(), + existing_interfaces_facts, ) commands.extend(self.set_config(existing_interfaces_facts)) @@ -120,7 +119,7 @@ def execute_module(self): "L2_enabled": False, "L3_enabled": False, "mode": "layer3", - } + }, } commands.extend(self.set_config(existing_interfaces_facts)) @@ -142,7 +141,7 @@ def execute_module(self): running_config = self._module.params["running_config"] if not running_config: self._module.fail_json( - msg="value of running_config parameter must not be empty for state parsed" + msg="value of running_config parameter must not be empty for state parsed", ) result["parsed"] = self.get_interfaces_facts(data=running_config) @@ -185,14 +184,11 @@ def set_state(self, want, have): to the desired configuration """ state = self._module.params["state"] - if ( - state in ("overridden", "merged", "replaced", "rendered") - and not want - ): + if state in ("overridden", "merged", "replaced", "rendered") and not want: self._module.fail_json( msg="value of config parameter must not be empty for state {0}".format( - state - ) + state, + ), ) commands = list() @@ -364,7 +360,9 @@ def default_enabled(self, want=None, have=None, action=""): ): # L2-L3 is changing or this is a new virtual intf. Get new default. intf_def_enabled = default_intf_enabled( - name=name, sysdefs=sysdefs, mode=want_mode + name=name, + sysdefs=sysdefs, + mode=want_mode, ) return intf_def_enabled @@ -412,8 +410,6 @@ def diff_of_dicts(self, w, obj): def add_commands(self, d, obj_in_have=None): commands = [] - if not d: - return commands if obj_in_have is None: obj_in_have = {} # mode/switchport changes should occur before other changes @@ -433,15 +429,17 @@ def add_commands(self, d, obj_in_have=None): if "duplex" in d: commands.append("duplex " + d["duplex"]) if "enabled" in d: - have_enabled = obj_in_have.get( - "enabled", self.default_enabled(d, obj_in_have) - ) + have_enabled = obj_in_have.get("enabled", self.default_enabled(d, obj_in_have)) or False if d["enabled"] is False and have_enabled is True: commands.append("shutdown") elif d["enabled"] is True and have_enabled is False: commands.append("no shutdown") - if "mtu" in d: - commands.append("mtu " + str(d["mtu"])) + if "mtu" in d or ("switchport" in commands): + # changing mode to layer2 defaults the MTU + # we need re-apply existing (non-default) MTU + mtu = d.get("mtu") or obj_in_have.get("mtu") + if mtu: + commands.append("mtu " + str(mtu)) if "ip_forward" in d: if d["ip_forward"] is True: commands.append("ip forward") @@ -472,35 +470,29 @@ def render_interface_defaults(self, config, intfs): and enabled/shutdown states. The default values for user-defined-default configurations may be different for legacy platforms. Notes: - - L3 enabled default state is False on N9K,N7K but True for N3K,N6K + - L3 enabled default state is False on N9K,N7K,N3K but True for N5K,N6K - Changing L2-L3 modes may change the default enabled value. - '(no) system default switchport shutdown' only applies to L2 interfaces. Run through the gathered interfaces and tag their default enabled state. """ intf_defs = {} - L3_enabled = ( - True if re.search("N[356]K", self.get_platform()) else False - ) + L3_enabled = True if re.search("N[56]K", self.get_platform()) else False intf_defs = { "sysdefs": { "mode": None, "L2_enabled": None, "L3_enabled": L3_enabled, - } + }, } pat = "(no )*system default switchport$" m = re.search(pat, config, re.MULTILINE) if m: - intf_defs["sysdefs"]["mode"] = ( - "layer3" if "no " in m.groups() else "layer2" - ) + intf_defs["sysdefs"]["mode"] = "layer3" if "no " in m.groups() else "layer2" pat = "(no )*system default switchport shutdown$" m = re.search(pat, config, re.MULTILINE) if m: - intf_defs["sysdefs"]["L2_enabled"] = ( - True if "no " in m.groups() else False - ) + intf_defs["sysdefs"]["L2_enabled"] = True if "no " in m.groups() else False for item in intfs: intf_defs[item["name"]] = default_intf_enabled( diff --git a/plugins/module_utils/network/nxos/config/l2_interfaces/l2_interfaces.py b/plugins/module_utils/network/nxos/config/l2_interfaces/l2_interfaces.py index 2096bd611..e7d91498f 100644 --- a/plugins/module_utils/network/nxos/config/l2_interfaces/l2_interfaces.py +++ b/plugins/module_utils/network/nxos/config/l2_interfaces/l2_interfaces.py @@ -13,26 +13,26 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type import re + from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( dict_diff, - to_list, remove_empties, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, -) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( flatten_dict, normalize_interface, search_obj_in_list, - vlan_range_to_list, vlan_list_to_range, + vlan_range_to_list, ) @@ -57,11 +57,11 @@ def get_l2_interfaces_facts(self, data=None): :returns: The current configuration as a dictionary """ facts, _warnings = Facts(self._module).get_facts( - self.gather_subset, self.gather_network_resources, data=data - ) - l2_interfaces_facts = facts["ansible_network_resources"].get( - "l2_interfaces" + self.gather_subset, + self.gather_network_resources, + data=data, ) + l2_interfaces_facts = facts["ansible_network_resources"].get("l2_interfaces") if not l2_interfaces_facts: return [] return l2_interfaces_facts @@ -102,11 +102,9 @@ def execute_module(self): running_config = self._module.params["running_config"] if not running_config: self._module.fail_json( - msg="value of running_config parameter must not be empty for state parsed" + msg="value of running_config parameter must not be empty for state parsed", ) - result["parsed"] = self.get_l2_interfaces_facts( - data=running_config - ) + result["parsed"] = self.get_l2_interfaces_facts(data=running_config) if self.state in self.ACTION_STATES: result["before"] = existing_l2_interfaces_facts @@ -161,14 +159,9 @@ def set_state(self, want, have): to the desired configuration """ state = self._module.params["state"] - if ( - state in ("overridden", "merged", "replaced", "rendered") - and not want - ): + if state in ("overridden", "merged", "replaced", "rendered") and not want: self._module.fail_json( - msg="value of config parameter must not be empty for state {0}".format( - state - ) + msg="value of config parameter must not be empty for state {0}".format(state), ) commands = list() @@ -181,9 +174,7 @@ def set_state(self, want, have): if state in ["merged", "rendered"]: commands.extend(self._state_merged(flatten_dict(w), have)) elif state == "replaced": - commands.extend( - self._state_replaced(flatten_dict(w), have) - ) + commands.extend(self._state_replaced(flatten_dict(w), have)) return commands def _state_replaced(self, w, have): @@ -227,9 +218,7 @@ def _state_overridden(self, want, have): commands = [] for h in have: h = flatten_dict(h) - obj_in_want = flatten_dict( - search_obj_in_list(h["name"], want, "name") - ) + obj_in_want = flatten_dict(search_obj_in_list(h["name"], want, "name")) if h == obj_in_want: continue for w in want: @@ -264,9 +253,7 @@ def _state_deleted(self, want, have): commands = [] if want: for w in want: - obj_in_have = flatten_dict( - search_obj_in_list(w["name"], have, "name") - ) + obj_in_have = flatten_dict(search_obj_in_list(w["name"], have, "name")) commands.extend(self.del_attribs(obj_in_have)) else: if not have: @@ -312,13 +299,9 @@ def add_commands(self, d, vlan_exists=False): commands.append(cmd + "access vlan " + str(d["vlan"])) if "allowed_vlans" in d: if vlan_exists: - commands.append( - cmd + "trunk allowed vlan add " + str(d["allowed_vlans"]) - ) + commands.append(cmd + "trunk allowed vlan add " + str(d["allowed_vlans"])) else: - commands.append( - cmd + "trunk allowed vlan " + str(d["allowed_vlans"]) - ) + commands.append(cmd + "trunk allowed vlan " + str(d["allowed_vlans"])) if "native_vlan" in d: commands.append(cmd + "trunk native vlan " + str(d["native_vlan"])) if commands: @@ -347,9 +330,7 @@ def set_commands(self, w, have, replace=False): if w_vlans in have_vlans: vlan_tobe_added.pop(vlan_tobe_added.index(w_vlans)) if vlan_tobe_added: - diff.update( - {"allowed_vlans": ",".join(vlan_tobe_added)} - ) + diff.update({"allowed_vlans": ",".join(vlan_tobe_added)}) if have_vlans: commands = self.add_commands(diff, True) else: diff --git a/plugins/module_utils/network/nxos/config/l3_interfaces/l3_interfaces.py b/plugins/module_utils/network/nxos/config/l3_interfaces/l3_interfaces.py index f7f80b358..d4da881f5 100644 --- a/plugins/module_utils/network/nxos/config/l3_interfaces/l3_interfaces.py +++ b/plugins/module_utils/network/nxos/config/l3_interfaces/l3_interfaces.py @@ -13,29 +13,26 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type import re from copy import deepcopy + from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, remove_empties, + to_list, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, -) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( normalize_interface, search_obj_in_list, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( - remove_rsvd_interfaces, - get_interface_type, -) class L3_interfaces(ConfigBase): @@ -62,12 +59,12 @@ def get_l3_interfaces_facts(self, data=None): self.gather_subset = ["!all", "!min"] facts, _warnings = Facts(self._module).get_facts( - self.gather_subset, self.gather_network_resources, data=data + self.gather_subset, + self.gather_network_resources, + data=data, ) - l3_interfaces_facts = facts["ansible_network_resources"].get( - "l3_interfaces" - ) + l3_interfaces_facts = facts["ansible_network_resources"].get("l3_interfaces") self.platform = facts.get("ansible_net_platform", "") return l3_interfaces_facts @@ -111,11 +108,9 @@ def execute_module(self): running_config = self._module.params["running_config"] if not running_config: self._module.fail_json( - msg="value of running_config parameter must not be empty for state parsed" + msg="value of running_config parameter must not be empty for state parsed", ) - result["parsed"] = self.get_l3_interfaces_facts( - data=running_config - ) + result["parsed"] = self.get_l3_interfaces_facts(data=running_config) if self.state in self.ACTION_STATES: result["before"] = existing_l3_interfaces_facts @@ -157,14 +152,9 @@ def set_state(self, want, have): to the desired configuration """ state = self._module.params["state"] - if ( - state in ("overridden", "merged", "replaced", "rendered") - and not want - ): + if state in ("overridden", "merged", "replaced", "rendered") and not want: self._module.fail_json( - msg="value of config parameter must not be empty for state {0}".format( - state - ) + msg="value of config parameter must not be empty for state {0}".format(state), ) commands = [] @@ -196,27 +186,20 @@ def _state_replaced(self, want, have): have_v6 = obj_in_have.pop("ipv6", []) if obj_in_have else [] # Process lists of dicts separately - v4_cmds = self._v4_cmds( - want.pop("ipv4", []), have_v4, state="replaced" - ) - v6_cmds = self._v6_cmds( - want.pop("ipv6", []), have_v6, state="replaced" - ) + v4_cmds = self._v4_cmds(want.pop("ipv4", []), have_v4, state="replaced") + v6_cmds = self._v6_cmds(want.pop("ipv6", []), have_v6, state="replaced") # Process remaining attrs if obj_in_have: # Find 'want' changes first diff = self.diff_of_dicts(want, obj_in_have) rmv = {"name": name} - haves_not_in_want = ( - set(obj_in_have.keys()) - set(want.keys()) - set(diff.keys()) - ) + haves_not_in_want = set(obj_in_have.keys()) - set(want.keys()) - set(diff.keys()) for i in haves_not_in_want: rmv[i] = obj_in_have[i] cmds.extend(self.generate_delete_commands(rmv)) else: diff = want - cmds.extend(self.add_commands(diff, name=name)) cmds.extend(v4_cmds) cmds.extend(v6_cmds) @@ -310,9 +293,7 @@ def _v4_cmds(self, want, have, state=None): sec_to_rmv = [] sec_diff = self.diff_list_of_dicts(sec_h, sec_w) for i in sec_diff: - if overridden or [ - w for w in sec_w if w["address"] == i["address"] - ]: + if overridden or [w for w in sec_w if w["address"] == i["address"]]: sec_to_rmv.append(i["address"]) # Check if new primary is currently a secondary @@ -329,7 +310,7 @@ def _v4_cmds(self, want, have, state=None): if diff: addr = diff.get("address") or pri_w.get("address") cmd = "ip address %s" % addr - tag = diff.get("tag") + tag = diff.get("tag") or pri_w.get("tag") cmd += " tag %s" % tag if tag else "" cmds.append(cmd) @@ -416,11 +397,20 @@ def generate_delete_commands(self, obj): commands.append("no encapsulation dot1q") if "redirects" in obj: if not self.check_existing(name, "has_secondary") or re.match( - "N[35679]", self.platform + "N[35679]", + self.platform, ): # device auto-enables redirects when secondaries are removed; # auto-enable may fail on legacy platforms so always do explicit enable commands.append("ip redirects") + if "ipv6_redirects" in obj: + if not self.check_existing(name, "has_secondary") or re.match( + "N[35679]", + self.platform, + ): + # device auto-enables redirects when secondaries are removed; + # auto-enable may fail on legacy platforms so always do explicit enable + commands.append("ipv6 redirects") if "unreachables" in obj: commands.append("no ip unreachables") if "ipv4" in obj: @@ -430,9 +420,7 @@ def generate_delete_commands(self, obj): if "evpn_multisite_tracking" in obj: have = self.existing_facts.get(name, {}) if have.get("evpn_multisite_tracking", False) is not False: - cmd = "no evpn multisite %s" % have.get( - "evpn_multisite_tracking" - ) + cmd = "no evpn multisite %s" % have.get("evpn_multisite_tracking") commands.append(cmd) return commands @@ -490,16 +478,18 @@ def add_commands(self, diff, name=""): no_cmd = "no " if diff["redirects"] is False else "" commands.append(no_cmd + "ip redirects") self.cmd_order_fixup(commands, name) + if "ipv6_redirects" in diff: + # Note: device will auto-disable redirects when secondaries are present + if diff["ipv6_redirects"] != self.check_existing(name, "ipv6_redirects"): + no_cmd = "no " if diff["ipv6_redirects"] is False else "" + commands.append(no_cmd + "ipv6 redirects") + self.cmd_order_fixup(commands, name) if "unreachables" in diff: - if diff["unreachables"] != self.check_existing( - name, "unreachables" - ): + if diff["unreachables"] != self.check_existing(name, "unreachables"): no_cmd = "no " if diff["unreachables"] is False else "" commands.append(no_cmd + "ip unreachables") if "evpn_multisite_tracking" in diff: - commands.append( - "evpn multisite " + str(diff["evpn_multisite_tracking"]) - ) + commands.append("evpn multisite " + str(diff["evpn_multisite_tracking"])) if "ipv4" in diff: commands.extend(self.generate_afi_commands(diff["ipv4"])) if "ipv6" in diff: @@ -511,11 +501,7 @@ def add_commands(self, diff, name=""): def generate_afi_commands(self, diff): cmds = [] for i in diff: - cmd = ( - "ipv6 address " - if re.search("::", i["address"]) - else "ip address " - ) + cmd = "ipv6 address " if re.search("::", i["address"]) else "ip address " cmd += i["address"] if i.get("secondary"): cmd += " secondary" @@ -532,12 +518,8 @@ def set_commands(self, w, have): commands = self.add_commands(w, name=name) else: # lists of dicts must be processed separately from non-list attrs - v4_cmds = self._v4_cmds( - w.pop("ipv4", []), obj_in_have.pop("ipv4", []), state="merged" - ) - v6_cmds = self._v6_cmds( - w.pop("ipv6", []), obj_in_have.pop("ipv6", []), state="merged" - ) + v4_cmds = self._v4_cmds(w.pop("ipv4", []), obj_in_have.pop("ipv4", []), state="merged") + v6_cmds = self._v6_cmds(w.pop("ipv6", []), obj_in_have.pop("ipv6", []), state="merged") # diff remaining attrs diff = self.diff_of_dicts(w, obj_in_have) @@ -551,14 +533,10 @@ def set_commands(self, w, have): def cmd_order_fixup(self, cmds, name): """Inserts 'interface ' config at the beginning of populated command list; reorders dependent commands that must process after others.""" if cmds: - if name and not [ - item for item in cmds if item.startswith("interface") - ]: + if name and not [item for item in cmds if item.startswith("interface")]: cmds.insert(0, "interface " + name) - redirects = [ - item for item in cmds if re.match("(no )*ip redirects", item) - ] + redirects = [item for item in cmds if re.match("(no )*ip(v6)* redirects", item)] if redirects: # redirects should occur after ipv4 commands, just move to end of list redirects = redirects.pop() diff --git a/plugins/module_utils/network/nxos/config/lacp/lacp.py b/plugins/module_utils/network/nxos/config/lacp/lacp.py index 015469d1e..526d70b85 100644 --- a/plugins/module_utils/network/nxos/config/lacp/lacp.py +++ b/plugins/module_utils/network/nxos/config/lacp/lacp.py @@ -12,6 +12,7 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( @@ -19,12 +20,11 @@ ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( dict_diff, - to_list, remove_empties, + to_list, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, -) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts class Lacp(ConfigBase): @@ -48,7 +48,9 @@ def get_lacp_facts(self, data=None): :returns: The current configuration as a dictionary """ facts, _warnings = Facts(self._module).get_facts( - self.gather_subset, self.gather_network_resources, data=data + self.gather_subset, + self.gather_network_resources, + data=data, ) lacp_facts = facts["ansible_network_resources"].get("lacp", {}) @@ -90,7 +92,7 @@ def execute_module(self): running_config = self._module.params["running_config"] if not running_config: self._module.fail_json( - msg="value of running_config parameter must not be empty for state parsed" + msg="value of running_config parameter must not be empty for state parsed", ) result["parsed"] = self.get_lacp_facts(data=running_config) @@ -130,9 +132,7 @@ def set_state(self, want, have): state = self._module.params["state"] if state in ("merged", "replaced", "rendered") and not want: self._module.fail_json( - msg="value of config parameter must not be empty for state {0}".format( - state - ) + msg="value of config parameter must not be empty for state {0}".format(state), ) commands = list() @@ -141,7 +141,7 @@ def set_state(self, want, have): commands.extend(self._state_deleted(want, have)) elif state in ["merged", "rendered"]: commands.extend(self._state_merged(want, have)) - elif state == "replaced": + elif state in ["replaced", "overridden"]: commands.extend(self._state_replaced(want, have)) return commands diff --git a/plugins/module_utils/network/nxos/config/lacp_interfaces/lacp_interfaces.py b/plugins/module_utils/network/nxos/config/lacp_interfaces/lacp_interfaces.py index 61eddc9e2..eaad0763d 100644 --- a/plugins/module_utils/network/nxos/config/lacp_interfaces/lacp_interfaces.py +++ b/plugins/module_utils/network/nxos/config/lacp_interfaces/lacp_interfaces.py @@ -12,24 +12,24 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, dict_diff, remove_empties, + to_list, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, -) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( flatten_dict, - search_obj_in_list, get_interface_type, normalize_interface, + search_obj_in_list, ) @@ -54,11 +54,11 @@ def get_lacp_interfaces_facts(self, data=None): :returns: The current configuration as a dictionary """ facts, _warnings = Facts(self._module).get_facts( - self.gather_subset, self.gather_network_resources, data=data - ) - lacp_interfaces_facts = facts["ansible_network_resources"].get( - "lacp_interfaces" + self.gather_subset, + self.gather_network_resources, + data=data, ) + lacp_interfaces_facts = facts["ansible_network_resources"].get("lacp_interfaces") if not lacp_interfaces_facts: return [] return lacp_interfaces_facts @@ -99,11 +99,9 @@ def execute_module(self): running_config = self._module.params["running_config"] if not running_config: self._module.fail_json( - msg="value of running_config parameter must not be empty for state parsed" + msg="value of running_config parameter must not be empty for state parsed", ) - result["parsed"] = self.get_lacp_interfaces_facts( - data=running_config - ) + result["parsed"] = self.get_lacp_interfaces_facts(data=running_config) if self.state in self.ACTION_STATES: result["before"] = existing_lacp_interfaces_facts @@ -133,7 +131,7 @@ def set_config(self, existing_lacp_interfaces_facts): "ethernet", ): self._module.fail_json( - msg="This module works with either portchannel or ethernet" + msg="This module works with either portchannel or ethernet", ) w.update({"name": normalize_interface(w["name"])}) want.append(remove_empties(w)) @@ -151,14 +149,9 @@ def set_state(self, want, have): to the desired configuration """ state = self._module.params["state"] - if ( - state in ("overridden", "merged", "replaced", "rendered") - and not want - ): + if state in ("overridden", "merged", "replaced", "rendered") and not want: self._module.fail_json( - msg="value of config parameter must not be empty for state {0}".format( - state - ) + msg="value of config parameter must not be empty for state {0}".format(state), ) commands = list() @@ -171,9 +164,7 @@ def set_state(self, want, have): if state in ["merged", "rendered"]: commands.extend(self._state_merged(flatten_dict(w), have)) elif state == "replaced": - commands.extend( - self._state_replaced(flatten_dict(w), have) - ) + commands.extend(self._state_replaced(flatten_dict(w), have)) return commands def _state_replaced(self, w, have): @@ -214,9 +205,7 @@ def _state_overridden(self, want, have): commands = [] for h in have: h = flatten_dict(h) - obj_in_want = flatten_dict( - search_obj_in_list(h["name"], want, "name") - ) + obj_in_want = flatten_dict(search_obj_in_list(h["name"], want, "name")) if h == obj_in_want: continue for w in want: @@ -251,9 +240,7 @@ def _state_deleted(self, want, have): commands = [] if want: for w in want: - obj_in_have = flatten_dict( - search_obj_in_list(w["name"], have, "name") - ) + obj_in_have = flatten_dict(search_obj_in_list(w["name"], have, "name")) commands.extend(self.del_attribs(obj_in_have)) else: if not have: diff --git a/plugins/module_utils/network/nxos/config/lag_interfaces/lag_interfaces.py b/plugins/module_utils/network/nxos/config/lag_interfaces/lag_interfaces.py index 39f632ace..fc3202a7f 100644 --- a/plugins/module_utils/network/nxos/config/lag_interfaces/lag_interfaces.py +++ b/plugins/module_utils/network/nxos/config/lag_interfaces/lag_interfaces.py @@ -12,20 +12,20 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, - remove_empties, dict_diff, + remove_empties, search_obj_in_list, + to_list, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, -) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( normalize_interface, ) @@ -50,11 +50,11 @@ def get_lag_interfaces_facts(self, data=None): :returns: The current configuration as a dictionary """ facts, _warnings = Facts(self._module).get_facts( - self.gather_subset, self.gather_network_resources, data=data - ) - lag_interfaces_facts = facts["ansible_network_resources"].get( - "lag_interfaces" + self.gather_subset, + self.gather_network_resources, + data=data, ) + lag_interfaces_facts = facts["ansible_network_resources"].get("lag_interfaces") if not lag_interfaces_facts: return [] return lag_interfaces_facts @@ -101,11 +101,9 @@ def execute_module(self): running_config = self._module.params["running_config"] if not running_config: self._module.fail_json( - msg="value of running_config parameter must not be empty for state parsed" + msg="value of running_config parameter must not be empty for state parsed", ) - result["parsed"] = self.get_lag_interfaces_facts( - data=running_config - ) + result["parsed"] = self.get_lag_interfaces_facts(data=running_config) if self.state in self.ACTION_STATES: result["before"] = existing_lag_interfaces_facts @@ -132,9 +130,7 @@ def set_config(self, existing_lag_interfaces_facts): w.update(remove_empties(w)) if "members" in w and w["members"]: for item in w["members"]: - item.update( - {"member": normalize_interface(item["member"])} - ) + item.update({"member": normalize_interface(item["member"])}) have = existing_lag_interfaces_facts resp = self.set_state(want, have) return to_list(resp) @@ -149,14 +145,9 @@ def set_state(self, want, have): to the desired configuration """ state = self._module.params["state"] - if ( - state in ("overridden", "merged", "replaced", "rendered") - and not want - ): + if state in ("overridden", "merged", "replaced", "rendered") and not want: self._module.fail_json( - msg="value of config parameter must not be empty for state {0}".format( - state - ) + msg="value of config parameter must not be empty for state {0}".format(state), ) commands = list() @@ -198,9 +189,7 @@ def _state_overridden(self, want, have): for h in have: obj_in_want = search_obj_in_list(h["name"], want, "name") if obj_in_want: - diff = self.diff_list_of_dicts( - h.get("members", []), obj_in_want["members"] - ) + diff = self.diff_list_of_dicts(h.get("members", []), obj_in_want["members"]) if not diff: continue commands.extend(self.del_all_commands(h)) @@ -245,12 +234,11 @@ def diff_list_of_dicts(self, want, have): diff = [] for w_item in want: - h_item = ( - search_obj_in_list(w_item["member"], have, key="member") or {} - ) + h_item = search_obj_in_list(w_item["member"], have, key="member") or {} delta = dict_diff(h_item, w_item) if delta: if h_item: + delta["exists"] = True if ( "mode" in delta.keys() and delta["mode"] == "on" @@ -283,19 +271,27 @@ def add_commands(self, diff, name): commands = [] name = name.strip("port-channel") for d in diff: - commands.append("interface" + " " + d["member"]) - cmd = "" + sub_cmd = "" + final_cmd = "" + member_exists = d.get("exists", False) group_cmd = "channel-group {0}".format(name) - if d.get("force"): - cmd = group_cmd + " force " + + # force does not appear in config + # will only be applied for a net new member + if d.get("force") and not member_exists: + sub_cmd += " force" if "mode" in d: - if cmd: - cmd = cmd + " mode " + d["mode"] - else: - cmd = group_cmd + " mode " + d["mode"] - if not cmd: - cmd = group_cmd - commands.append(cmd) + sub_cmd += " mode %s" % d["mode"] + + if sub_cmd: + final_cmd = group_cmd + sub_cmd + elif not member_exists: + final_cmd = group_cmd + + if final_cmd: + commands.append("interface" + " " + d["member"]) + commands.append(final_cmd) + return commands def set_commands(self, w, have): @@ -306,9 +302,7 @@ def set_commands(self, w, have): else: if "members" not in obj_in_have: obj_in_have["members"] = None - diff = self.diff_list_of_dicts( - w["members"], obj_in_have["members"] - ) + diff = self.diff_list_of_dicts(w["members"], obj_in_have["members"]) commands = self.add_commands(diff, w["name"]) return commands @@ -325,9 +319,7 @@ def del_intf_commands(self, w, have): commands = [] obj_in_have = search_obj_in_list(w["name"], have, "name") if obj_in_have: - lst_to_del = self.intersect_list_of_dicts( - w["members"], obj_in_have["members"] - ) + lst_to_del = self.intersect_list_of_dicts(w["members"], obj_in_have["members"]) if lst_to_del: for item in lst_to_del: commands.append("interface" + " " + item["member"]) diff --git a/plugins/module_utils/network/nxos/config/lldp_global/lldp_global.py b/plugins/module_utils/network/nxos/config/lldp_global/lldp_global.py index f338589b7..85f39682c 100644 --- a/plugins/module_utils/network/nxos/config/lldp_global/lldp_global.py +++ b/plugins/module_utils/network/nxos/config/lldp_global/lldp_global.py @@ -12,19 +12,19 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - remove_empties, dict_diff, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, + remove_empties, ) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts + class Lldp_global(ConfigBase): """ @@ -45,11 +45,11 @@ def get_lldp_global_facts(self, data=None): :returns: The current configuration as a dictionary """ facts, _warnings = Facts(self._module).get_facts( - self.gather_subset, self.gather_network_resources, data=data - ) - lldp_global_facts = facts["ansible_network_resources"].get( - "lldp_global" + self.gather_subset, + self.gather_network_resources, + data=data, ) + lldp_global_facts = facts["ansible_network_resources"].get("lldp_global") if not lldp_global_facts: return {} return lldp_global_facts @@ -90,7 +90,7 @@ def execute_module(self): running_config = self._module.params["running_config"] if not running_config: self._module.fail_json( - msg="value of running_config parameter must not be empty for state parsed" + msg="value of running_config parameter must not be empty for state parsed", ) result["parsed"] = self.get_lldp_global_facts(data=running_config) @@ -130,9 +130,7 @@ def set_state(self, want, have): state = self._module.params["state"] if state in ("merged", "replaced", "rendered") and not want: self._module.fail_json( - msg="value of config parameter must not be empty for state {0}".format( - state - ) + msg="value of config parameter must not be empty for state {0}".format(state), ) commands = list() @@ -140,7 +138,7 @@ def set_state(self, want, have): commands = self._state_deleted(have) elif state in ["merged", "rendered"]: commands = self._state_merged(want, have) - elif state == "replaced": + elif state in ["replaced", "overridden"]: commands = self._state_replaced(want, have) return commands @@ -175,9 +173,7 @@ def delete_nested_dict(self, have, want): return inner_dict else: if key in want.keys(): - outer_dict.update( - {key: self.delete_nested_dict(val, want[key])} - ) + outer_dict.update({key: self.delete_nested_dict(val, want[key])}) else: outer_dict.update({key: val}) return outer_dict @@ -193,11 +189,7 @@ def find_delete_params(self, have, want): else: if key == "tlv_select": delete_dict.update( - { - key: self.delete_nested_dict( - have["tlv_select"], want["tlv_select"] - ) - } + {key: self.delete_nested_dict(have["tlv_select"], want["tlv_select"])}, ) return delete_dict diff --git a/plugins/module_utils/network/nxos/config/lldp_interfaces/lldp_interfaces.py b/plugins/module_utils/network/nxos/config/lldp_interfaces/lldp_interfaces.py index f96f027c9..528f74970 100644 --- a/plugins/module_utils/network/nxos/config/lldp_interfaces/lldp_interfaces.py +++ b/plugins/module_utils/network/nxos/config/lldp_interfaces/lldp_interfaces.py @@ -12,24 +12,24 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, - remove_empties, dict_diff, + remove_empties, + to_list, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, -) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( flatten_dict, - search_obj_in_list, get_interface_type, normalize_interface, + search_obj_in_list, ) @@ -52,11 +52,11 @@ def get_lldp_interfaces_facts(self, data=None): :returns: The current configuration as a dictionary """ facts, _warnings = Facts(self._module).get_facts( - self.gather_subset, self.gather_network_resources, data=data - ) - lldp_interfaces_facts = facts["ansible_network_resources"].get( - "lldp_interfaces" + self.gather_subset, + self.gather_network_resources, + data=data, ) + lldp_interfaces_facts = facts["ansible_network_resources"].get("lldp_interfaces") if not lldp_interfaces_facts: return [] return lldp_interfaces_facts @@ -121,7 +121,7 @@ def set_config(self, existing_lldp_interfaces_facts): "ethernet", ): self._module.fail_json( - msg="This module works with either management or ethernet" + msg="This module works with either management or ethernet", ) w.update({"name": normalize_interface(w["name"])}) want.append(remove_empties(w)) @@ -154,9 +154,7 @@ def set_state(self, want, have): if state == "merged": commands.extend(self._state_merged(flatten_dict(w), have)) elif state == "replaced": - commands.extend( - self._state_replaced(flatten_dict(w), have) - ) + commands.extend(self._state_replaced(flatten_dict(w), have)) return commands def _state_parsed(self, want): @@ -189,9 +187,7 @@ def _state_replaced(self, want, have): commands = [] del_commands = [] delete_dict = {} - obj_in_have = flatten_dict( - search_obj_in_list(want["name"], have, "name") - ) + obj_in_have = flatten_dict(search_obj_in_list(want["name"], have, "name")) for k1 in obj_in_have.keys(): if k1 not in want.keys(): delete_dict.update({k1: obj_in_have[k1]}) @@ -256,9 +252,7 @@ def _state_deleted(self, want, have): commands = [] if want: for w in want: - obj_in_have = flatten_dict( - search_obj_in_list(w["name"], have, "name") - ) + obj_in_have = flatten_dict(search_obj_in_list(w["name"], have, "name")) commands.extend(self.del_commands(obj_in_have)) else: if not have: @@ -269,9 +263,7 @@ def _state_deleted(self, want, have): def set_commands(self, want, have): commands = [] - obj_in_have = flatten_dict( - search_obj_in_list(want["name"], have, "name") - ) + obj_in_have = flatten_dict(search_obj_in_list(want["name"], have, "name")) if not obj_in_have: commands = self.add_commands(flatten_dict(want)) else: @@ -297,9 +289,7 @@ def add_commands(self, d): else: commands.append("no lldp receive") if "management_address" in d: - commands.append( - "lldp tlv-set management-address " + d["management_address"] - ) + commands.append("lldp tlv-set management-address " + d["management_address"]) if "vlan" in d: commands.append("lldp tlv-set vlan " + str(d["vlan"])) @@ -315,10 +305,7 @@ def del_commands(self, obj): if "receive" in obj: commands.append("lldp receive") if "management_address" in obj: - commands.append( - "no lldp tlv-set management-address " - + obj["management_address"] - ) + commands.append("no lldp tlv-set management-address " + obj["management_address"]) if "vlan" in obj: commands.append("no lldp tlv-set vlan " + str(obj["vlan"])) diff --git a/plugins/module_utils/network/nxos/config/logging_global/logging_global.py b/plugins/module_utils/network/nxos/config/logging_global/logging_global.py index 2de0607bf..6e493ad36 100644 --- a/plugins/module_utils/network/nxos/config/logging_global/logging_global.py +++ b/plugins/module_utils/network/nxos/config/logging_global/logging_global.py @@ -7,6 +7,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -20,22 +21,21 @@ from copy import deepcopy from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - dict_merge, - get_from_dict, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( - get_logging_sevmap, -) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, + get_from_dict, ) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.logging_global import ( Logging_globalTemplate, ) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( + get_logging_sevmap, +) class Logging_global(ResourceModule): @@ -115,7 +115,7 @@ def generate_commands(self): self.state in self._state_set, have_k is False, want_k is None, - ) + ), ): # if want is missing and have is negated # set want to True in order to revert to default state diff --git a/plugins/module_utils/network/nxos/config/ntp_global/ntp_global.py b/plugins/module_utils/network/nxos/config/ntp_global/ntp_global.py index 7b485f6de..57a1a58d9 100644 --- a/plugins/module_utils/network/nxos/config/ntp_global/ntp_global.py +++ b/plugins/module_utils/network/nxos/config/ntp_global/ntp_global.py @@ -7,6 +7,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -20,15 +21,14 @@ from copy import deepcopy from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - dict_merge, -) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, ) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.ntp_global import ( Ntp_globalTemplate, ) @@ -148,9 +148,7 @@ def _ntp_list_to_dict(self, data): if "access_group" in tmp: for x in ["peer", "query_only", "serve", "serve_only"]: if x in tmp["access_group"]: - tmp["access_group"][x] = { - i["access_list"]: i for i in tmp["access_group"][x] - } + tmp["access_group"][x] = {i["access_list"]: i for i in tmp["access_group"][x]} pkey = { "authentication_keys": "id", "peers": "peer", diff --git a/plugins/module_utils/network/nxos/config/ospf_interfaces/ospf_interfaces.py b/plugins/module_utils/network/nxos/config/ospf_interfaces/ospf_interfaces.py index d2084edd8..0a1bc5806 100644 --- a/plugins/module_utils/network/nxos/config/ospf_interfaces/ospf_interfaces.py +++ b/plugins/module_utils/network/nxos/config/ospf_interfaces/ospf_interfaces.py @@ -7,6 +7,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -17,18 +18,15 @@ created. """ -from copy import deepcopy - from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - dict_merge, -) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.resource_module import ( +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, ) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.ospf_interfaces import ( Ospf_interfacesTemplate, ) @@ -92,9 +90,7 @@ def generate_commands(self): # if state is deleted, empty out wantd and set haved to wantd if self.state == "deleted": - haved = { - k: v for k, v in iteritems(haved) if k in wantd or not wantd - } + haved = {k: v for k, v in iteritems(haved) if k in wantd or not wantd} wantd = {} # remove superfluous config for overridden and deleted @@ -115,9 +111,7 @@ def _compare(self, want, have): begin = len(self.commands) self._compare_ospf_interfaces(want, have) if len(self.commands) != begin: - self.commands.insert( - begin, self._tmplt.render(want or have, "interface", False) - ) + self.commands.insert(begin, self._tmplt.render(want or have, "interface", False)) def _compare_ospf_interfaces(self, want, have): waf = want.get("address_family", {}) @@ -136,15 +130,10 @@ def _compare_ospf_interfaces(self, want, have): # this ensures that the "no" form of "ip ospf passive-interface" # command is executed even when there is no existing config - if ( - witem.get("passive_interface") is False - and "passive_interface" not in hitem - ): + if witem.get("passive_interface") is False and "passive_interface" not in hitem: hitem["passive_interface"] = True - if "passive_interface" in hitem and witem.get( - "default_passive_interface" - ): + if "passive_interface" in hitem and witem.get("default_passive_interface"): self.commands.append(self._generate_passive_intf(witem)) self.compare(parsers=self.parsers, want=witem, have=hitem) @@ -152,20 +141,14 @@ def _compare_ospf_interfaces(self, want, have): # compare top-level `multi_areas` config for area in witem.get("multi_areas", []): if area not in hitem.get("multi_areas", []): - self.addcmd( - {"afi": afi, "area": area}, "multi_areas", negate=False - ) + self.addcmd({"afi": afi, "area": area}, "multi_areas", negate=False) # remove superfluous top-level `multi_areas` config for area in hitem.get("multi_areas", []): if area not in witem.get("multi_areas", []): - self.addcmd( - {"afi": afi, "area": area}, "multi_areas", negate=True - ) + self.addcmd({"afi": afi, "area": area}, "multi_areas", negate=True) # compare config->address_family->processes - self._compare_processes( - afi, witem.get("processes", {}), hitem.get("processes", {}) - ) + self._compare_processes(afi, witem.get("processes", {}), hitem.get("processes", {})) def _compare_processes(self, afi, want, have): # add and update config->address_family->processes @@ -182,16 +165,12 @@ def _compare_processes(self, afi, want, have): for area in wproc.get("multi_areas", []): if area not in hproc.get("multi_areas", []): marea_dict["area"] = area - self.addcmd( - marea_dict, "processes_multi_areas", negate=False - ) + self.addcmd(marea_dict, "processes_multi_areas", negate=False) # remove superfluous processes->multi_areas config for area in hproc.get("multi_areas", []): if area not in wproc.get("multi_areas", []): marea_dict["area"] = area - self.addcmd( - marea_dict, "processes_multi_areas", negate=True - ) + self.addcmd(marea_dict, "processes_multi_areas", negate=True) # remove superflous config->address_family->processes for hproc in have.values(): @@ -210,12 +189,10 @@ def _list_to_dict(self, entry): for item in entry.values(): for ag in item.get("address_family", []): ag["processes"] = { - subentry["process_id"]: subentry - for subentry in ag.get("processes", []) + subentry["process_id"]: subentry for subentry in ag.get("processes", []) } item["address_family"] = { - subentry["afi"]: subentry - for subentry in item.get("address_family", []) + subentry["afi"]: subentry for subentry in item.get("address_family", []) } def _generate_passive_intf(self, data): diff --git a/plugins/module_utils/network/nxos/config/ospfv2/ospfv2.py b/plugins/module_utils/network/nxos/config/ospfv2/ospfv2.py index 0d67e9127..8a6f42e7a 100644 --- a/plugins/module_utils/network/nxos/config/ospfv2/ospfv2.py +++ b/plugins/module_utils/network/nxos/config/ospfv2/ospfv2.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -14,24 +15,21 @@ necessary to bring the current configuration to it's desired end-state is created """ -from copy import deepcopy + from ansible.module_utils.six import iteritems -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.ospfv2 import ( - Ospfv2Template, -) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - dict_merge, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, -) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.resource_module import ( +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, get_from_dict, ) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.ospfv2 import ( + Ospfv2Template, +) + class Ospfv2(ResourceModule): """ @@ -93,14 +91,8 @@ def gen_config(self): :returns: the commands necessary to migrate the current configuration to the desired configuration """ - wantd = { - (entry["process_id"]): entry - for entry in self.want.get("processes", []) - } - haved = { - (entry["process_id"]): entry - for entry in self.have.get("processes", []) - } + wantd = {(entry["process_id"]): entry for entry in self.want.get("processes", [])} + haved = {(entry["process_id"]): entry for entry in self.have.get("processes", [])} # turn all lists of dicts into dicts prior to merge for entry in wantd, haved: @@ -112,9 +104,7 @@ def gen_config(self): # if state is deleted, empty out wantd and set haved to wantd if self.state == "deleted": - haved = { - k: v for k, v in iteritems(haved) if k in wantd or not wantd - } + haved = {k: v for k, v in iteritems(haved) if k in wantd or not wantd} wantd = {} # if state is overridden, first remove processes that are in have but not in want @@ -138,9 +128,7 @@ def _compare(self, want, have): begin, self._tmplt.render( want or have, - "vrf" - if "vrf" in (want.keys() or have.keys()) - else "process_id", + "vrf" if "vrf" in (want.keys() or have.keys()) else "process_id", False, ), ) @@ -205,34 +193,24 @@ def _vrfs_compare(self, want, have): def _ospf_list_to_dict(self, entry): for _pid, proc in iteritems(entry): for area in proc.get("areas", []): - area["ranges"] = { - entry["prefix"]: entry for entry in area.get("ranges", []) - } + area["ranges"] = {entry["prefix"]: entry for entry in area.get("ranges", [])} area["filter_list"] = { - entry["direction"]: entry - for entry in area.get("filter_list", []) + entry["direction"]: entry for entry in area.get("filter_list", []) } mpls_areas = { entry["area_id"]: entry - for entry in proc.get("mpls", {}) - .get("traffic_eng", {}) - .get("areas", []) + for entry in proc.get("mpls", {}).get("traffic_eng", {}).get("areas", []) } if mpls_areas: proc["mpls"]["traffic_eng"]["areas"] = mpls_areas - proc["areas"] = { - entry["area_id"]: entry for entry in proc.get("areas", []) - } + proc["areas"] = {entry["area_id"]: entry for entry in proc.get("areas", [])} proc["summary_address"] = { - entry["prefix"]: entry - for entry in proc.get("summary_address", []) + entry["prefix"]: entry for entry in proc.get("summary_address", []) } proc["redistribute"] = { (entry.get("id"), entry["protocol"]): entry for entry in proc.get("redistribute", []) } if "vrfs" in proc: - proc["vrfs"] = { - entry["vrf"]: entry for entry in proc.get("vrfs", []) - } + proc["vrfs"] = {entry["vrf"]: entry for entry in proc.get("vrfs", [])} self._ospf_list_to_dict(proc["vrfs"]) diff --git a/plugins/module_utils/network/nxos/config/ospfv3/ospfv3.py b/plugins/module_utils/network/nxos/config/ospfv3/ospfv3.py index 464f7f07a..e60fc31a2 100644 --- a/plugins/module_utils/network/nxos/config/ospfv3/ospfv3.py +++ b/plugins/module_utils/network/nxos/config/ospfv3/ospfv3.py @@ -7,6 +7,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -17,19 +18,16 @@ created. """ -from copy import deepcopy - from ansible.module_utils.six import iteritems +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( + ResourceModule, +) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( dict_merge, get_from_dict, ) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.resource_module import ( - ResourceModule, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, -) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.ospfv3 import ( Ospfv3Template, ) @@ -83,14 +81,8 @@ def generate_commands(self): """Generate configuration commands to send based on want, have and desired state. """ - wantd = { - (entry["process_id"]): entry - for entry in self.want.get("processes", []) - } - haved = { - (entry["process_id"]): entry - for entry in self.have.get("processes", []) - } + wantd = {(entry["process_id"]): entry for entry in self.want.get("processes", [])} + haved = {(entry["process_id"]): entry for entry in self.have.get("processes", [])} # turn all lists of dicts into dicts prior to merge for entry in wantd, haved: @@ -102,9 +94,7 @@ def generate_commands(self): # if state is deleted, empty out wantd and set haved to wantd if self.state == "deleted": - haved = { - k: v for k, v in iteritems(haved) if k in wantd or not wantd - } + haved = {k: v for k, v in iteritems(haved) if k in wantd or not wantd} wantd = {} # if state is overridden, first remove processes that are in have but not in want @@ -133,9 +123,7 @@ def _compare(self, want, have): begin, self._tmplt.render( want or have, - "vrf" - if "vrf" in (want.keys() or have.keys()) - else "process_id", + "vrf" if "vrf" in (want.keys() or have.keys()) else "process_id", False, ), ) @@ -221,33 +209,22 @@ def _af_compare_lists(self, want, have): def _ospfv3_list_to_dict(self, entry): for _pid, proc in iteritems(entry): - proc["areas"] = { - entry["area_id"]: entry for entry in proc.get("areas", []) - } + proc["areas"] = {entry["area_id"]: entry for entry in proc.get("areas", [])} af = proc.get("address_family") if af: for area in af.get("areas", []): - area["ranges"] = { - entry["prefix"]: entry - for entry in area.get("ranges", []) - } + area["ranges"] = {entry["prefix"]: entry for entry in area.get("ranges", [])} area["filter_list"] = { - entry["direction"]: entry - for entry in area.get("filter_list", []) + entry["direction"]: entry for entry in area.get("filter_list", []) } - af["areas"] = { - entry["area_id"]: entry for entry in af.get("areas", []) - } + af["areas"] = {entry["area_id"]: entry for entry in af.get("areas", [])} af["summary_address"] = { - entry["prefix"]: entry - for entry in af.get("summary_address", []) + entry["prefix"]: entry for entry in af.get("summary_address", []) } af["redistribute"] = { (entry.get("id"), entry["protocol"]): entry for entry in af.get("redistribute", []) } if "vrfs" in proc: - proc["vrfs"] = { - entry["vrf"]: entry for entry in proc.get("vrfs", []) - } + proc["vrfs"] = {entry["vrf"]: entry for entry in proc.get("vrfs", [])} self._ospfv3_list_to_dict(proc["vrfs"]) diff --git a/plugins/module_utils/network/nxos/config/prefix_lists/prefix_lists.py b/plugins/module_utils/network/nxos/config/prefix_lists/prefix_lists.py index 4bfdae8b4..2c6bb8142 100644 --- a/plugins/module_utils/network/nxos/config/prefix_lists/prefix_lists.py +++ b/plugins/module_utils/network/nxos/config/prefix_lists/prefix_lists.py @@ -7,6 +7,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -18,15 +19,14 @@ """ from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - dict_merge, -) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, ) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.prefix_lists import ( Prefix_listsTemplate, ) @@ -74,18 +74,14 @@ def generate_commands(self): # if state is deleted, empty out wantd and set haved to wantd if self.state == "deleted": - haved = { - k: v for k, v in iteritems(haved) if k in wantd or not wantd - } + haved = {k: v for k, v in iteritems(haved) if k in wantd or not wantd} for key, hvalue in iteritems(haved): wvalue = wantd.pop(key, {}) if wvalue: wplists = wvalue.get("prefix_lists", {}) hplists = hvalue.get("prefix_lists", {}) hvalue["prefix_lists"] = { - k: v - for k, v in iteritems(hplists) - if k in wplists or not wplists + k: v for k, v in iteritems(hplists) if k in wplists or not wplists } # remove superfluous config for overridden and deleted @@ -109,17 +105,13 @@ def _compare(self, want, have): hentry = hplists.pop(wk, {}) self.compare(["description"], want=wentry, have=hentry) # compare sequences - self._compare_seqs( - wentry.pop("entries", {}), hentry.pop("entries", {}) - ) + self._compare_seqs(wentry.pop("entries", {}), hentry.pop("entries", {})) if self.state in ["overridden", "deleted"]: # remove remaining prefix lists for h in hplists.values(): self.commands.append( - "no {0} prefix-list {1}".format( - h["afi"].replace("ipv4", "ip"), h["name"] - ) + "no {0} prefix-list {1}".format(h["afi"].replace("ipv4", "ip"), h["name"]), ) def _compare_seqs(self, want, have): @@ -131,8 +123,9 @@ def _compare_seqs(self, want, have): self._module.fail_json( msg="Cannot update existing sequence {0} of prefix list {1} with state merged." " Please use state replaced or overridden.".format( - hentry["sequence"], hentry["name"] - ) + hentry["sequence"], + hentry["name"], + ), ) else: self.addcmd(hentry, "entry", negate=True) @@ -149,9 +142,5 @@ def _prefix_list_transform(self, entry): if "entries" in plist: for seq in plist["entries"]: seq.update({"afi": afi, "name": plist["name"]}) - plist["entries"] = { - x["sequence"]: x for x in plist["entries"] - } - value["prefix_lists"] = { - entry["name"]: entry for entry in value["prefix_lists"] - } + plist["entries"] = {x["sequence"]: x for x in plist["entries"]} + value["prefix_lists"] = {entry["name"]: entry for entry in value["prefix_lists"]} diff --git a/plugins/module_utils/network/nxos/config/route_maps/route_maps.py b/plugins/module_utils/network/nxos/config/route_maps/route_maps.py index 12d98ce12..fa7d57b1b 100644 --- a/plugins/module_utils/network/nxos/config/route_maps/route_maps.py +++ b/plugins/module_utils/network/nxos/config/route_maps/route_maps.py @@ -7,6 +7,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -17,19 +18,16 @@ created. """ -from copy import deepcopy - from ansible.module_utils.six import iteritems +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( + ResourceModule, +) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( dict_merge, get_from_dict, ) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.resource_module import ( - ResourceModule, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, -) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.route_maps import ( Route_mapsTemplate, ) @@ -72,6 +70,9 @@ def __init__(self, module): "set.path_selection", "set.tag", "set.weight", + "set.ip.next_hop.peer_address", + "set.ip.next_hop.redist_unchanged", + "set.ip.next_hop.unchanged", ] self.complex_parsers = [ "match.as_number.asn", @@ -101,6 +102,8 @@ def __init__(self, module): "set.distance", "set.evpn.gateway_ip", "set.community", + "set.ip.next_hop", + "set.ip.next_hop.verify_availability", ] def execute_module(self): @@ -127,9 +130,7 @@ def generate_commands(self): # if state is deleted, empty out wantd and set haved to wantd if self.state == "deleted": - haved = { - k: v for k, v in iteritems(haved) if k in wantd or not wantd - } + haved = {k: v for k, v in iteritems(haved) if k in wantd or not wantd} wantd = {} # remove superfluous config for overridden and deleted @@ -137,9 +138,7 @@ def generate_commands(self): for k, have in iteritems(haved): if k not in wantd: for _hk, hentry in iteritems(have.get("entries", {})): - self.commands.append( - self._tmplt.render(hentry, "route_map", True) - ) + self.commands.append(self._tmplt.render(hentry, "route_map", True)) for wk, want in iteritems(wantd): self._compare(want=want, have=haved.pop(wk, {})) @@ -160,21 +159,75 @@ def _compare_entries(self, want, have): begin = len(self.commands) self._compare_lists(wentry, hentry) + self._compare_extcomm(wentry, hentry) self.compare(parsers=self.linear_parsers, want=wentry, have=hentry) if len(self.commands) != begin: - self.commands.insert( - begin, self._tmplt.render(wentry, "route_map", False) - ) + # all 'no ' commands must be executed first to avoid NXOS command incompatibility errors + pos = begin + for i in range(begin, len(self.commands)): + if self.commands[i][0:3] == "no ": + self.commands.insert(pos, self.commands.pop(i)) + pos += 1 + self.commands.insert(begin, self._tmplt.render(wentry, "route_map", False)) # remove superfluos entries from have for _hk, hentry in iteritems(have): self.commands.append(self._tmplt.render(hentry, "route_map", True)) + def _compare_extcomm(self, want, have): + hentry = get_from_dict(data_dict=have, keypath="set.extcommunity.rt") or {} + wentry = get_from_dict(data_dict=want, keypath="set.extcommunity.rt") or {} + + h_nums = set(hentry.get("extcommunity_numbers", [])) + w_nums = set(wentry.get("extcommunity_numbers", [])) + + if h_nums != w_nums or wentry.get("additive") != hentry.get("additive"): + if self.state not in ["merged", "rendered"]: + # need to explicitly remove existing entry to correctly apply new one + self.commands.append(self._tmplt.render(hentry, "set.extcommunity.rt", negate=True)) + # default CLI behaviour is to 'merge' with existing entry + self.commands.append(self._tmplt.render(wentry, "set.extcommunity.rt", negate=False)) + def _compare_lists(self, want, have): for x in self.complex_parsers: wx = get_from_dict(want, x) or [] hx = get_from_dict(have, x) or [] + if x == "set.ip.next_hop.verify_availability": + w_set = {} + for i in range(0, len(wx)): + w_set[wx[i]["address"]] = wx[i] + h_set = {} + for i in range(0, len(hx)): + h_set[hx[i]["address"]] = hx[i] + sum_set = list(set(list(w_set) + list(h_set))) + for each in sum_set: + if each in w_set and each in h_set and w_set[each] == h_set[each]: + for i in range( + 0, + len(want["set"]["ip"]["next_hop"]["verify_availability"]), + ): + if ( + want["set"]["ip"]["next_hop"]["verify_availability"][i]["address"] + == each + ): + want["set"]["ip"]["next_hop"]["verify_availability"].pop(i) + break + for i in range( + 0, + len(have["set"]["ip"]["next_hop"]["verify_availability"]), + ): + if ( + have["set"]["ip"]["next_hop"]["verify_availability"][i]["address"] + == each + ): + have["set"]["ip"]["next_hop"]["verify_availability"].pop(i) + break + w_set.pop(each) + h_set.pop(each) + wx = w_set + hx = h_set + if isinstance(wx, list): wx = set(wx) if isinstance(hx, list): diff --git a/plugins/module_utils/network/nxos/config/snmp_server/snmp_server.py b/plugins/module_utils/network/nxos/config/snmp_server/snmp_server.py index cfda84e7c..472e7285f 100644 --- a/plugins/module_utils/network/nxos/config/snmp_server/snmp_server.py +++ b/plugins/module_utils/network/nxos/config/snmp_server/snmp_server.py @@ -7,6 +7,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -18,17 +19,17 @@ """ from copy import deepcopy + from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - dict_merge, - get_from_dict, -) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, + get_from_dict, ) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.snmp_server import ( Snmp_serverTemplate, ) @@ -229,14 +230,10 @@ def _build_key(x): tmp = deepcopy(data) if "communities" in tmp: - tmp["communities"] = { - _build_key(entry): entry for entry in tmp["communities"] - } + tmp["communities"] = {_build_key(entry): entry for entry in tmp["communities"]} if "users" in tmp: if "auth" in tmp["users"]: - tmp["users"]["auth"] = { - _build_key(entry): entry for entry in tmp["users"]["auth"] - } + tmp["users"]["auth"] = {_build_key(entry): entry for entry in tmp["users"]["auth"]} if "use_acls" in tmp["users"]: tmp["users"]["use_acls"] = { entry["user"]: entry for entry in tmp["users"]["use_acls"] diff --git a/plugins/module_utils/network/nxos/config/static_routes/static_routes.py b/plugins/module_utils/network/nxos/config/static_routes/static_routes.py index 59cd58399..3b554cea5 100644 --- a/plugins/module_utils/network/nxos/config/static_routes/static_routes.py +++ b/plugins/module_utils/network/nxos/config/static_routes/static_routes.py @@ -1,73 +1,50 @@ # # -*- coding: utf-8 -*- -# Copyright 2019 Red Hat +# Copyright 2023 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 + """ -The nxos_static_routes class +The nxos_static_routes config file. It is in this file where the current configuration (as dict) is compared to the provided configuration (as dict) and the command set -necessary to bring the current configuration to it's desired end-state is -created +necessary to bring the current configuration to its desired end-state is +created. """ -from __future__ import absolute_import, division, print_function -__metaclass__ = type -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( - ConfigBase, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( + ResourceModule, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, - remove_empties, - dict_diff, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, + dict_merge, ) -from copy import deepcopy -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( - flatten_dict, - search_obj_in_list, - get_interface_type, - normalize_interface, + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.static_routes import ( + Static_routesTemplate, ) -class Static_routes(ConfigBase): +class Static_routes(ResourceModule): """ - The nxos_xstatic_routes class + The nxos_static_routes config class """ - gather_subset = ["!all", "!min"] - - gather_network_resources = ["static_routes"] - def __init__(self, module): - super(Static_routes, self).__init__(module) - - def get_static_routes_facts(self, data=None): - """Get the 'facts' (the current configuration) - - :rtype: A dictionary - :returns: The current configuration as a dictionary - """ - facts, _warnings = Facts(self._module).get_facts( - self.gather_subset, self.gather_network_resources, data=data - ) - static_routes_facts = facts["ansible_network_resources"].get( - "static_routes" + super(Static_routes, self).__init__( + empty_fact_val={}, + facts_module=Facts(module), + module=module, + resource="static_routes", + tmplt=Static_routesTemplate(), ) - if not static_routes_facts: - return [] - - return static_routes_facts - - def edit_config(self, commands): - """Wrapper method for `_connection.edit_config()` - This exists solely to allow the unit test framework to mock device connection calls. - """ - return self._connection.edit_config(commands) def execute_module(self): """Execute the module @@ -75,547 +52,145 @@ def execute_module(self): :rtype: A dictionary :returns: The result from module execution """ - result = {"changed": False} - warnings = list() - commands = list() - state = self._module.params["state"] - action_states = ["merged", "replaced", "deleted", "overridden"] - - if state == "gathered": - result["gathered"] = self.get_static_routes_facts() - elif state == "rendered": - result["rendered"] = self.set_config({}) - # no need to fetch facts for rendered - elif state == "parsed": - result["parsed"] = self.set_config({}) - # no need to fetch facts for parsed - else: - existing_static_routes_facts = self.get_static_routes_facts() - commands.extend(self.set_config(existing_static_routes_facts)) - if commands and state in action_states: - if not self._module.check_mode: - self._connection.edit_config(commands) - result["changed"] = True - result["before"] = existing_static_routes_facts - result["commands"] = commands - - changed_static_routes_facts = self.get_static_routes_facts() - if result["changed"]: - result["after"] = changed_static_routes_facts - result["warnings"] = warnings - return result - - def set_config(self, existing_static_routes_facts): - """Collect the configuration from the args passed to the module, - collect the current configuration (as a dict from facts) - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - config = self._module.params["config"] - want = [] - if config: - for w in config: - want.append(remove_empties(w)) - have = existing_static_routes_facts - want = self.add_default_vrf(deepcopy(want)) - have = self.add_default_vrf(deepcopy(have)) - resp = self.set_state(want, have) - return to_list(resp) - - def set_state(self, want, have): - """Select the appropriate function based on the state provided - - :param want: the desired configuration as a dictionary - :param have: the current configuration as a dictionary - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration + if self.state not in ["parsed", "gathered"]: + self.generate_commands() + self.run_commands() + return self.result + + def generate_commands(self): + """Generate configuration commands to send based on + want, have and desired state. """ - state = self._module.params["state"] - commands = [] - if state == "overridden": - commands = self._state_overridden(want, have) - elif state == "deleted": - commands = self._state_deleted(want, have) - elif state == "rendered": - commands = self._state_rendered(want, have=[]) - elif state == "parsed": - want = self._module.params["running_config"] - commands = self._state_parsed(want) - else: - for w in want: - if state == "merged": - commands.extend(self._state_merged(w, have)) - elif state == "replaced": - commands.extend(self._state_replaced(w, have)) - return commands - - def _state_parsed(self, want): - return self.get_static_routes_facts(want) - - def _state_rendered(self, want, have): - commands = [] - for w in want: - commands.extend(self.set_commands(w, {})) - return commands - - def _state_replaced(self, want, have): - """The command generator when state is replaced - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - delete_commands = [] - state = self._module.params["state"] - merged_commands = [] - obj_in_have = search_obj_in_list(want["vrf"], have, "vrf") - # in replaced, we check if whatever in have is in want, unlike merged. This is because we need to apply deleted on have config - if obj_in_have and obj_in_have != {"vrf": "default"}: - want_afi_list = [] - if "address_families" in want.keys(): - want_afi_list = [w["afi"] for w in want["address_families"]] - if len(want_afi_list) > 0: - for h in obj_in_have["address_families"]: - if h["afi"] in want_afi_list: - want_afi = search_obj_in_list( - h["afi"], want["address_families"], "afi" - ) - want_dest_list = [] - if "routes" in want_afi.keys(): - want_dest_list = [ - w["dest"] for w in want_afi["routes"] - ] - if len(want_dest_list) > 0: - for ro in h["routes"]: - if ro["dest"] in want_dest_list: - want_dest = search_obj_in_list( - ro["dest"], want_afi["routes"], "dest" - ) - want_next_hops = [] - if "next_hops" in want_dest.keys(): - want_next_hops = list( - want_dest["next_hops"] - ) - if len(want_next_hops) > 0: - for next_hop in ro["next_hops"]: - if next_hop not in want_next_hops: - # have's next hop not in want, so delete it - delete_dict = { - "vrf": obj_in_have["vrf"], - "address_families": [ - { - "afi": h["afi"], - "routes": [ - { - "dest": ro[ - "dest" - ], - "next_hops": [ - next_hop - ], - } - ], - } - ], - } - delete_commands.extend( - self.del_commands( - [delete_dict] - ) - ) - else: - # want has no next_hops, so delete all next_hops under that dest - if state == "overridden": - delete_dict = { - "vrf": obj_in_have["vrf"], - "address_families": [ - { - "afi": h["afi"], - "routes": [ - { - "dest": ro[ - "dest" - ], - "next_hops": ro[ - "next_hops" - ], - } - ], - } - ], - } - delete_commands.extend( - self.del_commands( - [delete_dict] - ) - ) - else: - if state == "overridden": - delete_dict = { - "vrf": obj_in_have["vrf"], - "address_families": [ - { - "afi": h["afi"], - "routes": [ - { - "dest": ro["dest"], - "next_hops": ro[ - "next_hops" - ], - } - ], - } - ], - } - delete_commands.extend( - self.del_commands([delete_dict]) - ) - - else: - if ( - state == "overridden" - ): # want has no 'routes' key, so delete all routes under that afi - if "routes" in h.keys(): - delete_dict = { - "vrf": obj_in_have["vrf"], - "address_families": [ - { - "afi": h["afi"], - "routes": h["routes"], - } - ], - } - delete_commands.extend( - self.del_commands([delete_dict]) - ) - else: - if ( - state == "overridden" - ): # want has 'vrf' key only. So delete all address families in it - delete_commands.extend( - self.del_commands( - [ - { - "address_families": list( - obj_in_have["address_families"] - ), - "vrf": obj_in_have["vrf"], - } - ] - ) - ) - final_delete_commands = [] - for d in delete_commands: - if d not in final_delete_commands: - final_delete_commands.append(d) - # if there are two afis, 'vrf context..' is added twice fom del_commands. The above code removes the redundant 'vrf context ..' - merged_commands = self.set_commands(want, have) - if merged_commands: - cmds = set(final_delete_commands).intersection( - set(merged_commands) - ) - for c in cmds: - merged_commands.remove(c) - - # set_commands adds a 'vrf context..' line. The above code removes the redundant 'vrf context ..' - commands.extend(final_delete_commands) - commands.extend(merged_commands) - return commands - - def _state_overridden(self, want, have): - """The command generator when state is overridden - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - want_vrfs = [w["vrf"] for w in want] - for h in have: - if h["vrf"] not in want_vrfs and h["vrf"] != "management": - commands.extend(self._state_deleted([h], have)) - for w in want: - commands.extend(self._state_replaced(w, have)) - return commands - - def _state_merged(self, want, have): - """The command generator when state is merged - - :rtype: A list - :returns: the commands necessary to merge the provided into - the current configuration - """ - return self.set_commands(want, have) - - def _state_deleted(self, want, have): - """The command generator when state is deleted - - :rtype: A list - :returns: the commands necessary to remove the current configuration - of the provided objects - """ - commands = [] - if want: - for w in want: - delete_dict = {} - obj_in_have = search_obj_in_list(w["vrf"], have, "vrf") - if obj_in_have: - if "address_families" in w.keys(): - o1 = obj_in_have["address_families"] - afi_list = [o["afi"] for o in o1] # have's afi list - for w1 in w["address_families"]: - if w1["afi"] in afi_list: - o2 = search_obj_in_list(w1["afi"], o1, "afi") - state = self._module.params["state"] - if state != "deleted": - # Deleted scope is till afi only. Part below is for use by overridden state. - if "routes" in w1.keys(): - for w2 in w1["routes"]: - o3 = search_obj_in_list( - w2["dest"], - o2["routes"], - "dest", - ) - hops = [] - if "next_hops" in w2.keys(): - for nh in w2["next_hops"]: - if nh in o3["next_hops"]: - hops.append(nh) - else: - # if next hops not given - hops = o3["next_hops"] - - delete_dict = { - "vrf": obj_in_have["vrf"], - "address_families": [ - { - "afi": w1["afi"], - "routes": [ - { - "dest": w2[ - "dest" - ], - "next_hops": hops, - } - ], - } - ], - } - commands.extend( - self.del_commands( - [delete_dict] - ) - ) - else: - # case when only afi given for delete - delete_dict = { - "vrf": obj_in_have["vrf"], - "address_families": [ - { - "afi": o2["afi"], - "routes": o2["routes"], - } - ], - } - commands.extend( - self.del_commands([delete_dict]) - ) - else: - commands.extend( - self.del_commands( - [ - { - "vrf": obj_in_have["vrf"], - "address_families": [o2], - } - ] - ) - ) - else: - # only vrf given to delete - commands.extend(self.del_commands([obj_in_have])) - else: - if have: - # delete everything - del_have = [] - for h in have: - if h["vrf"] != "management": # protect management vrf - del_have.append(h) - commands = self.del_commands(del_have) - - final_delete_commands = [] - # del_commands might add 'vrf context..' twice for two routes in the same vrf. This removes it - for c in commands: - if c not in final_delete_commands: - final_delete_commands.append(c) - return final_delete_commands - - def del_commands(self, have): - commands = [] - for h in have: - if h != {"vrf": "default"}: - vrf = h["vrf"] - if "default" not in vrf: - commands.append("vrf context " + vrf) + wantd, delete_spcl = self.list_to_dict(self.want, "want") + haved, n_req = self.list_to_dict(self.have, "have") + + if delete_spcl and haved and self.state == "deleted": + for pk, to_rem in delete_spcl.items(): + if pk in ["ipv4", "ipv6"]: + _afis = haved.get("(_afis_)") + for k, v in _afis.get(pk, {}).items(): + for each_dest in to_rem: + if k.split("_")[0] == each_dest: + self.addcmd({pk: v}, pk, True) else: - # Default static routes are configured in global context. - # "vrf context default" command throws error 9.X release onwards. - # Changing the context to global is achieved by "configure terminal" - commands.append("configure terminal") - for af in h["address_families"]: - for route in af["routes"]: - for next_hop in route["next_hops"]: - command = self.del_next_hop(af, route, next_hop) - commands.append(command.strip()) - return commands - - def del_next_hop(self, af, route, next_hop): - command = "" - if af["afi"] == "ipv4": - command = ( - "no ip route " - + route["dest"] - + " " - + self.add_commands(next_hop) - ) - else: - command = ( - "no ipv6 route " - + route["dest"] - + " " - + self.add_commands(next_hop) - ) - return command - - def add_commands(self, want): - command = "" - params = want.keys() - pref = vrf = ip = intf = name = tag = track = "" - if "admin_distance" in params: - pref = str(want["admin_distance"]) + " " - if "track" in params: - track = "track " + str(want["track"]) + " " - if "dest_vrf" in params: - vrf = "vrf " + str(want["dest_vrf"]) + " " - if "forward_router_address" in params: - ip = want["forward_router_address"] + " " - if "interface" in params: - intf = normalize_interface(want["interface"]) + " " - if "null0" in intf: - ip = "" - intf = "null0 " - if "route_name" in params: - name = "name " + str(want["route_name"]) + " " - if "tag" in params: - tag = "tag " + str(want["tag"]) + " " - command = intf + ip + vrf + name + tag + track + pref - if intf != "Null0 " and ip == "": - self._module.fail_json(msg="forward_router_address error") - return command.strip() - - def set_commands(self, want, have): - commands = [] - h1 = h2 = h3 = {} - want = remove_empties(want) - vrf_list = [] - if have: - vrf_list = [h["vrf"] for h in have] - if want["vrf"] in vrf_list and have != [{"vrf": "default"}]: - for x in have: - if x["vrf"] == want["vrf"]: - h1 = x # this has the 'have' dict with same vrf as want - if "address_families" in h1.keys(): - afi_list = [h["afi"] for h in h1["address_families"]] - if "address_families" in want.keys(): - for af in want["address_families"]: - if af["afi"] in afi_list: - for x in h1["address_families"]: - if x["afi"] == af["afi"]: - h2 = x # this has the have dict with same vrf and afi as want - dest_list = [h["dest"] for h in h2["routes"]] - if "routes" in af.keys(): - for ro in af["routes"]: - if ro["dest"] in dest_list: - for x in h2["routes"]: - if x["dest"] == ro["dest"]: - h3 = x # this has the have dict with same vrf, afi and dest as want - next_hop_list = list(h3["next_hops"]) - if "next_hops" in ro.keys(): - for nh in ro["next_hops"]: - if "interface" in nh.keys(): - nh[ - "interface" - ] = normalize_interface( - nh["interface"] - ) - if nh not in next_hop_list: - # no match for next hop in have - commands = ( - self.set_next_hop( - want, - h2, - nh, - ro, - commands, - ) - ) - vrf_list.append( - want["vrf"] - ) - else: - # no match for dest - if "next_hops" in ro.keys(): - for nh in ro["next_hops"]: - commands = self.set_next_hop( - want, h2, nh, ro, commands - ) - else: - # no match for afi - if "routes" in af.keys(): - for ro in af["routes"]: - for nh in ro["next_hops"]: - commands = self.set_next_hop( - want, af, nh, ro, commands - ) - else: - # no match for vrf - vrf_list.append(want["vrf"]) - for af in want["address_families"]: - for ro in af["routes"]: - for nh in ro["next_hops"]: - commands = self.set_next_hop( - want, af, nh, ro, commands + sp_begin = len(self.commands) + _vrfs = haved.get(pk) + for ak, v in _vrfs.items(): + for k, srts in v.items(): + for each_dest in to_rem.get(ak): + if k.split("_")[0] == each_dest: + self.addcmd({ak: srts}, ak, True) + if len(self.commands) != sp_begin: + self.commands.insert( + sp_begin, + self._tmplt.render({"namevrf": pk}, "vrf", False), ) - return commands - def set_next_hop(self, want, h2, nh, ro, commands): - vrf = want["vrf"] - if h2["afi"] == "ipv4": - com = "ip route " + ro["dest"] + " " + self.add_commands(nh) else: - com = "ipv6 route " + ro["dest"] + " " + self.add_commands(nh) - commands.append(com.strip()) - if "default" not in vrf: - string = "vrf context " + str(vrf) - else: - # Default static routes are configured in global context. - # "vrf context default" command throws error 9.X release onwards. - # Changing the context to global is achieved by "configure terminal" - string = "configure terminal" - if string not in commands: - commands.insert(0, string) - return commands - - def add_default_vrf(self, dictionary): - """ - This method is used to add 'default' vrf to the facts collected as global/default vrf - is not shown in facts. vrf key exists for all vrfs except global. - """ - for d in dictionary: - if "vrf" not in d.keys(): - d.update({"vrf": "default"}) - return dictionary + # if state is merged, merge want onto have and then compare + if self.state == "merged": + wantd = dict_merge(haved, wantd) + + for k, want in wantd.items(): + self._compare_top_level_keys(want=want, have=haved.pop(k, {}), vrf_name=k) + + if (self.state == "deleted" and not wantd) or self.state in ["overridden"]: + for k, have in haved.items(): + self._compare_top_level_keys(want={}, have=have, vrf_name=k) + + def _compare_top_level_keys(self, want, have, vrf_name): + begin = len(self.commands) + + # if state is deleted, empty out wantd and set haved to wantd + if self.state == "deleted" and have: + _have = {} + for addf in ["ipv4", "ipv6"]: + _temp_sr = {} + for k, ha in have.get(addf, {}).items(): + if k in want.get(addf, {}): # or not want.get(addf) + _temp_sr[k] = ha + if _temp_sr: + _have[addf] = _temp_sr + if _have: + have = _have + want = {} + + if self.state != "deleted": + for _afi, routes in want.items(): + self._compare(s_want=routes, s_have=have.pop(_afi, {}), afi=_afi) + + if self.state in ["overridden", "deleted"]: + for _afi, routes in have.items(): + self._compare(s_want={}, s_have=routes, afi=_afi) + + if len(self.commands) != begin: + if vrf_name == "(_afis_)": + afi_cmds = [] + for cmds in range(begin, len(self.commands)): + self.commands.insert(0, self.commands.pop()) + # afi_cmds.append(self.commands.pop()) + # self.commands = afi_cmds + self.commands + else: + self.commands.insert(begin, self._tmplt.render({"namevrf": vrf_name}, "vrf", False)) + + def _compare(self, s_want, s_have, afi): + for name, w_srs in s_want.items(): + have_srs = s_have.pop(name, {}) + self.compare(parsers=afi, want={afi: w_srs}, have={afi: have_srs}) + + # remove remaining items in have for replaced state + for name, h_srs in s_have.items(): + self.compare(parsers=afi, want={}, have={afi: h_srs}) + + def list_to_dict(self, param, operation): + _static_rts = {} + _delete_spc = {} + if param: + for srs in param: + _vrf = srs.get("vrf") + _srts = {} + for adfs in srs.get("address_families", []): + _afi = adfs.get("afi") + _routes = {} + for rts in adfs.get("routes", []): + _dest = rts.get("dest", "") + + # below if specific to special delete + if ( + self.state == "deleted" + and operation == "want" + and not rts.get("next_hops") + ): + if _vrf: + if not _delete_spc.get(_vrf): + _delete_spc[_vrf] = {} + if not _delete_spc[_vrf].get(_afi): + _delete_spc[_vrf][_afi] = [] + _delete_spc[_vrf][_afi].append(_dest) + else: + if not _delete_spc.get(_afi): + _delete_spc[_afi] = [] + _delete_spc[_afi].append(_dest) + + for nxh in rts.get("next_hops", []): + _forw_rtr_add = nxh.get("forward_router_address", "").upper() + _intf = nxh.get("interface", "") + _key = _dest + "_" + _forw_rtr_add + _intf + + dummy_sr = { + "afi": _afi, + "dest": _dest, + } + + if _vrf: + dummy_sr["vrf"] = _vrf + if _intf: + dummy_sr["interface"] = _intf + if _forw_rtr_add: + dummy_sr["forward_router_address"] = _forw_rtr_add + dummy_sr.update(nxh) + + _routes[_key] = dummy_sr + _srts[_afi] = _routes + _static_rts[_vrf if _vrf else "(_afis_)"] = _srts + return _static_rts, _delete_spc diff --git a/plugins/module_utils/network/nxos/config/telemetry/telemetry.py b/plugins/module_utils/network/nxos/config/telemetry/telemetry.py index f66580447..da3f77439 100644 --- a/plugins/module_utils/network/nxos/config/telemetry/telemetry.py +++ b/plugins/module_utils/network/nxos/config/telemetry/telemetry.py @@ -12,42 +12,34 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import to_list + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.cmdref.telemetry.telemetry import ( - TMS_GLOBAL, TMS_DESTGROUP, + TMS_GLOBAL, TMS_SENSORGROUP, TMS_SUBSCRIPTION, ) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import NxosCmdRef from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.telemetry.telemetry import ( - normalize_data, - remove_duplicate_context, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.telemetry.telemetry import ( - valiate_input, + get_module_params_subsection, get_setval_path, massage_data, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.telemetry.telemetry import ( - get_module_params_subsection, + normalize_data, remove_duplicate_commands, + remove_duplicate_context, + valiate_input, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( normalize_interface, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - NxosCmdRef, -) class Telemetry(ConfigBase): @@ -68,7 +60,9 @@ def get_telemetry_facts(self, data=None): :returns: The current configuration as a dictionary """ facts, _warnings = Facts(self._module).get_facts( - self.gather_subset, self.gather_network_resources, data=data + self.gather_subset, + self.gather_network_resources, + data=data, ) telemetry_facts = facts["ansible_network_resources"].get("telemetry") if not telemetry_facts: @@ -89,24 +83,18 @@ def execute_module(self): state = self._module.params["state"] if "overridden" in state: - self._module.fail_json( - msg="State is invalid for this module." - ) + self._module.fail_json(msg="State is invalid for this module.") # When state is 'deleted', the module_params should not contain data # under the 'config' key if "deleted" in state and self._module.params.get("config"): - self._module.fail_json( - msg="Remove config key from playbook when state is " - ) + self._module.fail_json(msg="Remove config key from playbook when state is ") if self._module.params["config"] is None: self._module.params["config"] = {} # Normalize interface name. int = self._module.params["config"].get("source_interface") if int: - self._module.params["config"][ - "source_interface" - ] = normalize_interface(int) + self._module.params["config"]["source_interface"] = normalize_interface(int) if self.state in self.ACTION_STATES: existing_telemetry_facts = self.get_telemetry_facts() @@ -181,12 +169,8 @@ def set_state(self, want, have): # Build Telemetry Global NxosCmdRef Object cmd_ref["TMS_GLOBAL"]["ref"] = [] - self._module.params["config"] = get_module_params_subsection( - ALL_MP, "TMS_GLOBAL" - ) - cmd_ref["TMS_GLOBAL"]["ref"].append( - NxosCmdRef(self._module, TMS_GLOBAL) - ) + self._module.params["config"] = get_module_params_subsection(ALL_MP, "TMS_GLOBAL") + cmd_ref["TMS_GLOBAL"]["ref"].append(NxosCmdRef(self._module, TMS_GLOBAL)) ref = cmd_ref["TMS_GLOBAL"]["ref"][0] ref.set_context() ref.get_existing() @@ -204,25 +188,19 @@ def build_cmdref_objects(td): saved_ids.append(playvals["id"]) resource_key = td["cmd"].format(playvals["id"]) # Only build the NxosCmdRef object for the td['name'] module parameters. - self._module.params[ - "config" - ] = get_module_params_subsection( - ALL_MP, td["type"], playvals["id"] - ) - cmd_ref[td["type"]]["ref"].append( - NxosCmdRef(self._module, td["obj"]) + self._module.params["config"] = get_module_params_subsection( + ALL_MP, + td["type"], + playvals["id"], ) + cmd_ref[td["type"]]["ref"].append(NxosCmdRef(self._module, td["obj"])) ref = cmd_ref[td["type"]]["ref"][-1] ref.set_context([resource_key]) - if td["type"] == "TMS_SENSORGROUP" and get_setval_path( - self._module - ): + if td["type"] == "TMS_SENSORGROUP" and get_setval_path(self._module): # Sensor group path setting can contain optional values. # Call get_setval_path helper function to process any # optional setval keys. - ref._ref["path"]["setval"] = get_setval_path( - self._module - ) + ref._ref["path"]["setval"] = get_setval_path(self._module) ref.get_existing(device_cache) ref.get_playvals() if td["type"] == "TMS_DESTGROUP": @@ -276,9 +254,7 @@ def _state_replaced(want, have): ref["tms_global"] = NxosCmdRef([], TMS_GLOBAL, ref_only=True) ref["tms_destgroup"] = NxosCmdRef([], TMS_DESTGROUP, ref_only=True) ref["tms_sensorgroup"] = NxosCmdRef([], TMS_SENSORGROUP, ref_only=True) - ref["tms_subscription"] = NxosCmdRef( - [], TMS_SUBSCRIPTION, ref_only=True - ) + ref["tms_subscription"] = NxosCmdRef([], TMS_SUBSCRIPTION, ref_only=True) # Order matters for state replaced. # First remove all subscriptions, followed by sensor-groups and destination-groups. @@ -377,28 +353,20 @@ def _state_replaced(want, have): have_resources = massaged_have.get("destination_groups") if resource == "TMS_SENSORGROUP": name = "sensor-group" - global_ctx = ref["tms_sensorgroup"]._ref["_template"][ - "context" - ] + global_ctx = ref["tms_sensorgroup"]._ref["_template"]["context"] setval = {} - setval["data_source"] = ref["tms_sensorgroup"]._ref[ - "data_source" - ]["setval"] + setval["data_source"] = ref["tms_sensorgroup"]._ref["data_source"]["setval"] setval["path"] = ref["tms_sensorgroup"]._ref["path"]["setval"] want_resources = massaged_want.get("sensor_groups") have_resources = massaged_have.get("sensor_groups") if resource == "TMS_SUBSCRIPTION": name = "subscription" - global_ctx = ref["tms_subscription"]._ref["_template"][ - "context" - ] + global_ctx = ref["tms_subscription"]._ref["_template"]["context"] setval = {} - setval["destination_group"] = ref["tms_subscription"]._ref[ - "destination_group" - ]["setval"] - setval["sensor_group"] = ref["tms_subscription"]._ref[ - "sensor_group" - ]["setval"] + setval["destination_group"] = ref["tms_subscription"]._ref["destination_group"][ + "setval" + ] + setval["sensor_group"] = ref["tms_subscription"]._ref["sensor_group"]["setval"] want_resources = massaged_want.get("subscriptions") have_resources = massaged_have.get("subscriptions") @@ -427,17 +395,11 @@ def _state_replaced(want, have): cmd = {} if item.get("data_source"): cmd["data_source"] = [ - setval["data_source"].format( - item["data_source"] - ) + setval["data_source"].format(item["data_source"]), ] if item.get("path"): - setval["path"] = get_setval_path( - item.get("path") - ) - cmd["path"] = [ - setval["path"].format(**item["path"]) - ] + setval["path"] = get_setval_path(item.get("path")) + cmd["path"] = [setval["path"].format(**item["path"])] add[resource].extend(global_ctx) if property_ctx[0] not in add[resource]: add[resource].extend(property_ctx) @@ -450,22 +412,18 @@ def _state_replaced(want, have): if item.get("destination_group"): cmd["destination_group"] = [ setval["destination_group"].format( - item["destination_group"] - ) + item["destination_group"], + ), ] if item.get("sensor_group"): cmd["sensor_group"] = [ - setval["sensor_group"].format( - **item["sensor_group"] - ) + setval["sensor_group"].format(**item["sensor_group"]), ] add[resource].extend(global_ctx) if property_ctx[0] not in add[resource]: add[resource].extend(property_ctx) if cmd.get("destination_group"): - add[resource].extend( - cmd["destination_group"] - ) + add[resource].extend(cmd["destination_group"]) if cmd.get("sensor_group"): add[resource].extend(cmd["sensor_group"]) @@ -478,9 +436,7 @@ def _state_replaced(want, have): if item is None: continue # item wanted but does not exist so add it - property_ctx = [ - "{0} {1}".format(name, want_key) - ] + property_ctx = ["{0} {1}".format(name, want_key)] if resource == "TMS_DESTGROUP": cmd = [setval.format(**item[cmd_property])] add[resource].extend(global_ctx) @@ -491,26 +447,16 @@ def _state_replaced(want, have): cmd = {} if item.get("data_source"): cmd["data_source"] = [ - setval["data_source"].format( - item["data_source"] - ) + setval["data_source"].format(item["data_source"]), ] if item.get("path"): - setval["path"] = get_setval_path( - item.get("path") - ) - cmd["path"] = [ - setval["path"].format( - **item["path"] - ) - ] + setval["path"] = get_setval_path(item.get("path")) + cmd["path"] = [setval["path"].format(**item["path"])] add[resource].extend(global_ctx) if property_ctx[0] not in add[resource]: add[resource].extend(property_ctx) if cmd.get("data_source"): - add[resource].extend( - cmd["data_source"] - ) + add[resource].extend(cmd["data_source"]) if cmd.get("path"): add[resource].extend(cmd["path"]) if resource == "TMS_SUBSCRIPTION": @@ -518,26 +464,20 @@ def _state_replaced(want, have): if item.get("destination_group"): cmd["destination_group"] = [ setval["destination_group"].format( - item["destination_group"] - ) + item["destination_group"], + ), ] if item.get("sensor_group"): cmd["sensor_group"] = [ - setval["sensor_group"].format( - **item["sensor_group"] - ) + setval["sensor_group"].format(**item["sensor_group"]), ] add[resource].extend(global_ctx) if property_ctx[0] not in add[resource]: add[resource].extend(property_ctx) if cmd.get("destination_group"): - add[resource].extend( - cmd["destination_group"] - ) + add[resource].extend(cmd["destination_group"]) if cmd.get("sensor_group"): - add[resource].extend( - cmd["sensor_group"] - ) + add[resource].extend(cmd["sensor_group"]) # process haves: for have_key in have_resources.keys(): @@ -555,14 +495,9 @@ def _state_replaced(want, have): if item is None: continue # have item not wanted so remove it - property_ctx = [ - "{0} {1}".format(name, have_key) - ] + property_ctx = ["{0} {1}".format(name, have_key)] if resource == "TMS_DESTGROUP": - cmd = [ - "no " - + setval.format(**item[cmd_property]) - ] + cmd = ["no " + setval.format(**item[cmd_property])] delete[resource].extend(global_ctx) if property_ctx[0] not in delete[resource]: delete[resource].extend(property_ctx) @@ -572,27 +507,18 @@ def _state_replaced(want, have): if item.get("data_source"): cmd["data_source"] = [ "no " - + setval["data_source"].format( - item["data_source"] - ) + + setval["data_source"].format(item["data_source"]), ] if item.get("path"): - setval["path"] = get_setval_path( - item.get("path") - ) + setval["path"] = get_setval_path(item.get("path")) cmd["path"] = [ - "no " - + setval["path"].format( - **item["path"] - ) + "no " + setval["path"].format(**item["path"]), ] delete[resource].extend(global_ctx) if property_ctx[0] not in delete[resource]: delete[resource].extend(property_ctx) if cmd.get("data_source"): - delete[resource].extend( - cmd["data_source"] - ) + delete[resource].extend(cmd["data_source"]) if cmd.get("path"): delete[resource].extend(cmd["path"]) if resource == "TMS_SUBSCRIPTION": @@ -600,28 +526,22 @@ def _state_replaced(want, have): if item.get("destination_group"): cmd["destination_group"] = [ "no " - + setval[ - "destination_group" - ].format(item["destination_group"]) + + setval["destination_group"].format( + item["destination_group"], + ), ] if item.get("sensor_group"): cmd["sensor_group"] = [ "no " - + setval["sensor_group"].format( - **item["sensor_group"] - ) + + setval["sensor_group"].format(**item["sensor_group"]), ] delete[resource].extend(global_ctx) if property_ctx[0] not in delete[resource]: delete[resource].extend(property_ctx) if cmd.get("destination_group"): - delete[resource].extend( - cmd["destination_group"] - ) + delete[resource].extend(cmd["destination_group"]) if cmd.get("sensor_group"): - delete[resource].extend( - cmd["sensor_group"] - ) + delete[resource].extend(cmd["sensor_group"]) add[resource] = remove_duplicate_context(add[resource]) delete[resource] = remove_duplicate_context(delete[resource]) diff --git a/plugins/module_utils/network/nxos/config/vlans/vlans.py b/plugins/module_utils/network/nxos/config/vlans/vlans.py index ca572ef45..515618ad8 100644 --- a/plugins/module_utils/network/nxos/config/vlans/vlans.py +++ b/plugins/module_utils/network/nxos/config/vlans/vlans.py @@ -13,20 +13,21 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type import re + from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( dict_diff, - to_list, remove_empties, + to_list, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, -) + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( search_obj_in_list, ) @@ -57,7 +58,9 @@ def get_vlans_facts(self, data=None): :returns: The current configuration as a dictionary """ self.facts, _warnings = Facts(self._module).get_facts( - self.gather_subset, self.gather_network_resources, data=data + self.gather_subset, + self.gather_network_resources, + data=data, ) vlans_facts = self.facts["ansible_network_resources"].get("vlans") if not vlans_facts: @@ -109,7 +112,7 @@ def execute_module(self): running_config = self._module.params["running_config"] if not running_config: self._module.fail_json( - msg="value of running_config parameter must not be empty for state parsed" + msg="value of running_config parameter must not be empty for state parsed", ) result["parsed"] = self.get_vlans_facts(data=running_config) @@ -147,14 +150,9 @@ def set_state(self, want, have): to the desired configuration """ state = self._module.params["state"] - if ( - state in ("overridden", "merged", "replaced", "rendered") - and not want - ): + if state in ("overridden", "merged", "replaced", "rendered") and not want: self._module.fail_json( - msg="value of config parameter must not be empty for state {0}".format( - state - ) + msg="value of config parameter must not be empty for state {0}".format(state), ) commands = list() diff --git a/plugins/module_utils/network/nxos/facts/acl_interfaces/acl_interfaces.py b/plugins/module_utils/network/nxos/facts/acl_interfaces/acl_interfaces.py index d143ecc3f..053b56a91 100644 --- a/plugins/module_utils/network/nxos/facts/acl_interfaces/acl_interfaces.py +++ b/plugins/module_utils/network/nxos/facts/acl_interfaces/acl_interfaces.py @@ -12,19 +12,18 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type import re + from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.acl_interfaces.acl_interfaces import ( Acl_interfacesArgs, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( - normalize_interface, -) class Acl_interfacesFacts(object): @@ -63,9 +62,7 @@ def populate_facts(self, connection, ansible_facts, data=None): for i in range(len(data)): intf = data[i].split("\n") for l in range(1, len(intf)): - if not re.search( - "ip(v6)?( port)? (access-group|traffic-filter)", intf[l] - ): + if not re.search("ip(v6)?( port)? (access-group|traffic-filter)", intf[l]): intf[l] = "" intf = list(filter(None, intf)) resources.append(intf) @@ -80,9 +77,7 @@ def populate_facts(self, connection, ansible_facts, data=None): ansible_facts["ansible_network_resources"].pop("acl_interfaces", None) facts = {} if objs: - params = utils.validate_config( - self.argument_spec, {"config": objs} - ) + params = utils.validate_config(self.argument_spec, {"config": objs}) params = utils.remove_empties(params) facts["acl_interfaces"] = params["config"] diff --git a/plugins/module_utils/network/nxos/facts/acls/acls.py b/plugins/module_utils/network/nxos/facts/acls/acls.py index 9c7c25bbe..ca086bcf9 100644 --- a/plugins/module_utils/network/nxos/facts/acls/acls.py +++ b/plugins/module_utils/network/nxos/facts/acls/acls.py @@ -11,17 +11,22 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type import re + from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.acls.acls import ( AclsArgs, ) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( + validate_ipv4_addr, + validate_ipv6_addr, +) class AclsFacts(object): @@ -41,9 +46,7 @@ def __init__(self, module, subspec="config", options="options"): self.generated_spec = utils.generate_dict(facts_argument_spec) def get_device_data(self, connection): - data = connection.get( - "show running-config | section 'ip(v6)* access-list'" - ) + data = connection.get("show running-config | section '^ip(v6)* access-list'") if data == "{}": return "" return data @@ -82,9 +85,7 @@ def populate_facts(self, connection, ansible_facts, data=None): ansible_facts["ansible_network_resources"].pop("acls", None) facts = {} if objs: - params = utils.validate_config( - self.argument_spec, {"config": objs} - ) + params = utils.validate_config(self.argument_spec, {"config": objs}) params = utils.remove_empties(params) facts["acls"] = params["config"] @@ -99,11 +100,15 @@ def get_endpoint(self, ace, pro): else: # it could be a.b.c.d or a.b.c.d/x or a.b.c.d/32 if "/" in option: # or 'host' in option: - ip = re.search(r"(.*)/(\d+)", option) - if int(ip.group(2)) < 32 or 32 < int(ip.group(2)) < 128: - ret_dict.update({"prefix": option}) + prefix = re.search(r"(.*)/(\d+)", option) + ip = prefix.group(1) + cidr = prefix.group(2) + if (validate_ipv4_addr(option) and int(cidr) == 32) or ( + validate_ipv6_addr(option) and int(cidr) == 128 + ): + ret_dict.update({"host": ip}) else: - ret_dict.update({"host": ip.group(1)}) + ret_dict.update({"prefix": option}) else: ret_dict.update({"address": option}) wb = ace.split()[1] @@ -114,26 +119,26 @@ def get_endpoint(self, ace, pro): keywords = ["eq", "lt", "gt", "neq", "range"] if len(ace.split()) and ace.split()[0] in keywords: port_protocol = {} - port_pro = re.search(r"(eq|lt|gt|neq) (\w*)", ace) + port_pro = re.search(r"(eq|lt|gt|neq) (\S+)", ace) if port_pro: - port_protocol.update( - {port_pro.group(1): port_pro.group(2)} - ) + port_protocol.update({port_pro.group(1): port_pro.group(2)}) ace = re.sub(port_pro.group(1), "", ace, 1) ace = re.sub(port_pro.group(2), "", ace, 1) else: - limit = re.search(r"(range) (\w*) (\w*)", ace) + limit = re.search(r"range\s(?P\S+)\s(?P\S+)", ace) if limit: + rstart = limit.groupdict()["rstart"] + rend = limit.groupdict()["rend"] port_protocol.update( { "range": { - "start": limit.group(2), - "end": limit.group(3), - } - } + "start": rstart, + "end": rend, + }, + }, ) - ace = re.sub(limit.group(2), "", ace, 1) - ace = re.sub(limit.group(3), "", ace, 1) + range_substring = "range %s %s" % (rstart, rend) + ace = re.sub(range_substring, "", ace, 1) if port_protocol: ret_dict.update({"port_protocol": port_protocol}) return ace, ret_dict @@ -158,8 +163,8 @@ def render_config(self, spec, conf): "dod_host_prohibited", "dod_net_prohibited", "echo_request", - "echo", "echo_reply", + "echo", "general_parameter_problem", "host_isolated", "host_precedence_unreachable", @@ -185,6 +190,7 @@ def render_config(self, spec, conf): "port_unreachable", "precedence_unreachable", "protocol_unreachable", + "unreachable", "reassembly_timeout", "redirect", "router_advertisement", @@ -196,7 +202,39 @@ def render_config(self, spec, conf): "timestamp_request", "traceroute", "ttl_exceeded", + ], + "icmpv6": [ + "beyond_scope", + "destination_unreachable", + "echo_reply", + "echo_request", + "fragments", + "header", + "hop_limit", + "mld_query", + "mld_reduction", + "mld_report", + "mldv2", + "nd_na", + "nd_ns", + "next_header", + "no_admin", + "no_route", + "packet_too_big", + "parameter_option", + "parameter_problem", + "port_unreachable", + "reassembly_timeout", + "renum_command", + "renum_result", + "renum_seq_number", + "router_advertisement", + "router_renumbering", + "router_solicitation", + "time_exceeded", "unreachable", + "telemetry_path", + "telemetry_queue", ], "igmp": ["dvmrp", "host_query", "host_report"], } @@ -214,9 +252,9 @@ def render_config(self, spec, conf): acl = acl.split("\n") acl = [a.strip() for a in acl] acl = list(filter(None, acl)) - acls["name"] = re.match( - r"(ip)?(v6)?\s?access-list (.*)", acl[0] - ).group(3) + acls["name"] = re.match(r"(ip)?(v6)?\s?access-list (.*)", acl[0]).group( + 3, + ) acls["aces"] = [] for ace in list(filter(None, acl[1:])): if re.search(r"^ip(.*)access-list.*", ace): @@ -238,8 +276,13 @@ def render_config(self, spec, conf): if not rem and seq: ace = re.sub(grant, "", ace, 1) + pro = ace.split()[0] - entry.update({"protocol": pro}) + if pro == "icmp" and config["afi"] == "ipv6": + entry.update({"protocol": "icmpv6"}) + else: + entry.update({"protocol": pro}) + ace = re.sub(pro, "", ace, 1) ace, source = self.get_endpoint(ace, pro) entry.update({"source": source}) @@ -262,17 +305,20 @@ def render_config(self, spec, conf): if log: entry.update({"log": True}) - if pro == "tcp" or pro == "icmp" or pro == "igmp": + pro = entry.get("protocol", "") + if pro in ["tcp", "icmp", "icmpv6", "igmp"]: pro_options = {} options = {} for option in protocol_options[pro]: - option = re.sub("_", "-", option) + if option not in ["telemetry_path", "telemetry_queue"]: + option = re.sub("_", "-", option) if option in ace: - if ( - option == "echo" - and "echo_request" in options + if option == "echo" and ( + "echo_request" in options or "echo_reply" in options ): continue + elif option == "unreachable" and "port_unreachable" in options: + continue option = re.sub("-", "_", option) options.update({option: True}) if options: diff --git a/plugins/module_utils/network/nxos/facts/bfd_interfaces/bfd_interfaces.py b/plugins/module_utils/network/nxos/facts/bfd_interfaces/bfd_interfaces.py index 16eb10aea..9d7cceac3 100644 --- a/plugins/module_utils/network/nxos/facts/bfd_interfaces/bfd_interfaces.py +++ b/plugins/module_utils/network/nxos/facts/bfd_interfaces/bfd_interfaces.py @@ -5,6 +5,7 @@ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -12,11 +13,11 @@ Populate the facts tree based on the current device configuration. """ import re + from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.bfd_interfaces.bfd_interfaces import ( Bfd_interfacesArgs, ) @@ -53,9 +54,7 @@ def populate_facts(self, connection, ansible_facts, data=None): objs = [] if not data: - data = connection.get( - "show running-config | section '^interface|^feature bfd'" - ) + data = connection.get("show running-config | section '^interface|^feature bfd'") # Some of the bfd attributes if "feature bfd" in data.split("\n"): @@ -73,9 +72,7 @@ def populate_facts(self, connection, ansible_facts, data=None): facts = {} if objs: facts["bfd_interfaces"] = [] - params = utils.validate_config( - self.argument_spec, {"config": objs} - ) + params = utils.validate_config(self.argument_spec, {"config": objs}) for cfg in params["config"]: facts["bfd_interfaces"].append(utils.remove_empties(cfg)) @@ -101,13 +98,7 @@ def render_config(self, spec, conf): config["name"] = intf # 'bfd'/'bfd echo' do not nvgen when enabled thus set to 'enable' when None. # 'bfd' is not supported on some platforms - config["bfd"] = ( - utils.parse_conf_cmd_arg(conf, "bfd", "enable", "disable") - or "enable" - ) - config["echo"] = ( - utils.parse_conf_cmd_arg(conf, "bfd echo", "enable", "disable") - or "enable" - ) + config["bfd"] = utils.parse_conf_cmd_arg(conf, "bfd", "enable", "disable") or "enable" + config["echo"] = utils.parse_conf_cmd_arg(conf, "bfd echo", "enable", "disable") or "enable" return utils.remove_empties(config) diff --git a/plugins/module_utils/network/nxos/facts/bgp_address_family/bgp_address_family.py b/plugins/module_utils/network/nxos/facts/bgp_address_family/bgp_address_family.py index 09cda33d5..a1b0bc22d 100644 --- a/plugins/module_utils/network/nxos/facts/bgp_address_family/bgp_address_family.py +++ b/plugins/module_utils/network/nxos/facts/bgp_address_family/bgp_address_family.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -14,18 +15,15 @@ based on the configuration. """ -from copy import deepcopy - from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.bgp_address_family.bgp_address_family import ( + Bgp_address_familyArgs, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.bgp_address_family import ( Bgp_address_familyTemplate, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.bgp_address_family.bgp_address_family import ( - Bgp_address_familyArgs, -) class Bgp_address_familyFacts(object): @@ -60,9 +58,7 @@ def populate_facts(self, connection, ansible_facts, data=None): data = self._flatten_config(data) # parse native config using the Bgp_address_family template - bgp_address_family_parser = Bgp_address_familyTemplate( - lines=data.splitlines() - ) + bgp_address_family_parser = Bgp_address_familyTemplate(lines=data.splitlines()) objs = bgp_address_family_parser.parse() if objs: nbr = [] @@ -83,9 +79,7 @@ def populate_facts(self, connection, ansible_facts, data=None): key=lambda k, s="prefix": k[s], ) if "networks" in x: - x["networks"] = sorted( - x["networks"], key=lambda k, s="prefix": k[s] - ) + x["networks"] = sorted(x["networks"], key=lambda k, s="prefix": k[s]) if "redistribute" in x: x["redistribute"] = sorted( x["redistribute"], @@ -100,13 +94,9 @@ def populate_facts(self, connection, ansible_facts, data=None): ), ) - ansible_facts["ansible_network_resources"].pop( - "bgp_address_family", None - ) + ansible_facts["ansible_network_resources"].pop("bgp_address_family", None) - params = utils.remove_empties( - utils.validate_config(self.argument_spec, {"config": objs}) - ) + params = utils.remove_empties(utils.validate_config(self.argument_spec, {"config": objs})) facts["bgp_address_family"] = params.get("config", {}) ansible_facts["ansible_network_resources"].update(facts) diff --git a/plugins/module_utils/network/nxos/facts/bgp_global/bgp_global.py b/plugins/module_utils/network/nxos/facts/bgp_global/bgp_global.py index ce48700c0..9e149d8f6 100644 --- a/plugins/module_utils/network/nxos/facts/bgp_global/bgp_global.py +++ b/plugins/module_utils/network/nxos/facts/bgp_global/bgp_global.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -14,24 +15,21 @@ based on the configuration. """ -from copy import deepcopy - from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.bgp_global.bgp_global import ( + Bgp_globalArgs, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.bgp_global import ( Bgp_globalTemplate, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.bgp_global.bgp_global import ( - Bgp_globalArgs, -) class Bgp_globalFacts(object): """The nxos bgp_global facts class""" - def __init__(self, module, subspec="config", options="options"): + def __init__(self, module): self._module = module self.argument_spec = Bgp_globalArgs.argument_spec @@ -59,9 +57,7 @@ def populate_facts(self, connection, ansible_facts, data=None): data = self._flatten_config(data) # parse native config using the Bgp_global template - bgp_global_parser = Bgp_globalTemplate( - lines=data.splitlines(), module=self._module - ) + bgp_global_parser = Bgp_globalTemplate(lines=data.splitlines(), module=self._module) obj = bgp_global_parser.parse() vrfs = obj.get("vrfs", {}) @@ -75,9 +71,7 @@ def populate_facts(self, connection, ansible_facts, data=None): # transform vrfs into a list if vrfs: - obj["vrfs"] = sorted( - list(obj["vrfs"].values()), key=lambda k, sk="vrf": k[sk] - ) + obj["vrfs"] = sorted(list(obj["vrfs"].values()), key=lambda k, sk="vrf": k[sk]) for vrf in obj["vrfs"]: self._post_parse(vrf) @@ -87,9 +81,7 @@ def populate_facts(self, connection, ansible_facts, data=None): ansible_facts["ansible_network_resources"].pop("bgp_global", None) params = utils.remove_empties( - bgp_global_parser.validate_config( - self.argument_spec, {"config": obj}, redact=True - ) + bgp_global_parser.validate_config(self.argument_spec, {"config": obj}, redact=True), ) facts["bgp_global"] = params.get("config", {}) diff --git a/plugins/module_utils/network/nxos/facts/bgp_neighbor_address_family/bgp_neighbor_address_family.py b/plugins/module_utils/network/nxos/facts/bgp_neighbor_address_family/bgp_neighbor_address_family.py index 778b18236..625ed5082 100644 --- a/plugins/module_utils/network/nxos/facts/bgp_neighbor_address_family/bgp_neighbor_address_family.py +++ b/plugins/module_utils/network/nxos/facts/bgp_neighbor_address_family/bgp_neighbor_address_family.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -14,25 +15,20 @@ based on the configuration. """ -from copy import deepcopy +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils -from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.bgp_neighbor_address_family.bgp_neighbor_address_family import ( + Bgp_neighbor_address_familyArgs, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.bgp_neighbor_address_family import ( Bgp_neighbor_address_familyTemplate, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.bgp_neighbor_address_family.bgp_neighbor_address_family import ( - Bgp_neighbor_address_familyArgs, -) - class Bgp_neighbor_address_familyFacts(object): """The nxos bgp_neighbor_address_family facts class""" - def __init__(self, module, subspec="config", options="options"): + def __init__(self, module): self._module = module self.argument_spec = Bgp_neighbor_address_familyArgs.argument_spec @@ -61,29 +57,21 @@ def populate_facts(self, connection, ansible_facts, data=None): data = self._flatten_config(data) # parse native config using the Bgp_neighbor_address_family template - bgp_neighbor_address_family_parser = ( - Bgp_neighbor_address_familyTemplate(lines=data) - ) + bgp_neighbor_address_family_parser = Bgp_neighbor_address_familyTemplate(lines=data) objs = bgp_neighbor_address_family_parser.parse() if objs: top_lvl_nbrs = objs.get("vrfs", {}).pop("vrf_", {}) - objs["neighbors"] = self._post_parse(top_lvl_nbrs).get( - "neighbors", [] - ) + objs["neighbors"] = self._post_parse(top_lvl_nbrs).get("neighbors", []) if "vrfs" in objs: for vrf in objs["vrfs"].values(): vrf["neighbors"] = self._post_parse(vrf)["neighbors"] objs["vrfs"] = list(objs["vrfs"].values()) - ansible_facts["ansible_network_resources"].pop( - "bgp_neighbor_address_family", None - ) + ansible_facts["ansible_network_resources"].pop("bgp_neighbor_address_family", None) - params = utils.remove_empties( - utils.validate_config(self.argument_spec, {"config": objs}) - ) + params = utils.remove_empties(utils.validate_config(self.argument_spec, {"config": objs})) facts["bgp_neighbor_address_family"] = params.get("config", {}) ansible_facts["ansible_network_resources"].update(facts) diff --git a/plugins/module_utils/network/nxos/facts/bgp_templates/__init__.py b/plugins/module_utils/network/nxos/facts/bgp_templates/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/module_utils/network/nxos/facts/bgp_templates/bgp_templates.py b/plugins/module_utils/network/nxos/facts/bgp_templates/bgp_templates.py new file mode 100644 index 000000000..021e518a7 --- /dev/null +++ b/plugins/module_utils/network/nxos/facts/bgp_templates/bgp_templates.py @@ -0,0 +1,113 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 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 + +""" +The nxos bgp_templates fact class +It is in this file the configuration is collected from the device +for a given resource, parsed, and the facts tree is populated +based on the configuration. +""" + +from ansible.module_utils.six import iteritems +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.bgp_templates.bgp_templates import ( + Bgp_templatesArgs, +) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.bgp_templates import ( + Bgp_templatesTemplate, +) + + +class Bgp_templatesFacts(object): + """The nxos bgp_templates facts class""" + + def __init__(self, module): + self._module = module + self.argument_spec = Bgp_templatesArgs.argument_spec + + def get_config(self, connection): + """Wrapper method for `connection.get()` + This method exists solely to allow the unit test framework to mock device connection calls. + """ + as_number = connection.get("show running-config bgp | include 'router bgp'") + templates = connection.get("show running-config bgp | section 'template'") + + return as_number + "\n" + templates + + def populate_facts(self, connection, ansible_facts, data=None): + """Populate the facts for Bgp_templates network resource + + :param connection: the device connection + :param ansible_facts: Facts dictionary + :param data: previously collected conf + + :rtype: dictionary + :returns: facts + """ + facts = {} + + if not data: + data = self.get_config(connection) + + data = self._flatten_config(data) + + # parse native config using the Bgp_templates template + bgp_templates_parser = Bgp_templatesTemplate(lines=data, module=self._module) + parsed = bgp_templates_parser.parse() + + objs = {} + # pop top-level keys and assign values to them + for k, v in iteritems(parsed): + if k == "as_number": + objs[k] = v + else: + objs[k] = list(v.values()) + for x in objs[k]: + if "address_family" in x: + x["address_family"] = list(x["address_family"].values()) + + for nbr in objs.get("neighbor", []): + for af in nbr.get("address_family", []): + std = af.pop("send_community_std", False) + ext = af.pop("send_community_ext", False) + if std and ext: + af["send_community"] = "both" + elif std: + af["send_community"] = "standard" + elif ext: + af["send_community"] = "extended" + + ansible_facts["ansible_network_resources"].pop("bgp_templates", None) + + params = utils.remove_empties( + bgp_templates_parser.validate_config(self.argument_spec, {"config": objs}, redact=True), + ) + + facts["bgp_templates"] = params.get("config", {}) + ansible_facts["ansible_network_resources"].update(facts) + + return ansible_facts + + def _flatten_config(self, data): + flattened_data = [] + cur_peer = "" + data = data.split("\n") + + for x in data: + x = x.strip() + if x.startswith("template peer"): + cur_peer = x + " " + elif x.startswith("address-family"): + # a template peer <> line has to preceed AF line + x = cur_peer + x + flattened_data.append(x) + + return flattened_data diff --git a/plugins/module_utils/network/nxos/facts/facts.py b/plugins/module_utils/network/nxos/facts/facts.py index 3291f2026..a7c2ab350 100644 --- a/plugins/module_utils/network/nxos/facts/facts.py +++ b/plugins/module_utils/network/nxos/facts/facts.py @@ -5,6 +5,7 @@ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type """ The facts class for nxos @@ -14,17 +15,34 @@ from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts import ( FactsBase, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.legacy.base import ( - Default, - Legacy, - Hardware, - Config, - Interfaces, - Features, + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.acl_interfaces.acl_interfaces import ( + Acl_interfacesFacts, +) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.acls.acls import ( + AclsFacts, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.bfd_interfaces.bfd_interfaces import ( Bfd_interfacesFacts, ) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.bgp_address_family.bgp_address_family import ( + Bgp_address_familyFacts, +) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.bgp_global.bgp_global import ( + Bgp_globalFacts, +) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.bgp_neighbor_address_family.bgp_neighbor_address_family import ( + Bgp_neighbor_address_familyFacts, +) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.bgp_templates.bgp_templates import ( + Bgp_templatesFacts, +) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.fc_interfaces.fc_interfaces import ( + Fc_interfacesFacts, +) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.hostname.hostname import ( + HostnameFacts, +) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.hsrp_interfaces.hsrp_interfaces import ( Hsrp_interfacesFacts, ) @@ -34,23 +52,25 @@ from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.l2_interfaces.l2_interfaces import ( L2_interfacesFacts, ) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.l3_interfaces.l3_interfaces import ( + L3_interfacesFacts, +) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.lacp.lacp import ( LacpFacts, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.l3_interfaces.l3_interfaces import ( - L3_interfacesFacts, +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.lacp_interfaces.lacp_interfaces import ( + Lacp_interfacesFacts, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.lag_interfaces.lag_interfaces import ( Lag_interfacesFacts, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.telemetry.telemetry import ( - TelemetryFacts, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.vlans.vlans import ( - VlansFacts, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.lacp_interfaces.lacp_interfaces import ( - Lacp_interfacesFacts, +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.legacy.base import ( + Config, + Default, + Features, + Hardware, + Interfaces, + Legacy, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.lldp_global.lldp_global import ( Lldp_globalFacts, @@ -58,14 +78,14 @@ from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.lldp_interfaces.lldp_interfaces import ( Lldp_interfacesFacts, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.acl_interfaces.acl_interfaces import ( - Acl_interfacesFacts, +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.logging_global.logging_global import ( + Logging_globalFacts, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.acls.acls import ( - AclsFacts, +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.ntp_global.ntp_global import ( + Ntp_globalFacts, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.static_routes.static_routes import ( - Static_routesFacts, +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.ospf_interfaces.ospf_interfaces import ( + Ospf_interfacesFacts, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.ospfv2.ospfv2 import ( Ospfv2Facts, @@ -73,35 +93,23 @@ from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.ospfv3.ospfv3 import ( Ospfv3Facts, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.ospf_interfaces.ospf_interfaces import ( - Ospf_interfacesFacts, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.bgp_global.bgp_global import ( - Bgp_globalFacts, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.bgp_address_family.bgp_address_family import ( - Bgp_address_familyFacts, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.bgp_neighbor_address_family.bgp_neighbor_address_family import ( - Bgp_neighbor_address_familyFacts, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.route_maps.route_maps import ( - Route_mapsFacts, -) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.prefix_lists.prefix_lists import ( Prefix_listsFacts, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.logging_global.logging_global import ( - Logging_globalFacts, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.ntp_global.ntp_global import ( - Ntp_globalFacts, +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.route_maps.route_maps import ( + Route_mapsFacts, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.snmp_server.snmp_server import ( Snmp_serverFacts, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.hostname.hostname import ( - HostnameFacts, +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.static_routes.static_routes import ( + Static_routesFacts, +) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.telemetry.telemetry import ( + TelemetryFacts, +) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.vlans.vlans import ( + VlansFacts, ) @@ -113,7 +121,7 @@ config=Config, features=Features, ) -FACT_RESOURCE_SUBSETS = dict( +NX_FACT_RESOURCE_SUBSETS = dict( bfd_interfaces=Bfd_interfacesFacts, hsrp_interfaces=Hsrp_interfacesFacts, lag_interfaces=Lag_interfacesFacts, @@ -141,6 +149,13 @@ ntp_global=Ntp_globalFacts, snmp_server=Snmp_serverFacts, hostname=HostnameFacts, + bgp_templates=Bgp_templatesFacts, +) +MDS_FACT_RESOURCE_SUBSETS = dict( + fc_interfaces=Fc_interfacesFacts, + logging_global=Logging_globalFacts, + ntp_global=Ntp_globalFacts, + snmp_server=Snmp_serverFacts, ) @@ -148,14 +163,21 @@ class Facts(FactsBase): """The fact class for nxos""" VALID_LEGACY_GATHER_SUBSETS = frozenset(FACT_LEGACY_SUBSETS.keys()) - VALID_RESOURCE_SUBSETS = frozenset(FACT_RESOURCE_SUBSETS.keys()) - def __init__(self, module): + def __init__(self, module, chassis_type="nexus"): super(Facts, self).__init__(module) + self.chassis_type = chassis_type - def get_facts( - self, legacy_facts_type=None, resource_facts_type=None, data=None - ): + def get_resource_subsets(self): + """Return facts resource subsets based on + target device model. + """ + facts_resource_subsets = NX_FACT_RESOURCE_SUBSETS + if self.chassis_type == "mds": + facts_resource_subsets = MDS_FACT_RESOURCE_SUBSETS + return facts_resource_subsets + + def get_facts(self, legacy_facts_type=None, resource_facts_type=None, data=None): """Collect the facts for nxos :param legacy_facts_type: List of legacy facts types :param resource_facts_type: List of resource fact types @@ -163,14 +185,12 @@ def get_facts( :rtype: dict :return: the facts gathered """ - if self.VALID_RESOURCE_SUBSETS: - self.get_network_resources_facts( - FACT_RESOURCE_SUBSETS, resource_facts_type, data - ) + VALID_RESOURCE_SUBSETS = self.get_resource_subsets() + + if frozenset(VALID_RESOURCE_SUBSETS.keys()): + self.get_network_resources_facts(VALID_RESOURCE_SUBSETS, resource_facts_type, data) if self.VALID_LEGACY_GATHER_SUBSETS: - self.get_network_legacy_facts( - FACT_LEGACY_SUBSETS, legacy_facts_type - ) + self.get_network_legacy_facts(FACT_LEGACY_SUBSETS, legacy_facts_type) return self.ansible_facts, self._warnings diff --git a/plugins/module_utils/network/nxos/facts/fc_interfaces/__init__.py b/plugins/module_utils/network/nxos/facts/fc_interfaces/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/module_utils/network/nxos/facts/fc_interfaces/fc_interfaces.py b/plugins/module_utils/network/nxos/facts/fc_interfaces/fc_interfaces.py new file mode 100644 index 000000000..e9d85c086 --- /dev/null +++ b/plugins/module_utils/network/nxos/facts/fc_interfaces/fc_interfaces.py @@ -0,0 +1,103 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 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 + +import operator +import re + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.fc_interfaces.fc_interfaces import ( + Fc_interfacesArgs, +) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.fc_interfaces import ( + Fc_interfacesTemplate, +) + + +__metaclass__ = type + +""" +The nxos fc_interfaces fact class +It is in this file the configuration is collected from the device +for a given resource, parsed, and the facts tree is populated +based on the configuration. +""" + + +class Fc_interfacesFacts(object): + """The nxos fc_interfaces facts class""" + + def __init__(self, module, subspec="config", options="options"): + self._module = module + self.argument_spec = Fc_interfacesArgs.argument_spec + + def get_interfaces_data(self, connection): + return connection.get("show running-config interface all") + + def populate_facts(self, connection, ansible_facts, data=None): + """Populate the facts for Fc_interfaces network resource + + :param connection: the device connection + :param ansible_facts: Facts dictionary + :param data: previously collected conf + + :rtype: dictionary + :returns: facts + """ + facts = {} + objs = [] + + if not data: + data = self.get_interfaces_data(connection) + + # parse native config using the Fc_interfaces template + fc_interfaces_parser = Fc_interfacesTemplate(lines=data.splitlines(), module=self._module) + + objs = list(fc_interfaces_parser.parse().values()) + + # - populate only fc interfaces + # - populate "analytics" value based on the presence or absense of "analytics_nvme" or "analytics_scsi" keys + # - dummy key "m" and "p" is added for sorting, which is removed after sorting + modified_objs = [] + # match only fc interface + regex = re.compile(r"^fc\d+\S+") + for parsed_data in objs: + if not re.match(regex, parsed_data["name"]): + continue + m, p = parsed_data["name"].strip("fc").split("/") + parsed_data["m"] = int(m) + parsed_data["p"] = int(p) + + if "analytics_scsi" in parsed_data: + parsed_data.pop("analytics_scsi") + if "analytics_nvme" in parsed_data: + parsed_data.pop("analytics_nvme") + parsed_data["analytics"] = "fc-all" + else: + parsed_data["analytics"] = "fc-scsi" + else: + if "analytics_nvme" in parsed_data: + parsed_data.pop("analytics_nvme") + parsed_data["analytics"] = "fc-nvme" + modified_objs.append(parsed_data) + + sorted_dict = sorted(modified_objs, key=operator.itemgetter("m", "p")) + objs = [ + {key: value for key, value in eachdict.items() if key not in ["m", "p"]} + for eachdict in sorted_dict + ] + + ansible_facts["ansible_network_resources"].pop("fc_interfaces", None) + + params = utils.remove_empties( + fc_interfaces_parser.validate_config(self.argument_spec, {"config": objs}, redact=True), + ) + + facts["fc_interfaces"] = params.get("config", []) + ansible_facts["ansible_network_resources"].update(facts) + + return ansible_facts diff --git a/plugins/module_utils/network/nxos/facts/hostname/hostname.py b/plugins/module_utils/network/nxos/facts/hostname/hostname.py index e38a3ae3b..981648c0c 100644 --- a/plugins/module_utils/network/nxos/facts/hostname/hostname.py +++ b/plugins/module_utils/network/nxos/facts/hostname/hostname.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -14,18 +15,14 @@ based on the configuration. """ -from copy import deepcopy +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils -from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.hostname.hostname import ( + HostnameArgs, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.hostname import ( HostnameTemplate, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.hostname.hostname import ( - HostnameArgs, -) class HostnameFacts(object): @@ -58,17 +55,13 @@ def populate_facts(self, connection, ansible_facts, data=None): data = self.get_config(connection) # parse native config using the Hostname template - hostname_parser = HostnameTemplate( - lines=data.splitlines(), module=self._module - ) + hostname_parser = HostnameTemplate(lines=data.splitlines(), module=self._module) objs = hostname_parser.parse() ansible_facts["ansible_network_resources"].pop("hostname", None) params = utils.remove_empties( - hostname_parser.validate_config( - self.argument_spec, {"config": objs}, redact=True - ) + hostname_parser.validate_config(self.argument_spec, {"config": objs}, redact=True), ) facts["hostname"] = params.get("config", {}) diff --git a/plugins/module_utils/network/nxos/facts/hsrp_interfaces/hsrp_interfaces.py b/plugins/module_utils/network/nxos/facts/hsrp_interfaces/hsrp_interfaces.py index 644ab3763..d12e32233 100644 --- a/plugins/module_utils/network/nxos/facts/hsrp_interfaces/hsrp_interfaces.py +++ b/plugins/module_utils/network/nxos/facts/hsrp_interfaces/hsrp_interfaces.py @@ -5,6 +5,7 @@ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -12,11 +13,11 @@ Populate the facts tree based on the current device configuration. """ import re + from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.hsrp_interfaces.hsrp_interfaces import ( Hsrp_interfacesArgs, ) @@ -66,9 +67,7 @@ def populate_facts(self, connection, ansible_facts, data=None): facts = {} if objs: facts["hsrp_interfaces"] = [] - params = utils.validate_config( - self.argument_spec, {"config": objs} - ) + params = utils.validate_config(self.argument_spec, {"config": objs}) for cfg in params["config"]: facts["hsrp_interfaces"].append(utils.remove_empties(cfg)) @@ -92,8 +91,6 @@ def render_config(self, spec, conf): if get_interface_type(intf) == "unknown": return {} config["name"] = intf - config["bfd"] = utils.parse_conf_cmd_arg( - conf, "hsrp bfd", "enable", "disable" - ) + config["bfd"] = utils.parse_conf_cmd_arg(conf, "hsrp bfd", "enable", "disable") return utils.remove_empties(config) diff --git a/plugins/module_utils/network/nxos/facts/interfaces/interfaces.py b/plugins/module_utils/network/nxos/facts/interfaces/interfaces.py index 106f4adcf..92592b07c 100644 --- a/plugins/module_utils/network/nxos/facts/interfaces/interfaces.py +++ b/plugins/module_utils/network/nxos/facts/interfaces/interfaces.py @@ -11,23 +11,21 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type import re + from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.interfaces.interfaces import ( InterfacesArgs, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( get_interface_type, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - default_intf_enabled, -) class InterfacesFacts(object): @@ -70,9 +68,7 @@ def populate_facts(self, connection, ansible_facts, data=None): facts = {} facts["interfaces"] = [] if objs: - params = utils.validate_config( - self.argument_spec, {"config": objs} - ) + params = utils.validate_config(self.argument_spec, {"config": objs}) for cfg in params["config"]: facts["interfaces"].append(utils.remove_empties(cfg)) @@ -99,20 +95,16 @@ def render_config(self, spec, conf): config["speed"] = utils.parse_conf_arg(conf, "speed") config["mtu"] = utils.parse_conf_arg(conf, "mtu") config["duplex"] = utils.parse_conf_arg(conf, "duplex") - config["mode"] = utils.parse_conf_cmd_arg( - conf, "switchport", "layer2", "layer3" - ) + config["mode"] = utils.parse_conf_cmd_arg(conf, "switchport", "layer2", "layer3") - config["enabled"] = utils.parse_conf_cmd_arg( - conf, "shutdown", False, True - ) + config["enabled"] = utils.parse_conf_cmd_arg(conf, "shutdown", False, True) config["fabric_forwarding_anycast_gateway"] = utils.parse_conf_cmd_arg( - conf, "fabric forwarding mode anycast-gateway", True - ) - config["ip_forward"] = utils.parse_conf_cmd_arg( - conf, "ip forward", True + conf, + "fabric forwarding mode anycast-gateway", + True, ) + config["ip_forward"] = utils.parse_conf_cmd_arg(conf, "ip forward", True) interfaces_cfg = utils.remove_empties(config) return interfaces_cfg diff --git a/plugins/module_utils/network/nxos/facts/l2_interfaces/l2_interfaces.py b/plugins/module_utils/network/nxos/facts/l2_interfaces/l2_interfaces.py index 8655be88f..cf55552b8 100644 --- a/plugins/module_utils/network/nxos/facts/l2_interfaces/l2_interfaces.py +++ b/plugins/module_utils/network/nxos/facts/l2_interfaces/l2_interfaces.py @@ -11,14 +11,15 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type import re + from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.l2_interfaces.l2_interfaces import ( L2_interfacesArgs, ) @@ -67,9 +68,7 @@ def populate_facts(self, connection, ansible_facts, data=None): facts = {} if objs: facts["l2_interfaces"] = [] - params = utils.validate_config( - self.argument_spec, {"config": objs} - ) + params = utils.validate_config(self.argument_spec, {"config": objs}) for cfg in params["config"]: facts["l2_interfaces"].append(utils.remove_empties(cfg)) @@ -95,14 +94,11 @@ def render_config(self, spec, conf): config["name"] = intf config["mode"] = utils.parse_conf_arg(conf, "switchport mode") config["ip_forward"] = utils.parse_conf_arg(conf, "ip forward") - config["access"]["vlan"] = utils.parse_conf_arg( - conf, "switchport access vlan" - ) + config["access"]["vlan"] = utils.parse_conf_arg(conf, "switchport access vlan") config["trunk"]["allowed_vlans"] = utils.parse_conf_arg( - conf, "switchport trunk allowed vlan" - ) - config["trunk"]["native_vlan"] = utils.parse_conf_arg( - conf, "switchport trunk native vlan" + conf, + "switchport trunk allowed vlan", ) + config["trunk"]["native_vlan"] = utils.parse_conf_arg(conf, "switchport trunk native vlan") return utils.remove_empties(config) diff --git a/plugins/module_utils/network/nxos/facts/l3_interfaces/l3_interfaces.py b/plugins/module_utils/network/nxos/facts/l3_interfaces/l3_interfaces.py index 663ccc669..ad36e17ca 100644 --- a/plugins/module_utils/network/nxos/facts/l3_interfaces/l3_interfaces.py +++ b/plugins/module_utils/network/nxos/facts/l3_interfaces/l3_interfaces.py @@ -11,14 +11,15 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type import re + from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.l3_interfaces.l3_interfaces import ( L3_interfacesArgs, ) @@ -67,9 +68,7 @@ def populate_facts(self, connection, ansible_facts, data=None): facts = {} if objs: facts["l3_interfaces"] = [] - params = utils.validate_config( - self.argument_spec, {"config": objs} - ) + params = utils.validate_config(self.argument_spec, {"config": objs}) for cfg in params["config"]: facts["l3_interfaces"].append(utils.remove_empties(cfg)) @@ -92,15 +91,10 @@ def render_config(self, spec, conf): return {} config["name"] = intf config["dot1q"] = utils.parse_conf_arg(conf, "encapsulation dot1[qQ]") - config["redirects"] = utils.parse_conf_cmd_arg( - conf, "no ip redirects", False, True - ) - config["unreachables"] = utils.parse_conf_cmd_arg( - conf, "ip unreachables", True, False - ) - config["evpn_multisite_tracking"] = utils.parse_conf_arg( - conf, "evpn multisite" - ) + config["redirects"] = utils.parse_conf_cmd_arg(conf, "no ip redirects", False, True) + config["ipv6_redirects"] = utils.parse_conf_cmd_arg(conf, "no ipv6 redirects", False, True) + config["unreachables"] = utils.parse_conf_cmd_arg(conf, "ip unreachables", True, False) + config["evpn_multisite_tracking"] = utils.parse_conf_arg(conf, "evpn multisite") ipv4_match = re.compile(r"\n ip address (.*)") matches = ipv4_match.findall(conf) if matches: @@ -117,9 +111,7 @@ def render_config(self, spec, conf): config_dict.update({"secondary": True}) if len(ipv4_conf) == 4: if ipv4_conf[2] == "tag": - config_dict.update( - {"tag": int(ipv4_conf[-1])} - ) + config_dict.update({"tag": int(ipv4_conf[-1])}) elif d == "tag": config_dict.update({"tag": int(ipv4_conf[-1])}) config["ipv4"].append(config_dict) diff --git a/plugins/module_utils/network/nxos/facts/lacp/lacp.py b/plugins/module_utils/network/nxos/facts/lacp/lacp.py index b2c7bd708..51b1413da 100644 --- a/plugins/module_utils/network/nxos/facts/lacp/lacp.py +++ b/plugins/module_utils/network/nxos/facts/lacp/lacp.py @@ -11,14 +11,15 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type import re + from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.lacp.lacp import ( LacpArgs, ) @@ -56,9 +57,7 @@ def populate_facts(self, connection, ansible_facts, data=None): ansible_facts["ansible_network_resources"].pop("lacp", None) facts = {} if objs: - params = utils.validate_config( - self.argument_spec, {"config": objs} - ) + params = utils.validate_config(self.argument_spec, {"config": objs}) facts["lacp"] = utils.remove_empties(params["config"]) ansible_facts["ansible_network_resources"].update(facts) return ansible_facts @@ -83,9 +82,7 @@ def render_config(self, spec, conf): if a_match: address = a_match.group(1) config["system"]["mac"]["address"] = address - r_match = re.search( - r"lacp system-mac {0} role (\S+)".format(address), conf, re.M - ) + r_match = re.search(r"lacp system-mac {0} role (\S+)".format(address), conf, re.M) if r_match: config["system"]["mac"]["role"] = r_match.group(1) diff --git a/plugins/module_utils/network/nxos/facts/lacp_interfaces/lacp_interfaces.py b/plugins/module_utils/network/nxos/facts/lacp_interfaces/lacp_interfaces.py index cd5d12380..c60d8abd0 100644 --- a/plugins/module_utils/network/nxos/facts/lacp_interfaces/lacp_interfaces.py +++ b/plugins/module_utils/network/nxos/facts/lacp_interfaces/lacp_interfaces.py @@ -11,14 +11,15 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type import re + from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.lacp_interfaces.lacp_interfaces import ( Lacp_interfacesArgs, ) @@ -68,9 +69,7 @@ def populate_facts(self, connection, ansible_facts, data=None): facts = {} if objs: facts["lacp_interfaces"] = [] - params = utils.validate_config( - self.argument_spec, {"config": objs} - ) + params = utils.validate_config(self.argument_spec, {"config": objs}) for cfg in params["config"]: facts["lacp_interfaces"].append(utils.remove_empties(cfg)) @@ -94,9 +93,7 @@ def render_config(self, spec, conf): if get_interface_type(intf) == "unknown": return {} config["name"] = intf - config["port_priority"] = utils.parse_conf_arg( - conf, "lacp port-priority" - ) + config["port_priority"] = utils.parse_conf_arg(conf, "lacp port-priority") config["rate"] = utils.parse_conf_arg(conf, "lacp rate") config["mode"] = utils.parse_conf_arg(conf, "lacp mode") suspend_individual = re.search(r"no lacp suspend-individual", conf) diff --git a/plugins/module_utils/network/nxos/facts/lag_interfaces/lag_interfaces.py b/plugins/module_utils/network/nxos/facts/lag_interfaces/lag_interfaces.py index 5253923a5..b94c57e27 100644 --- a/plugins/module_utils/network/nxos/facts/lag_interfaces/lag_interfaces.py +++ b/plugins/module_utils/network/nxos/facts/lag_interfaces/lag_interfaces.py @@ -11,21 +11,18 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type import re + from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.lag_interfaces.lag_interfaces import ( Lag_interfacesArgs, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( - get_interface_type, - normalize_interface, -) class Lag_interfacesFacts(object): @@ -62,9 +59,7 @@ def populate_facts(self, connection, ansible_facts, data=None): facts = {} if objs: facts["lag_interfaces"] = [] - params = utils.validate_config( - self.argument_spec, {"config": objs} - ) + params = utils.validate_config(self.argument_spec, {"config": objs}) for cfg in params["config"]: facts["lag_interfaces"].append(utils.remove_empties(cfg)) @@ -101,9 +96,7 @@ def render_config(self, spec, conf, connection): member.update(match_line.groupdict()) if member and member.get("port_channel", None): - port_channel = "port-channel{0}".format( - member.pop("port_channel") - ) + port_channel = "port-channel{0}".format(member.pop("port_channel")) for x in result: if x["name"] == port_channel: x["members"].append(utils.remove_empties(member)) diff --git a/plugins/module_utils/network/nxos/facts/legacy/base.py b/plugins/module_utils/network/nxos/facts/legacy/base.py index 5619db82d..16540a435 100644 --- a/plugins/module_utils/network/nxos/facts/legacy/base.py +++ b/plugins/module_utils/network/nxos/facts/legacy/base.py @@ -4,21 +4,23 @@ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type import platform import re +from ansible.module_utils.six import iteritems + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - run_commands, - get_config, get_capabilities, + get_config, + run_commands, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( get_interface_type, normalize_interface, ) -from ansible.module_utils.six import iteritems g_config = None @@ -36,14 +38,29 @@ def populate(self): def run(self, command, output="text"): command_string = command + if output == "json": + # Not all devices support | json-pretty but is a workaround for + # libssh issue https://github.com/ansible/pylibssh/issues/208 + output = "json-pretty" + + resp = [] command = {"command": command, "output": output} - resp = run_commands(self.module, [command], check_rc="retry_json") + try: + resp = run_commands(self.module, [command], check_rc="retry_json") + except Exception: + if output == "json-pretty": + # reattempt with | json + resp = run_commands( + self.module, + [{"command": command, "output": "json"}], + check_rc="retry_json", + ) + try: return resp[0] except IndexError: self.warnings.append( - "command %s failed, facts for this command will not be populated" - % command_string + "command %s failed, facts for this command will not be populated" % command_string, ) return None @@ -139,16 +156,32 @@ def populate(self): if data: if isinstance(data, dict): - self.facts["memtotal_mb"] = ( - int(data["memory_usage_total"]) / 1024 - ) - self.facts["memfree_mb"] = ( - int(data["memory_usage_free"]) / 1024 - ) + self.facts["memtotal_mb"] = int(data["memory_usage_total"]) / 1024 + self.facts["memfree_mb"] = int(data["memory_usage_free"]) / 1024 else: self.facts["memtotal_mb"] = self.parse_memtotal_mb(data) self.facts["memfree_mb"] = self.parse_memfree_mb(data) + data = None + data = self.run("show processes cpu | json") + + if data: + self.facts["cpu_utilization"] = self.parse_cpu_utilization(data) + + def parse_cpu_utilization(self, data): + return { + "core": { + "five_minutes": int(data.get("fivemin_percent", 0)), + "five_seconds": int( + data.get("fivesec_percent", 0), + ), + "five_seconds_interrupt": int( + data.get("fivesec_intr_percent", 0), + ), + "one_minute": int(data.get("onemin_percent", 0)), + }, + } + def parse_filesystems(self, data): return re.findall(r"^Usage for (\S+)//", data, re.M) @@ -166,7 +199,6 @@ def parse_memfree_mb(self, data): class Interfaces(FactsBase): - INTERFACE_MAP = frozenset( [ ("state", "state"), @@ -178,7 +210,7 @@ class Interfaces(FactsBase): ("eth_hw_addr", "macaddress"), ("eth_mtu", "mtu"), ("eth_hw_desc", "type"), - ] + ], ) INTERFACE_SVI_MAP = frozenset( @@ -188,16 +220,12 @@ class Interfaces(FactsBase): ("svi_mac", "macaddress"), ("svi_mtu", "mtu"), ("type", "type"), - ] + ], ) - INTERFACE_IPV4_MAP = frozenset( - [("eth_ip_addr", "address"), ("eth_ip_mask", "masklen")] - ) + INTERFACE_IPV4_MAP = frozenset([("eth_ip_addr", "address"), ("eth_ip_mask", "masklen")]) - INTERFACE_SVI_IPV4_MAP = frozenset( - [("svi_ip_addr", "address"), ("svi_ip_mask", "masklen")] - ) + INTERFACE_SVI_IPV4_MAP = frozenset([("svi_ip_addr", "address"), ("svi_ip_mask", "masklen")]) INTERFACE_IPV6_MAP = frozenset([("addr", "address"), ("prefix", "subnet")]) @@ -221,9 +249,7 @@ def populate(self): if data: if isinstance(data, dict): - self.facts["interfaces"] = self.populate_structured_interfaces( - data - ) + self.facts["interfaces"] = self.populate_structured_interfaces(data) else: interfaces = self.parse_interfaces(data) self.facts["interfaces"] = self.populate_interfaces(interfaces) @@ -242,22 +268,16 @@ def populate(self): data = self.run("show lldp neighbors", output="json") if data: if isinstance(data, dict): - self.facts["neighbors"].update( - self.populate_structured_neighbors_lldp(data) - ) + self.facts["neighbors"].update(self.populate_structured_neighbors_lldp(data)) else: self.facts["neighbors"].update(self.populate_neighbors(data)) data = self.run("show cdp neighbors detail", output="json") if data: if isinstance(data, dict): - self.facts["neighbors"].update( - self.populate_structured_neighbors_cdp(data) - ) + self.facts["neighbors"].update(self.populate_structured_neighbors_cdp(data)) else: - self.facts["neighbors"].update( - self.populate_neighbors_cdp(data) - ) + self.facts["neighbors"].update(self.populate_neighbors_cdp(data)) self.facts["neighbors"].pop(None, None) # Remove null key @@ -272,21 +292,17 @@ def populate_structured_interfaces(self, data): name = item["interface"] intf = dict() - if "type" in item: + if any(key.startswith("svi_") for key in item): intf.update(self.transform_dict(item, self.INTERFACE_SVI_MAP)) else: intf.update(self.transform_dict(item, self.INTERFACE_MAP)) if "eth_ip_addr" in item: - intf["ipv4"] = self.transform_dict( - item, self.INTERFACE_IPV4_MAP - ) + intf["ipv4"] = self.transform_dict(item, self.INTERFACE_IPV4_MAP) self.facts["all_ipv4_addresses"].append(item["eth_ip_addr"]) if "svi_ip_addr" in item: - intf["ipv4"] = self.transform_dict( - item, self.INTERFACE_SVI_IPV4_MAP - ) + intf["ipv4"] = self.transform_dict(item, self.INTERFACE_SVI_IPV4_MAP) self.facts["all_ipv4_addresses"].append(item["svi_ip_addr"]) interfaces[name] = intf @@ -302,15 +318,11 @@ def populate_structured_ipv6_interfaces(self, data): for item in data: name = item["ROW_intf"]["intf-name"] intf = self.facts["interfaces"][name] - intf["ipv6"] = self.transform_dict( - item, self.INTERFACE_IPV6_MAP - ) + intf["ipv6"] = self.transform_dict(item, self.INTERFACE_IPV6_MAP) try: addr = item["ROW_intf"]["addr"] except KeyError: - addr = item["ROW_intf"]["TABLE_addr"]["ROW_addr"][ - "addr" - ] + addr = item["ROW_intf"]["TABLE_addr"]["ROW_addr"]["addr"] self.facts["all_ipv6_addresses"].append(addr) else: return "" @@ -336,9 +348,7 @@ def populate_structured_neighbors_lldp(self, data): def populate_structured_neighbors_cdp(self, data): objects = dict() - data = data["TABLE_cdp_neighbor_detail_info"][ - "ROW_cdp_neighbor_detail_info" - ] + data = data["TABLE_cdp_neighbor_detail_info"]["ROW_cdp_neighbor_detail_info"] if isinstance(data, dict): data = [data] @@ -369,9 +379,7 @@ def parse_interfaces(self, data): match = re.match(r"^(\S+)", line) if match: key = match.group(1) - if not key.startswith("admin") or not key.startswith( - "IPv6 Interface" - ): + if not key.startswith("admin") or not key.startswith("IPv6 Interface"): parsed[key] = line return parsed @@ -381,18 +389,12 @@ def populate_interfaces(self, interfaces): intf = dict() if get_interface_type(key) == "svi": intf["state"] = self.parse_state(key, value, intf_type="svi") - intf["macaddress"] = self.parse_macaddress( - value, intf_type="svi" - ) + intf["macaddress"] = self.parse_macaddress(value, intf_type="svi") intf["mtu"] = self.parse_mtu(value, intf_type="svi") - intf["bandwidth"] = self.parse_bandwidth( - value, intf_type="svi" - ) + intf["bandwidth"] = self.parse_bandwidth(value, intf_type="svi") intf["type"] = self.parse_type(value, intf_type="svi") if "Internet Address" in value: - intf["ipv4"] = self.parse_ipv4_address( - value, intf_type="svi" - ) + intf["ipv4"] = self.parse_ipv4_address(value, intf_type="svi") facts[key] = intf else: intf["state"] = self.parse_state(key, value) @@ -564,7 +566,7 @@ class Legacy(FactsBase): ("host_name", "_hostname"), ("kickstart_ver_str", "_os"), ("chassis_id", "_platform"), - ] + ], ) MODULE_MAP = frozenset( @@ -573,7 +575,7 @@ class Legacy(FactsBase): ("modtype", "type"), ("ports", "ports"), ("status", "status"), - ] + ], ) FAN_MAP = frozenset( @@ -583,7 +585,7 @@ class Legacy(FactsBase): ("fanhwver", "hw_ver"), ("fandir", "direction"), ("fanstatus", "status"), - ] + ], ) POWERSUP_MAP = frozenset( @@ -598,7 +600,7 @@ class Legacy(FactsBase): ("input_type", "input_type"), ("watts", "watts"), ("amps", "amps"), - ] + ], ) def populate(self): @@ -616,9 +618,7 @@ def populate(self): data = self.run("show interface", output="json") if data: if isinstance(data, dict): - self.facts[ - "interfaces_list" - ] = self.parse_structured_interfaces(data) + self.facts["interfaces_list"] = self.parse_structured_interfaces(data) else: self.facts["interfaces_list"] = self.parse_interfaces(data) @@ -646,13 +646,9 @@ def populate(self): data = self.run("show environment power", output="json") if data: if isinstance(data, dict): - self.facts[ - "power_supply_info" - ] = self.parse_structured_power_supply_info(data) + self.facts["power_supply_info"] = self.parse_structured_power_supply_info(data) else: - self.facts["power_supply_info"] = self.parse_power_supply_info( - data - ) + self.facts["power_supply_info"] = self.parse_power_supply_info(data) def parse_structured_interfaces(self, data): objects = list() @@ -675,10 +671,17 @@ def parse_structured_vlans(self, data): return objects def parse_structured_module(self, data): - data = data["TABLE_modinfo"]["ROW_modinfo"] - if isinstance(data, dict): - data = [data] - objects = list(self.transform_iterable(data, self.MODULE_MAP)) + modinfo = data["TABLE_modinfo"] + if isinstance(modinfo, dict): + modinfo = [modinfo] + + objects = [] + for entry in modinfo: + entry = entry["ROW_modinfo"] + if isinstance(entry, dict): + entry = [entry] + entry_objects = list(self.transform_iterable(entry, self.MODULE_MAP)) + objects.extend(entry_objects) return objects def parse_structured_fan_info(self, data): diff --git a/plugins/module_utils/network/nxos/facts/lldp_global/lldp_global.py b/plugins/module_utils/network/nxos/facts/lldp_global/lldp_global.py index c25a9e7ab..6e8aabde2 100644 --- a/plugins/module_utils/network/nxos/facts/lldp_global/lldp_global.py +++ b/plugins/module_utils/network/nxos/facts/lldp_global/lldp_global.py @@ -11,14 +11,15 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type import re + from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.lldp_global.lldp_global import ( Lldp_globalArgs, ) @@ -58,9 +59,7 @@ def populate_facts(self, connection, ansible_facts, data=None): ansible_facts["ansible_network_resources"].pop("lldp_global", None) facts = {} if objs: - params = utils.validate_config( - self.argument_spec, {"config": objs} - ) + params = utils.validate_config(self.argument_spec, {"config": objs}) facts["lldp_global"] = params["config"] facts = utils.remove_empties(facts) ansible_facts["ansible_network_resources"].update((facts)) @@ -79,9 +78,7 @@ def render_config(self, spec, conf): config = deepcopy(spec) conf = re.split("\n", conf) for command in conf: - param = re.search( - r"(.*)lldp (\w+(-?)\w+)", command - ) # get the word after 'lldp' + param = re.search(r"(.*)lldp (\w+(-?)\w+)", command) # get the word after 'lldp' if param: # get the nested-dict/value for that param key2 = re.search(r"%s(.*)" % param.group(2), command) @@ -95,9 +92,7 @@ def render_config(self, spec, conf): key2 = key2.split() key2[0] = key2[0].replace("-", "_") if len(key2) == 1: - if ( - "port" in key2[0] or "system" in key2[0] - ): # nested dicts + if "port" in key2[0] or "system" in key2[0]: # nested dicts key2 = key2[0].split("_") # config[tlv_select][system][name]=False config[key1][key2[0]][key2[1]] = False diff --git a/plugins/module_utils/network/nxos/facts/lldp_interfaces/lldp_interfaces.py b/plugins/module_utils/network/nxos/facts/lldp_interfaces/lldp_interfaces.py index 09ec886ee..4cd8b2115 100644 --- a/plugins/module_utils/network/nxos/facts/lldp_interfaces/lldp_interfaces.py +++ b/plugins/module_utils/network/nxos/facts/lldp_interfaces/lldp_interfaces.py @@ -11,14 +11,15 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type import re + from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.lldp_interfaces.lldp_interfaces import ( Lldp_interfacesArgs, ) @@ -82,9 +83,7 @@ def populate_facts(self, connection, ansible_facts, data=None): facts = {} if objs: facts["lldp_interfaces"] = [] - params = utils.validate_config( - self.argument_spec, {"config": objs} - ) + params = utils.validate_config(self.argument_spec, {"config": objs}) for cfg in params["config"]: facts["lldp_interfaces"].append(utils.remove_empties(cfg)) @@ -121,7 +120,8 @@ def render_config(self, spec, conf): config["transmit"] = False if "management-address" in conf: config["tlv_set"]["management_address"] = re.search( - r"management-address (\S*)", conf + r"management-address (\S*)", + conf, ).group(1) if "vlan" in conf: config["tlv_set"]["vlan"] = re.search(r"vlan (\S*)", conf).group(1) diff --git a/plugins/module_utils/network/nxos/facts/logging_global/logging_global.py b/plugins/module_utils/network/nxos/facts/logging_global/logging_global.py index 57b944c45..189db0e41 100644 --- a/plugins/module_utils/network/nxos/facts/logging_global/logging_global.py +++ b/plugins/module_utils/network/nxos/facts/logging_global/logging_global.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -14,20 +15,16 @@ based on the configuration. """ -from copy import deepcopy +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils -from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( - get_logging_sevmap, +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.logging_global.logging_global import ( + Logging_globalArgs, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.logging_global import ( Logging_globalTemplate, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.logging_global.logging_global import ( - Logging_globalArgs, +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( + get_logging_sevmap, ) @@ -62,9 +59,7 @@ def populate_facts(self, connection, ansible_facts, data=None): data = self.get_config(connection) # parse native config using the Logging_global template - logging_global_parser = Logging_globalTemplate( - lines=data.splitlines(), module=self._module - ) + logging_global_parser = Logging_globalTemplate(lines=data.splitlines(), module=self._module) objs = logging_global_parser.parse() if objs: @@ -84,8 +79,10 @@ def populate_facts(self, connection, ansible_facts, data=None): params = utils.remove_empties( logging_global_parser.validate_config( - self.argument_spec, {"config": objs}, redact=True - ) + self.argument_spec, + {"config": objs}, + redact=True, + ), ) facts["logging_global"] = params.get("config", {}) diff --git a/plugins/module_utils/network/nxos/facts/ntp_global/ntp_global.py b/plugins/module_utils/network/nxos/facts/ntp_global/ntp_global.py index 81e11fee5..258b68aaf 100644 --- a/plugins/module_utils/network/nxos/facts/ntp_global/ntp_global.py +++ b/plugins/module_utils/network/nxos/facts/ntp_global/ntp_global.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -14,18 +15,14 @@ based on the configuration. """ -from copy import deepcopy +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils -from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.ntp_global.ntp_global import ( + Ntp_globalArgs, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.ntp_global import ( Ntp_globalTemplate, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.ntp_global.ntp_global import ( - Ntp_globalArgs, -) class Ntp_globalFacts(object): @@ -58,16 +55,15 @@ def populate_facts(self, connection, ansible_facts, data=None): data = self.get_config(connection) # parse native config using the Ntp_global template - ntp_global_parser = Ntp_globalTemplate( - lines=data.splitlines(), module=self._module - ) + ntp_global_parser = Ntp_globalTemplate(lines=data.splitlines(), module=self._module) objs = ntp_global_parser.parse() if "access_group" in objs: for x in ["peer", "query_only", "serve", "serve_only"]: if x in objs["access_group"]: objs["access_group"][x] = sorted( - objs["access_group"][x], key=lambda k: k["access_list"] + objs["access_group"][x], + key=lambda k: k["access_list"], ) pkey = { @@ -84,9 +80,7 @@ def populate_facts(self, connection, ansible_facts, data=None): ansible_facts["ansible_network_resources"].pop("ntp_global", None) params = utils.remove_empties( - ntp_global_parser.validate_config( - self.argument_spec, {"config": objs}, redact=True - ) + ntp_global_parser.validate_config(self.argument_spec, {"config": objs}, redact=True), ) facts["ntp_global"] = params.get("config", {}) diff --git a/plugins/module_utils/network/nxos/facts/ospf_interfaces/ospf_interfaces.py b/plugins/module_utils/network/nxos/facts/ospf_interfaces/ospf_interfaces.py index b5c78ce9b..745f373b2 100644 --- a/plugins/module_utils/network/nxos/facts/ospf_interfaces/ospf_interfaces.py +++ b/plugins/module_utils/network/nxos/facts/ospf_interfaces/ospf_interfaces.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -14,18 +15,14 @@ based on the configuration. """ -from copy import deepcopy +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils -from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.ospf_interfaces.ospf_interfaces import ( + Ospf_interfacesArgs, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.ospf_interfaces import ( Ospf_interfacesTemplate, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.ospf_interfaces.ospf_interfaces import ( - Ospf_interfacesArgs, -) class Ospf_interfacesFacts(object): @@ -59,7 +56,8 @@ def populate_facts(self, connection, ansible_facts, data=None): # parse native config using the Ospf_interfaces template ospf_interfaces_parser = Ospf_interfacesTemplate( - lines=data.splitlines(), module=self._module + lines=data.splitlines(), + module=self._module, ) objs = list(ospf_interfaces_parser.parse().values()) if objs: @@ -71,14 +69,12 @@ def populate_facts(self, connection, ansible_facts, data=None): af["processes"] = list(af["processes"].values()) if af.get("multi_areas"): af["multi_areas"].sort() - item["address_family"] = sorted( - item["address_family"], key=lambda i: i["afi"] - ) + item["address_family"] = sorted(item["address_family"], key=lambda i: i["afi"]) objs = sorted( objs, key=lambda i: [ - int(k) if k.isdigit() else k for k in i["name"].split("/") + int(k) if k.isdigit() else k for k in i["name"].replace(".", "/").split("/") ], ) @@ -86,8 +82,10 @@ def populate_facts(self, connection, ansible_facts, data=None): params = utils.remove_empties( ospf_interfaces_parser.validate_config( - self.argument_spec, {"config": objs}, redact=True - ) + self.argument_spec, + {"config": objs}, + redact=True, + ), ) facts["ospf_interfaces"] = params.get("config", []) diff --git a/plugins/module_utils/network/nxos/facts/ospfv2/ospfv2.py b/plugins/module_utils/network/nxos/facts/ospfv2/ospfv2.py index f49a46e64..248f3ed49 100644 --- a/plugins/module_utils/network/nxos/facts/ospfv2/ospfv2.py +++ b/plugins/module_utils/network/nxos/facts/ospfv2/ospfv2.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -16,15 +17,14 @@ from copy import deepcopy from ansible.module_utils.six import iteritems -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.ospfv2 import ( - Ospfv2Template, -) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.ospfv2.ospfv2 import ( Ospfv2Args, ) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.ospfv2 import ( + Ospfv2Template, +) class Ospfv2Facts(object): @@ -48,9 +48,7 @@ def get_config(self, connection): """Wrapper method for `connection.get()` This method exists solely to allow the unit test framework to mock device connection calls. """ - return connection.get( - "show running-config | section '^router ospf .*'" - ) + return connection.get("show running-config | section '^router ospf .*'") def populate_facts(self, connection, ansible_facts, data=None): """Populate the facts for interfaces diff --git a/plugins/module_utils/network/nxos/facts/ospfv3/ospfv3.py b/plugins/module_utils/network/nxos/facts/ospfv3/ospfv3.py index c739683e4..796dacfb5 100644 --- a/plugins/module_utils/network/nxos/facts/ospfv3/ospfv3.py +++ b/plugins/module_utils/network/nxos/facts/ospfv3/ospfv3.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -13,18 +14,16 @@ for a given resource, parsed, and the facts tree is populated based on the configuration. """ -from copy import deepcopy from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.ospfv3.ospfv3 import ( + Ospfv3Args, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.ospfv3 import ( Ospfv3Template, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.ospfv3.ospfv3 import ( - Ospfv3Args, -) class Ospfv3Facts(object): @@ -76,7 +75,7 @@ def populate_facts(self, connection, ansible_facts, data=None): if "address_family" in entry: if "areas" in entry["address_family"]: entry["address_family"]["areas"] = list( - entry["address_family"]["areas"].values() + entry["address_family"]["areas"].values(), ) ipv6["processes"].append(entry) diff --git a/plugins/module_utils/network/nxos/facts/prefix_lists/prefix_lists.py b/plugins/module_utils/network/nxos/facts/prefix_lists/prefix_lists.py index 0a9b97d72..7bb186315 100644 --- a/plugins/module_utils/network/nxos/facts/prefix_lists/prefix_lists.py +++ b/plugins/module_utils/network/nxos/facts/prefix_lists/prefix_lists.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -14,15 +15,14 @@ based on the configuration. """ -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.prefix_lists.prefix_lists import ( + Prefix_listsArgs, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.prefix_lists import ( Prefix_listsTemplate, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.prefix_lists.prefix_lists import ( - Prefix_listsArgs, -) class Prefix_listsFacts(object): @@ -36,9 +36,7 @@ def get_config(self, connection): """Wrapper method for `connection.get()` This method exists solely to allow the unit test framework to mock device connection calls. """ - return connection.get( - "show running-config | section 'ip(.*) prefix-list'" - ) + return connection.get("show running-config | section 'ip(.*) prefix-list'") def populate_facts(self, connection, ansible_facts, data=None): """Populate the facts for Prefix_lists network resource @@ -56,9 +54,7 @@ def populate_facts(self, connection, ansible_facts, data=None): data = self.get_config(connection) # parse native config using the Prefix_lists template - prefix_lists_parser = Prefix_listsTemplate( - lines=data.splitlines(), module=self._module - ) + prefix_lists_parser = Prefix_listsTemplate(lines=data.splitlines(), module=self._module) objs = list(prefix_lists_parser.parse().values()) if objs: @@ -70,16 +66,12 @@ def populate_facts(self, connection, ansible_facts, data=None): ) for x in item["prefix_lists"]: if "entries" in x: - x["entries"] = sorted( - x["entries"], key=lambda k: k["sequence"] - ) + x["entries"] = sorted(x["entries"], key=lambda k: k["sequence"]) objs = sorted(objs, key=lambda k: k["afi"]) ansible_facts["ansible_network_resources"].pop("prefix_lists", None) params = utils.remove_empties( - prefix_lists_parser.validate_config( - self.argument_spec, {"config": objs}, redact=True - ) + prefix_lists_parser.validate_config(self.argument_spec, {"config": objs}, redact=True), ) facts["prefix_lists"] = params.get("config", []) ansible_facts["ansible_network_resources"].update(facts) diff --git a/plugins/module_utils/network/nxos/facts/route_maps/route_maps.py b/plugins/module_utils/network/nxos/facts/route_maps/route_maps.py index 4829860f0..d1bad913a 100644 --- a/plugins/module_utils/network/nxos/facts/route_maps/route_maps.py +++ b/plugins/module_utils/network/nxos/facts/route_maps/route_maps.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -14,18 +15,14 @@ based on the configuration. """ -from copy import deepcopy +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils -from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.route_maps.route_maps import ( + Route_mapsArgs, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.route_maps import ( Route_mapsTemplate, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.route_maps.route_maps import ( - Route_mapsArgs, -) class Route_mapsFacts(object): @@ -58,9 +55,7 @@ def populate_facts(self, connection, ansible_facts, data=None): data = self.get_config(connection) # parse native config using the Route_maps template - route_maps_parser = Route_mapsTemplate( - lines=data.splitlines(), module=self._module - ) + route_maps_parser = Route_mapsTemplate(lines=data.splitlines(), module=self._module) objs = list(route_maps_parser.parse().values()) @@ -70,9 +65,7 @@ def populate_facts(self, connection, ansible_facts, data=None): ansible_facts["ansible_network_resources"].pop("route_maps", None) params = utils.remove_empties( - route_maps_parser.validate_config( - self.argument_spec, {"config": objs}, redact=True - ) + route_maps_parser.validate_config(self.argument_spec, {"config": objs}, redact=True), ) facts["route_maps"] = params.get("config", []) diff --git a/plugins/module_utils/network/nxos/facts/snmp_server/snmp_server.py b/plugins/module_utils/network/nxos/facts/snmp_server/snmp_server.py index d958ab28e..c46e1a78a 100644 --- a/plugins/module_utils/network/nxos/facts/snmp_server/snmp_server.py +++ b/plugins/module_utils/network/nxos/facts/snmp_server/snmp_server.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -14,15 +15,14 @@ based on the configuration. """ from ansible.module_utils._text import to_text -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.snmp_server.snmp_server import ( + Snmp_serverArgs, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.snmp_server import ( Snmp_serverTemplate, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.snmp_server.snmp_server import ( - Snmp_serverArgs, -) class Snmp_serverFacts(object): @@ -55,32 +55,28 @@ def populate_facts(self, connection, ansible_facts, data=None): data = self.get_config(connection) # parse native config using the Snmp_server template - snmp_server_parser = Snmp_serverTemplate( - lines=data.splitlines(), module=self._module - ) + snmp_server_parser = Snmp_serverTemplate(lines=data.splitlines(), module=self._module) objs = snmp_server_parser.parse() if "communities" in objs: - objs["communities"] = sorted( - objs["communities"], key=lambda k: to_text(k["name"]) - ) + objs["communities"] = sorted(objs["communities"], key=lambda k: to_text(k["name"])) if "users" in objs: if "auth" in objs["users"]: objs["users"]["auth"] = sorted( - objs["users"]["auth"], key=lambda k: to_text(k["user"]) + objs["users"]["auth"], + key=lambda k: to_text(k["user"]), ) if "use_acls" in objs["users"]: objs["users"]["use_acls"] = sorted( - objs["users"]["use_acls"], key=lambda k: to_text(k["user"]) + objs["users"]["use_acls"], + key=lambda k: to_text(k["user"]), ) ansible_facts["ansible_network_resources"].pop("snmp_server", None) params = utils.remove_empties( - snmp_server_parser.validate_config( - self.argument_spec, {"config": objs}, redact=True - ) + snmp_server_parser.validate_config(self.argument_spec, {"config": objs}, redact=True), ) facts["snmp_server"] = params.get("config", {}) diff --git a/plugins/module_utils/network/nxos/facts/static_routes/static_routes.py b/plugins/module_utils/network/nxos/facts/static_routes/static_routes.py index 53605fc12..991b552ff 100644 --- a/plugins/module_utils/network/nxos/facts/static_routes/static_routes.py +++ b/plugins/module_utils/network/nxos/facts/static_routes/static_routes.py @@ -12,16 +12,17 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type -import re -from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.static_routes.static_routes import ( Static_routesArgs, ) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.static_routes import ( + Static_routesTemplate, +) class Static_routesFacts(object): @@ -30,219 +31,113 @@ class Static_routesFacts(object): def __init__(self, module, subspec="config", options="options"): self._module = module self.argument_spec = Static_routesArgs.argument_spec - spec = deepcopy(self.argument_spec) - if subspec: - if options: - facts_argument_spec = spec[subspec][options] - else: - facts_argument_spec = spec[subspec] - else: - facts_argument_spec = spec - self.generated_spec = utils.generate_dict(facts_argument_spec) - - def get_device_data(self, connection, data): - vrf_data = [] - non_vrf_data = [] - if not data: - non_vrf_data = connection.get( - "show running-config | include '^ip(v6)* route'" - ) - vrf_data = connection.get( - "show running-config | section '^vrf context'" - ) - if non_vrf_data: - non_vrf_data = non_vrf_data.split("\n") + def get_static_routes_data(self, connection): + non_vrf_data = connection.get("show running-config | include '^ip(v6)* route'") + vrf_data = connection.get("show running-config | section '^vrf context'") + if vrf_data: + non_vrf_data += "\n" + vrf_data + return non_vrf_data + + def process_static_routes(self, objs): + strout = {} + for k, obj in objs.items(): + _routes = {"next_hops": []} + _nx_hop = [] + is_vrf = False + + for routes in obj: + grp_vrf = routes.pop("_vrf", None) + if grp_vrf: + is_vrf = True + _afi = routes.pop("_afi") + + _routes["dest"] = routes.pop("_dest") + _nx_hop.append(routes) + + _routes["next_hops"].extend(_nx_hop) + + if is_vrf: + if strout.get(grp_vrf) and strout[grp_vrf].get(_afi): + strout[grp_vrf][_afi].append(_routes) + else: + if strout.get(grp_vrf): + _tma = {_afi: [_routes]} + strout[grp_vrf].update(_tma) + else: + _tm = {grp_vrf: {_afi: [_routes]}} + strout.update(_tm) else: - non_vrf_data = [] - vrf_data = vrf_data.split("\nvrf context") - # as we split based on 'vrf context', it is stripped from the data except the first element - else: - # used for parsed state where data is from the 'running-config' key - data = data.split("\n") - i = 0 - while i <= (len(data) - 1): - if "vrf context " in data[i]: - vrf_conf = data[i] - j = i + 1 - while j < len(data) and "vrf context " not in data[j]: - vrf_conf += "\n" + data[j] - j += 1 - i = j - vrf_data.append(vrf_conf) + if strout.get(_afi): + strout[_afi].append(_routes) else: - non_vrf_data.append(data[i]) - i += 1 + _tma = {_afi: [_routes]} + strout.update(_tma) + return strout + + def structure_static_routes(self, strout): + _static_route_facts = [] + afi_v4 = strout.pop("ipv4", None) + afi_v6 = strout.pop("ipv6", None) - new_vrf_data = [] - for v in vrf_data: - if re.search(r"\n\s*ip(v6)? route", v): - new_vrf_data.append(v) - # dont consider vrf if it does not have routes - for i in range(len(new_vrf_data)): - if not re.search("^vrf context", new_vrf_data[i]): - new_vrf_data[i] = "vrf context" + new_vrf_data[i] + if afi_v4 or afi_v6: + _triv_static_route = {"address_families": []} - resources = non_vrf_data + new_vrf_data - return resources + if afi_v4: + _triv_static_route["address_families"].append({"afi": "ipv4", "routes": afi_v4}) + if afi_v6: + _triv_static_route["address_families"].append({"afi": "ipv6", "routes": afi_v6}) + + _static_route_facts.append(_triv_static_route) + + for k, v in strout.items(): + afi_v4 = v.pop("ipv4", None) + afi_v6 = v.pop("ipv6", None) + + _vrf_static_route = { + "vrf": k, + "address_families": [], + } + + if afi_v4: + _vrf_static_route["address_families"].append({"afi": "ipv4", "routes": afi_v4}) + if afi_v6: + _vrf_static_route["address_families"].append({"afi": "ipv6", "routes": afi_v6}) + + _static_route_facts.append(_vrf_static_route) + return _static_route_facts def populate_facts(self, connection, ansible_facts, data=None): - """Populate the facts for static_routes + """Populate the facts for Static_routes network resource + :param connection: the device connection :param ansible_facts: Facts dictionary :param data: previously collected conf + :rtype: dictionary :returns: facts """ - objs = [] - resources = self.get_device_data(connection, data) - objs = self.render_config(self.generated_spec, resources) - ansible_facts["ansible_network_resources"].pop("static_routes", None) + facts = {} - if objs: - params = utils.validate_config( - self.argument_spec, {"config": objs} - ) - params = utils.remove_empties(params) - for c in params["config"]: - if c == {"vrf": "default"}: - params["config"].remove(c) - facts["static_routes"] = params["config"] - ansible_facts["ansible_network_resources"].update(facts) - return ansible_facts + objs = [] - def get_inner_dict(self, conf, inner_dict): - """ - This method parses the command to create the innermost dictionary of the config - """ - conf = re.sub(r"\s*ip(v6)? route", "", conf) - # strip 'ip route' - inner_dict["dest"] = re.match(r"^\s*(\S+\/\d+) .*", conf).group(1) + if not data: + data = self.get_static_routes_data(connection) + + # parse native config using the Static_routes template + static_routes_parser = Static_routesTemplate(lines=data.splitlines(), module=self._module) + objs = static_routes_parser.parse() + + strout = self.process_static_routes(objs) + objs = self.structure_static_routes(strout) - # ethernet1/2/23 - iface = re.match( - r".* (Ethernet|loopback|mgmt|port\-channel)(\S*) .*", conf + ansible_facts["ansible_network_resources"].pop("static_routes", None) + + params = utils.remove_empties( + static_routes_parser.validate_config(self.argument_spec, {"config": objs}, redact=True), ) - i = ["Ethernet", "loopback", "mgmt", "port-channel"] - if iface and iface.group(1) in i: - inner_dict["interface"] = (iface.group(1)) + (iface.group(2)) - conf = re.sub(inner_dict["interface"], "", conf) - - if "." in inner_dict["dest"]: - conf = re.sub(inner_dict["dest"], "", conf) - inner_dict["afi"] = "ipv4" - ipv4 = re.match( - r".* (\d+\.\d+\.\d+\.\d+\/?\d*).*", conf - ) # gets next hop ip - if ipv4: - inner_dict["forward_router_address"] = ipv4.group(1) - conf = re.sub(inner_dict["forward_router_address"], "", conf) - else: - inner_dict["afi"] = "ipv6" - conf = re.sub(inner_dict["dest"], "", conf) - ipv6 = re.match(r".* (\S*:\S*:\S*\/?\d*).*", conf) - if ipv6: - inner_dict["forward_router_address"] = ipv6.group(1) - conf = re.sub(inner_dict["forward_router_address"], "", conf) - - nullif = re.search(r"null0", conf, re.IGNORECASE) - if nullif: - inner_dict["interface"] = "Null0" - inner_dict["forward_router_address"] = None - return inner_dict # dest IP not needed for null if - - keywords = ["vrf", "name", "tag", "track"] - for key in keywords: - pattern = re.match(r".* (?:%s) (\S+).*" % key, conf) - if pattern: - if key == "vrf": - key = "dest_vrf" - elif key == "name": - key = "route_name" - inner_dict[key] = pattern.group(1).strip() - conf = re.sub(key + " " + inner_dict[key], "", conf) - - pref = re.match(r"(?:.*) (\d+)$", conf) - if pref: - # if something is left at the end without any key, it is the pref - inner_dict["admin_distance"] = pref.group(1) - return inner_dict - - def get_command(self, conf, afi_list, dest_list, af): - inner_dict = {} - inner_dict = self.get_inner_dict(conf, inner_dict) - if inner_dict["afi"] not in afi_list: - af.append({"afi": inner_dict["afi"], "routes": []}) - afi_list.append(inner_dict["afi"]) - - next_hop = {} - params = [ - "forward_router_address", - "interface", - "admin_distance", - "route_name", - "tag", - "track", - "dest_vrf", - ] - for p in params: - if p in inner_dict.keys(): - next_hop.update({p: inner_dict[p]}) - - if inner_dict["dest"] not in dest_list: - dest_list.append(inner_dict["dest"]) - af[-1]["routes"].append( - {"dest": inner_dict["dest"], "next_hops": []} - ) - # if 'dest' is new, create new list under 'routes' - af[-1]["routes"][-1]["next_hops"].append(next_hop) - else: - af[-1]["routes"][-1]["next_hops"].append(next_hop) - # just append if dest already exists - return af - - def render_config(self, spec, con): - """ - Render config as dictionary structure and delete keys - from spec for null values - :param spec: The facts tree, generated from the argspec - :param conf: The configuration - :rtype: dictionary - :returns: The generated config - """ - # config=deepcopy(spec) - config = [] - global_afi_list = [] - global_af = [] - global_dest_list = [] - if con: - for conf in con: - if conf.startswith("vrf context"): - svrf = re.match(r"vrf context (\S+)\n", conf).group(1) - afi_list = [] - af = [] - dest_list = [] - config_dict = {"vrf": svrf, "address_families": []} - conf = conf.split("\n") - # considering from the second line as first line is 'vrf context..' - conf = conf[1:] - for c in conf: - if ( - "ip route" in c or "ipv6 route" in c - ) and "bfd" not in c: - self.get_command(c, afi_list, dest_list, af) - config_dict["address_families"] = af - config.append(config_dict) - else: - if ( - "ip route" in conf or "ipv6 route" in conf - ) and "bfd" not in conf: - self.get_command( - conf, global_afi_list, global_dest_list, global_af - ) - if global_af: - config.append( - utils.remove_empties({"address_families": global_af}) - ) - return config + facts["static_routes"] = params.get("config") + ansible_facts["ansible_network_resources"].update(facts) + + return ansible_facts diff --git a/plugins/module_utils/network/nxos/facts/telemetry/telemetry.py b/plugins/module_utils/network/nxos/facts/telemetry/telemetry.py index 4a766a333..bdb280310 100644 --- a/plugins/module_utils/network/nxos/facts/telemetry/telemetry.py +++ b/plugins/module_utils/network/nxos/facts/telemetry/telemetry.py @@ -11,33 +11,30 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type import re + from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.telemetry.telemetry import ( TelemetryArgs, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.cmdref.telemetry.telemetry import ( - TMS_GLOBAL, TMS_DESTGROUP, + TMS_GLOBAL, TMS_SENSORGROUP, TMS_SUBSCRIPTION, ) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import NxosCmdRef from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.telemetry.telemetry import ( - get_instance_data, cr_key_lookup, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.telemetry.telemetry import ( + get_instance_data, normalize_data, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - NxosCmdRef, -) class TelemetryFacts(object): @@ -82,9 +79,7 @@ def populate_facts(self, connection, ansible_facts, data=None): # Get Telemetry Global Data cmd_ref["TMS_GLOBAL"]["ref"] = [] - cmd_ref["TMS_GLOBAL"]["ref"].append( - NxosCmdRef(self._module, TMS_GLOBAL) - ) + cmd_ref["TMS_GLOBAL"]["ref"].append(NxosCmdRef(self._module, TMS_GLOBAL)) ref = cmd_ref["TMS_GLOBAL"]["ref"][0] ref.set_context() ref.get_existing() @@ -100,9 +95,7 @@ def populate_facts(self, connection, ansible_facts, data=None): for line in device_cache_lines: if re.search(r"destination-group", line): resource_key = line.strip() - cmd_ref["TMS_DESTGROUP"]["ref"].append( - NxosCmdRef(self._module, TMS_DESTGROUP) - ) + cmd_ref["TMS_DESTGROUP"]["ref"].append(NxosCmdRef(self._module, TMS_DESTGROUP)) ref = cmd_ref["TMS_DESTGROUP"]["ref"][-1] ref.set_context([resource_key]) ref.get_existing(device_cache) @@ -113,9 +106,7 @@ def populate_facts(self, connection, ansible_facts, data=None): for line in device_cache_lines: if re.search(r"sensor-group", line): resource_key = line.strip() - cmd_ref["TMS_SENSORGROUP"]["ref"].append( - NxosCmdRef(self._module, TMS_SENSORGROUP) - ) + cmd_ref["TMS_SENSORGROUP"]["ref"].append(NxosCmdRef(self._module, TMS_SENSORGROUP)) ref = cmd_ref["TMS_SENSORGROUP"]["ref"][-1] ref.set_context([resource_key]) ref.get_existing(device_cache) @@ -126,7 +117,7 @@ def populate_facts(self, connection, ansible_facts, data=None): if re.search(r"subscription", line): resource_key = line.strip() cmd_ref["TMS_SUBSCRIPTION"]["ref"].append( - NxosCmdRef(self._module, TMS_SUBSCRIPTION) + NxosCmdRef(self._module, TMS_SUBSCRIPTION), ) ref = cmd_ref["TMS_SUBSCRIPTION"]["ref"][-1] ref.set_context([resource_key]) @@ -171,39 +162,24 @@ def render_config(self, spec, cmd_ref): for cr in cmd_ref[mo]["ref"]: cr_keys = cr_key_lookup(key, mo) for cr_key in cr_keys: - if cr._ref.get(cr_key) and cr._ref[cr_key].get( - "existing" - ): + if cr._ref.get(cr_key) and cr._ref[cr_key].get("existing"): if isinstance(config[key], dict): for k in config[key].keys(): - for existing_key in cr._ref[cr_key][ - "existing" - ].keys(): - config[key][k] = cr._ref[cr_key][ - "existing" - ][existing_key][k] + for existing_key in cr._ref[cr_key]["existing"].keys(): + config[key][k] = cr._ref[cr_key]["existing"][existing_key][ + k + ] continue if isinstance(config[key], list): - for existing_key in cr._ref[cr_key][ - "existing" - ].keys(): - data = get_instance_data( - key, cr_key, cr, existing_key - ) + for existing_key in cr._ref[cr_key]["existing"].keys(): + data = get_instance_data(key, cr_key, cr, existing_key) config[key].append(data) continue - for existing_key in cr._ref[cr_key][ - "existing" - ].keys(): - config[key] = cr._ref[cr_key]["existing"][ - existing_key - ] + for existing_key in cr._ref[cr_key]["existing"].keys(): + config[key] = cr._ref[cr_key]["existing"][existing_key] elif cr._ref.get(cr_key): data = get_instance_data(key, cr_key, cr, None) - if ( - isinstance(config[key], list) - and data not in config[key] - ): + if isinstance(config[key], list) and data not in config[key]: config[key].append(data) return utils.remove_empties(config) diff --git a/plugins/module_utils/network/nxos/facts/vlans/vlans.py b/plugins/module_utils/network/nxos/facts/vlans/vlans.py index a38c1f3e8..f7ac798f1 100644 --- a/plugins/module_utils/network/nxos/facts/vlans/vlans.py +++ b/plugins/module_utils/network/nxos/facts/vlans/vlans.py @@ -12,19 +12,19 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type -import re import ast +import re + from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( parse_conf_arg, - parse_conf_cmd_arg, ) + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.vlans.vlans import ( VlansArgs, ) @@ -74,19 +74,13 @@ def populate_facts(self, connection, ansible_facts, data=None): try: # Not all devices support | json-pretty but is a workaround for # libssh issue https://github.com/ansible/pylibssh/issues/208 - structured = self.get_device_data( - connection, "show vlan | json-pretty" - ) + structured = self.get_device_data(connection, "show vlan | json-pretty") except Exception: # When json-pretty is not supported, we fall back to | json - structured = self.get_device_data( - connection, "show vlan | json" - ) + structured = self.get_device_data(connection, "show vlan | json") # Raw cli config is needed for mapped_vni, which is not included in structured. - run_cfg_output = self.get_device_data( - connection, "show running-config | section ^vlan" - ) + run_cfg_output = self.get_device_data(connection, "show running-config | section ^vlan") else: running_config = data.split("\n\n") structured, run_cfg_output = running_config[0], running_config[1] @@ -103,9 +97,7 @@ def populate_facts(self, connection, ansible_facts, data=None): facts = {} if objs: facts["vlans"] = [] - params = utils.validate_config( - self.argument_spec, {"config": objs} - ) + params = utils.validate_config(self.argument_spec, {"config": objs}) for cfg in params["config"]: facts["vlans"].append(utils.remove_empties(cfg)) ansible_facts["ansible_network_resources"].update(facts) @@ -135,9 +127,7 @@ def render_config(self, spec, vlan): obj["mode"] = vlan["vlanshowinfo-vlanmode"].replace("-vlan", "") # enabled: shutdown, noshutdown - obj["enabled"] = ( - True if "noshutdown" in vlan["vlanshowbr-shutstate"] else False - ) + obj["enabled"] = True if "noshutdown" in vlan["vlanshowbr-shutstate"] else False # state: active, suspend obj["state"] = vlan["vlanshowbr-vlanstate"] @@ -176,7 +166,7 @@ def normalize_table_data(self, structured, run_cfg_output): # "vlanshowinfo-vlanmode": "ce-vlan"}} mtuinfo = structured["TABLE_mtuinfo"]["ROW_mtuinfo"] - if type(vlanbrief) is not list: + if not isinstance(vlanbrief, list): # vlanbrief is not a list when only one vlan is found. vlanbrief = [vlanbrief] mtuinfo = [mtuinfo] diff --git a/plugins/module_utils/network/nxos/nxos.py b/plugins/module_utils/network/nxos/nxos.py index aa1cc8866..f34046b39 100644 --- a/plugins/module_utils/network/nxos/nxos.py +++ b/plugins/module_utils/network/nxos/nxos.py @@ -28,32 +28,29 @@ # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from __future__ import absolute_import, division, print_function + __metaclass__ = type -import collections import json import re -import sys + from copy import deepcopy from ansible.module_utils._text import to_text -from ansible.module_utils.basic import env_fallback -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, - ComplexList, -) -from ansible.module_utils.connection import Connection, ConnectionError from ansible.module_utils.common._collections_compat import Mapping +from ansible.module_utils.connection import Connection, ConnectionError +from ansible.module_utils.six import PY2, PY3 from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( + CustomNetworkConfig, NetworkConfig, dumps, ) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( - CustomNetworkConfig, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + ComplexList, + to_list, ) -from ansible.module_utils.six import iteritems, PY2, PY3 -from ansible.module_utils.urls import fetch_url + try: import yaml @@ -62,75 +59,19 @@ except ImportError: HAS_YAML = False -try: - if sys.version_info[:2] < (2, 7): - from ordereddict import OrderedDict - else: - from collections import OrderedDict - HAS_ORDEREDDICT = True -except ImportError: - HAS_ORDEREDDICT = False _DEVICE_CONNECTION = None -nxos_provider_spec = { - "host": dict(type="str"), - "port": dict(type="int"), - "username": dict( - type="str", fallback=(env_fallback, ["ANSIBLE_NET_USERNAME"]) - ), - "password": dict( - type="str", - no_log=True, - fallback=(env_fallback, ["ANSIBLE_NET_PASSWORD"]), - ), - "ssh_keyfile": dict( - type="str", - fallback=(env_fallback, ["ANSIBLE_NET_SSH_KEYFILE"]), - no_log=False, - ), - "authorize": dict( - type="bool", - default=False, - fallback=(env_fallback, ["ANSIBLE_NET_AUTHORIZE"]), - ), - "auth_pass": dict( - type="str", - no_log=True, - fallback=(env_fallback, ["ANSIBLE_NET_AUTH_PASS"]), - ), - "use_ssl": dict(type="bool", default=False), - "use_proxy": dict(type="bool", default=True), - "validate_certs": dict(type="bool", default=False), - "timeout": dict(type="int"), - "transport": dict(type="str", default="cli", choices=["cli", "nxapi"]), -} -nxos_argument_spec = { - "provider": dict( - type="dict", - options=nxos_provider_spec, - removed_at_date="2022-06-01", - removed_from_collection="cisco.nxos", - ) -} - - -def get_provider_argspec(): - return nxos_provider_spec - def get_connection(module): global _DEVICE_CONNECTION if not _DEVICE_CONNECTION: - if is_local_nxapi(module): - conn = LocalNxapi(module) - else: - connection_proxy = Connection(module._socket_path) - cap = json.loads(connection_proxy.get_capabilities()) - if cap["network_api"] == "cliconf": - conn = Cli(module) - elif cap["network_api"] == "nxapi": - conn = HttpApi(module) + connection_proxy = Connection(module._socket_path) + cap = json.loads(connection_proxy.get_capabilities()) + if cap["network_api"] == "cliconf": + conn = Cli(module) + elif cap["network_api"] == "nxapi": + conn = HttpApi(module) _DEVICE_CONNECTION = conn return _DEVICE_CONNECTION @@ -163,9 +104,7 @@ def get_config(self, flags=None): try: out = connection.get_config(flags=flags) except ConnectionError as exc: - self._module.fail_json( - msg=to_text(exc, errors="surrogate_then_replace") - ) + self._module.fail_json(msg=to_text(exc, errors="surrogate_then_replace")) cfg = to_text(out, errors="surrogate_then_replace").strip() + "\n" self._device_configs[cmd] = cfg @@ -184,14 +123,11 @@ def run_commands(self, commands, check_rc=True): if network_api == "cliconf" and out: for index, resp in enumerate(out): if ( - "Invalid command at" in resp - or "Ambiguous command at" in resp + "Invalid command at" in resp or "Ambiguous command at" in resp ) and "json" in resp: if commands[index]["output"] == "json": commands[index]["output"] = "text" - out = connection.run_commands( - commands, check_rc - ) + out = connection.run_commands(commands, check_rc) return out except ConnectionError as exc: self._module.fail_json(msg=to_text(exc)) @@ -215,10 +151,7 @@ def load_config(self, config, return_error=False, opts=None, replace=None): responses.append(err) return responses elif code and "no graceful-restart" in err: - if ( - "ISSU/HA will be affected if Graceful Restart is disabled" - in err - ): + if "ISSU/HA will be affected if Graceful Restart is disabled" in err: msg = [""] responses.extend(msg) return responses @@ -250,9 +183,7 @@ def get_diff( diff_replace=diff_replace, ) except ConnectionError as exc: - self._module.fail_json( - msg=to_text(exc, errors="surrogate_then_replace") - ) + self._module.fail_json(msg=to_text(exc, errors="surrogate_then_replace")) return response def get_capabilities(self): @@ -264,9 +195,7 @@ def get_capabilities(self): try: capabilities = connection.get_capabilities() except ConnectionError as exc: - self._module.fail_json( - msg=to_text(exc, errors="surrogate_then_replace") - ) + self._module.fail_json(msg=to_text(exc, errors="surrogate_then_replace")) self._module._capabilities = json.loads(capabilities) return self._module._capabilities @@ -275,9 +204,7 @@ def read_module_context(self, module_key): try: module_context = connection.read_module_context(module_key) except ConnectionError as exc: - self._module.fail_json( - msg=to_text(exc, errors="surrogate_then_replace") - ) + self._module.fail_json(msg=to_text(exc, errors="surrogate_then_replace")) return module_context @@ -286,336 +213,7 @@ def save_module_context(self, module_key, module_context): try: connection.save_module_context(module_key, module_context) except ConnectionError as exc: - self._module.fail_json( - msg=to_text(exc, errors="surrogate_then_replace") - ) - - return None - - -class LocalNxapi: - - OUTPUT_TO_COMMAND_TYPE = { - "text": "cli_show_ascii", - "json": "cli_show", - "bash": "bash", - "config": "cli_conf", - } - - def __init__(self, module): - self._module = module - self._nxapi_auth = None - self._device_configs = {} - self._module_context = {} - - provider = self._module.params.get("provider") or {} - self._module.params["url_username"] = provider.get("username") - self._module.params["url_password"] = provider.get("password") - - host = provider.get("host") - port = provider.get("port") - - if provider.get("use_ssl"): - proto = "https" - port = port or 443 - else: - proto = "http" - port = port or 80 - - self._url = "%s://%s:%s/ins" % (proto, host, port) - - def _error(self, msg, **kwargs): - self._nxapi_auth = None - if "url" not in kwargs: - kwargs["url"] = self._url - self._module.fail_json(msg=msg, **kwargs) - - def _request_builder( - self, commands, output, version="1.0", chunk="0", sid=None - ): - """Encodes a NXAPI JSON request message""" - try: - command_type = self.OUTPUT_TO_COMMAND_TYPE[output] - except KeyError: - msg = "invalid format, received %s, expected one of %s" % ( - output, - ",".join(self.OUTPUT_TO_COMMAND_TYPE.keys()), - ) - self._error(msg=msg) - - if isinstance(commands, (list, set, tuple)): - commands = " ;".join(commands) - - # Order should not matter but some versions of NX-OS software fail - # to process the payload properly if 'input' gets serialized before - # 'type' and the payload of 'input' contains the word 'type'. - msg = collections.OrderedDict() - msg["version"] = version - msg["type"] = command_type - msg["chunk"] = chunk - msg["sid"] = sid - msg["input"] = commands - msg["output_format"] = "json" - - return dict(ins_api=msg) - - def send_request( - self, - commands, - output="text", - check_status=True, - return_error=False, - opts=None, - ): - # only 10 show commands can be encoded in each request - # messages sent to the remote device - if opts is None: - opts = {} - if output != "config": - commands = collections.deque(to_list(commands)) - stack = list() - requests = list() - - while commands: - stack.append(commands.popleft()) - if len(stack) == 10: - body = self._request_builder(stack, output) - data = self._module.jsonify(body) - requests.append(data) - stack = list() - - if stack: - body = self._request_builder(stack, output) - data = self._module.jsonify(body) - requests.append(data) - - else: - body = self._request_builder(commands, "config") - requests = [self._module.jsonify(body)] - - headers = {"Content-Type": "application/json"} - result = list() - timeout = self._module.params["provider"]["timeout"] - use_proxy = self._module.params["provider"]["use_proxy"] - - for req in requests: - if self._nxapi_auth: - headers["Cookie"] = self._nxapi_auth - - response, headers = fetch_url( - self._module, - self._url, - data=req, - headers=headers, - timeout=timeout, - method="POST", - use_proxy=use_proxy, - ) - self._nxapi_auth = headers.get("set-cookie") - - if opts.get("ignore_timeout") and re.search( - r"(-1|5\d\d)", str(headers["status"]) - ): - result.append(headers["status"]) - return result - elif headers["status"] != 200: - self._error(**headers) - - try: - response = self._module.from_json(response.read()) - except ValueError: - self._module.fail_json(msg="unable to parse response") - - if response["ins_api"].get("outputs"): - output = response["ins_api"]["outputs"]["output"] - for item in to_list(output): - if check_status is True and item["code"] != "200": - if return_error: - result.append(item) - else: - self._error(output=output, **item) - elif "body" in item: - result.append(item["body"]) - # else: - # error in command but since check_status is disabled - # silently drop it. - # result.append(item['msg']) - - return result - - def get_config(self, flags=None): - """Retrieves the current config from the device or cache""" - flags = [] if flags is None else flags - - cmd = "show running-config " - cmd += " ".join(flags) - cmd = cmd.strip() - - try: - return self._device_configs[cmd] - except KeyError: - out = self.send_request(cmd) - cfg = str(out[0]).strip() - self._device_configs[cmd] = cfg - return cfg - - def run_commands(self, commands, check_rc=True): - """Run list of commands on remote device and return results""" - output = None - queue = list() - responses = list() - - def _send(commands, output): - return self.send_request(commands, output, check_status=check_rc) - - for item in to_list(commands): - if is_json(item["command"]): - item["command"] = str(item["command"]).rsplit("|", 1)[0] - item["output"] = "json" - - if all((output == "json", item["output"] == "text")) or all( - (output == "text", item["output"] == "json") - ): - responses.extend(_send(queue, output)) - queue = list() - - output = item["output"] or "json" - queue.append(item["command"]) - - if queue: - responses.extend(_send(queue, output)) - - return responses - - def load_config( - self, commands, return_error=False, opts=None, replace=None - ): - """Sends the ordered set of commands to the device""" - - if opts is None: - opts = {} - - responses = [] - - if replace: - device_info = self.get_device_info() - if "9K" not in device_info.get("network_os_platform", ""): - self._module.fail_json( - msg="replace is supported only on Nexus 9K devices" - ) - commands = "config replace {0}".format(replace) - - commands = to_list(commands) - try: - resp = self.send_request( - commands, - output="config", - check_status=True, - return_error=return_error, - opts=opts, - ) - except ValueError as exc: - code = getattr(exc, "code", 1) - message = getattr(exc, "err", exc) - err = to_text(message, errors="surrogate_then_replace") - if opts.get("ignore_timeout") and code: - responses.append(code) - return responses - elif code and "no graceful-restart" in err: - if ( - "ISSU/HA will be affected if Graceful Restart is disabled" - in err - ): - msg = [""] - responses.extend(msg) - return responses - else: - self._module.fail_json(msg=err) - elif code: - self._module.fail_json(msg=err) - - if return_error: - return resp - else: - return responses.extend(resp) - - def get_diff( - self, - candidate=None, - running=None, - diff_match="line", - diff_ignore_lines=None, - path=None, - diff_replace="line", - ): - diff = {} - - # prepare candidate configuration - candidate_obj = NetworkConfig(indent=2) - candidate_obj.load(candidate) - - if running and diff_match != "none" and diff_replace != "config": - # running configuration - running_obj = NetworkConfig( - indent=2, contents=running, ignore_lines=diff_ignore_lines - ) - configdiffobjs = candidate_obj.difference( - running_obj, path=path, match=diff_match, replace=diff_replace - ) - - else: - configdiffobjs = candidate_obj.items - - diff["config_diff"] = ( - dumps(configdiffobjs, "commands") if configdiffobjs else "" - ) - return diff - - def get_device_info(self): - device_info = {} - - device_info["network_os"] = "nxos" - reply = self.run_commands( - {"command": "show version", "output": "json"} - ) - data = reply[0] - - platform_reply = self.run_commands( - {"command": "show inventory", "output": "json"} - ) - platform_info = platform_reply[0] - - device_info["network_os_version"] = data.get( - "sys_ver_str" - ) or data.get("kickstart_ver_str") - device_info["network_os_model"] = data["chassis_id"] - device_info["network_os_hostname"] = data["host_name"] - device_info["network_os_image"] = data.get( - "isan_file_name" - ) or data.get("kick_file_name") - - if platform_info: - inventory_table = platform_info["TABLE_inv"]["ROW_inv"] - for info in inventory_table: - if "Chassis" in info["name"]: - device_info["network_os_platform"] = info["productid"] - - return device_info - - def get_capabilities(self): - result = {} - result["device_info"] = self.get_device_info() - result["network_api"] = "nxapi" - return result - - def read_module_context(self, module_key): - if self._module_context.get(module_key): - return self._module_context[module_key] - - return None - - def save_module_context(self, module_key, module_context): - self._module_context[module_key] = module_context + self._module.fail_json(msg=to_text(exc, errors="surrogate_then_replace")) return None @@ -667,9 +265,7 @@ def get_config(self, flags=None): try: out = self._connection.send_request(cmd) except ConnectionError as exc: - self._module.fail_json( - msg=to_text(exc, errors="surrogate_then_replace") - ) + self._module.fail_json(msg=to_text(exc, errors="surrogate_then_replace")) cfg = to_text(out).strip() self._device_configs[cmd] = cfg @@ -692,24 +288,21 @@ def get_diff( if running and diff_match != "none" and diff_replace != "config": # running configuration - running_obj = NetworkConfig( - indent=2, contents=running, ignore_lines=diff_ignore_lines - ) + running_obj = NetworkConfig(indent=2, contents=running, ignore_lines=diff_ignore_lines) configdiffobjs = candidate_obj.difference( - running_obj, path=path, match=diff_match, replace=diff_replace + running_obj, + path=path, + match=diff_match, + replace=diff_replace, ) else: configdiffobjs = candidate_obj.items - diff["config_diff"] = ( - dumps(configdiffobjs, "commands") if configdiffobjs else "" - ) + diff["config_diff"] = dumps(configdiffobjs, "commands") if configdiffobjs else "" return diff - def load_config( - self, commands, return_error=False, opts=None, replace=None - ): + def load_config(self, commands, return_error=False, opts=None, replace=None): """Sends the ordered set of commands to the device""" if opts is None: opts = {} @@ -727,10 +320,7 @@ def load_config( elif opts.get("catch_clierror") and "400" in code: return [code, err] elif code and "no graceful-restart" in err: - if ( - "ISSU/HA will be affected if Graceful Restart is disabled" - in err - ): + if "ISSU/HA will be affected if Graceful Restart is disabled" in err: msg = [""] responses.extend(msg) return responses @@ -742,9 +332,7 @@ def load_config( responses.extend(resp) return responses - def edit_config( - self, candidate=None, commit=True, replace=None, comment=None - ): + def edit_config(self, candidate=None, commit=True, replace=None, comment=None): resp = list() self.check_edit_config_capability(candidate, commit, replace, comment) @@ -766,21 +354,15 @@ def get_capabilities(self): try: capabilities = self._connection.get_capabilities() except ConnectionError as exc: - self._module.fail_json( - msg=to_text(exc, errors="surrogate_then_replace") - ) + self._module.fail_json(msg=to_text(exc, errors="surrogate_then_replace")) return json.loads(capabilities) - def check_edit_config_capability( - self, candidate=None, commit=True, replace=None, comment=None - ): + def check_edit_config_capability(self, candidate=None, commit=True, replace=None, comment=None): operations = self._connection.get_device_operations() if not candidate and not replace: - raise ValueError( - "must provide a candidate or replace to load configuration" - ) + raise ValueError("must provide a candidate or replace to load configuration") if commit not in (True, False): raise ValueError("'commit' must be a bool, got %s" % commit) @@ -795,9 +377,7 @@ def read_module_context(self, module_key): try: module_context = self._connection.read_module_context(module_key) except ConnectionError as exc: - self._module.fail_json( - msg=to_text(exc, errors="surrogate_then_replace") - ) + self._module.fail_json(msg=to_text(exc, errors="surrogate_then_replace")) return module_context @@ -805,9 +385,7 @@ def save_module_context(self, module_key, module_context): try: self._connection.save_module_context(module_key, module_context) except ConnectionError as exc: - self._module.fail_json( - msg=to_text(exc, errors="surrogate_then_replace") - ) + self._module.fail_json(msg=to_text(exc, errors="surrogate_then_replace")) return None @@ -895,7 +473,7 @@ def feature_enable(self): output = self.execute_show_command(show_cmd, "text") if not output or "CLI command error" in output: msg = "** 'feature {0}' is not enabled. Module will auto-enable feature {0} ** ".format( - feature + feature, ) self._module.warn(msg) ref["_proposed"].append("feature {0}".format(feature)) @@ -919,9 +497,7 @@ def get_platform_shortname(self): return None # Supported Platforms: N3K,N5K,N6K,N7K,N9K,N3K-F,N9K-F - m = re.match( - "(?PN[35679][K57])-(?PC35)*", network_os_platform - ) + m = re.match("(?PN[35679][K57])-(?PC35)*", network_os_platform) if not m: return None shortname = m.group("short") @@ -1008,21 +584,13 @@ def pattern_match_existing(self, output, k): if not match: return None if len(match) > 1 and not multiple: - raise ValueError( - "get_existing: multiple matches found for property {0}".format( - k - ) - ) + raise ValueError("get_existing: multiple matches found for property {0}".format(k)) else: match = [m.groups() for m in match_lines if m] if not match: return None if len(match) > 1 and not multiple: - raise ValueError( - "get_existing: multiple matches found for property {0}".format( - k - ) - ) + raise ValueError("get_existing: multiple matches found for property {0}".format(k)) for item in match: index = match.index(item) match[index] = list(item) # tuple to list @@ -1086,10 +654,7 @@ def get_existing(self, cache_output=None): # We need to remove the last item in context for state absent case. if ref["_state"] in self.absent_states and ref["_context"]: - if ( - ref["_resource_key"] - and ref["_resource_key"] == ref["_context"][-1] - ): + if ref["_resource_key"] and ref["_resource_key"] == ref["_context"][-1]: if ref["_context"][-1] in output: ref["_context"][-1] = "no " + ref["_context"][-1] else: @@ -1122,9 +687,7 @@ def get_existing(self, cache_output=None): ref[k]["existing"][index] = item[0] else: raise ValueError( - "get_existing: unknown 'kind' value specified for key '{0}'".format( - k - ) + "get_existing: unknown 'kind' value specified for key '{0}'".format(k), ) def get_playvals(self): @@ -1180,23 +743,27 @@ def build_cmd_set(self, playval, existing, k): # match up with the getval regex named group keys; e.g. # getval: my-cmd (?P\d+) bar (?P\d+) # setval: my-cmd {foo} bar {baz} - cmd = ref[k]["setval"].format(**playval) + if ref[k]["setval"].startswith("path"): + tmplt = "path {name}" + if "depth" in playval: + tmplt += " depth {depth}" + if "query_condition" in playval: + tmplt += " query-condition {query_condition}" + if "filter_condition" in playval: + tmplt += " filter-condition {filter_condition}" + cmd = tmplt.format(**playval) + else: + cmd = ref[k]["setval"].format(**playval) elif "str" == kind: - if "deleted" in playval: + if "deleted" in str(playval): if existing: cmd = "no " + ref[k]["setval"].format(existing) else: cmd = ref[k]["setval"].format(playval) else: - raise ValueError( - "get_proposed: unknown 'kind' value specified for key '{0}'".format( - k - ) - ) + raise ValueError("get_proposed: unknown 'kind' value specified for key '{0}'".format(k)) if cmd: - if ref["_state"] in self.absent_states and not re.search( - r"^no", cmd - ): + if ref["_state"] in self.absent_states and not re.search(r"^no", cmd): cmd = "no " + cmd # Commands may require parent commands for proper context. # Global _template context is replaced by parameter context @@ -1224,17 +791,13 @@ def compare(playval, existing): if ref["_state"] in self.present_states: if existing is None: return False - elif playval == existing: + elif str(playval) == str(existing): return True - elif ( - isinstance(existing, dict) and playval in existing.values() - ): + elif isinstance(existing, dict) and playval in existing.values(): return True if ref["_state"] in self.absent_states: - if isinstance(existing, dict) and all( - x is None for x in existing.values() - ): + if isinstance(existing, dict) and all(x is None for x in existing.values()): existing = None if existing is None or playval not in existing.values(): return True @@ -1254,9 +817,7 @@ def compare(playval, existing): for ekey, evalue in existing.items(): if isinstance(evalue, dict): # Remove values set to string 'None' from dvalue - evalue = dict( - (k, v) for k, v in evalue.items() if v != "None" - ) + evalue = dict((k, v) for k, v in evalue.items() if v != "None") for pkey, pvalue in playval.items(): if compare(pvalue, evalue): if playval_copy.get(pkey): @@ -1292,14 +853,8 @@ def compare(playval, existing): def nxosCmdRef_import_check(): """Return import error messages or empty string""" msg = "" - if PY2: - if not HAS_ORDEREDDICT and sys.version_info[:2] < (2, 7): - msg += "Mandatory python library 'ordereddict' is not present, try 'pip install ordereddict'\n" - if not HAS_YAML: - msg += "Mandatory python library 'yaml' is not present, try 'pip install yaml'\n" - elif PY3: - if not HAS_YAML: - msg += "Mandatory python library 'PyYAML' is not present, try 'pip install PyYAML'\n" + if not HAS_YAML: + msg += "Mandatory python library 'PyYAML' is not present, try 'pip install PyYAML'\n" return msg @@ -1311,23 +866,11 @@ def is_text(cmd): return not is_json(cmd) -def is_local_nxapi(module): - provider = module.params.get("provider") - if provider: - return provider.get("transport") == "nxapi" - return False - - def to_command(module, commands): - if is_local_nxapi(module): - default_output = "json" - else: - default_output = "text" - transform = ComplexList( dict( command=dict(key=True), - output=dict(default=default_output), + output=dict(type="str", default="text"), prompt=dict(type="list"), answer=dict(type="list"), newline=dict(type="bool", default=True), @@ -1466,6 +1009,8 @@ def default_intf_enabled(name="", sysdefs=None, mode=None): if re.search("port-channel|loopback", name): default = True + elif re.search("Vlan", name): + default = False else: if mode is None: # intf 'switchport' cli is not present so use the user-system-default diff --git a/plugins/module_utils/network/nxos/rm_templates/bgp_address_family.py b/plugins/module_utils/network/nxos/rm_templates/bgp_address_family.py index 527566bdb..942e993e3 100644 --- a/plugins/module_utils/network/nxos/rm_templates/bgp_address_family.py +++ b/plugins/module_utils/network/nxos/rm_templates/bgp_address_family.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -15,7 +16,8 @@ """ import re -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network_template import ( + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) @@ -66,9 +68,7 @@ def _tmplt_redistribute(redis): class Bgp_address_familyTemplate(NetworkTemplate): def __init__(self, lines=None): - super(Bgp_address_familyTemplate, self).__init__( - lines=lines, tmplt=self - ) + super(Bgp_address_familyTemplate, self).__init__(lines=lines, tmplt=self) # fmt: off PARSERS = [ @@ -77,13 +77,13 @@ def __init__(self, lines=None): "getval": re.compile( r""" ^router\sbgp\s(?P\S+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "router bgp {{ as_number }}", "result": { "as_number": "{{ as_number }}", }, - "shared": True + "shared": True, }, { "name": "address_family", @@ -104,8 +104,8 @@ def __init__(self, lines=None): "vrf": "{{ vrf }}", "afi": "{{ afi }}", "safi": "{{ safi }}", - } - } + }, + }, }, "shared": True, }, @@ -124,9 +124,9 @@ def __init__(self, lines=None): '{{ nbr|d("nbr_") + afi + "_" + safi|d() + "_" + vrf|d() }}': { "additional_paths": { "install_backup": "{{ not not backup }}", - } - } - } + }, + }, + }, }, }, { @@ -144,9 +144,9 @@ def __init__(self, lines=None): '{{ nbr|d("nbr_") + afi + "_" + safi|d() + "_" + vrf|d() }}': { "additional_paths": { "receive": "{{ not not receive }}", - } - } - } + }, + }, + }, }, }, { @@ -166,10 +166,10 @@ def __init__(self, lines=None): "additional_paths": { "selection": { "route_map": "{{ route_map }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -187,9 +187,9 @@ def __init__(self, lines=None): '{{ nbr|d("nbr_") + afi + "_" + safi|d() + "_" + vrf|d() }}': { "additional_paths": { "send": "{{ not not send }}", - } - } - } + }, + }, + }, }, }, { @@ -205,8 +205,8 @@ def __init__(self, lines=None): "address_family": { '{{ nbr|d("nbr_") + afi + "_" + safi|d() + "_" + vrf|d() }}': { "advertise_l2vpn_evpn": "{{ not not advertise_l2vpn_evpn }}", - } - } + }, + }, }, }, { @@ -222,8 +222,8 @@ def __init__(self, lines=None): "address_family": { '{{ nbr|d("nbr_") + afi + "_" + safi|d() + "_" + vrf|d() }}': { "advertise_pip": "{{ not not advertise_pip }}", - } - } + }, + }, }, }, { @@ -239,8 +239,8 @@ def __init__(self, lines=None): "address_family": { '{{ nbr|d("nbr_") + afi + "_" + safi|d() + "_" + vrf|d() }}': { "advertise_system_mac": "{{ not not advertise_system_mac }}", - } - } + }, + }, }, }, { @@ -256,8 +256,8 @@ def __init__(self, lines=None): "address_family": { '{{ nbr|d("nbr_") + afi + "_" + safi|d() + "_" + vrf|d() }}': { "allow_vni_in_ethertag": "{{ not not allow_vni_in_ethertag }}", - } - } + }, + }, }, }, { @@ -286,10 +286,10 @@ def __init__(self, lines=None): "advertise_map": "{{ advertise_map }}", "attribute_map": "{{ attribute_map }}", "suppress_map": "{{ suppress_map }}", - } - ] - } - } + }, + ], + }, + }, }, }, { @@ -307,9 +307,9 @@ def __init__(self, lines=None): '{{ nbr|d("nbr_") + afi + "_" + safi|d() + "_" + vrf|d() }}': { "client_to_client": { "no_reflection": "{{ not not reflection }}", - } - } - } + }, + }, + }, }, }, { @@ -326,8 +326,8 @@ def __init__(self, lines=None): "address_family": { '{{ nbr|d("nbr_") + afi + "_" + safi|d() + "_" + vrf|d() }}': { "dampen_igp_metric": "{{ dampen_igp_metric }}", - } - } + }, + }, }, }, { @@ -357,9 +357,9 @@ def __init__(self, lines=None): "start_suppress_route": "{{ start_suppress_route }}", "max_suppress_time": "{{ max_suppress_time }}", "route_map": "{{ route_map }}", - } - } - } + }, + }, + }, }, }, { @@ -377,9 +377,9 @@ def __init__(self, lines=None): '{{ nbr|d("nbr_") + afi + "_" + safi|d() + "_" + vrf|d() }}': { "default_information": { "originate": "{{ not not originate }}", - } - } - } + }, + }, + }, }, }, { @@ -396,8 +396,8 @@ def __init__(self, lines=None): "address_family": { '{{ nbr|d("nbr_") + afi + "_" + safi|d() + "_" + vrf|d() }}': { "default_metric": "{{ default_metric }}", - } - } + }, + }, }, }, { @@ -418,10 +418,10 @@ def __init__(self, lines=None): "distance": { "ebgp_routes": "{{ ebgp_routes }}", "ibgp_routes": "{{ ibgp_routes }}", - "local_routes": "{{ local_routes }}" - } - } - } + "local_routes": "{{ local_routes }}", + }, + }, + }, }, }, { @@ -437,8 +437,8 @@ def __init__(self, lines=None): "address_family": { '{{ nbr|d("nbr_") + afi + "_" + safi|d() + "_" + vrf|d() }}': { "export_gateway_ip": "{{ not not export_gateway_ip }}", - } - } + }, + }, }, }, { @@ -461,10 +461,10 @@ def __init__(self, lines=None): "route_map": "{{ route_map }}", "exist_map": "{{ exist_map }}", "copy_attributes": "{{ not not copy_attributes }}", - } - ] - } - } + }, + ], + }, + }, }, }, { @@ -482,9 +482,9 @@ def __init__(self, lines=None): '{{ nbr|d("nbr_") + afi + "_" + safi|d() + "_" + vrf|d() }}': { "maximum_paths": { "parallel_paths": "{{ parallel_paths }}", - } - } - } + }, + }, + }, }, }, { @@ -503,10 +503,10 @@ def __init__(self, lines=None): "maximum_paths": { "ibgp": { "parallel_paths": "{{ parallel_paths }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -525,10 +525,10 @@ def __init__(self, lines=None): "maximum_paths": { "eibgp": { "parallel_paths": "{{ parallel_paths }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -547,10 +547,10 @@ def __init__(self, lines=None): "maximum_paths": { "local": { "parallel_paths": "{{ parallel_paths }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -569,10 +569,10 @@ def __init__(self, lines=None): "maximum_paths": { "mixed": { "parallel_paths": "{{ parallel_paths }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -593,10 +593,10 @@ def __init__(self, lines=None): { "prefix": "{{ prefix }}", "route_map": "{{ route_map }}", - } - ] - } - } + }, + ], + }, + }, }, }, { @@ -614,9 +614,9 @@ def __init__(self, lines=None): '{{ nbr|d("nbr_") + afi + "_" + safi|d() + "_" + vrf|d() }}': { "nexthop": { "route_map": "{{ route_map }}", - } - } - } + }, + }, + }, }, }, { @@ -638,10 +638,10 @@ def __init__(self, lines=None): "trigger_delay": { "critical_delay": "{{ critical_delay }}", "non_critical_delay": "{{ non_critical_delay }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -665,9 +665,9 @@ def __init__(self, lines=None): "id": "{{ id }}", "route_map": "{{ rmap }}", }, - ] - } - } + ], + }, + }, }, }, { @@ -686,10 +686,10 @@ def __init__(self, lines=None): "retain": { "route_target": { "retain_all": "{{ not not retain_all }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -708,10 +708,10 @@ def __init__(self, lines=None): "retain": { "route_target": { "route_map": "{{ route_map }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -727,8 +727,8 @@ def __init__(self, lines=None): "address_family": { '{{ nbr|d("nbr_") + afi + "_" + safi|d() + "_" + vrf|d() }}': { "suppress_inactive": "{{ not not suppress_inactive }}", - } - } + }, + }, }, }, { @@ -748,9 +748,9 @@ def __init__(self, lines=None): "table_map": { "name": "{{ name }}", "filter": "{{ not not filter }}", - } - } - } + }, + }, + }, }, }, { @@ -771,10 +771,10 @@ def __init__(self, lines=None): "bestpath_defer": { "defer_time": "{{ defer_time }}", "maximum_defer_time": "{{ maximum_defer_time }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -790,8 +790,8 @@ def __init__(self, lines=None): "address_family": { '{{ nbr|d("nbr_") + afi + "_" + safi|d() + "_" + vrf|d() }}': { "wait_igp_convergence": "{{ not not wait_igp_convergence }}", - } - } + }, + }, }, }, ] diff --git a/plugins/module_utils/network/nxos/rm_templates/bgp_global.py b/plugins/module_utils/network/nxos/rm_templates/bgp_global.py index 33fde2c9a..255ba7db2 100644 --- a/plugins/module_utils/network/nxos/rm_templates/bgp_global.py +++ b/plugins/module_utils/network/nxos/rm_templates/bgp_global.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -15,7 +16,8 @@ """ import re -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network_template import ( + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) @@ -56,9 +58,7 @@ def _tmplt_bfd(proc): class Bgp_globalTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): - super(Bgp_globalTemplate, self).__init__( - lines=lines, tmplt=self, module=module - ) + super(Bgp_globalTemplate, self).__init__(lines=lines, tmplt=self, module=module) # fmt: off PARSERS = [ @@ -67,13 +67,13 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" ^router\sbgp\s(?P\S+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "router bgp {{ as_number }}", "result": { "as_number": "{{ as_number }}", }, - "shared": True + "shared": True, }, { "name": "vrf", @@ -87,9 +87,9 @@ def __init__(self, lines=None, module=None): "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { - "vrf": "{{ vrf }}" - } - } + "vrf": "{{ vrf }}", + }, + }, }, "shared": True, }, @@ -99,21 +99,21 @@ def __init__(self, lines=None, module=None): r""" \s+affinity-group \sactivate\s(?P\S+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "affinity-group activate {{ affinity_group.group_id }}", "result": { "affinity_group": { "group_id": "{{ group_id }}", }, - } + }, }, { "name": "bestpath.always_compare_med", "getval": re.compile( r""" \s+bestpath\s(?Palways-compare-med) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "bestpath always-compare-med", "result": { @@ -121,17 +121,17 @@ def __init__(self, lines=None, module=None): '{{ "vrf_" + vrf|d() }}': { "bestpath": { "always_compare_med": "{{ not not always_compare_med }}", - } - } - } - } + }, + }, + }, + }, }, { "name": "bestpath.as_path.ignore", "getval": re.compile( r""" \s+bestpath\sas-path\s(?Pignore) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "bestpath as-path ignore", "result": { @@ -140,18 +140,18 @@ def __init__(self, lines=None, module=None): "bestpath": { "as_path": { "ignore": "{{ not not ignore }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, { "name": "bestpath.as_path.multipath_relax", "getval": re.compile( r""" \s+bestpath\sas-path\s(?Pmultipath-relax) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "bestpath as-path multipath-relax", "result": { @@ -160,18 +160,18 @@ def __init__(self, lines=None, module=None): "bestpath": { "as_path": { "multipath_relax": "{{ not not multipath_relax }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, { "name": "bestpath.compare_neighborid", "getval": re.compile( r""" \s+bestpath\s(?Pcompare-neighborid) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "bestpath compare-neighborid", "result": { @@ -179,18 +179,18 @@ def __init__(self, lines=None, module=None): '{{ "vrf_" + vrf|d() }}': { "bestpath": { "compare_neighborid": "{{ not not compare_neighborid }}", - } - } - } + }, + }, + }, - } + }, }, { "name": "bestpath.compare_routerid", "getval": re.compile( r""" \s+bestpath\s(?Pcompare-routerid) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "bestpath compare-routerid", "result": { @@ -198,17 +198,17 @@ def __init__(self, lines=None, module=None): '{{ "vrf_" + vrf|d() }}': { "bestpath": { "compare_routerid": "{{ not not compare_routerid }}", - } - } - } - } + }, + }, + }, + }, }, { "name": "bestpath.cost_community_ignore", "getval": re.compile( r""" \s+bestpath\scost-community\s(?Pignore) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "bestpath cost-community ignore", "result": { @@ -216,17 +216,17 @@ def __init__(self, lines=None, module=None): '{{ "vrf_" + vrf|d() }}': { "bestpath": { "cost_community_ignore": "{{ not not cost_community_ignore }}", - } - } - } - } + }, + }, + }, + }, }, { "name": "bestpath.igp_metric_ignore", "getval": re.compile( r""" \s+bestpath\sigp-metric\s(?Pignore) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "bestpath igp-metric ignore", "result": { @@ -234,17 +234,17 @@ def __init__(self, lines=None, module=None): '{{ "vrf_" + vrf|d() }}': { "bestpath": { "igp_metric_ignore": "{{ not not igp_metric_ignore }}", - } - } - } - } + }, + }, + }, + }, }, { "name": "bestpath.med.confed", "getval": re.compile( r""" \s+bestpath\smed\s(?Pconfed) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "bestpath med confed", "result": { @@ -253,18 +253,18 @@ def __init__(self, lines=None, module=None): "bestpath": { "med": { "confed": "{{ not not confed }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, { "name": "bestpath.med.missing_as_worst", "getval": re.compile( r""" \s+bestpath\smed\s(?Pmissing-as-worst) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "bestpath med missing-as-worst", "result": { @@ -273,18 +273,18 @@ def __init__(self, lines=None, module=None): "bestpath": { "med": { "missing_as_worst": "{{ not not missing_as_worst }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, { "name": "bestpath.med.non_deterministic", "getval": re.compile( r""" \s+bestpath\smed\s(?Pnon-deterministic) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "bestpath med non-deterministic", "result": { @@ -293,34 +293,34 @@ def __init__(self, lines=None, module=None): "bestpath": { "med": { "non_deterministic": "{{ not not non_deterministic }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, { "name": "cluster_id", "getval": re.compile( r""" \s+cluster-id\s(?P\S+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "cluster-id {{ cluster_id }}", "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { "cluster_id": "{{ cluster_id }}", - } - } - } + }, + }, + }, }, { "name": "confederation.identifier", "getval": re.compile( r""" \s+confederation\sidentifier\s(?P\S+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "confederation identifier {{ confederation.identifier }}", "result": { @@ -329,8 +329,8 @@ def __init__(self, lines=None, module=None): "confederation": { "identifier": "{{ identifier }}", }, - } - } + }, + }, }, }, { @@ -338,7 +338,7 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" \s+confederation\speers\s(?P.*) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": _tmplt_confederation_peers, "result": { @@ -347,23 +347,23 @@ def __init__(self, lines=None, module=None): "confederation": { "peers": "{{ peers }}", }, - } + }, }, - } + }, }, { "name": "disable_policy_batching", "getval": re.compile( r""" \s+(?Pdisable-policy-batching) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "disable-policy-batching", "result": { "disable_policy_batching": { "set": "{{ not not disable_policy_batching }}", }, - } + }, }, { "name": "disable_policy_batching.ipv4.prefix_list", @@ -371,16 +371,16 @@ def __init__(self, lines=None, module=None): r""" \s+disable-policy-batching\sipv4 \sprefix-list\s(?P\S+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "disable-policy-batching ipv4 prefix-list {{ disable_policy_batching.ipv4.prefix_list }}", "result": { "disable_policy_batching": { "ipv4": { "prefix_list": "{{ ipv4_prefix_list }}", - } + }, }, - } + }, }, { "name": "disable_policy_batching.ipv6.prefix_list", @@ -388,97 +388,97 @@ def __init__(self, lines=None, module=None): r""" \s+disable-policy-batching\sipv6 \sprefix-list\s(?P\S+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "disable-policy-batching ipv6 prefix-list {{ disable_policy_batching.ipv6.prefix_list }}", "result": { "disable_policy_batching": { "ipv6": { "prefix_list": "{{ ipv6_prefix_list }}", - } + }, }, - } + }, }, { "name": "disable_policy_batching.nexthop", "getval": re.compile( r""" \s+disable-policy-batching\s(?Pnexthop) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "disable-policy-batching nexthop", "result": { "disable_policy_batching": { "nexthop": "{{ not not nexthop }}", }, - } + }, }, { "name": "dynamic_med_interval", "getval": re.compile( r""" \s+dynamic-med-interval\s(?P\d+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "dynamic-med-interval {{ dynamic_med_interval }}", "result": { "dynamic_med_interval": "{{ dynamic_med_interval }}", - } + }, }, { "name": "enforce_first_as", "getval": re.compile( r""" \s+no\s(?Penforce-first-as) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "enforce-first-as", "result": { "enforce_first_as": "{{ not enforce_first_as }}", - } + }, }, { "name": "enhanced_error", "getval": re.compile( r""" \s+no\s(?Penhanced-error) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "enhanced-error", "result": { "enhanced_error": "{{ not enhanced_error }}", - } + }, }, { "name": "fast_external_fallover", "getval": re.compile( r""" \s+no\s(?Pfast-external-fallover) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "fast-external-fallover", "result": { "fast_external_fallover": "{{ not fast_external_fallover }}", - } + }, }, { "name": "flush_routes", "getval": re.compile( r""" \s+(?Pflush-routes) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "flush-routes", "result": { "flush_routes": "{{ not not flush_routes }}", - } + }, }, { "name": "graceful_restart", "getval": re.compile( r""" \s+no\s(?Pgraceful-restart) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "graceful-restart", "result": { @@ -487,16 +487,16 @@ def __init__(self, lines=None, module=None): "graceful_restart": { "set": "{{ not graceful_restart }}", }, - } - } - } + }, + }, + }, }, { "name": "graceful_restart.restart_time", "getval": re.compile( r""" \s+graceful-restart\srestart-time\s(?P\d+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "graceful-restart restart-time {{ graceful_restart.restart_time }}", "result": { @@ -505,16 +505,16 @@ def __init__(self, lines=None, module=None): "graceful_restart": { "restart_time": "{{ restart_time }}", }, - } - } - } + }, + }, + }, }, { "name": "graceful_restart.stalepath_time", "getval": re.compile( r""" \s+graceful-restart\sstalepath-time\s(?P\d+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "graceful-restart stalepath-time {{ graceful_restart.stalepath_time }}", "result": { @@ -523,16 +523,16 @@ def __init__(self, lines=None, module=None): "graceful_restart": { "stalepath_time": "{{ stalepath_time }}", }, - } - } - } + }, + }, + }, }, { "name": "graceful_restart.helper", "getval": re.compile( r""" \s+(?Pgraceful-restart-helper) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "graceful-restart-helper", "result": { @@ -541,9 +541,9 @@ def __init__(self, lines=None, module=None): "graceful_restart": { "helper": "{{ not not helper }}", }, - } - } - } + }, + }, + }, }, { "name": "graceful_shutdown.activate", @@ -553,7 +553,7 @@ def __init__(self, lines=None, module=None): \s(?Pactivate) (\sroute-map \s(?P\S+))? - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "graceful-shutdown activate{{ ' route-map ' + graceful_shutdown.activate.route_map if graceful_shutdown.activate.route_map is defined }}", "result": { @@ -561,9 +561,9 @@ def __init__(self, lines=None, module=None): "activate": { "set": "{{ True if activate is defined and route_map is undefined else None }}", "route_map": "{{ route_map }}", - } + }, }, - } + }, }, { "name": "graceful_shutdown.aware", @@ -571,14 +571,14 @@ def __init__(self, lines=None, module=None): r""" \s+no\sgraceful-shutdown \s(?Paware) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "graceful-shutdown aware", "result": { "graceful_shutdown": { - "aware": "{{ not aware }}" + "aware": "{{ not aware }}", }, - } + }, }, { "name": "isolate", @@ -586,7 +586,7 @@ def __init__(self, lines=None, module=None): r""" \s+(?Pisolate) (\s(?Pinclude-local))? - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "isolate{{ ' include-local' if isolate.include_local|d(False) is True }}", "result": { @@ -594,39 +594,39 @@ def __init__(self, lines=None, module=None): "set": "{{ True if isolate is defined and include_local is not defined else None }}", "include_local": "{{ not not include_local }}", }, - } + }, }, { "name": "log_neighbor_changes", "getval": re.compile( r""" \s+(?Plog-neighbor-changes) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "log-neighbor-changes", "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { "log_neighbor_changes": "{{ not not log_neighbor_changes }}", - } - } - } + }, + }, + }, }, { "name": "maxas_limit", "getval": re.compile( r""" \s+maxas-limit\s(?P\d+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "maxas-limit {{ maxas_limit }}", "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { "maxas_limit": "{{ maxas_limit }}", - } - } - } + }, + }, + }, }, # start neighbor parsers { @@ -634,20 +634,25 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" \s+neighbor\s(?P\S+) - $""", re.VERBOSE + (\sremote-as\sroute-map\s(?P\S+))? + (\sremote-as\s(?P\S+))? + $""", re.VERBOSE, ), - "setval": "neighbor {{ neighbor_address }}", + "setval": "neighbor {{ neighbor_address }}" + "{{ (' remote-as route-map ' + remote_as_route_map) if remote_as_route_map|d(None) else '' }}", "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { "neighbors": { "{{ neighbor_address }}": { "neighbor_address": "{{ neighbor_address }}", - } - } - } - } - } + "remote_as": "{{ remote_as }}", + "remote_as_route_map": "{{ remote_as_route_map }}", + }, + }, + }, + }, + }, }, { "name": "bfd", @@ -657,7 +662,7 @@ def __init__(self, lines=None, module=None): \s(?Pbfd) (\s(?Psinglehop))? (\s(?Pmultihop))? - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": _tmplt_bfd, "result": { @@ -670,13 +675,13 @@ def __init__(self, lines=None, module=None): "singlehop": "{{ not not singlehop }}", "multihop": { "set": "{{ not not multihop }}", - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, }, { "name": "bfd.multihop.interval", @@ -687,7 +692,7 @@ def __init__(self, lines=None, module=None): \s(?P\d+) \smin_rx\s(?P\d+) \smultiplier\s(?P\d+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "bfd multihop interval" " {{ bfd.multihop.interval.tx_interval }}" @@ -704,14 +709,14 @@ def __init__(self, lines=None, module=None): "tx_interval": "{{ tx_interval }}", "min_rx_interval": "{{ min_rx_interval }}", "multiplier": "{{ multiplier }}", - } - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, + }, }, { "name": "remote_as", @@ -719,7 +724,7 @@ def __init__(self, lines=None, module=None): r""" \s+neighbor\s(?P\S+) \sremote-as\s(?P\S+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "remote-as {{ remote_as }}", "result": { @@ -728,11 +733,11 @@ def __init__(self, lines=None, module=None): "neighbors": { "{{ neighbor_address }}": { "remote_as": "{{ remote_as }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, { "name": "neighbor_affinity_group.group_id", @@ -740,7 +745,7 @@ def __init__(self, lines=None, module=None): r""" \s+neighbor\s(?P\S+) \saffinity-group\s(?P\d+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "affinity-group {{ neighbor_affinity_group.group_id }}", "result": { @@ -750,12 +755,12 @@ def __init__(self, lines=None, module=None): "{{ neighbor_address }}": { "neighbor_affinity_group": { "group_id": "{{ group_id }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, { "name": "bmp_activate_server", @@ -763,7 +768,7 @@ def __init__(self, lines=None, module=None): r""" \s+neighbor\s(?P\S+) \sbmp-activate-server\s(?P\d+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "bmp-activate-server {{ bmp_activate_server }}", "result": { @@ -772,11 +777,11 @@ def __init__(self, lines=None, module=None): "neighbors": { "{{ neighbor_address }}": { "bmp_activate_server": "{{ bmp_activate_server }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, { "name": "capability", @@ -784,7 +789,7 @@ def __init__(self, lines=None, module=None): r""" \s+neighbor\s(?P\S+) \scapability\ssuppress\s(?P4-byte-as) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "capability suppress 4-byte-as", "result": { @@ -794,20 +799,21 @@ def __init__(self, lines=None, module=None): "{{ neighbor_address }}": { "capability": { "suppress_4_byte_as": "{{ not not suppress_4_byte_as }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, { "name": "description", "getval": re.compile( r""" \s+neighbor\s(?P\S+) + (\sremote-as\sroute-map\s\S+)? \sdescription\s(?P\S+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "description {{ description }}", "result": { @@ -816,11 +822,11 @@ def __init__(self, lines=None, module=None): "neighbors": { "{{ neighbor_address }}": { "description": "{{ description }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, { "name": "disable_connected_check", @@ -828,7 +834,7 @@ def __init__(self, lines=None, module=None): r""" \s+neighbor\s(?P\S+) \s(?Pdisable-connected-check) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "disable-connected-check", "result": { @@ -837,11 +843,11 @@ def __init__(self, lines=None, module=None): "neighbors": { "{{ neighbor_address }}": { "disable_connected_check": "{{ not not disable_connected_check }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, { "name": "dont_capability_negotiate", @@ -849,7 +855,7 @@ def __init__(self, lines=None, module=None): r""" \s+neighbor\s(?P\S+) \s(?Pdont-capability-negotiate) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "dont-capability-negotiate", "result": { @@ -858,11 +864,11 @@ def __init__(self, lines=None, module=None): "neighbors": { "{{ neighbor_address }}": { "dont_capability_negotiate": "{{ not not dont_capability_negotiate}}", - } - } - } - } - } + }, + }, + }, + }, + }, }, { "name": "dscp", @@ -870,7 +876,7 @@ def __init__(self, lines=None, module=None): r""" \s+neighbor\s(?P\S+) \sdscp\s(?P\S+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "dscp {{ dscp }}", "result": { @@ -879,11 +885,11 @@ def __init__(self, lines=None, module=None): "neighbors": { "{{ neighbor_address }}": { "dscp": "{{ dscp }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, { "name": "dynamic_capability", @@ -891,7 +897,7 @@ def __init__(self, lines=None, module=None): r""" \s+neighbor\s(?P\S+) \s(?Pdynamic-capability) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "dynamic-capability", "result": { @@ -900,11 +906,11 @@ def __init__(self, lines=None, module=None): "neighbors": { "{{ neighbor_address }}": { "dynamic_capability": "{{ not not dynamic_capability }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, { "name": "ebgp_multihop", @@ -912,7 +918,7 @@ def __init__(self, lines=None, module=None): r""" \s+neighbor\s(?P\S+) \sebgp-multihop\s(?P\d+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "ebgp-multihop {{ ebgp_multihop }}", "result": { @@ -921,11 +927,11 @@ def __init__(self, lines=None, module=None): "neighbors": { "{{ neighbor_address }}": { "ebgp_multihop": "{{ ebgp_multihop }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, { "name": "graceful_shutdown", @@ -935,7 +941,7 @@ def __init__(self, lines=None, module=None): \sgraceful-shutdown \s(?Pactivate) (\sroute-map\s(?P\S+))? - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "graceful-shutdown{{ (' route-map ' + graceful_shutdown.route_map) if graceful_shutdown.route_map is defined }}", "result": { @@ -948,12 +954,12 @@ def __init__(self, lines=None, module=None): "set": "{{ True if activate is defined and route_map is undefined else None }}", "route_map": "{{ route_map }}", }, - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, { "name": "inherit.peer", @@ -962,7 +968,7 @@ def __init__(self, lines=None, module=None): \s+neighbor\s(?P\S+) \sinherit \speer\s(?P\S+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "inherit peer {{ inherit.peer }}", "result": { @@ -972,12 +978,12 @@ def __init__(self, lines=None, module=None): "{{ neighbor_address }}": { "inherit": { "peer": "{{ peer }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, { "name": "inherit.peer_session", @@ -986,7 +992,7 @@ def __init__(self, lines=None, module=None): \s+neighbor\s(?P\S+) \sinherit \speer-session\s(?P\S+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "inherit peer-session {{ inherit.peer_session }}", "result": { @@ -996,12 +1002,12 @@ def __init__(self, lines=None, module=None): "{{ neighbor_address }}": { "inherit": { "peer_session": "{{ peer_session }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, { "name": "local_as", @@ -1009,7 +1015,7 @@ def __init__(self, lines=None, module=None): r""" \s+neighbor\s(?P\S+) \slocal-as\s(?P\S+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "local-as {{ local_as }}", "result": { @@ -1018,11 +1024,11 @@ def __init__(self, lines=None, module=None): "neighbors": { "{{ neighbor_address }}": { "local_as": "{{ local_as }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, { "name": "log_neighbor_changes", @@ -1031,7 +1037,7 @@ def __init__(self, lines=None, module=None): \s+neighbor\s(?P\S+) \s(?Plog-neighbor-changes) (\s(?Pdisable))? - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "log-neighbor-changes{{ ' disable' if log_neighbor_changes.disable is defined }}", "result": { @@ -1042,12 +1048,12 @@ def __init__(self, lines=None, module=None): "log_neighbor_changes": { "set": "{{ True if log_neighbor_changes is defined and disable is undefined }}", "disable": "{{ not not disable }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, { "name": "low_memory", @@ -1055,7 +1061,7 @@ def __init__(self, lines=None, module=None): r""" \s+neighbor\s(?P\S+) \slow-memory\s(?Pexempt) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "low-memory exempt", "result": { @@ -1065,12 +1071,12 @@ def __init__(self, lines=None, module=None): "{{ neighbor_address }}": { "low_memory": { "exempt": "{{ not not exempt }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, { "name": "password", @@ -1079,7 +1085,7 @@ def __init__(self, lines=None, module=None): \s+neighbor\s(?P\S+) \spassword\s(?P\d+) \s(?P\S+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "password{{ (' ' + password.encryption|string) if password.encryption is defined }} {{ password.key }}", "result": { @@ -1090,12 +1096,12 @@ def __init__(self, lines=None, module=None): "password": { "encryption": "{{ encryption }}", "key": "{{ key }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, { "name": "path_attribute", @@ -1106,7 +1112,7 @@ def __init__(self, lines=None, module=None): (?P\d+)? (range\s(?P\d+)\s(?P\d+))? \sin - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": _tmplt_path_attribute, "result": { @@ -1120,15 +1126,15 @@ def __init__(self, lines=None, module=None): "type": "{{ type if type is defined else None }}", "range": { "start": "{{ start if start is defined }}", - "end": "{{ end if end is defined }}" + "end": "{{ end if end is defined }}", }, }, - ] - } - } - } - } - } + ], + }, + }, + }, + }, + }, }, { "name": "peer_type", @@ -1136,7 +1142,7 @@ def __init__(self, lines=None, module=None): r""" \s+neighbor\s(?P\S+) \speer-type\s(?P\S+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "peer-type {{ peer_type }}", "result": { @@ -1145,11 +1151,11 @@ def __init__(self, lines=None, module=None): "neighbors": { "{{ neighbor_address }}": { "peer_type": "{{ peer_type }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, { "name": "remove_private_as", @@ -1159,7 +1165,7 @@ def __init__(self, lines=None, module=None): \s(?Premove-private-as) (\s(?Pall))? (\s(?Preplace-as))? - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "remove-private-as", "result": { @@ -1171,12 +1177,12 @@ def __init__(self, lines=None, module=None): "set": "{{ True if remove_private_as is defined and replace_as is undefined and all is undefined else None }}", "replace_as": "{{ not not replace_as }}", "all": "{{ not not all }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, { "name": "shutdown", @@ -1184,7 +1190,7 @@ def __init__(self, lines=None, module=None): r""" \s+neighbor\s(?P\S+) \s(?Pshutdown) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "shutdown", "result": { @@ -1193,11 +1199,11 @@ def __init__(self, lines=None, module=None): "neighbors": { "{{ neighbor_address }}": { "shutdown": "{{ not not shutdown }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, { "name": "timers", @@ -1205,7 +1211,7 @@ def __init__(self, lines=None, module=None): r""" \s+neighbor\s(?P\S+) \stimers\s(?P\d+)\s(?P\d+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "timers {{ timers.keepalive }} {{ timers.holdtime }}", "result": { @@ -1216,12 +1222,12 @@ def __init__(self, lines=None, module=None): "timers": { "keepalive": "{{ keepalive }}", "holdtime": "{{ holdtime }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, { "name": "transport", @@ -1230,7 +1236,7 @@ def __init__(self, lines=None, module=None): \s+neighbor\s(?P\S+) \stransport\sconnection-mode \s(?Ppassive) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "transport connection-mode passive", "result": { @@ -1241,13 +1247,13 @@ def __init__(self, lines=None, module=None): "transport": { "connection_mode": { "passive": "{{ not not passive }}", - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, }, { "name": "ttl_security", @@ -1255,7 +1261,7 @@ def __init__(self, lines=None, module=None): r""" \s+neighbor\s(?P\S+) \sttl-security\shops\s(?P\d+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "ttl-security hops {{ ttl_security.hops }}", "result": { @@ -1265,12 +1271,12 @@ def __init__(self, lines=None, module=None): "{{ neighbor_address }}": { "ttl_security": { "hops": "{{ hops }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, { "name": "update_source", @@ -1278,7 +1284,7 @@ def __init__(self, lines=None, module=None): r""" \s+neighbor\s(?P\S+) \supdate-source\s(?P\S+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "update-source {{ update_source }}", "result": { @@ -1287,11 +1293,11 @@ def __init__(self, lines=None, module=None): "neighbors": { "{{ neighbor_address }}": { "update_source": "{{ update_source }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, # end neighbor parsers { @@ -1299,7 +1305,7 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" \s+neighbor-down\s(?Pfib-accelerate) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "neighbor-down fib-accelerate", "result": { @@ -1307,10 +1313,10 @@ def __init__(self, lines=None, module=None): '{{ "vrf_" + vrf|d() }}': { "neighbor_down": { "fib_accelerate": "{{ not not fib_accelerate }}", - } - } - } - } + }, + }, + }, + }, }, { "name": "nexthop.suppress_default_resolution", @@ -1318,14 +1324,14 @@ def __init__(self, lines=None, module=None): r""" \s+nexthop \s(?Psuppress-default-resolution) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "nexthop suppress-default-resolution", "result": { "nexthop": { "suppress_default_resolution": "{{ not not suppress_default_resolution }}", }, - } + }, }, { "name": "reconnect_interval", @@ -1333,16 +1339,16 @@ def __init__(self, lines=None, module=None): r""" \s+reconnect-interval \s(?P\d+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "reconnect-interval {{ reconnect_interval }}", "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { "reconnect_interval": "{{ reconnect_interval }}", - } - } - } + }, + }, + }, }, { "name": "router_id", @@ -1350,40 +1356,40 @@ def __init__(self, lines=None, module=None): r""" \s+router-id \s(?P\S+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "router-id {{ router_id }}", "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { "router_id": "{{ router_id }}", - } - } - } + }, + }, + }, }, { "name": "shutdown", "getval": re.compile( r""" \s+(?Pshutdown) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "shutdown", "result": { "shutdown": "{{ not not shutdown }}", - } + }, }, { "name": "suppress_fib_pending", "getval": re.compile( r""" \s+no\s(?Psuppress-fib-pending) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "suppress-fib-pending", "result": { "suppress_fib_pending": "{{ not suppress_fib_pending }}", - } + }, }, { "name": "timers.bestpath_limit", @@ -1392,7 +1398,7 @@ def __init__(self, lines=None, module=None): \s+timers\sbestpath-limit \s(?P\d+) (\s(?Palways))? - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "timers bestpath-limit {{ timers.bestpath_limit.timeout }}{{ ' always' if timers.bestpath_limit.timeout is defined }}", "result": { @@ -1402,11 +1408,11 @@ def __init__(self, lines=None, module=None): "bestpath_limit": { "timeout": "{{ timeout }}", "always": "{{ not not always }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, { "name": "timers.bgp", @@ -1415,7 +1421,7 @@ def __init__(self, lines=None, module=None): \s+timers\sbgp \s(?P\d+) (\s(?P\d+))? - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "timers bgp {{ timers.bgp.keepalive }} {{ timers.bgp.holdtime }}", "result": { @@ -1425,11 +1431,11 @@ def __init__(self, lines=None, module=None): "bgp": { "keepalive": "{{ keepalive }}", "holdtime": "{{ holdtime }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, { "name": "timers.prefix_peer_timeout", @@ -1437,7 +1443,7 @@ def __init__(self, lines=None, module=None): r""" \s+timers \sprefix-peer-timeout\s(?P\d+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "timers prefix-peer-timeout {{ timers.prefix_peer_timeout }}", "result": { @@ -1445,10 +1451,10 @@ def __init__(self, lines=None, module=None): '{{ "vrf_" + vrf|d() }}': { "timers": { "prefix_peer_timeout": "{{ prefix_peer_timeout }}", - } - } - } - } + }, + }, + }, + }, }, { "name": "timers.prefix_peer_wait", @@ -1456,7 +1462,7 @@ def __init__(self, lines=None, module=None): r""" \s+timers \sprefix-peer-wait\s(?P\d+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "timers prefix-peer-wait {{ timers.prefix_peer_wait }}", "result": { @@ -1464,10 +1470,10 @@ def __init__(self, lines=None, module=None): '{{ "vrf_" + vrf|d() }}': { "timers": { "prefix_peer_wait": "{{ prefix_peer_wait }}", - } - } - } - } + }, + }, + }, + }, }, { "name": "fabric_soo", @@ -1475,12 +1481,12 @@ def __init__(self, lines=None, module=None): r""" \s+fabric-soo \s(?P\S+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "fabric-soo {{ fabric_soo }}", "result": { "fabric_soo": "{{ fabric_soo }}", - } + }, }, { "name": "rd", @@ -1488,15 +1494,15 @@ def __init__(self, lines=None, module=None): r""" \s+rd\s(?Pdual) (\sid\s(?P\d+))? - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "rd dual{{' id ' + rd.id if rd.id is defined }}", "result": { "rd": { "dual": "{{ not not dual }}", "id": "{{ id }}", - } - } + }, + }, }, # VRF only { @@ -1504,16 +1510,16 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" \s+allocate-index\s(?P\d+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "allocate-index {{ allocate_index }}", "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { "allocate_index": "{{ allocate_index }}", - } + }, }, - } + }, }, # VRF only { @@ -1521,16 +1527,16 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" \s+local-as\s(?P\d+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "local-as {{ local_as }}", "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { "local_as": "{{ local_as }}", - } - } - } + }, + }, + }, }, ] # fmt: on diff --git a/plugins/module_utils/network/nxos/rm_templates/bgp_neighbor_address_family.py b/plugins/module_utils/network/nxos/rm_templates/bgp_neighbor_address_family.py index 5960ba33f..7db4b860d 100644 --- a/plugins/module_utils/network/nxos/rm_templates/bgp_neighbor_address_family.py +++ b/plugins/module_utils/network/nxos/rm_templates/bgp_neighbor_address_family.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -15,7 +16,8 @@ """ import re -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network_template import ( + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) @@ -34,9 +36,7 @@ def _tmplt_maximum_prefix(data): class Bgp_neighbor_address_familyTemplate(NetworkTemplate): def __init__(self, lines=None): - super(Bgp_neighbor_address_familyTemplate, self).__init__( - lines=lines, tmplt=self - ) + super(Bgp_neighbor_address_familyTemplate, self).__init__(lines=lines, tmplt=self) # fmt: off PARSERS = [ @@ -45,13 +45,13 @@ def __init__(self, lines=None): "getval": re.compile( r""" ^router\sbgp\s(?P\S+) - $""", re.VERBOSE + $""", re.VERBOSE, ), "setval": "router bgp {{ as_number }}", "result": { "as_number": "{{ as_number }}", }, - "shared": True + "shared": True, }, { "name": "address_family", @@ -59,6 +59,7 @@ def __init__(self, lines=None): r""" (vrf\s(?P\S+))? \s*neighbor\s(?P\S+) + (\sremote-as\s\S+)? \saddress-family \s(?P\S+) (\s(?P\S+))? @@ -77,12 +78,12 @@ def __init__(self, lines=None): '{{ afi + "_" + safi|d() }}': { "afi": "{{ afi }}", "safi": "{{ safi }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, "shared": True, }, @@ -108,14 +109,14 @@ def __init__(self, lines=None): "advertise_map": { "route_map": "{{ route_map }}", "exist_map": "{{ exist_map }}", - } - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, + }, }, { "name": "advertise_map.non_exist_map", @@ -139,14 +140,14 @@ def __init__(self, lines=None): "advertise_map": { "route_map": "{{ route_map }}", "non_exist_map": "{{ non_exist_map }}", - } - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, + }, }, { "name": "advertisement_interval", @@ -167,13 +168,13 @@ def __init__(self, lines=None): "address_family": { '{{ afi + "_" + safi|d() }}': { "advertisement_interval": "{{ advertisement_interval }}", - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, }, { "name": "allowas_in", @@ -196,14 +197,14 @@ def __init__(self, lines=None): "allowas_in": { "set": "{{ True if allowas_in is defined and max_occurences is undefined }}", "max_occurences": "{{ max_occurences }}", - } - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, + }, }, { "name": "as_override", @@ -223,13 +224,13 @@ def __init__(self, lines=None): "address_family": { '{{ afi + "_" + safi|d() }}': { "as_override": "{{ not not as_override }}", - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, }, { "name": "capability.additional_paths.receive", @@ -253,15 +254,15 @@ def __init__(self, lines=None): "capability": { "additional_paths": { "receive": "{{ 'disable' if disable is defined else 'enable' }}", - } - } - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, + }, + }, }, { "name": "capability.additional_paths.send", @@ -286,14 +287,14 @@ def __init__(self, lines=None): "additional_paths": { "send": "{{ 'disable' if disable is defined else 'enable' }}", }, - } - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, + }, }, { "name": "default_originate", @@ -316,14 +317,14 @@ def __init__(self, lines=None): "default_originate": { "set": "{{ True if default_originate is defined and route_map is not defined }}", "route_map": "{{ route_map }}", - } - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, + }, }, { "name": "disable_peer_as_check", @@ -343,13 +344,13 @@ def __init__(self, lines=None): "address_family": { '{{ afi + "_" + safi|d() }}': { "disable_peer_as_check": "{{ not not disable_peer_as_check }}", - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, }, { "name": "filter_list.inbound", @@ -371,14 +372,14 @@ def __init__(self, lines=None): '{{ afi + "_" + safi|d() }}': { "filter_list": { "inbound": "{{ in }}", - } - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, + }, }, { "name": "filter_list.outbound", @@ -400,14 +401,14 @@ def __init__(self, lines=None): '{{ afi + "_" + safi|d() }}': { "filter_list": { "outbound": "{{ out }}", - } - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, + }, }, { "name": "inherit", @@ -431,14 +432,14 @@ def __init__(self, lines=None): "inherit": { "template": "{{ template }}", "sequence": "{{ sequence }}", - } - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, + }, }, { "name": "maximum_prefix", @@ -466,14 +467,14 @@ def __init__(self, lines=None): "generate_warning_threshold": "{{ generate_warning_threshold }}", "restart_interval": "{{ restart_interval }}", "warning_only": "{{ not not warning_only }}", - } - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, + }, }, { "name": "next_hop_self", @@ -496,14 +497,14 @@ def __init__(self, lines=None): "next_hop_self": { "set": "{{ True if next_hop_self is defined and all_routes is not defined }}", "all_routes": "{{ not not all_routes }}", - } - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, + }, }, { "name": "next_hop_third_party", @@ -523,13 +524,13 @@ def __init__(self, lines=None): "address_family": { '{{ afi + "_" + safi|d() }}': { "next_hop_third_party": "{{ not next_hop_third_party }}", - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, }, { "name": "prefix_list.inbound", @@ -551,14 +552,14 @@ def __init__(self, lines=None): '{{ afi + "_" + safi|d() }}': { "prefix_list": { "inbound": "{{ in }}", - } - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, + }, }, { "name": "prefix_list.outbound", @@ -580,14 +581,14 @@ def __init__(self, lines=None): '{{ afi + "_" + safi|d() }}': { "prefix_list": { "outbound": "{{ out }}", - } - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, + }, }, { "name": "rewrite_evpn_rt_asn", @@ -607,13 +608,39 @@ def __init__(self, lines=None): "address_family": { '{{ afi + "_" + safi|d() }}': { "rewrite_evpn_rt_asn": "{{ not not rewrite_evpn_rt_asn }}", - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, + }, + { + "name": "rewrite_rt_asn", + "getval": re.compile( + r""" + (?Prewrite-rt-asn) + $""", + re.VERBOSE, + ), + "setval": "rewrite-rt-asn", + "result": { + "vrfs": { + "{{ 'vrf_' + vrf|d() }}": { + "vrf": "{{ vrf }}", + "neighbors": { + "{{ neighbor }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "rewrite_rt_asn": "{{ not not rewrite_rt_asn }}", + }, + }, + }, + }, + }, + }, + }, }, { "name": "route_map.inbound", @@ -635,14 +662,14 @@ def __init__(self, lines=None): '{{ afi + "_" + safi|d() }}': { "route_map": { "inbound": "{{ in }}", - } - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, + }, }, { "name": "route_map.outbound", @@ -664,14 +691,14 @@ def __init__(self, lines=None): '{{ afi + "_" + safi|d() }}': { "route_map": { "outbound": "{{ out }}", - } - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, + }, }, { "name": "route_reflector_client", @@ -691,13 +718,13 @@ def __init__(self, lines=None): "address_family": { '{{ afi + "_" + safi|d() }}': { "route_reflector_client": "{{ not not route_reflector_client }}", - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, }, { "name": "send_community.standard", @@ -718,14 +745,14 @@ def __init__(self, lines=None): '{{ afi + "_" + safi|d() }}': { "send_community": { "standard": "{{ True if send_community is defined }}", - } - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, + }, }, { "name": "send_community.extended", @@ -747,14 +774,14 @@ def __init__(self, lines=None): '{{ afi + "_" + safi|d() }}': { "send_community": { "extended": "{{ True if extended is defined }}", - } - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, + }, }, { "name": "soft_reconfiguration_inbound", @@ -777,14 +804,14 @@ def __init__(self, lines=None): "soft_reconfiguration_inbound": { "set": "{{ True if soft_reconfiguration_inbound is defined and always is undefined }}", "always": "{{ not not always }}", - } - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, + }, }, { "name": "soo", @@ -804,13 +831,13 @@ def __init__(self, lines=None): "address_family": { '{{ afi + "_" + safi|d() }}': { "soo": "{{ soo }}", - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, }, { "name": "suppress_inactive", @@ -830,13 +857,13 @@ def __init__(self, lines=None): "address_family": { '{{ afi + "_" + safi|d() }}': { "suppress_inactive": "{{ not not suppress_inactive }}", - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, }, { "name": "unsuppress_map", @@ -856,13 +883,13 @@ def __init__(self, lines=None): "address_family": { '{{ afi + "_" + safi|d() }}': { "unsuppress_map": "{{ unsuppress_map }}", - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, }, { "name": "weight", @@ -882,13 +909,13 @@ def __init__(self, lines=None): "address_family": { '{{ afi + "_" + safi|d() }}': { "weight": "{{ weight }}", - } - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, }, ] # fmt: on diff --git a/plugins/module_utils/network/nxos/rm_templates/bgp_templates.py b/plugins/module_utils/network/nxos/rm_templates/bgp_templates.py new file mode 100644 index 000000000..7e7bb5828 --- /dev/null +++ b/plugins/module_utils/network/nxos/rm_templates/bgp_templates.py @@ -0,0 +1,1208 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 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 + +""" +The Bgp_templates parser templates file. This contains +a list of parser definitions and associated functions that +facilitates both facts gathering and native command generation for +the given network resource. +""" + +import re + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( + NetworkTemplate, +) + + +def _tmplt_bfd(proc): + bfd = proc.get("bfd", {}) + cmd = None + + if bfd.get("set"): + cmd = "bfd" + if bfd.get("singlehop"): + cmd = "bfd singlehop" + elif bfd.get("multihop", {}).get("set"): + cmd = "bfd multihop" + + return cmd + + +def _tmplt_path_attribute(proc): + cmd = "path-attribute {action}".format(**proc) + + if "type" in proc: + cmd += " {type}".format(**proc) + elif "range" in proc: + cmd += " range {start} {end}".format(**proc["range"]) + cmd += " in" + return cmd + + +class Bgp_templatesTemplate(NetworkTemplate): + def __init__(self, lines=None, module=None): + super(Bgp_templatesTemplate, self).__init__(lines=lines, tmplt=self, module=module) + + # fmt: off + PARSERS = [ + { + "name": "as_number", + "getval": re.compile( + r""" + ^router\sbgp\s(?P\S+) + $""", re.VERBOSE, + ), + "setval": "router bgp {{ as_number }}", + "result": { + "as_number": "{{ as_number }}", + }, + }, + { + "name": "peer.name", + "getval": re.compile( + r""" + template\speer\s(?P\S+) + $""", re.VERBOSE, + ), + "setval": "template peer {{ name }}", + "result": { + "neighbor": { + "{{ name }}": { + "name": "{{ name }}", + }, + }, + }, + "shared": True, + }, + { + "name": "bfd", + "getval": re.compile( + r""" + (?Pbfd) + (\s(?Psinglehop))? + (\s(?Pmultihop))? + $""", re.VERBOSE, + ), + "setval": _tmplt_bfd, + "result": { + "neighbor": { + "{{ name }}": { + "bfd": { + "set": "{{ True if bfd is defined and singlehop is undefined and multihop is undefined else None }}", + "singlehop": "{{ not not singlehop }}", + "multihop": { + "set": "{{ not not multihop }}", + }, + }, + }, + }, + }, + }, + { + "name": "bfd.multihop.interval", + "getval": re.compile( + r""" + bfd\smultihop\sinterval + \s(?P\d+) + \smin_rx\s(?P\d+) + \smultiplier\s(?P\d+) + $""", re.VERBOSE, + ), + "setval": "bfd multihop interval" + " {{ bfd.multihop.interval.tx_interval }}" + " min_rx {{ bfd.multihop.interval.min_rx_interval }}" + " multiplier {{ bfd.multihop.interval.multiplier }}", + "result": { + "neighbor": { + "{{ name }}": { + "bfd": { + "multihop": { + "interval": { + "tx_interval": "{{ tx_interval }}", + "min_rx_interval": "{{ min_rx_interval }}", + "multiplier": "{{ multiplier }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "bmp_activate_server", + "getval": re.compile( + r""" + bmp-activate-server\s(?P\d+) + $""", re.VERBOSE, + ), + "setval": "bmp-activate-server {{ bmp_activate_server }}", + "result": { + "neighbor": { + "{{ name }}": { + "bmp_activate_server": "{{ bmp_activate_server }}", + }, + }, + }, + }, + { + "name": "capability", + "getval": re.compile( + r""" + capability\ssuppress\s(?P4-byte-as) + $""", re.VERBOSE, + ), + "setval": "capability suppress 4-byte-as", + "result": { + "neighbor": { + "{{ name }}": { + "capability": { + "suppress_4_byte_as": "{{ not not suppress_4_byte_as }}", + }, + }, + }, + }, + }, + { + "name": "description", + "getval": re.compile( + r""" + description\s(?P\S+) + $""", re.VERBOSE, + ), + "setval": "description {{ description }}", + "result": { + "neighbor": { + "{{ name }}": { + "description": "{{ description }}", + }, + }, + }, + }, + { + "name": "disable_connected_check", + "getval": re.compile( + r""" + (?Pdisable-connected-check) + $""", re.VERBOSE, + ), + "setval": "disable-connected-check", + "result": { + "neighbor": { + "{{ name }}": { + "disable_connected_check": "{{ not not disable_connected_check }}", + }, + }, + }, + }, + { + "name": "dont_capability_negotiate", + "getval": re.compile( + r""" + (?Pdont-capability-negotiate) + $""", re.VERBOSE, + ), + "setval": "dont-capability-negotiate", + "result": { + "neighbor": { + "{{ name }}": { + "dont_capability_negotiate": "{{ not not dont_capability_negotiate }}", + }, + }, + }, + }, + { + "name": "dscp", + "getval": re.compile( + r""" + dscp\s(?P\S+) + $""", re.VERBOSE, + ), + "setval": "dscp {{ dscp }}", + "result": { + "neighbor": { + "{{ name }}": { + "dscp": "{{ dscp }}", + }, + }, + }, + }, + { + "name": "dynamic_capability", + "getval": re.compile( + r""" + (?Pdynamic-capability) + $""", re.VERBOSE, + ), + "setval": "dynamic-capability", + "result": { + "neighbor": { + "{{ name }}": { + "dynamic_capability": "{{ not not dynamic_capability }}", + }, + }, + }, + }, + { + "name": "ebgp_multihop", + "getval": re.compile( + r""" + ebgp-multihop\s(?P\d+) + $""", re.VERBOSE, + ), + "setval": "ebgp-multihop {{ ebgp_multihop }}", + "result": { + "neighbor": { + "{{ name }}": { + "ebgp_multihop": "{{ ebgp_multihop }}", + }, + }, + }, + }, + { + "name": "graceful_shutdown", + "getval": re.compile( + r""" + graceful-shutdown + \s(?Pactivate) + (\sroute-map\s(?P\S+))? + $""", re.VERBOSE, + ), + "setval": "graceful-shutdown activate" + "{{ (' route-map ' + graceful_shutdown.activate.route_map) if graceful_shutdown.activate.route_map is defined }}", + "result": { + "neighbor": { + "{{ name }}": { + "graceful_shutdown": { + "activate": { + "set": "{{ True if activate is defined and route_map is undefined else None }}", + "route_map": "{{ route_map }}", + }, + }, + }, + }, + }, + }, + { + "name": "inherit.peer_session", + "getval": re.compile( + r""" + inherit + \speer-session\s(?P\S+) + $""", re.VERBOSE, + ), + "setval": "inherit peer-session {{ inherit.peer_session }}", + "result": { + "neighbor": { + "{{ name }}": { + "inherit": { + "peer_session": "{{ peer_session }}", + }, + }, + }, + }, + }, + { + "name": "local_as", + "getval": re.compile( + r""" + local-as\s(?P\S+) + $""", re.VERBOSE, + ), + "setval": "local-as {{ local_as }}", + "result": { + "neighbor": { + "{{ name }}": { + "local_as": "{{ local_as }}", + }, + }, + }, + }, + { + "name": "log_neighbor_changes", + "getval": re.compile( + r""" + (?Plog-neighbor-changes) + (\s(?Pdisable))? + $""", re.VERBOSE, + ), + "setval": "log-neighbor-changes{{ ' disable' if log_neighbor_changes.disable is defined }}", + "result": { + "neighbor": { + "{{ name }}": { + "log_neighbor_changes": { + "set": "{{ True if log_neighbor_changes is defined and disable is undefined }}", + "disable": "{{ not not disable }}", + }, + }, + }, + }, + }, + { + "name": "low_memory", + "getval": re.compile( + r""" + low-memory\s(?Pexempt) + $""", re.VERBOSE, + ), + "setval": "low-memory exempt", + "result": { + "neighbor": { + "{{ name }}": { + "low_memory": { + "exempt": "{{ not not exempt }}", + }, + }, + }, + }, + }, + { + "name": "password", + "getval": re.compile( + r""" + password\s(?P\d+)\s(?P\S+) + $""", re.VERBOSE, + ), + "setval": "password{{ (' ' + password.encryption|string) if password.encryption is defined }} {{ password.key }}", + "result": { + "neighbor": { + "{{ name }}": { + "password": { + "encryption": "{{ encryption }}", + "key": "{{ key }}", + }, + }, + }, + }, + }, + { + "name": "path_attribute", + "getval": re.compile( + r""" + path-attribute\s(?P\S+)\s + (?P\d+)? + (range\s(?P\d+)\s(?P\d+))? + \sin + $""", re.VERBOSE, + ), + "setval": _tmplt_path_attribute, + "result": { + "neighbor": { + "{{ name }}": { + "path_attribute": [ + { + "action": "{{ action }}", + "type": "{{ type if type is defined else None }}", + "range": { + "start": "{{ start if start is defined }}", + "end": "{{ end if end is defined }}", + }, + }, + ], + }, + }, + }, + }, + { + "name": "remote_as", + "getval": re.compile( + r""" + remote-as\s(?P.+) + $""", re.VERBOSE, + ), + "setval": "remote-as {{ remote_as }}", + "result": { + "neighbor": { + "{{ name }}": { + "remote_as": "{{ remote_as|string }}", + }, + }, + }, + }, + { + "name": "remove_private_as", + "getval": re.compile( + r""" + (?Premove-private-as) + (\s(?Pall))? + (\s(?Preplace-as))? + $""", re.VERBOSE, + ), + "setval": "remove-private-as" + "{{ ' replace-as' if remove_private_as.replace_as|d(False) else '' }}" + "{{ ' all' if remove_private_as.all|d(False) else '' }}", + "result": { + "neighbor": { + "{{ name }}": { + "remove_private_as": { + "set": "{{ True if remove_private_as is defined and replace_as is undefined and all is undefined else None }}", + "replace_as": "{{ not not replace_as }}", + "all": "{{ not not all }}", + }, + }, + }, + }, + }, + { + "name": "shutdown", + "getval": re.compile( + r""" + (?Pshutdown) + $""", re.VERBOSE, + ), + "setval": "shutdown", + "result": { + "neighbor": { + "{{ name }}": { + "shutdown": "{{ not not shutdown }}", + }, + }, + }, + }, + { + "name": "timers", + "getval": re.compile( + r""" + timers\s(?P\d+)\s(?P\d+) + $""", re.VERBOSE, + ), + "setval": "timers {{ timers.keepalive }} {{ timers.holdtime }}", + "result": { + "neighbor": { + "{{ name }}": { + "timers": { + "keepalive": "{{ keepalive }}", + "holdtime": "{{ holdtime }}", + }, + }, + }, + }, + }, + { + "name": "transport", + "getval": re.compile( + r""" + transport\sconnection-mode + \s(?Ppassive) + $""", re.VERBOSE, + ), + "setval": "transport connection-mode passive", + "result": { + "neighbor": { + "{{ name }}": { + "transport": { + "connection_mode": { + "passive": "{{ not not passive }}", + }, + }, + }, + }, + }, + }, + { + "name": "ttl_security", + "getval": re.compile( + r""" + ttl-security\shops\s(?P\d+) + $""", re.VERBOSE, + ), + "setval": "ttl-security hops {{ ttl_security.hops|string }}", + "result": { + "neighbor": { + "{{ name }}": { + "ttl_security": { + "hops": "{{ hops }}", + }, + }, + }, + }, + }, + { + "name": "update_source", + "getval": re.compile( + r""" + update-source\s(?P\S+) + $""", re.VERBOSE, + ), + "setval": "update-source {{ update_source }}", + "result": { + "neighbor": { + "{{ name }}": { + "update_source": "{{ update_source }}", + }, + }, + }, + }, + # start template AF parsers + { + "name": "address_family", + "getval": re.compile( + r""" + template\speer\s(?P\S+) + \saddress-family\s(?P\S+)\s(?P\S+) + $""", + re.VERBOSE, + ), + "setval": "address-family {{ afi }}{{ (' ' + safi) if safi is defined else '' }}", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + "{{ afi + '_' + safi|d() }}": { + "afi": "{{ afi }}", + "safi": "{{ safi }}", + }, + }, + }, + }, + }, + "shared": True, + }, + { + "name": "advertise_map.exist_map", + "getval": re.compile( + r""" + advertise-map + \s(?P\S+) + \sexist-map\s(?P\S+) + $""", + re.VERBOSE, + ), + "setval": "advertise-map {{ advertise_map.route_map }} exist-map {{ advertise_map.exist_map }}", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "advertise_map": { + "route_map": "{{ route_map }}", + "exist_map": "{{ exist_map }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "advertise_map.non_exist_map", + "getval": re.compile( + r""" + advertise-map + \s(?P\S+) + \snon-exist-map\s(?P\S+) + $""", + re.VERBOSE, + ), + "setval": "advertise-map {{ advertise_map.route_map }} non-exist-map {{ advertise_map.non_exist_map }}", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "advertise_map": { + "route_map": "{{ route_map }}", + "non_exist_map": "{{ non_exist_map }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "advertisement_interval", + "getval": re.compile( + r""" + advertisement-interval + \s(?P\d+) + $""", + re.VERBOSE, + ), + "setval": "advertisement-interval {{ advertisement_interval }}", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "advertisement_interval": "{{ advertisement_interval }}", + }, + }, + }, + }, + }, + }, + { + "name": "allowas_in", + "getval": re.compile( + r""" + (?Pallowas-in)\s(?P\d+) + $""", + re.VERBOSE, + ), + "setval": "allowas-in{{ ' ' + allowas_in.max_occurences|string if allowas_in.max_occurences is defined else '' }}", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + "{{ afi + '_' + safi|d() }}": { + "allowas_in": { + "set": "{{ True if allowas_in is defined and max_occurences is undefined }}", + "max_occurences": "{{ max_occurences }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "as_override", + "getval": re.compile( + r""" + (?Pas-override) + $""", + re.VERBOSE, + ), + "setval": "as-override", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + "{{ afi + '_' + safi|d() }}": { + "as_override": "{{ not not as_override }}", + }, + }, + }, + }, + }, + }, + { + "name": "capability.additional_paths.receive", + "getval": re.compile( + r""" + capability\sadditional-paths + \s(?Preceive) + (\s(?Pdisable))? + $""", + re.VERBOSE, + ), + "setval": "capability additional-paths receive{{ ' disable' if capability.additional_paths.receive == 'disable' else '' }}", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + "{{ afi + '_' + safi|d() }}": { + "capability": { + "additional_paths": { + "receive": "{{ 'disable' if disable is defined else 'enable' }}", + }, + }, + }, + }, + }, + }, + }, + }, + { + "name": "capability.additional_paths.send", + "getval": re.compile( + r""" + capability\sadditional-paths + \s(?Psend) + (\s(?Pdisable))? + $""", + re.VERBOSE, + ), + "setval": "capability additional-paths send{{ ' disable' if capability.additional_paths.send == 'disable' else '' }}", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "capability": { + "additional_paths": { + "send": "{{ 'disable' if disable is defined else 'enable' }}", + }, + }, + }, + }, + }, + }, + }, + }, + { + "name": "default_originate", + "getval": re.compile( + r""" + (?Pdefault-originate) + (\sroute-map\s(?P\S+))? + $""", + re.VERBOSE, + ), + "setval": "default-originate{{ ' route-map ' + default_originate.route_map if default_originate.route_map is defined else '' }}", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "default_originate": { + "set": "{{ True if default_originate is defined and route_map is not defined }}", + "route_map": "{{ route_map }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "disable_peer_as_check", + "getval": re.compile( + r""" + (?Pdisable-peer-as-check) + $""", + re.VERBOSE, + ), + "setval": "disable-peer-as-check", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "disable_peer_as_check": "{{ not not disable_peer_as_check }}", + }, + }, + }, + }, + }, + }, + { + "name": "filter_list.inbound", + "getval": re.compile( + r""" + filter-list + \s(?P\S+)\s(?:in) + $""", + re.VERBOSE, + ), + "setval": "filter-list {{ filter_list.inbound }} in", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "filter_list": { + "inbound": "{{ in }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "filter_list.outbound", + "getval": re.compile( + r""" + filter-list + \s(?P\S+)\s(?:out) + $""", + re.VERBOSE, + ), + "setval": "filter-list {{ filter_list.outbound }} out", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "filter_list": { + "outbound": "{{ out }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "inherit.peer_policy", + "getval": re.compile( + r""" + inherit\speer-policy + \s(?P\S+) + $""", + re.VERBOSE, + ), + "setval": "inherit peer-policy {{ inherit.peer_policy }}", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "inherit": { + "peer_policy": "{{ peer_policy }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "maximum_prefix", + "getval": re.compile( + r""" + maximum-prefix + \s(?P\d+) + (\s(?P\d+))? + (\srestart\s(?P\d+))? + (\s(?Pwarning-only))? + $""", + re.VERBOSE, + ), + "setval": "maximum-prefix" + "{{ ' ' + maximum_prefix.max_prefix_limit|string if maximum_prefix.max_prefix_limit|d(None) else '' }}" + "{{ ' ' + maximum_prefix.generate_warning_threshold|string if maximum_prefix.generate_warning_threshold|d(None) else '' }}" + "{{ ' restart ' + maximum_prefix.restart_interval|string if maximum_prefix.restart_interval|d(None) else '' }}" + "{{ ' warning-only' if maximum_prefix.warning_only|d(False) else '' }}", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "maximum_prefix": { + "max_prefix_limit": "{{ max_prefix_limit }}", + "generate_warning_threshold": "{{ generate_warning_threshold }}", + "restart_interval": "{{ restart_interval }}", + "warning_only": "{{ not not warning_only }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "next_hop_self", + "getval": re.compile( + r""" + (?Pnext-hop-self) + (\s(?Pall))? + $""", + re.VERBOSE, + ), + "setval": "next-hop-self{{ ' all' if next_hop_self.all_routes|d(False) else '' }}", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "next_hop_self": { + "set": "{{ True if next_hop_self is defined and all_routes is not defined }}", + "all_routes": "{{ not not all_routes }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "next_hop_third_party", + "getval": re.compile( + r""" + no\s(?Pnext-hop-third-party) + $""", + re.VERBOSE, + ), + "setval": "next-hop-third-party", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "next_hop_third_party": "{{ not next_hop_third_party }}", + }, + }, + }, + }, + }, + }, + { + "name": "prefix_list.inbound", + "getval": re.compile( + r""" + prefix-list + \s(?P\S+)\s(?:in) + $""", + re.VERBOSE, + ), + "setval": "prefix-list {{ prefix_list.inbound }} in", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "prefix_list": { + "inbound": "{{ in }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "prefix_list.outbound", + "getval": re.compile( + r""" + prefix-list + \s(?P\S+)\s(?:out) + $""", + re.VERBOSE, + ), + "setval": "prefix-list {{ prefix_list.outbound }} out", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "prefix_list": { + "outbound": "{{ out }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "route_map.inbound", + "getval": re.compile( + r""" + route-map + \s(?P\S+)\s(?:in) + $""", + re.VERBOSE, + ), + "setval": "route-map {{ route_map.inbound }} in", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "route_map": { + "inbound": "{{ in }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "route_map.outbound", + "getval": re.compile( + r""" + route-map + \s(?P\S+)\s(?:out) + $""", + re.VERBOSE, + ), + "setval": "route-map {{ route_map.outbound }} out", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "route_map": { + "outbound": "{{ out }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "route_reflector_client", + "getval": re.compile( + r""" + (?Proute-reflector-client) + $""", + re.VERBOSE, + ), + "setval": "route-reflector-client", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "route_reflector_client": "{{ not not route_reflector_client }}", + }, + }, + }, + }, + }, + }, + { + "name": "send_community_standard", + "getval": re.compile( + r""" + (?Psend-community) + $""", + re.VERBOSE, + ), + "setval": "send-community", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "send_community_std": "{{ not not send_community_std }}", + }, + }, + }, + }, + }, + }, + { + "name": "send_community_extended", + "getval": re.compile( + r""" + (?Psend-community\sextended) + $""", + re.VERBOSE, + ), + "setval": "send-community extended", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "send_community_ext": "{{ not not send_community_ext }}", + }, + }, + }, + }, + }, + }, + { + "name": "soft_reconfiguration_inbound", + "getval": re.compile( + r""" + (?Psoft-reconfiguration\sinbound) + (\s(?Palways))? + $""", + re.VERBOSE, + ), + "setval": "soft-reconfiguration inbound{{ ' always' if soft_reconfiguration_inbound.always|d(False) else '' }}", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "soft_reconfiguration_inbound": { + "set": "{{ True if soft_reconfiguration_inbound is defined and always is undefined }}", + "always": "{{ not not always }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "soo", + "getval": re.compile( + r""" + soo\s(?P\S+) + $""", + re.VERBOSE, + ), + "setval": "soo {{ soo }}", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "soo": "{{ soo }}", + }, + }, + }, + }, + }, + }, + { + "name": "suppress_inactive", + "getval": re.compile( + r""" + (?Psuppress-inactive) + $""", + re.VERBOSE, + ), + "setval": "suppress-inactive", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "suppress_inactive": "{{ not not suppress_inactive }}", + }, + }, + }, + }, + }, + }, + { + "name": "unsuppress_map", + "getval": re.compile( + r""" + unsuppress-map\s(?P\S+) + $""", + re.VERBOSE, + ), + "setval": "unsuppress-map {{ unsuppress_map }}", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "unsuppress_map": "{{ unsuppress_map }}", + }, + }, + }, + }, + }, + }, + { + "name": "weight", + "getval": re.compile( + r""" + weight\s(?P\d+) + $""", + re.VERBOSE, + ), + "setval": "weight {{ weight }}", + "result": { + "neighbor": { + "{{ name }}": { + "address_family": { + '{{ afi + "_" + safi|d() }}': { + "weight": "{{ weight }}", + }, + }, + }, + }, + }, + }, + ] + # fmt: on diff --git a/plugins/module_utils/network/nxos/rm_templates/fc_interfaces.py b/plugins/module_utils/network/nxos/rm_templates/fc_interfaces.py new file mode 100644 index 000000000..1cc9d5973 --- /dev/null +++ b/plugins/module_utils/network/nxos/rm_templates/fc_interfaces.py @@ -0,0 +1,194 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 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 + +""" +The Fc_interfaces parser templates file. This contains +a list of parser definitions and associated functions that +facilitates both facts gathering and native command generation for +the given network resource. +""" + +import re + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( + NetworkTemplate, +) + + +allowed_speed_values = [ + "auto", + "1000", + "2000", + "4000", + "8000", + "10000", + "16000", + "32000", + "64000", + "auto max 2000", + "auto max 4000", + "auto max 8000", + "auto max 16000", + "auto max 32000", + "auto max 64000", +] + +allowed_port_modes = [ + "auto", + "E", + "F", + "Fx", + "NP", + "SD", +] + +allowed_values_pattern = "|".join(re.escape(val) for val in allowed_speed_values) + + +class Fc_interfacesTemplate(NetworkTemplate): + def __init__(self, lines=None, module=None): + super(Fc_interfacesTemplate, self).__init__(lines=lines, tmplt=self, module=module) + + # fmt: off + PARSERS = [ + { + "name": "interface", + "getval": re.compile( + r""" + ^interface\s + (?P\S+)$""", re.VERBOSE, + ), + "setval": "interface {{ name }}", + "result": { + "{{ name }}": { + "name": "{{ name }}", + }, + }, + "shared": True, + }, + { + "name": "description", + "getval": re.compile( + r""" + \s+switchport\s+description\s+(?P.*) + $""", re.VERBOSE, + ), + "setval": "switchport description {{ description }}", + "remval": "switchport description", + "result": { + "{{ name }}": { + "description": "{{ description }}", + }, + }, + }, + { + "name": "enabled", + "getval": re.compile( + r""" + (?P\s+no)? + (?P\s+shutdown) + $""", re.VERBOSE, + ), + "setval": "shutdown", + "result": { + "{{ name }}": { + "enabled": "{{ False if shutdown is defined and negate is not defined else True }}", + }, + }, + }, + { + "name": "speed", + "getval": re.compile( + rf"""\s+switchport\s+speed\s+(?P{allowed_values_pattern})$""", re.VERBOSE, + ), + "setval": "switchport speed {{ speed|string }}", + "result": { + "{{ name }}": { + "speed": "{{ speed|string }}", + }, + }, + }, + { + "name": "mode", + "getval": re.compile( + r""" + \s+switchport\s+mode\s+(?P\S+) + $""", re.VERBOSE, + ), + "setval": "switchport mode {{ mode|string }}", + "result": { + "{{ name }}": { + "mode": "{{ mode }}", + }, + }, + }, + { + "name": "trunk_mode", + "getval": re.compile( + r""" + \s+switchport\s+trunk\s+mode\s+(?P\S+) + $""", re.VERBOSE, + ), + "setval": "switchport trunk mode {{ trunk_mode|string }}", + "result": { + "{{ name }}": { + "trunk_mode": "{{ trunk_mode }}", + }, + }, + }, + + { + "name": "analytics_scsi", + "getval": re.compile( + r""" + (?P\s+no)? + \s+analytics\s+type\s+(?Pfc-scsi) + $""", re.VERBOSE, + ), + "setval": "analytics type {{ analytics_scsi|string }}", + "result": { + "{{ name }}": { + "analytics_scsi": "{{ analytics_scsi }}", + }, + }, + }, + { + "name": "analytics_nvme", + "getval": re.compile( + r""" + (?P\s+no)? + \s+analytics\s+type\s+(?Pfc-nvme) + $""", re.VERBOSE, + ), + "setval": "analytics type {{ analytics_nvme|string }}", + "result": { + "{{ name }}": { + "analytics_nvme": "{{ analytics_nvme }}", + }, + }, + }, + + { + "name": "analytics", + "getval": re.compile( + r""" + \s+analytics\s+type\s+(?P\S+) + $""", re.VERBOSE, + ), + # "setval": "analytics type {{ analytics|string }}", + "setval": "", + "result": { + "{{ name }}": { + "analytics": "{{ analytics }}", + }, + }, + }, + ] + # fmt: on diff --git a/plugins/module_utils/network/nxos/rm_templates/hostname.py b/plugins/module_utils/network/nxos/rm_templates/hostname.py index 47decb3d8..bf922fb4c 100644 --- a/plugins/module_utils/network/nxos/rm_templates/hostname.py +++ b/plugins/module_utils/network/nxos/rm_templates/hostname.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -15,6 +16,7 @@ """ import re + from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) @@ -22,9 +24,7 @@ class HostnameTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): - super(HostnameTemplate, self).__init__( - lines=lines, tmplt=self, module=module - ) + super(HostnameTemplate, self).__init__(lines=lines, tmplt=self, module=module) # fmt: off PARSERS = [ @@ -33,7 +33,8 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" ^hostname\s(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "hostname {{ hostname }}", "result": { "hostname": "{{ hostname }}", diff --git a/plugins/module_utils/network/nxos/rm_templates/logging_global.py b/plugins/module_utils/network/nxos/rm_templates/logging_global.py index c2749ebb7..8287794e0 100644 --- a/plugins/module_utils/network/nxos/rm_templates/logging_global.py +++ b/plugins/module_utils/network/nxos/rm_templates/logging_global.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -15,6 +16,7 @@ """ import re + from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) @@ -22,9 +24,7 @@ def _tmplt_hosts(data): cmd = "logging server {host}" - data["client_identity"] = ( - data.get("secure", {}).get("trustpoint", {}).get("client_identity") - ) + data["client_identity"] = data.get("secure", {}).get("trustpoint", {}).get("client_identity") if "severity" in data: cmd += " {severity}" @@ -44,9 +44,7 @@ def _tmplt_hosts(data): class Logging_globalTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): - super(Logging_globalTemplate, self).__init__( - lines=lines, tmplt=self, module=module - ) + super(Logging_globalTemplate, self).__init__(lines=lines, tmplt=self, module=module) # fmt: off PARSERS = [ @@ -57,7 +55,8 @@ def __init__(self, lines=None, module=None): ^(?Pno\s)? logging\sconsole (\s(?P\d))? - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "{{ 'no ' if console.state|d('') == 'disabled' else '' }}" "logging console" "{{ (' ' + console.severity|string) if console.severity is defined else '' }}", @@ -74,14 +73,15 @@ def __init__(self, lines=None, module=None): r""" ^(?Pno\s)? logging\sevent\slink-status\senable - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "logging event link-status enable", "result": { "event": { "link_status": { "enable": "{{ False if negated is defined else True }}", - } - } + }, + }, }, }, { @@ -90,14 +90,15 @@ def __init__(self, lines=None, module=None): r""" ^(?Pno\s)? logging\sevent\slink-status\sdefault - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "logging event link-status default", "result": { "event": { "link_status": { "default": "{{ False if negated is defined else True }}", - } - } + }, + }, }, }, { @@ -106,14 +107,15 @@ def __init__(self, lines=None, module=None): r""" ^(?Pno\s)? logging\sevent\strunk-status\senable - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "logging event trunk-status enable", "result": { "event": { "trunk_status": { "enable": "{{ False if negated is defined else True }}", - } - } + }, + }, }, }, { @@ -122,14 +124,15 @@ def __init__(self, lines=None, module=None): r""" ^(?Pno\s)? logging\sevent\strunk-status\sdefault - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "logging event trunk-status default", "result": { "event": { "trunk_status": { "default": "{{ False if negated is defined else True }}", - } - } + }, + }, }, }, { @@ -138,7 +141,8 @@ def __init__(self, lines=None, module=None): r""" ^logging\shistory \s(?P\d) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "logging history {{ history.severity }}", "result": { "history": { @@ -152,7 +156,8 @@ def __init__(self, lines=None, module=None): r""" ^logging\shistory\ssize \s(?P\d+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "logging history size {{ history.size }}", "result": { "history": { @@ -166,7 +171,8 @@ def __init__(self, lines=None, module=None): r""" ^logging\sip\saccess-list\scache \sentries\s(?P\d+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "logging ip access-list cache entries {{ ip.access_list.cache.entries }}", "result": { "ip": { @@ -174,7 +180,7 @@ def __init__(self, lines=None, module=None): "cache": { "entries": "{{ entries }}", }, - } + }, }, }, }, @@ -184,7 +190,8 @@ def __init__(self, lines=None, module=None): r""" ^logging\sip\saccess-list\scache \sinterval\s(?P\d+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "logging ip access-list cache interval {{ ip.access_list.cache.interval }}", "result": { "ip": { @@ -192,7 +199,7 @@ def __init__(self, lines=None, module=None): "cache": { "interval": "{{ interval }}", }, - } + }, }, }, }, @@ -202,7 +209,8 @@ def __init__(self, lines=None, module=None): r""" ^logging\sip\saccess-list\scache \sthreshold\s(?P\d+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "logging ip access-list cache threshold {{ ip.access_list.cache.threshold }}", "result": { "ip": { @@ -210,7 +218,7 @@ def __init__(self, lines=None, module=None): "cache": { "threshold": "{{ threshold }}", }, - } + }, }, }, }, @@ -220,13 +228,14 @@ def __init__(self, lines=None, module=None): r""" ^logging\sip\saccess-list \s(?Pdetailed) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "logging ip access-list detailed", "result": { "ip": { "access_list": { "detailed": "{{ not not detailed }}", - } + }, }, }, }, @@ -236,15 +245,16 @@ def __init__(self, lines=None, module=None): r""" ^logging\sip\saccess-list\sinclude \s(?Psgt) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "logging ip access-list include sgt", "result": { "ip": { "access_list": { "include": { "sgt": "{{ not not sgt }}", - } - } + }, + }, }, }, }, @@ -258,7 +268,8 @@ def __init__(self, lines=None, module=None): \s(?P\S+) \s(?P\d+) \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "logging level {{ facility }} {{ severity }}", "result": { "facilities": [ @@ -266,7 +277,7 @@ def __init__(self, lines=None, module=None): "facility": "{{ facility }}", "severity": "{{ severity }}", }, - ] + ], }, }, { @@ -279,7 +290,8 @@ def __init__(self, lines=None, module=None): (\s(?P\d+))? (\ssize\s(?P\d+))? (\spersistent\sthreshold\s(?P\d+))? - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "{{ 'no ' if logfile.state|d('') == 'disabled' else '' }}" "logging logfile" "{{ ' ' + logfile.name if logfile.name|d('') else '' }}" @@ -303,7 +315,8 @@ def __init__(self, lines=None, module=None): ^(?Pno\s)? logging\smodule (\s(?P\d))? - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "{{ 'no ' if module.state|d('') == 'disabled' else '' }}" "logging module" "{{ (' ' + module.severity|string) if module.severity is defined else '' }}", @@ -321,7 +334,8 @@ def __init__(self, lines=None, module=None): ^(?Pno\s)? logging\smonitor (\s(?P\d))? - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "{{ 'no ' if monitor.state|d('') == 'disabled' else '' }}" "logging monitor" "{{ (' ' + monitor.severity|string) if monitor.severity is defined else '' }}", @@ -338,12 +352,13 @@ def __init__(self, lines=None, module=None): r""" ^logging\sorigin-id \s(?Phostname) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "logging origin-id hostname", "result": { "origin_id": { "hostname": "{{ not not hostname }}", - } + }, }, }, { @@ -352,12 +367,13 @@ def __init__(self, lines=None, module=None): r""" ^logging\sorigin-id \sip\s(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "logging origin-id ip {{ origin_id.ip }}", "result": { "origin_id": { "ip": "{{ ip }}", - } + }, }, }, { @@ -366,12 +382,13 @@ def __init__(self, lines=None, module=None): r""" ^logging\sorigin-id \sstring\s(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "logging origin-id string {{ origin_id.string }}", "result": { "origin_id": { "string": "{{ string }}", - } + }, }, }, { @@ -381,7 +398,8 @@ def __init__(self, lines=None, module=None): ^(?Pno\s)? logging \s(?Prate-limit) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "{{ 'no ' if rate_limit|d('') == 'disabled' else '' }}" "logging rate-limit", "result": { @@ -394,7 +412,8 @@ def __init__(self, lines=None, module=None): r""" logging\srfc-strict \s(?P5424) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "logging rfc-strict 5424", "result": { "rfc_strict": "{{ not not rfc_strict }}", @@ -411,7 +430,8 @@ def __init__(self, lines=None, module=None): (\ssecure\strustpoint\sclient-identity\s(?P\S+))? (\suse-vrf\s(?P\S+))? (\sfacility\s(?P\S+))? - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": _tmplt_hosts, "result": { "hosts": [ @@ -421,13 +441,13 @@ def __init__(self, lines=None, module=None): "secure": { "trustpoint": { "client_identity": "{{ client_identity }}", - } + }, }, "port": "{{ port }}", "facility": "{{ facility }}", "use_vrf": "{{ use_vrf }}", - } - ] + }, + ], }, }, { @@ -436,7 +456,8 @@ def __init__(self, lines=None, module=None): r""" ^logging\ssource-interface \s(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "logging source-interface {{ source_interface }}", "result": { "source_interface": "{{ source_interface }}", @@ -448,7 +469,8 @@ def __init__(self, lines=None, module=None): r""" ^logging\stimestamp \s(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "logging timestamp {{ timestamp }}", "result": { "timestamp": "{{ timestamp }}", diff --git a/plugins/module_utils/network/nxos/rm_templates/ntp_global.py b/plugins/module_utils/network/nxos/rm_templates/ntp_global.py index 85f46e70d..9fd6e4d6e 100644 --- a/plugins/module_utils/network/nxos/rm_templates/ntp_global.py +++ b/plugins/module_utils/network/nxos/rm_templates/ntp_global.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -15,6 +16,7 @@ """ import re + from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) @@ -22,9 +24,7 @@ class Ntp_globalTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): - super(Ntp_globalTemplate, self).__init__( - lines=lines, tmplt=self, module=module - ) + super(Ntp_globalTemplate, self).__init__(lines=lines, tmplt=self, module=module) # fmt: off PARSERS = [ @@ -33,12 +33,13 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" ^ntp\saccess-group\s(?Pmatch-all) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ntp access-group match-all", "result": { "access_group": { "match_all": "{{ True if match_all is defined else None }}", - } + }, }, }, { @@ -46,16 +47,17 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" ^ntp\saccess-group\speer\s(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ntp access-group peer {{ access_list }}", "result": { "access_group": { "peer": [ { "access_list": "{{ acl }}", - } + }, ], - } + }, }, }, { @@ -63,16 +65,17 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" ^ntp\saccess-group\squery-only\s(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ntp access-group query-only {{ access_list }}", "result": { "access_group": { "query_only": [ { "access_list": "{{ acl }}", - } + }, ], - } + }, }, }, { @@ -80,16 +83,17 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" ^ntp\saccess-group\sserve\s(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ntp access-group serve {{ access_list }}", "result": { "access_group": { "serve": [ { "access_list": "{{ acl }}", - } + }, ], - } + }, }, }, { @@ -97,16 +101,17 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" ^ntp\saccess-group\sserve-only\s(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ntp access-group serve-only {{ access_list }}", "result": { "access_group": { "serve_only": [ { "access_list": "{{ acl }}", - } + }, ], - } + }, }, }, { @@ -114,14 +119,15 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" ^ntp\sallow\scontrol\srate-limit\s(?P\d+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ntp allow control rate-limit {{ allow.control.rate_limit }}", "result": { "allow": { "control": { "rate_limit": "{{ rate_limit }}", - } - } + }, + }, }, }, { @@ -129,12 +135,13 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" ^ntp\sallow\s(?Pprivate) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ntp allow private", "result": { "allow": { "private": "{{ not not private }}", - } + }, }, }, { @@ -142,7 +149,8 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" ^ntp\s(?Pauthenticate) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ntp authenticate", "result": { "authenticate": "{{ not not authenticate }}", @@ -153,7 +161,8 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" ^ntp\sauthentication-key\s(?P\d+)\smd5\s(?P\S+)\s(?P\d+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ntp authentication-key {{ id }} md5 {{ key }} {{ encryption }}", "result": { "authentication_keys": [ @@ -162,7 +171,7 @@ def __init__(self, lines=None, module=None): "key": "{{ key }}", "encryption": "{{ encryption }}", }, - ] + ], }, }, { @@ -170,7 +179,8 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" ^ntp\s(?Plogging) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ntp logging", "result": { "logging": "{{ not not logging }}", @@ -181,12 +191,13 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" ^ntp\smaster\s(?P\d+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ntp master {{ master.stratum }}", "result": { "master": { "stratum": "{{ stratum }}", - } + }, }, }, { @@ -194,7 +205,8 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" ^ntp\s(?Ppassive) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ntp passive", "result": { "passive": "{{ not not passive }}", @@ -211,9 +223,10 @@ def __init__(self, lines=None, module=None): (\skey\s(?P\d+))? (\sminpoll\s(?P\d+))? (\smaxpoll\s(?P\d+))? - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ntp peer {{ peer }}" - "{{ ' prefer' if prefer is defined else ''}}" + "{{ ' prefer' if prefer|d(False) else ''}}" "{{ (' use-vrf ' + vrf) if vrf is defined else '' }}" "{{ (' key ' + key_id|string) if key_id is defined else '' }}" "{{ (' minpoll ' + minpoll|string) if minpoll is defined else '' }}" @@ -227,8 +240,8 @@ def __init__(self, lines=None, module=None): "key_id": "{{ key }}", "minpoll": "{{ minpoll }}", "maxpoll": "{{ maxpoll }}", - } - ] + }, + ], }, }, { @@ -242,9 +255,10 @@ def __init__(self, lines=None, module=None): (\skey\s(?P\d+))? (\sminpoll\s(?P\d+))? (\smaxpoll\s(?P\d+))? - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ntp server {{ server }}" - "{{ ' prefer' if prefer is defined else ''}}" + "{{ ' prefer' if prefer|d(False) else ''}}" "{{ (' use-vrf ' + vrf) if vrf is defined else '' }}" "{{ (' key ' + key_id|string) if key_id is defined else '' }}" "{{ (' minpoll ' + minpoll|string) if minpoll is defined else '' }}" @@ -258,8 +272,8 @@ def __init__(self, lines=None, module=None): "key_id": "{{ key }}", "minpoll": "{{ minpoll }}", "maxpoll": "{{ maxpoll }}", - } - ] + }, + ], }, }, { @@ -267,7 +281,8 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" ^ntp\ssource\s(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ntp source {{ source }}", "result": { "source": "{{ source }}", @@ -278,7 +293,8 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" ^ntp\ssource-interface(\s)+(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ntp source-interface {{ source_interface }}", "result": { "source_interface": "{{ source_interface }}", @@ -289,14 +305,15 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" ^ntp\strusted-key\s(?P\d+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ntp trusted-key {{ key_id|string }}", "result": { "trusted_keys": [ { "key_id": "{{ key }}", - } - ] + }, + ], }, }, ] diff --git a/plugins/module_utils/network/nxos/rm_templates/ospf_interfaces.py b/plugins/module_utils/network/nxos/rm_templates/ospf_interfaces.py index 76edd06ee..2321fcaf1 100644 --- a/plugins/module_utils/network/nxos/rm_templates/ospf_interfaces.py +++ b/plugins/module_utils/network/nxos/rm_templates/ospf_interfaces.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -15,7 +16,8 @@ """ import re -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network_template import ( + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) @@ -36,17 +38,17 @@ def _tmplt_authentication(data): class Ospf_interfacesTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): - super(Ospf_interfacesTemplate, self).__init__( - lines=lines, tmplt=self, module=module - ) + super(Ospf_interfacesTemplate, self).__init__(lines=lines, tmplt=self, module=module) # fmt: off PARSERS = [ { "name": "interface", - "getval": re.compile(r''' + "getval": re.compile( + r''' ^interface - \s(?P\S+)$''', re.VERBOSE), + \s(?P\S+)$''', re.VERBOSE, + ), "setval": "interface {{ name }}", "result": { "{{ name }}": { @@ -82,12 +84,12 @@ def __init__(self, lines=None, module=None): "area_id": "{{ area_id }}", "secondaries": "{{ False if secondaries is defined else None }}", }, - } - } + }, + }, }, - } - } - } + }, + }, + }, }, { "name": "processes_multi_areas", @@ -113,12 +115,12 @@ def __init__(self, lines=None, module=None): "multi_areas": [ "{{ area }}", ], - } - } + }, + }, }, - } - } - } + }, + }, + }, }, { "name": "multi_areas", @@ -139,11 +141,11 @@ def __init__(self, lines=None, module=None): "afi": "{{ 'ipv4' if afi == 'ip' else 'ipv6' }}", "multi_areas": [ "{{ area }}", - ] + ], }, - } - } - } + }, + }, + }, }, { "name": "authentication", @@ -165,11 +167,11 @@ def __init__(self, lines=None, module=None): "enable": "{{ True if authentication is defined and opt is undefined }}", "message_digest": "{{ True if opt == 'message-digest' else None }}", "null_auth": "{{ True if opt == 'null' else None }}", - } + }, }, - } - } - } + }, + }, + }, }, { "name": "authentication.key_chain", @@ -189,11 +191,11 @@ def __init__(self, lines=None, module=None): "afi": "{{ afi|replace('ip', 'ipv4') }}", "authentication": { "key_chain": "{{ key_chain }}", - } + }, }, - } - } - } + }, + }, + }, }, { "name": "authentication_key", @@ -216,11 +218,11 @@ def __init__(self, lines=None, module=None): "authentication_key": { "encryption": "{{ encryption }}", "key": "{{ key }}", - } + }, }, - } - } - } + }, + }, + }, }, { "name": "message_digest_key", @@ -247,11 +249,11 @@ def __init__(self, lines=None, module=None): "key_id": "{{ key_id }}", "encryption": "{{ encryption }}", "key": "{{ key }}", - } + }, }, - } - } - } + }, + }, + }, }, { "name": "cost", @@ -272,9 +274,9 @@ def __init__(self, lines=None, module=None): "afi": "{{ 'ipv4' if afi is defined else 'ipv6' }}", "cost": "{{ cost }}", }, - } - } - } + }, + }, + }, }, { "name": "dead_interval", @@ -295,9 +297,9 @@ def __init__(self, lines=None, module=None): "afi": "{{ 'ipv4' if afi is defined else 'ipv6' }}", "dead_interval": "{{ dead_interval }}", }, - } - } - } + }, + }, + }, }, { "name": "hello_interval", @@ -318,9 +320,9 @@ def __init__(self, lines=None, module=None): "afi": "{{ 'ipv4' if afi is defined else 'ipv6' }}", "hello_interval": "{{ hello_interval }}", }, - } - } - } + }, + }, + }, }, { "name": "instance", @@ -338,9 +340,9 @@ def __init__(self, lines=None, module=None): "afi": "ipv6", "instance": "{{ instance }}", }, - } - } - } + }, + }, + }, }, { "name": "mtu_ignore", @@ -361,9 +363,9 @@ def __init__(self, lines=None, module=None): "afi": "{{ 'ipv4' if afi is defined else 'ipv6' }}", "mtu_ignore": "{{ not not mtu_ignore }}", }, - } - } - } + }, + }, + }, }, { "name": "network", @@ -384,9 +386,9 @@ def __init__(self, lines=None, module=None): "afi": "{{ 'ipv4' if afi is defined else 'ipv6' }}", "network": "{{ network }}", }, - } - } - } + }, + }, + }, }, { "name": "passive_interface", @@ -408,9 +410,9 @@ def __init__(self, lines=None, module=None): "afi": "{{ 'ipv4' if afi is defined else 'ipv6' }}", "passive_interface": "{{ False if negated is defined else (not not passive_interface) }}", }, - } - } - } + }, + }, + }, }, { "name": "priority", @@ -431,9 +433,9 @@ def __init__(self, lines=None, module=None): "afi": "{{ 'ipv4' if afi is defined else 'ipv6' }}", "priority": "{{ priority }}", }, - } - } - } + }, + }, + }, }, { "name": "retransmit_interval", @@ -454,9 +456,9 @@ def __init__(self, lines=None, module=None): "afi": "{{ 'ipv4' if afi is defined else 'ipv6' }}", "retransmit_interval": "{{ retransmit_interval }}", }, - } - } - } + }, + }, + }, }, { "name": "shutdown", @@ -477,9 +479,9 @@ def __init__(self, lines=None, module=None): "afi": "{{ 'ipv4' if afi is defined else 'ipv6' }}", "shutdown": "{{ not not shutdown }}", }, - } - } - } + }, + }, + }, }, { "name": "transmit_delay", @@ -500,9 +502,9 @@ def __init__(self, lines=None, module=None): "afi": "{{ 'ipv4' if afi is defined else 'ipv6' }}", "transmit_delay": "{{ transmit_delay }}", }, - } - } - } + }, + }, + }, }, ] # fmt: on diff --git a/plugins/module_utils/network/nxos/rm_templates/ospfv2.py b/plugins/module_utils/network/nxos/rm_templates/ospfv2.py index 8aaf41a55..c8b518dd6 100644 --- a/plugins/module_utils/network/nxos/rm_templates/ospfv2.py +++ b/plugins/module_utils/network/nxos/rm_templates/ospfv2.py @@ -1,10 +1,11 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type import re -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network_template import ( +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) @@ -20,10 +21,7 @@ def _tmplt_area_range(arange): def _tmplt_default_information(proc): command = "default-information originate" - if ( - "always" in proc["default_information"] - and proc["default_information"]["always"] - ): + if "always" in proc["default_information"] and proc["default_information"]["always"]: command += " always" if "route_map" in proc["default_information"]: command += " route-map" @@ -110,9 +108,7 @@ def _tmplt_max_metric(proc): if on_startup.get("wait_period"): command += " {wait_period}".format(**on_startup) if on_startup.get("wait_for_bgp_asn"): - command += " wait-for bgp {wait_for_bgp_asn}".format( - **on_startup - ) + command += " wait-for bgp {wait_for_bgp_asn}".format(**on_startup) if summary_lsa: command += " summary-lsa" if summary_lsa.get("max_metric_value"): @@ -221,9 +217,9 @@ def __init__(self, lines=None): "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { - "vrf": "{{ vrf }}" - } - } + "vrf": "{{ vrf }}", + }, + }, }, "shared": True, }, @@ -238,9 +234,9 @@ def __init__(self, lines=None): "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { - "bfd": "{{ not not bfd }}" - } - } + "bfd": "{{ not not bfd }}", + }, + }, }, }, { @@ -269,8 +265,8 @@ def __init__(self, lines=None): "vrfs": { '{{ "vrf_" + vrf|d() }}': { "down_bit_ignore": "{{ not not down_bit_ignore }}", - } - } + }, + }, }, }, { @@ -292,10 +288,10 @@ def __init__(self, lines=None): "vrf_lite": { "set": "{{ True if vrf_lite is defined and evpn is undefined else None }}", "evpn": "{{ not not evpn }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -317,9 +313,9 @@ def __init__(self, lines=None): "auto_cost": { "reference_bandwidth": "{{ acrb }}", "unit": "{{ unit }}", - } - } - } + }, + }, + }, }, }, { @@ -331,7 +327,7 @@ def __init__(self, lines=None): ), "setval": "flush-routes", "result": { - "flush_routes": "{{ not not flush_routes }}" + "flush_routes": "{{ not not flush_routes }}", }, }, { @@ -348,10 +344,10 @@ def __init__(self, lines=None): "vrfs": { '{{ "vrf_" + vrf|d() }}': { "graceful_restart": { - "set": "{{ not graceful_restart }}" - } - } - } + "set": "{{ not graceful_restart }}", + }, + }, + }, }, }, { @@ -369,9 +365,9 @@ def __init__(self, lines=None): '{{ "vrf_" + vrf|d() }}': { "graceful_restart": { "helper_disable": "{{ not not helper_disable }}", - } - } - } + }, + }, + }, }, }, { @@ -390,9 +386,9 @@ def __init__(self, lines=None): '{{ "vrf_" + vrf|d() }}': { "graceful_restart": { "grace_period": "{{ grace_period }}", - } - } - } + }, + }, + }, }, }, { @@ -420,9 +416,9 @@ def __init__(self, lines=None): "log_adjacency_changes": { "log": "{{ True if log is defined and detail is undefined else None }}", "detail": "{{ True if detail is defined else None }}", - } - } - } + }, + }, + }, }, }, { @@ -451,9 +447,9 @@ def __init__(self, lines=None): "ignore_count": "{{ ig_count }}", "reset_time": "{{ rst_time }}", "warning_only": "{{ not not warning_only }}", - } - } - } + }, + }, + }, }, }, { @@ -471,10 +467,10 @@ def __init__(self, lines=None): "areas": [ { "area_id": "{{ area_id }}", - } - ] - } - } + }, + ], + }, + }, }, }, { @@ -504,9 +500,9 @@ def __init__(self, lines=None): "result": { "mpls": { "traffic_eng": { - "multicast_intact": "{{ not not multicast_intact }}" - } - } + "multicast_intact": "{{ not not multicast_intact }}", + }, + }, }, }, { @@ -521,9 +517,9 @@ def __init__(self, lines=None): "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { - "name_lookup": "{{ not not name_lookup }}" - } - } + "name_lookup": "{{ not not name_lookup }}", + }, + }, }, }, { @@ -539,9 +535,9 @@ def __init__(self, lines=None): "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { - "passive_interface": {"default": "{{ not not default }}"} - } - } + "passive_interface": {"default": "{{ not not default }}"}, + }, + }, }, }, { @@ -555,9 +551,9 @@ def __init__(self, lines=None): "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { - "rfc1583compatibility": "{{ not not rfc }}" - } - } + "rfc1583compatibility": "{{ not not rfc }}", + }, + }, }, }, { @@ -572,9 +568,9 @@ def __init__(self, lines=None): "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { - "router_id": "{{ router_id }}" - } - } + "router_id": "{{ router_id }}", + }, + }, }, }, { @@ -588,9 +584,9 @@ def __init__(self, lines=None): "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { - "shutdown": "{{ not not shutdown }}" - } - } + "shutdown": "{{ not not shutdown }}", + }, + }, }, }, { @@ -613,10 +609,10 @@ def __init__(self, lines=None): "set": "{{ True if originate is defined and always is undefined and route_map is undefined else None }}", "always": "{{ not not always }}", "route_map": "{{ route_map }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -631,9 +627,9 @@ def __init__(self, lines=None): "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { - "default_metric": "{{ default_metric }}" - } - } + "default_metric": "{{ default_metric }}", + }, + }, }, }, { @@ -648,9 +644,9 @@ def __init__(self, lines=None): "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { - "distance": "{{ distance }}" - } - } + "distance": "{{ distance }}", + }, + }, }, }, { @@ -670,9 +666,9 @@ def __init__(self, lines=None): "table_map": { "name": "{{ rmap }}", "filter": "{{ not not filter }}", - } - } - } + }, + }, + }, }, }, { @@ -690,10 +686,10 @@ def __init__(self, lines=None): "vrfs": { '{{ "vrf_" + vrf|d() }}': { "timers": { - "lsa_arrival": "{{ lsa_arrival_val }}" - } - } - } + "lsa_arrival": "{{ lsa_arrival_val }}", + }, + }, + }, }, }, { @@ -711,10 +707,10 @@ def __init__(self, lines=None): "vrfs": { '{{ "vrf_" + vrf|d() }}': { "timers": { - "lsa_group_pacing": "{{ lsa_group_pacing }}" - } - } - } + "lsa_group_pacing": "{{ lsa_group_pacing }}", + }, + }, + }, }, }, { @@ -740,11 +736,11 @@ def __init__(self, lines=None): "start_interval": "{{ start }}", "hold_interval": "{{ hold }}", "max_interval": "{{ max }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, }, { @@ -770,11 +766,11 @@ def __init__(self, lines=None): "initial_spf_delay": "{{ initial }}", "min_hold_time": "{{ min }}", "max_wait_time": "{{ max }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, }, { @@ -795,10 +791,10 @@ def __init__(self, lines=None): "{{ area_id }}": { "area_id": "{{ area_id }}", "default_cost": "{{ default_cost|int }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -822,12 +818,12 @@ def __init__(self, lines=None): "area_id": "{{ area_id }}", "authentication": { "set": "{{ True if auth is defined and md is undefined }}", - "message_digest": "{{ True if md is defined else False }}" + "message_digest": "{{ True if md is defined else False }}", }, - } - } - } - } + }, + }, + }, + }, }, }, { @@ -853,10 +849,10 @@ def __init__(self, lines=None): "direction": "{{ dir }}", }, ], - } - } - } - } + }, + }, + }, + }, }, }, { @@ -880,9 +876,9 @@ def __init__(self, lines=None): "id": "{{ id }}", "route_map": "{{ rmap }}", }, - ] - } - } + ], + }, + }, }, }, { @@ -912,10 +908,10 @@ def __init__(self, lines=None): "no_redistribution": "{{ not not no_redis }}", "default_information_originate": "{{ not not def_info }}", }, - } - } - } - } + }, + }, + }, + }, }, }, { @@ -944,13 +940,13 @@ def __init__(self, lines=None): "always": '{{ True if choice == "always" else None }}', "never": '{{ True if choice == "never" else None }}', "supress_fa": "{{ not not supress_fa }}", - } - } + }, + }, }, - } - } - } - } + }, + }, + }, + }, }, }, { @@ -979,10 +975,10 @@ def __init__(self, lines=None): "not_advertise": "{{ not not not_adver }}", }, ], - } - } - } - } + }, + }, + }, + }, }, }, { @@ -1006,9 +1002,9 @@ def __init__(self, lines=None): "not_advertise": "{{ not not not_adver }}", "tag": "{{ tag }}", }, - ] - } - } + ], + }, + }, }, }, { @@ -1034,10 +1030,10 @@ def __init__(self, lines=None): "set": "{{ True if stub is defined and no_summary is undefined else None }}", "no_summary": "{{ not not no_summary }}", }, - } - } - } - } + }, + }, + }, + }, }, }, { @@ -1051,8 +1047,8 @@ def __init__(self, lines=None): "setval": ("maximum-paths {{ maximum_paths }}"), "result": { "vrfs": { - '{{ "vrf_" + vrf|d() }}': {"maximum_paths": "{{ maximum_paths }}"} - } + '{{ "vrf_" + vrf|d() }}': {"maximum_paths": "{{ maximum_paths }}"}, + }, }, }, { @@ -1095,10 +1091,10 @@ def __init__(self, lines=None): "set": "{{ True if summary_lsa is defined and sum_lsa_max_metric_value is undefined else None }}", "max_metric_value": "{{ sum_lsa_max_metric_value }}", }, - } - } - } - } + }, + }, + }, + }, }, }, ] diff --git a/plugins/module_utils/network/nxos/rm_templates/ospfv3.py b/plugins/module_utils/network/nxos/rm_templates/ospfv3.py index f2bd7cad5..b46c3cf4e 100644 --- a/plugins/module_utils/network/nxos/rm_templates/ospfv3.py +++ b/plugins/module_utils/network/nxos/rm_templates/ospfv3.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -15,7 +16,8 @@ """ import re -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network_template import ( + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) @@ -88,13 +90,9 @@ def _tmplt_max_metric(proc): command = "no {0}".format(command) else: external_lsa = max_metric.get("router_lsa", {}).get("external_lsa", {}) - stub_prefix_lsa = max_metric.get("router_lsa", {}).get( - "stub_prefix_lsa", {} - ) + stub_prefix_lsa = max_metric.get("router_lsa", {}).get("stub_prefix_lsa", {}) on_startup = max_metric.get("router_lsa", {}).get("on_startup", {}) - inter_area_prefix_lsa = max_metric.get("router_lsa", {}).get( - "inter_area_prefix_lsa", {} - ) + inter_area_prefix_lsa = max_metric.get("router_lsa", {}).get("inter_area_prefix_lsa", {}) if external_lsa: command += " external-lsa" if external_lsa.get("max_metric_value"): @@ -106,15 +104,11 @@ def _tmplt_max_metric(proc): if on_startup.get("wait_period"): command += " {wait_period}".format(**on_startup) if on_startup.get("wait_for_bgp_asn"): - command += " wait-for bgp {wait_for_bgp_asn}".format( - **on_startup - ) + command += " wait-for bgp {wait_for_bgp_asn}".format(**on_startup) if inter_area_prefix_lsa: command += " inter-area-prefix-lsa" if inter_area_prefix_lsa.get("max_metric_value"): - command += " {max_metric_value}".format( - **inter_area_prefix_lsa - ) + command += " {max_metric_value}".format(**inter_area_prefix_lsa) return command @@ -187,9 +181,9 @@ def __init__(self, lines=None): "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { - "vrf": "{{ vrf }}" - } - } + "vrf": "{{ vrf }}", + }, + }, }, "shared": True, }, @@ -219,9 +213,9 @@ def __init__(self, lines=None): "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { - "router_id": "{{ router_id }}" - } - } + "router_id": "{{ router_id }}", + }, + }, }, }, { @@ -239,7 +233,7 @@ def __init__(self, lines=None): "address_family": { "afi": "{{ afi }}", "safi": "{{ safi }}", - } + }, }, 'shared': True, }, @@ -260,9 +254,9 @@ def __init__(self, lines=None): "{{ area_id }}": { "area_id": "{{ area_id }}", "default_cost": "{{ default_cost|int }}", - } - } - } + }, + }, + }, }, }, { @@ -287,9 +281,9 @@ def __init__(self, lines=None): "direction": "{{ dir }}", }, ], - } - } - } + }, + }, + }, }, }, { @@ -317,9 +311,9 @@ def __init__(self, lines=None): "not_advertise": "{{ not not not_adver }}", }, ], - } - } - } + }, + }, + }, }, }, { @@ -341,9 +335,9 @@ def __init__(self, lines=None): "set": "{{ True if originate is defined and always is undefined and route_map is undefined else None }}", "always": "{{ not not always }}", "route_map": "{{ route_map }}", - } - } - } + }, + }, + }, }, }, { @@ -357,8 +351,8 @@ def __init__(self, lines=None): "setval": "distance {{ distance }}", "result": { "address_family": { - "distance": "{{ distance }}" - } + "distance": "{{ distance }}", + }, }, }, { @@ -372,8 +366,8 @@ def __init__(self, lines=None): "setval": ("maximum-paths {{ maximum_paths }}"), "result": { "address_family": { - "maximum_paths": "{{ maximum_paths }}" - } + "maximum_paths": "{{ maximum_paths }}", + }, }, }, { @@ -396,8 +390,8 @@ def __init__(self, lines=None): "id": "{{ id }}", "route_map": "{{ rmap }}", }, - ] - } + ], + }, }, }, { @@ -420,8 +414,8 @@ def __init__(self, lines=None): "not_advertise": "{{ not not not_adver }}", "tag": "{{ tag }}", }, - ] - } + ], + }, }, }, { @@ -440,8 +434,8 @@ def __init__(self, lines=None): "table_map": { "name": "{{ rmap }}", "filter": "{{ not not filter }}", - } - } + }, + }, }, }, { @@ -466,10 +460,10 @@ def __init__(self, lines=None): "initial_spf_delay": "{{ initial }}", "min_hold_time": "{{ min }}", "max_wait_time": "{{ max }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -502,10 +496,10 @@ def __init__(self, lines=None): "default_information_originate": "{{ not not def_info }}", "route_map": "{{ rmap }}", }, - } - } - } - } + }, + }, + }, + }, }, }, { @@ -534,13 +528,13 @@ def __init__(self, lines=None): "always": '{{ True if choice == "always" else None }}', "never": '{{ True if choice == "never" else None }}', "supress_fa": "{{ not not supress_fa }}", - } - } + }, + }, }, - } - } - } - } + }, + }, + }, + }, }, }, { @@ -566,10 +560,10 @@ def __init__(self, lines=None): "set": "{{ True if stub is defined and no_summary is undefined else None }}", "no_summary": "{{ not not no_summary }}", }, - } - } - } - } + }, + }, + }, + }, }, }, { @@ -592,9 +586,9 @@ def __init__(self, lines=None): "area_id": "{{ area_id }}", "virtual_link": "{{ virtual_link }}", }, - } - } - } + }, + }, + }, }, }, { @@ -616,9 +610,9 @@ def __init__(self, lines=None): "auto_cost": { "reference_bandwidth": "{{ acrb }}", "unit": "{{ unit }}", - } - } - } + }, + }, + }, }, }, { @@ -630,7 +624,7 @@ def __init__(self, lines=None): ), "setval": "flush-routes", "result": { - "flush_routes": "{{ not not flush_routes }}" + "flush_routes": "{{ not not flush_routes }}", }, }, { @@ -647,10 +641,10 @@ def __init__(self, lines=None): "vrfs": { '{{ "vrf_" + vrf|d() }}': { "graceful_restart": { - "set": "{{ not graceful_restart }}" - } - } - } + "set": "{{ not graceful_restart }}", + }, + }, + }, }, }, { @@ -668,9 +662,9 @@ def __init__(self, lines=None): '{{ "vrf_" + vrf|d() }}': { "graceful_restart": { "helper_disable": "{{ not not helper_disable }}", - } - } - } + }, + }, + }, }, }, { @@ -689,9 +683,9 @@ def __init__(self, lines=None): '{{ "vrf_" + vrf|d() }}': { "graceful_restart": { "grace_period": "{{ grace_period }}", - } - } - } + }, + }, + }, }, }, { @@ -710,9 +704,9 @@ def __init__(self, lines=None): '{{ "vrf_" + vrf|d() }}': { "graceful_restart": { "planned_only": "{{ not planned_only }}", - } - } - } + }, + }, + }, }, }, { @@ -740,9 +734,9 @@ def __init__(self, lines=None): "log_adjacency_changes": { "log": "{{ True if log is defined and detail is undefined else None }}", "detail": "{{ True if detail is defined else None }}", - } - } - } + }, + }, + }, }, }, { @@ -772,9 +766,9 @@ def __init__(self, lines=None): "ignore_count": "{{ ig_count }}", "reset_time": "{{ rst_time }}", "warning_only": "{{ not not warning_only }}", - } - } - } + }, + }, + }, }, }, { @@ -818,10 +812,10 @@ def __init__(self, lines=None): "set": "{{ True if inter_area_prefix_lsa is defined and max_metric_summary_lsa is undefined else None }}", "max_metric_value": "{{ max_metric_summary_lsa }}", }, - } - } - } - } + }, + }, + }, + }, }, }, { @@ -836,9 +830,9 @@ def __init__(self, lines=None): "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { - "name_lookup": "{{ not not name_lookup }}" - } - } + "name_lookup": "{{ not not name_lookup }}", + }, + }, }, }, { @@ -854,9 +848,9 @@ def __init__(self, lines=None): "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { - "passive_interface": {"default": "{{ not not default }}"} - } - } + "passive_interface": {"default": "{{ not not default }}"}, + }, + }, }, }, { @@ -870,9 +864,9 @@ def __init__(self, lines=None): "result": { "vrfs": { '{{ "vrf_" + vrf|d() }}': { - "shutdown": "{{ not not shutdown }}" - } - } + "shutdown": "{{ not not shutdown }}", + }, + }, }, }, { @@ -890,10 +884,10 @@ def __init__(self, lines=None): "vrfs": { '{{ "vrf_" + vrf|d() }}': { "timers": { - "lsa_arrival": "{{ lsa_arrival_val }}" - } - } - } + "lsa_arrival": "{{ lsa_arrival_val }}", + }, + }, + }, }, }, { @@ -911,10 +905,10 @@ def __init__(self, lines=None): "vrfs": { '{{ "vrf_" + vrf|d() }}': { "timers": { - "lsa_group_pacing": "{{ lsa_group_pacing }}" - } - } - } + "lsa_group_pacing": "{{ lsa_group_pacing }}", + }, + }, + }, }, }, { @@ -940,11 +934,11 @@ def __init__(self, lines=None): "start_interval": "{{ start }}", "hold_interval": "{{ hold }}", "max_interval": "{{ max }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, }, ] diff --git a/plugins/module_utils/network/nxos/rm_templates/prefix_lists.py b/plugins/module_utils/network/nxos/rm_templates/prefix_lists.py index 6dd25bd00..0bb66eada 100644 --- a/plugins/module_utils/network/nxos/rm_templates/prefix_lists.py +++ b/plugins/module_utils/network/nxos/rm_templates/prefix_lists.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -15,6 +16,7 @@ """ import re + from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) @@ -22,9 +24,7 @@ class Prefix_listsTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): - super(Prefix_listsTemplate, self).__init__( - lines=lines, tmplt=self, module=module - ) + super(Prefix_listsTemplate, self).__init__(lines=lines, tmplt=self, module=module) # fmt: off PARSERS = [ @@ -43,7 +43,8 @@ def __init__(self, lines=None, module=None): (\sle\s(?P\d+))? (\smask\s(?P\S+))? \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "{{ 'ip' if afi == 'ipv4' else afi }} prefix-list {{ name }}" "{{ (' seq ' + sequence|string) if sequence|d('') else '' }}" " {{ action }}" @@ -67,10 +68,10 @@ def __init__(self, lines=None, module=None): "ge": "{{ ge }}", "le": "{{ le }}", "mask": "{{ mask }}", - } + }, ], - } - } + }, + }, }, }, }, @@ -82,7 +83,8 @@ def __init__(self, lines=None, module=None): \sprefix-list \s(?P\S+) \sdescription\s(?P.+)\s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "{{ 'ip' if afi == 'ipv4' else afi }} prefix-list {{ name }} description {{ description }}", "result": { "{{ 'ipv4' if afi == 'ip' else 'ipv6' }}": { @@ -91,8 +93,8 @@ def __init__(self, lines=None, module=None): "{{ name }}": { "name": "{{ name }}", "description": "{{ description }}", - } - } + }, + }, }, }, }, diff --git a/plugins/module_utils/network/nxos/rm_templates/route_maps.py b/plugins/module_utils/network/nxos/rm_templates/route_maps.py index f9109f357..7e876682a 100644 --- a/plugins/module_utils/network/nxos/rm_templates/route_maps.py +++ b/plugins/module_utils/network/nxos/rm_templates/route_maps.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -15,11 +16,23 @@ """ import re -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network_template import ( + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) +def _tmplt_set_extcomm_rt(data): + cmd = "set extcommunity rt" + extcomm_numbers = " ".join(data.get("extcommunity_numbers", [])) + if extcomm_numbers: + cmd += " " + extcomm_numbers + if data.get("additive"): + cmd += " additive" + + return cmd + + def _tmplt_match_ip_multicast(data): cmd = "match ip multicast" multicast = data["match"]["ip"]["multicast"] @@ -83,11 +96,24 @@ def _tmplt_set_metric(data): return cmd +def _tmplt_set_ip_next_hop_verify_availability(data): + cmd = [] + for each in data["set"]["ip"]["next_hop"]["verify_availability"]: + cmd_tmpl = "set ip next-hop verify-availability" + cmd_tmpl += " {address} track {track}".format(**each) + if "load_share" in each and each["load_share"]: + cmd_tmpl += " load-share" + if "force_order" in each and each["force_order"]: + cmd_tmpl += " force-order" + if "drop_on_fail" in each and each["drop_on_fail"]: + cmd_tmpl += " drop-on-fail" + cmd.append(cmd_tmpl) + return cmd + + class Route_mapsTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): - super(Route_mapsTemplate, self).__init__( - lines=lines, tmplt=self, module=module - ) + super(Route_mapsTemplate, self).__init__(lines=lines, tmplt=self, module=module) # fmt: off PARSERS = [ @@ -96,7 +122,8 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" ^route-map\s(?P\S+)\s(?P\S+)\s(?P\d+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "route-map {{ route_map }}" "{{ ' ' + action if action is defined else '' }}" "{{ ' ' + sequence|string if sequence is defined else '' }}", @@ -107,9 +134,9 @@ def __init__(self, lines=None, module=None): "{{ sequence }}": { "sequence": "{{ sequence }}", "action": "{{ action }}", - } - } - } + }, + }, + }, }, "shared": True, }, @@ -118,33 +145,35 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" \s+continue\s(?P\d+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "continue {{ continue_sequence }}", "result": { "{{ route_map }}": { "entries": { "{{ sequence }}": { "continue_sequence": "{{ continue_sequence }}", - } - } - } + }, + }, + }, }, }, { "name": "description", "getval": re.compile( r""" - \s+description\s(?P\S+) - $""", re.VERBOSE), + \s+description\s(?P.+) + $""", re.VERBOSE, + ), "setval": "description {{ description }}", "result": { "{{ route_map }}": { "entries": { "{{ sequence }}": { "description": "{{ description }}", - } - } - } + }, + }, + }, }, }, { @@ -154,7 +183,8 @@ def __init__(self, lines=None, module=None): \s+match\sas-number (?!\sas-path-list) \s(?P.+)\s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "match as-number {{ match.as_number.asn|join(', ') }}", "result": { "{{ route_map }}": { @@ -164,11 +194,11 @@ def __init__(self, lines=None, module=None): "match": { "as_number": { "asn": "{{ asn.rstrip().split(', ') }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, }, { @@ -177,7 +207,8 @@ def __init__(self, lines=None, module=None): r""" \s+match\sas-number \sas-path-list\s(?P.+)\s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "match as-number as-path-list {{ match.as_number.as_path_list|join(' ') }}", "result": { "{{ route_map }}": { @@ -186,11 +217,11 @@ def __init__(self, lines=None, module=None): "match": { "as_number": { "as_path_list": "{{ as_path_list.split() }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, }, { @@ -198,7 +229,8 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" \s+match\sas-path\s(?P.+)\s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "match as-path {{ match.as_path|join(' ') }}", "result": { "{{ route_map }}": { @@ -206,10 +238,10 @@ def __init__(self, lines=None, module=None): "{{ sequence }}": { "match": { "as_path": "{{ as_path.split() }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -220,7 +252,8 @@ def __init__(self, lines=None, module=None): \s(?P.+) (\s(?Pexact-match))? \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "match community {{ match.community.community_list|join(' ') }}{{ ' exact-match' if match.community.exact_match|d(False) else '' }}", "result": { "{{ route_map }}": { @@ -230,11 +263,11 @@ def __init__(self, lines=None, module=None): "community": { "community_list": "{{ community_list.split() }}", "exact_match": "{{ not not exact_match }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, }, { @@ -244,7 +277,8 @@ def __init__(self, lines=None, module=None): \s+match\sevpn \sroute-type \s(?P.+)\s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "match evpn route-type {{ match.evpn.route_types|join(' ') }}", "result": { "{{ route_map }}": { @@ -253,11 +287,11 @@ def __init__(self, lines=None, module=None): "match": { "evpn": { "route_types": "{{ route_types.split() }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, }, { @@ -268,7 +302,8 @@ def __init__(self, lines=None, module=None): \s(?P.+) \s(?Pexact-match)? \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "match extcommunity {{ match.extcommunity.extcommunity_list|join(' ') }}" "{{ ' exact-match' if match.extcommunity.exact_match|d(False) else '' }}", "result": { @@ -279,11 +314,11 @@ def __init__(self, lines=None, module=None): "extcommunity": { "extcommunity_list": "{{ extcommunity_list.split() }}", "exact_match": "{{ not not exact_match }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, }, { @@ -293,18 +328,19 @@ def __init__(self, lines=None, module=None): \s+match\sinterface \s(?P.+) \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "match interface {{ match.interfaces|join(' ') }}", "result": { "{{ route_map }}": { "entries": { "{{ sequence }}": { "match": { - "interfaces": "{{ interfaces.split() }}" - } - } - } - } + "interfaces": "{{ interfaces.split() }}", + }, + }, + }, + }, }, }, { @@ -314,7 +350,8 @@ def __init__(self, lines=None, module=None): \s+match\sip\saddress \s(?P\S+) \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "match ip address {{ match.ip.address.access_list }}", "result": { "{{ route_map }}": { @@ -324,12 +361,12 @@ def __init__(self, lines=None, module=None): "ip": { "address": { "access_list": "{{ access_list }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, }, { @@ -340,7 +377,8 @@ def __init__(self, lines=None, module=None): \sprefix-list \s(?P.+) \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "match ip address prefix-list {{ match.ip.address.prefix_lists|join(' ') }}", "result": { "{{ route_map }}": { @@ -350,12 +388,12 @@ def __init__(self, lines=None, module=None): "ip": { "address": { "prefix_lists": "{{ prefix_lists.split() }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, }, # match ip multicast source 192.1.2.0/24 group-range 239.0.0.1 to 239.255.255.255 rp 209.165.201.0/27 rp-type Bidir @@ -373,7 +411,8 @@ def __init__(self, lines=None, module=None): (\srp\s(?P\S+))? (\srp-type\s(?P\S+))? \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": _tmplt_match_ip_multicast, "result": { "{{ route_map }}": { @@ -395,11 +434,11 @@ def __init__(self, lines=None, module=None): }, "source": "{{ source }}", }, - } - } - } - } - } + }, + }, + }, + }, + }, }, }, { @@ -409,7 +448,8 @@ def __init__(self, lines=None, module=None): \s+match\sip\snext-hop \sprefix-list\s(?P.+) \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "match ip next-hop prefix-list {{ match.ip.next_hop.prefix_lists|join(' ') }}", "result": { "{{ route_map }}": { @@ -419,12 +459,12 @@ def __init__(self, lines=None, module=None): "ip": { "next_hop": { "prefix_lists": "{{ prefix_lists.split() }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, }, { @@ -434,7 +474,8 @@ def __init__(self, lines=None, module=None): \s+match\sip\sroute-source \sprefix-list\s(?P.+) \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "match ip route-source prefix-list {{ match.ip.route_source.prefix_lists|join(' ') }}", "result": { "{{ route_map }}": { @@ -444,12 +485,12 @@ def __init__(self, lines=None, module=None): "ip": { "route_source": { "prefix_lists": "{{ prefix_lists.split() }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, }, { @@ -459,7 +500,8 @@ def __init__(self, lines=None, module=None): \s+match\sipv6\saddress \s(?P\S+) \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "match ipv6 address {{ match.ipv6.address.access_list }}", "result": { "{{ route_map }}": { @@ -469,12 +511,12 @@ def __init__(self, lines=None, module=None): "ipv6": { "address": { "access_list": "{{ access_list }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, }, { @@ -485,7 +527,8 @@ def __init__(self, lines=None, module=None): \sprefix-list \s(?P.+) \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "match ipv6 address prefix-list {{ match.ipv6.address.prefix_lists|join(' ') }}", "result": { "{{ route_map }}": { @@ -495,12 +538,12 @@ def __init__(self, lines=None, module=None): "ipv6": { "address": { "prefix_lists": "{{ prefix_lists.split() }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, }, { @@ -517,7 +560,8 @@ def __init__(self, lines=None, module=None): (\srp\s(?P\S+))? (\srp-type\s(?P\S+))? \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": _tmplt_match_ipv6_multicast, "result": { "{{ route_map }}": { @@ -539,11 +583,11 @@ def __init__(self, lines=None, module=None): }, "source": "{{ source }}", }, - } - } - } - } - } + }, + }, + }, + }, + }, }, }, { @@ -553,7 +597,8 @@ def __init__(self, lines=None, module=None): \s+match\sipv6\snext-hop \sprefix-list\s(?P.+) \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "match ipv6 next-hop prefix-list {{ match.ipv6.next_hop.prefix_lists|join(' ') }}", "result": { "{{ route_map }}": { @@ -563,12 +608,12 @@ def __init__(self, lines=None, module=None): "ipv6": { "next_hop": { "prefix_lists": "{{ prefix_lists.split() }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, }, { @@ -578,7 +623,8 @@ def __init__(self, lines=None, module=None): \s+match\sipv6\sroute-source \sprefix-list\s(?P.+) \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "match ipv6 route-source prefix-list {{ match.ipv6.route_source.prefix_lists|join(' ') }}", "result": { "{{ route_map }}": { @@ -588,12 +634,12 @@ def __init__(self, lines=None, module=None): "ipv6": { "route_source": { "prefix_lists": "{{ prefix_lists.split() }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, }, { @@ -603,7 +649,8 @@ def __init__(self, lines=None, module=None): \s+match\smac-list \s(?P.+) \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "match mac-list {{ match.mac_list|join(' ') }}", "result": { "{{ route_map }}": { @@ -611,10 +658,10 @@ def __init__(self, lines=None, module=None): "{{ sequence }}": { "match": { "mac_list": "{{ mac_list.split() }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -624,7 +671,8 @@ def __init__(self, lines=None, module=None): \s+match\smetric \s(?P.+) \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "match metric {{ match.metric|join(' ') }}", "result": { "{{ route_map }}": { @@ -632,10 +680,10 @@ def __init__(self, lines=None, module=None): "{{ sequence }}": { "match": { "metric": "{{ metric.split() }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -645,7 +693,8 @@ def __init__(self, lines=None, module=None): \s+match\sospf-area \s(?P.+) \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "match ospf-area {{ match.ospf_area|join(' ') }}", "result": { "{{ route_map }}": { @@ -653,10 +702,10 @@ def __init__(self, lines=None, module=None): "{{ sequence }}": { "match": { "ospf_area": "{{ ospf_area.split() }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -666,7 +715,8 @@ def __init__(self, lines=None, module=None): \s+match\sroute-type \s(?P.+) \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "match route-type {{ match.route_types|join(' ') }}", "result": { "{{ route_map }}": { @@ -674,10 +724,10 @@ def __init__(self, lines=None, module=None): "{{ sequence }}": { "match": { "route_types": "{{ route_types.split() }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -687,7 +737,8 @@ def __init__(self, lines=None, module=None): \s+match\ssource-protocol \s(?P.+) \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "match source-protocol {{ match.source_protocol|join(' ') }}", "result": { "{{ route_map }}": { @@ -695,10 +746,10 @@ def __init__(self, lines=None, module=None): "{{ sequence }}": { "match": { "source_protocol": "{{ source_protocol.split() }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -708,7 +759,8 @@ def __init__(self, lines=None, module=None): \s+match\stag \s(?P.+) \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "match tag {{ match.tags|join(' ') }}", "result": { "{{ route_map }}": { @@ -716,10 +768,10 @@ def __init__(self, lines=None, module=None): "{{ sequence }}": { "match": { "tags": "{{ tags.split() }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -729,7 +781,8 @@ def __init__(self, lines=None, module=None): \s+set\sas-path\sprepend \s(?P(?!last-as).+) \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "set as-path prepend {{ set.as_path.prepend.as_number|join(' ') }}", "result": { "{{ route_map }}": { @@ -739,12 +792,12 @@ def __init__(self, lines=None, module=None): "as_path": { "prepend": { "as_number": "{{ as_number.split() }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, }, { @@ -754,7 +807,8 @@ def __init__(self, lines=None, module=None): \s+set\sas-path\sprepend \slast-as\s(?P\d+) \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "set as-path prepend last-as {{ set.as_path.prepend.last_as|string }}", "result": { "{{ route_map }}": { @@ -764,12 +818,12 @@ def __init__(self, lines=None, module=None): "as_path": { "prepend": { "last_as": "{{ last_as }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, }, { @@ -779,7 +833,8 @@ def __init__(self, lines=None, module=None): \s+set\sas-path \s(?Ptag) \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "set as-path tag", "result": { "{{ route_map }}": { @@ -788,11 +843,11 @@ def __init__(self, lines=None, module=None): "set": { "as_path": { "tag": "{{ not not tag }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, }, { @@ -802,7 +857,8 @@ def __init__(self, lines=None, module=None): \s+set\scomm-list \s(?P\S+) \s*delete - \s*$""", re.VERBOSE), + \s*$""", re.VERBOSE, + ), "setval": "set comm-list {{ set.comm_list }} delete", "result": { "{{ route_map }}": { @@ -810,10 +866,10 @@ def __init__(self, lines=None, module=None): "{{ sequence }}": { "set": { "comm_list": "{{ comm_list }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -828,7 +884,8 @@ def __init__(self, lines=None, module=None): (\s(?Plocal-AS))? (\s(?Pgraceful-shutdown))? (\s(?Padditive))?\s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "set community" "{{ ' internet' if set.community.internet|d(False) else '' }}" "{{ ' ' + set.community.number|join(' ') if set.community.number|d(False) else '' }}" @@ -850,11 +907,11 @@ def __init__(self, lines=None, module=None): "local_as": "{{ not not local_as }}", "graceful_shutdown": "{{ not not graceful_shutdown }}", "additive": "{{ not not additive }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, }, { @@ -867,7 +924,8 @@ def __init__(self, lines=None, module=None): \s(?P\d+) \s(?P\d+) \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "set dampening {{ set.dampening.half_life }}" " {{ set.dampening.start_reuse_route }}" " {{ set.dampening.start_suppress_route }}" @@ -882,11 +940,11 @@ def __init__(self, lines=None, module=None): "start_reuse_route": "{{ start_reuse_route }}", "start_suppress_route": "{{ start_suppress_route }}", "max_suppress_time": "{{ max_suppress_time }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, }, { @@ -898,7 +956,8 @@ def __init__(self, lines=None, module=None): (\s(?P\d+))? (\s(?P\d+))? \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "set distance {{ set.distance.igp_ebgp_routes }}" "{{ ' ' + set.distance.internal_routes|string if set.distance.internal_routes|d(False) else '' }}" "{{ ' ' + set.distance.local_routes|string if set.distance.internal_routes|d(False) else '' }}", @@ -911,11 +970,11 @@ def __init__(self, lines=None, module=None): "igp_ebgp_routes": "{{ igp_ebgp_routes }}", "internal_routes": "{{ internal_routes }}", "local_routes": "{{ local_routes }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, }, { @@ -927,7 +986,8 @@ def __init__(self, lines=None, module=None): (\s(?P(?!use-nexthop)\S+))? (\s(?Puse-nexthop))? \s* - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "set evpn gateway-ip" "{{ ' ' + set.evpn.gateway_ip.ip if set.evpn.gateway_ip.ip|d(False) else ''}}" "{{ ' use-nexthop' if set.evpn.gateway_ip.use_nexthop|d(False) else '' }}", @@ -940,12 +1000,12 @@ def __init__(self, lines=None, module=None): "gateway_ip": { "ip": "{{ ip }}", "use_nexthop": "{{ not not use_nexthop }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, }, { @@ -955,7 +1015,8 @@ def __init__(self, lines=None, module=None): \s+set\sextcomm-list \s(?P\S+) \s*delete - \s*$""", re.VERBOSE), + \s*$""", re.VERBOSE, + ), "setval": "set extcomm-list {{ set.extcomm_list }} delete", "result": { "{{ route_map }}": { @@ -963,10 +1024,38 @@ def __init__(self, lines=None, module=None): "{{ sequence }}": { "set": { "extcomm_list": "{{ extcomm_list }}", - } - } - } - } + }, + }, + }, + }, + }, + }, + { + "name": "set.extcommunity.rt", + "getval": re.compile( + r""" + \s+set\sextcommunity\srt + (?P(\s\S+:\S+)*)? + (\s(?Padditive))? + \s*$""", re.VERBOSE, + ), + "setval": _tmplt_set_extcomm_rt, + "result": { + "{{ route_map }}": { + "entries": { + "{{ sequence }}": { + "set": { + "extcommunity": { + "rt": { + "additive": "{{ not not additive }}", + "extcommunity_numbers": + "{{ extcommunity_numbers.strip().split(' ') if extcommunity_numbers|d('') else None }}", + }, + }, + }, + }, + }, + }, }, }, { @@ -975,7 +1064,8 @@ def __init__(self, lines=None, module=None): r""" \s+set \s(?Pforwarding-address) - \s*$""", re.VERBOSE), + \s*$""", re.VERBOSE, + ), "setval": "set forwarding-address", "result": { "{{ route_map }}": { @@ -983,10 +1073,10 @@ def __init__(self, lines=None, module=None): "{{ sequence }}": { "set": { "forwarding_address": "{{ not not forwarding_address }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -995,7 +1085,8 @@ def __init__(self, lines=None, module=None): r""" \s+set\sinterface \s(?P\S+) - \s*$""", re.VERBOSE), + \s*$""", re.VERBOSE, + ), "setval": "set interface {{ set.null_interface }}", "result": { "{{ route_map }}": { @@ -1003,10 +1094,10 @@ def __init__(self, lines=None, module=None): "{{ sequence }}": { "set": { "null_interface": "{{ interface }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -1015,7 +1106,8 @@ def __init__(self, lines=None, module=None): r""" \s+set\sip\saddress \sprefix-list\s(?P\S+) - \s*$""", re.VERBOSE), + \s*$""", re.VERBOSE, + ), "setval": "set ip address prefix-list {{ set.ip.address.prefix_list }}", "result": { "{{ route_map }}": { @@ -1025,12 +1117,12 @@ def __init__(self, lines=None, module=None): "ip": { "address": { "prefix_list": "{{ prefix_list }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, }, { @@ -1039,7 +1131,8 @@ def __init__(self, lines=None, module=None): r""" \s+set\sip \sprecedence\s(?P\S+) - \s*$""", re.VERBOSE), + \s*$""", re.VERBOSE, + ), "setval": "set ip precedence {{ set.ip.precedence }}", "result": { "{{ route_map }}": { @@ -1048,11 +1141,157 @@ def __init__(self, lines=None, module=None): "set": { "ip": { "precedence": "{{ precedence }}", - } - } - } - } - } + }, + }, + }, + }, + }, + }, + }, + { + "name": "set.ip.next_hop", + "getval": re.compile( + r""" + \s+set\sip\snext-hop + \s(?P
(\s?((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4})+) + (\s+(?Pload-share))? + (\s+(?Pforce-order))? + (\s+(?Pdrop-on-fail))? + \s*$""", re.VERBOSE, + ), + "setval": "set ip next-hop {{ set.ip.next_hop.address }}" + "{{ ' load-share' if set.ip.next_hop.load_share else '' }}" + "{{ ' force-order' if set.ip.next_hop.force_order else '' }}" + "{{ ' drop-on-fail' if set.ip.next_hop.drop_on_fail else '' }}", + "result": { + "{{ route_map }}": { + "entries": { + "{{ sequence }}": { + "set": { + "ip": { + "next_hop": { + "address": "{{ address }}", + "load_share": "{{ not not load_share|d(False) }}", + "force_order": "{{ not not force_order|d(False) }}", + "drop_on_fail": "{{ not not drop_on_fail|d(False) }}", + }, + }, + }, + }, + }, + }, + }, + }, + { + "name": "set.ip.next_hop.peer_address", + "getval": re.compile( + r""" + \s+set\sip\snext-hop + \s(?Ppeer-address) + \s*$""", re.VERBOSE, + ), + "setval": "set ip next-hop peer-address", + "result": { + "{{ route_map }}": { + "entries": { + "{{ sequence }}": { + "set": { + "ip": { + "next_hop": { + "peer_address": "{{ not not peer_address }}", + }, + }, + }, + }, + }, + }, + }, + }, + { + "name": "set.ip.next_hop.redist_unchanged", + "getval": re.compile( + r""" + \s+set\sip\snext-hop + \s(?Predist-unchanged) + \s*$""", re.VERBOSE, + ), + "setval": "set ip next-hop redist-unchanged", + "result": { + "{{ route_map }}": { + "entries": { + "{{ sequence }}": { + "set": { + "ip": { + "next_hop": { + "redist_unchanged": "{{ not not redist_unchanged }}", + }, + }, + }, + }, + }, + }, + }, + }, + { + "name": "set.ip.next_hop.unchanged", + "getval": re.compile( + r""" + \s+set\sip\snext-hop + \s(?Punchanged) + \s*$""", re.VERBOSE, + ), + "setval": "set ip next-hop unchanged", + "result": { + "{{ route_map }}": { + "entries": { + "{{ sequence }}": { + "set": { + "ip": { + "next_hop": { + "unchanged": "{{ not not unchanged }}", + }, + }, + }, + }, + }, + }, + }, + }, + { + "name": "set.ip.next_hop.verify_availability", + "getval": re.compile( + r""" + \s+set\sip\snext-hop\sverify-availability + \s(?P
\S+) + \strack\s(?P\d) + (\s(?Pload-share))? + (\s(?Pforce-order))? + (\s(?Pdrop-on-fail))? + \s*$""", re.VERBOSE, + ), + "setval": _tmplt_set_ip_next_hop_verify_availability, + "result": { + "{{ route_map }}": { + "entries": { + "{{ sequence }}": { + "set": { + "ip": { + "next_hop": { + "verify_availability": [ + { + "address": "{{ address }}", + "track": "{{ track }}", + "load_share": "{{ not not load_share|d(False) }}", + "force_order": "{{ not not force_order|d(False) }}", + "drop_on_fail": "{{ not not drop_on_fail|d(False) }}", + }, + ], + }, + }, + }, + }, + }, + }, }, }, { @@ -1061,7 +1300,8 @@ def __init__(self, lines=None, module=None): r""" \s+set\sipv6\saddress \sprefix-list\s(?P\S+) - \s*$""", re.VERBOSE), + \s*$""", re.VERBOSE, + ), "setval": "set ipv6 address prefix-list {{ set.ipv6.address.prefix_list }}", "result": { "{{ route_map }}": { @@ -1071,12 +1311,12 @@ def __init__(self, lines=None, module=None): "ipv6": { "address": { "prefix_list": "{{ prefix_list }}", - } - } - } - } - } - } + }, + }, + }, + }, + }, + }, }, }, { @@ -1085,7 +1325,8 @@ def __init__(self, lines=None, module=None): r""" \s+set\sipv6 \sprecedence\s(?P\S+) - \s*$""", re.VERBOSE), + \s*$""", re.VERBOSE, + ), "setval": "set ipv6 precedence {{ set.ipv6.precedence }}", "result": { "{{ route_map }}": { @@ -1094,11 +1335,11 @@ def __init__(self, lines=None, module=None): "set": { "ipv6": { "precedence": "{{ precedence }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, }, { @@ -1107,7 +1348,8 @@ def __init__(self, lines=None, module=None): r""" \s+set\slabel-index \s(?P\d+) - \s*$""", re.VERBOSE), + \s*$""", re.VERBOSE, + ), "setval": "set label-index {{ set.label_index }}", "result": { "{{ route_map }}": { @@ -1115,10 +1357,10 @@ def __init__(self, lines=None, module=None): "{{ sequence }}": { "set": { "label_index": "{{ label_index }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -1127,7 +1369,8 @@ def __init__(self, lines=None, module=None): r""" \s+set\slevel \s(?P\S+) - \s*$""", re.VERBOSE), + \s*$""", re.VERBOSE, + ), "setval": "set level {{ set.level }}", "result": { "{{ route_map }}": { @@ -1135,10 +1378,10 @@ def __init__(self, lines=None, module=None): "{{ sequence }}": { "set": { "level": "{{ level }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -1147,7 +1390,8 @@ def __init__(self, lines=None, module=None): r""" \s+set\slocal-preference \s(?P\d+) - \s*$""", re.VERBOSE), + \s*$""", re.VERBOSE, + ), "setval": "set local-preference {{ set.local_preference }}", "result": { "{{ route_map }}": { @@ -1155,10 +1399,10 @@ def __init__(self, lines=None, module=None): "{{ sequence }}": { "set": { "local_preference": "{{ local_preference }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -1171,7 +1415,8 @@ def __init__(self, lines=None, module=None): (\s(?P\d+))? (\s(?P\d+))? (\s(?P\d+))? - \s*$""", re.VERBOSE), + \s*$""", re.VERBOSE, + ), "setval": _tmplt_set_metric, "result": { "{{ route_map }}": { @@ -1184,11 +1429,11 @@ def __init__(self, lines=None, module=None): "igrp_reliability_metric": "{{ igrp_reliability_metric }}", "igrp_effective_bandwidth_metric": "{{ igrp_effective_bandwidth_metric }}", "igrp_mtu": "{{ igrp_mtu }}", - } - } - } - } - } + }, + }, + }, + }, + }, }, }, { @@ -1197,7 +1442,8 @@ def __init__(self, lines=None, module=None): r""" \s+set\smetric-type \s(?P\S+) - \s*$""", re.VERBOSE), + \s*$""", re.VERBOSE, + ), "setval": "set metric-type {{ set.metric_type }}", "result": { "{{ route_map }}": { @@ -1205,10 +1451,10 @@ def __init__(self, lines=None, module=None): "{{ sequence }}": { "set": { "metric_type": "{{ metric_type }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -1217,7 +1463,8 @@ def __init__(self, lines=None, module=None): r""" \s+set \s(?Pnssa-only) - \s*$""", re.VERBOSE), + \s*$""", re.VERBOSE, + ), "setval": "set nssa-only", "result": { "{{ route_map }}": { @@ -1225,10 +1472,10 @@ def __init__(self, lines=None, module=None): "{{ sequence }}": { "set": { "nssa_only": "{{ not not nssa_only }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -1237,7 +1484,8 @@ def __init__(self, lines=None, module=None): r""" \s+set\sorigin \s(?P\S+) - \s*$""", re.VERBOSE), + \s*$""", re.VERBOSE, + ), "setval": "set origin {{ set.origin }}", "result": { "{{ route_map }}": { @@ -1245,10 +1493,10 @@ def __init__(self, lines=None, module=None): "{{ sequence }}": { "set": { "origin": "{{ origin }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -1258,7 +1506,8 @@ def __init__(self, lines=None, module=None): \s+set\spath-selection \s(?P\S+) \sadvertise - \s*$""", re.VERBOSE), + \s*$""", re.VERBOSE, + ), "setval": "set path-selection {{ set.path_selection }} advertise", "result": { "{{ route_map }}": { @@ -1266,10 +1515,10 @@ def __init__(self, lines=None, module=None): "{{ sequence }}": { "set": { "path_selection": "{{ path_selection }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -1278,7 +1527,8 @@ def __init__(self, lines=None, module=None): r""" \s+set\stag \s(?P\d+) - \s*$""", re.VERBOSE), + \s*$""", re.VERBOSE, + ), "setval": "set tag {{ set.tag }}", "result": { "{{ route_map }}": { @@ -1286,10 +1536,10 @@ def __init__(self, lines=None, module=None): "{{ sequence }}": { "set": { "tag": "{{ tag }}", - } - } - } - } + }, + }, + }, + }, }, }, { @@ -1298,7 +1548,8 @@ def __init__(self, lines=None, module=None): r""" \s+set\sweight \s(?P\d+) - \s*$""", re.VERBOSE), + \s*$""", re.VERBOSE, + ), "setval": "set weight {{ set.weight }}", "result": { "{{ route_map }}": { @@ -1306,10 +1557,10 @@ def __init__(self, lines=None, module=None): "{{ sequence }}": { "set": { "weight": "{{ weight }}", - } - } - } - } + }, + }, + }, + }, }, }, ] diff --git a/plugins/module_utils/network/nxos/rm_templates/snmp_server.py b/plugins/module_utils/network/nxos/rm_templates/snmp_server.py index 490cf93d9..35451a47b 100644 --- a/plugins/module_utils/network/nxos/rm_templates/snmp_server.py +++ b/plugins/module_utils/network/nxos/rm_templates/snmp_server.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -15,6 +16,7 @@ """ import re + from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) @@ -66,34 +68,17 @@ def _tmplt_users_auth(data): cmd += " {0}".format(priv["privacy_password"]) if auth.get("localized_key", False): cmd += " localizedkey" + elif auth.get("localizedv2_key", False): + cmd += " localizedV2key" if "engine_id" in auth: cmd += " engineID {0}".format(auth["engine_id"]) return cmd -def _template_communities(data): - cmd = "snmp-server community {0}".format(data["name"]) - - if "group" in data: - cmd += " group {0}".format(data["group"]) - elif "use_ipv4acl" in data: - cmd += " use-ipv4acl {0}".format(data["use_ipv4acl"]) - elif "use_ipv6acl" in data: - cmd += " use-ipv6acl {0}".format(data["use_ipv6acl"]) - elif data.get("ro", False): - cmd += " ro" - elif data.get("rw", False): - cmd += " rw" - - return cmd - - class Snmp_serverTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): - super(Snmp_serverTemplate, self).__init__( - lines=lines, tmplt=self, module=module - ) + super(Snmp_serverTemplate, self).__init__(lines=lines, tmplt=self, module=module) # fmt: off PARSERS = [ @@ -103,12 +88,13 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server\saaa-user \scache-timeout\s(?P\d+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server aaa-user cache-timeout {{ aaa_user.cache_timeout }}", "result": { "aaa_user": { "cache_timeout": "{{ cache_timeout }}", - } + }, }, }, { @@ -120,8 +106,15 @@ def __init__(self, lines=None, module=None): (\sgroup\s(?P\S+))? (\suse-ipv4acl\s(?P\S+))? (\suse-ipv6acl\s(?P\S+))? - $""", re.VERBOSE), - "setval": _template_communities, + $""", re.VERBOSE, + ), + "setval": "snmp-server community " + "{{ name }}" + "{{ (' group ' + group) if group is defined else '' }}" + "{{ (' use-ipv4acl ' + use_ipv4acl) if use_ipv4acl is defined else '' }}" + "{{ (' use-ipv6acl ' + use_ipv6acl) if use_ipv6acl is defined else '' }}" + "{{ ' ro' if ro|d(False) else ''}}" + "{{ ' rw' if rw|d(False) else ''}}", "result": { "communities": [ { @@ -129,8 +122,8 @@ def __init__(self, lines=None, module=None): "group": "{{ group }}", "use_ipv4acl": "{{ use_ipv4acl }}", "use_ipv6acl": "{{ use_ipv6acl }}", - } - ] + }, + ], }, }, { @@ -139,7 +132,8 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server \scontact\s(?P.+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server contact {{ contact }}", "result": { "contact": "{{ contact }}", @@ -154,7 +148,8 @@ def __init__(self, lines=None, module=None): (\sinstance\s(?P\S+))? (\svrf\s(?P\S+))? (\stopology\s(?P\S+))? - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server context {{ context.name }}" "{{ ' instance ' + context.instance if context.instance is defined else '' }}" "{{ ' topology ' + context.topology if context.topology is defined else '' }}" @@ -165,7 +160,7 @@ def __init__(self, lines=None, module=None): "instance": "{{ instance }}", "vrf": "{{ vrf }}", "topology": "{{ topology }}", - } + }, }, }, @@ -176,14 +171,15 @@ def __init__(self, lines=None, module=None): ^snmp-server \scounter \scache\s(?Penable) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server counter cache enable", "result": { "counter": { "cache": { "enable": "{{ True if enable is defined else None }}", - } - } + }, + }, }, }, { @@ -193,14 +189,15 @@ def __init__(self, lines=None, module=None): ^snmp-server \scounter \scache\stimeout\s(?P\d+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server counter cache timeout {{ counter.cache.timeout }}", "result": { "counter": { "cache": { "timeout": "{{ timeout }}", - } - } + }, + }, }, }, { @@ -209,12 +206,13 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server\sdrop \s(?Punknown-engine-id) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server drop unknown-engine-id", "result": { "drop": { "unknown_engine_id": "{{ not not unknown_engine_id }}", - } + }, }, }, { @@ -223,12 +221,13 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server\sdrop \s(?Punknown-user) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server drop unknown-user", "result": { "drop": { "unknown_user": "{{ not not unknown_user }}", - } + }, }, }, { @@ -237,15 +236,16 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server\senable \straps\saaa\s(?Pserver-state-change) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps aaa" "{{ ' server-state-change' if traps.aaa.server_state_change|d(False) else ''}}", "result": { "traps": { "aaa": { "server_state_change": "{{ not not server_state_change }}", - } - } + }, + }, }, }, { @@ -254,14 +254,15 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server\senable \straps\s(?Pbgp) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps bgp", "result": { "traps": { "bgp": { "enable": "{{ not not enable }}", - } - } + }, + }, }, }, { @@ -271,14 +272,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \sbridge\s(?Pnewroot) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps bridge newroot", "result": { "traps": { "bridge": { "newroot": "{{ not not newroot }}", - } - } + }, + }, }, }, { @@ -288,14 +290,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \sbridge\s(?Ptopologychange) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps bridge topologychange", "result": { "traps": { "bridge": { "topologychange": "{{ not not topologychange }}", - } - } + }, + }, }, }, { @@ -305,14 +308,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \scallhome\s(?Pevent-notify) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps callhome event-notify", "result": { "traps": { "callhome": { "event_notify": "{{ not not event_notify }}", - } - } + }, + }, }, }, { @@ -322,14 +326,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \scallhome\s(?Psmtp-send-fail) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps callhome smtp-send-fail", "result": { "traps": { "callhome": { "smtp_send_fail": "{{ not not smtp_send_fail }}", - } - } + }, + }, }, }, { @@ -339,14 +344,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \scfs\s(?Pmerge-failure) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps cfs merge-failure", "result": { "traps": { "cfs": { "merge_failure": "{{ not not merge_failure }}", - } - } + }, + }, }, }, { @@ -356,14 +362,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \scfs\s(?Pstate-change-notif) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps cfs state-change-notif", "result": { "traps": { "cfs": { "state_change_notif": "{{ not not state_change_notif }}", - } - } + }, + }, }, }, { @@ -373,14 +380,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \sconfig\s(?PccmCLIRunningConfigChanged) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps config ccmCLIRunningConfigChanged", "result": { "traps": { "config": { "ccmCLIRunningConfigChanged": "{{ not not ccmCLIRunningConfigChanged }}", - } - } + }, + }, }, }, { @@ -390,14 +398,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \sentity\s(?PcefcMIBEnableStatusNotification) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps entity cefcMIBEnableStatusNotification", "result": { "traps": { "entity": { "cefcMIBEnableStatusNotification": "{{ not not cefcMIBEnableStatusNotification }}", - } - } + }, + }, }, }, { @@ -407,14 +416,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \sentity\s(?Pentity-fan-status-change) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps entity entity-fan-status-change", "result": { "traps": { "entity": { "entity_fan_status_change": "{{ not not entity_fan_status_change }}", - } - } + }, + }, }, }, { @@ -424,14 +434,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \sentity\s(?Pentity-mib-change) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps entity entity-mib-change", "result": { "traps": { "entity": { "entity_mib_change": "{{ not not entity_mib_change }}", - } - } + }, + }, }, }, { @@ -441,14 +452,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \sentity\s(?Pentity-module-inserted) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps entity entity-module-inserted", "result": { "traps": { "entity": { "entity_module_inserted": "{{ not not entity_module_inserted }}", - } - } + }, + }, }, }, { @@ -458,14 +470,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \sentity\s(?Pentity-module-status-change) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps entity entity-module-status-change", "result": { "traps": { "entity": { "entity_module_status_change": "{{ not not entity_module_status_change }}", - } - } + }, + }, }, }, { @@ -475,14 +488,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \sentity\s(?Pentity-power-out-change) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps entity entity-power-out-change", "result": { "traps": { "entity": { "entity_power_out_change": "{{ not not entity_power_out_change }}", - } - } + }, + }, }, }, { @@ -492,14 +506,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \sentity\s(?Pentity_power_status_change) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps entity entity-power-status-change", "result": { "traps": { "entity": { "entity_power_status_change": "{{ not not entity_power_status_change }}", - } - } + }, + }, }, }, { @@ -509,14 +524,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \sentity\s(?Pentity-sensor) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps entity entity-sensor", "result": { "traps": { "entity": { "entity_sensor": "{{ not not entity_sensor }}", - } - } + }, + }, }, }, { @@ -526,14 +542,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \sentity\s(?Pentity-unrecognised-module) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps entity entity-unrecognised-module", "result": { "traps": { "entity": { "entity_unrecognised_module": "{{ not not entity_unrecognised_module }}", - } - } + }, + }, }, }, { @@ -543,14 +560,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \sfeature-control\s(?PfeatureOpStatusChange) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps feature-control featureOpStatusChange", "result": { "traps": { "feature_control": { "featureOpStatusChange": "{{ not not featureOpStatusChange }}", - } - } + }, + }, }, }, { @@ -560,14 +578,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \sfeature-control\s(?PciscoFeatOpStatusChange) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps feature-control ciscoFeatOpStatusChange", "result": { "traps": { "feature_control": { "ciscoFeatOpStatusChange": "{{ not not ciscoFeatOpStatusChange }}", - } - } + }, + }, }, }, { @@ -577,14 +596,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \sgeneric\s(?PcoldStart) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps generic coldStart", "result": { "traps": { "generic": { "coldStart": "{{ not not coldStart }}", - } - } + }, + }, }, }, { @@ -594,14 +614,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \sgeneric\s(?PwarmStart) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps generic warmStart", "result": { "traps": { "generic": { "warmStart": "{{ not not warmStart }}", - } - } + }, + }, }, }, { @@ -611,14 +632,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \slicense\s(?Pnotify_license_expiry) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps license notify-license-expiry", "result": { "traps": { "license": { "notify_license_expiry": "{{ not not notify_license_expiry }}", - } - } + }, + }, }, }, { @@ -628,14 +650,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \slicense\s(?Pnotify-license-expiry-warning) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps license notify-license-expiry-warning", "result": { "traps": { "license": { "notify_license_expiry_warning": "{{ not not notify_license_expiry_warning }}", - } - } + }, + }, }, }, { @@ -645,14 +668,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \slicense\s(?Pnotify-licensefile-missing) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps license notify-licensefile-missing", "result": { "traps": { "license": { "notify_licensefile_missing": "{{ not not notify_licensefile_missing }}", - } - } + }, + }, }, }, { @@ -662,14 +686,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \slicense\s(?Pnotify-no-license-for-feature) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps license notify-no-license-for-feature", "result": { "traps": { "license": { "notify_no_license_for_feature": "{{ not not notify_no_license_for_feature }}", - } - } + }, + }, }, }, { @@ -679,14 +704,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \slink\s(?PcErrDisableInterfaceEventRev1) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps link cErrDisableInterfaceEventRev1", "result": { "traps": { "link": { "cErrDisableInterfaceEventRev1": "{{ not not cErrDisableInterfaceEventRev1 }}", - } - } + }, + }, }, }, { @@ -696,14 +722,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \slink\s(?PcieLinkDown) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps link cieLinkDown", "result": { "traps": { "link": { "cieLinkDown": "{{ not not cieLinkDown }}", - } - } + }, + }, }, }, { @@ -713,14 +740,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \slink\s(?PcieLinkUp) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps link cieLinkUp", "result": { "traps": { "link": { "cieLinkUp": "{{ not not cieLinkUp }}", - } - } + }, + }, }, }, { @@ -730,14 +758,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \slink\s(?Pcisco-xcvr-mon-status-chg) - $""", re.VERBOSE), - "setval": "snmp-server enable traps link cisco_xcvr_mon_status_chg", + $""", re.VERBOSE, + ), + "setval": "snmp-server enable traps link cisco-xcvr-mon-status-chg", "result": { "traps": { "link": { "cisco_xcvr_mon_status_chg": "{{ not not cisco_xcvr_mon_status_chg }}", - } - } + }, + }, }, }, { @@ -747,14 +776,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \slink\s(?Pcmn-mac-move-notification) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps link cmn-mac-move-notification", "result": { "traps": { "link": { "cmn_mac_move_notification": "{{ not not cmn_mac_move_notification }}", - } - } + }, + }, }, }, { @@ -764,14 +794,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \slink\s(?Pdelayed-link-state-change) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps link delayed-link-state-change", "result": { "traps": { "link": { "delayed_link_state_change": "{{ not not delayed_link_state_change }}", - } - } + }, + }, }, }, { @@ -781,14 +812,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \slink\s(?Pextended-linkDown) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps link extended-linkDown", "result": { "traps": { "link": { "extended_linkDown": "{{ not not extended_linkDown }}", - } - } + }, + }, }, }, { @@ -798,14 +830,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \slink\s(?Pextended-linkUp) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps link extended-linkUp", "result": { "traps": { "link": { "extended_linkUp": "{{ not not extended_linkUp }}", - } - } + }, + }, }, }, { @@ -815,14 +848,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \slink\s(?PlinkDown) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps link linkDown", "result": { "traps": { "link": { "linkDown": "{{ not not linkDown }}", - } - } + }, + }, }, }, { @@ -832,14 +866,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \slink\s(?PlinkUp) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps link linkUp", "result": { "traps": { "link": { "linkUp": "{{ not not linkUp }}", - } - } + }, + }, }, }, { @@ -849,14 +884,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \smmode\s(?PcseMaintModeChangeNotify) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps mmode cseMaintModeChangeNotify", "result": { "traps": { "mmode": { "cseMaintModeChangeNotify": "{{ not not cseMaintModeChangeNotify }}", - } - } + }, + }, }, }, { @@ -866,14 +902,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \smmode\s(?PcseNormalModeChangeNotify) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps mmode cseNormalModeChangeNotify", "result": { "traps": { "mmode": { "cseNormalModeChangeNotify": "{{ not not cseNormalModeChangeNotify }}", - } - } + }, + }, }, }, { @@ -882,14 +919,15 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server\senable \straps\s(?Pospf) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps ospf", "result": { "traps": { "ospf": { "enable": "{{ not not enable }}", - } - } + }, + }, }, }, { @@ -898,14 +936,15 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server\senable \straps\s(?Pospfv3) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps ospfv3", "result": { "traps": { "ospfv3": { "enable": "{{ not not enable }}", - } - } + }, + }, }, }, { @@ -915,14 +954,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \srf\s(?Predundancy-framework) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps rf redundancy-framework", "result": { "traps": { "rf": { "redundancy_framework": "{{ not not redundancy_framework }}", - } - } + }, + }, }, }, { @@ -932,14 +972,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \srmon\s(?PfallingAlarm) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps rmon fallingAlarm", "result": { "traps": { "rmon": { "fallingAlarm": "{{ not not fallingAlarm }}", - } - } + }, + }, }, }, { @@ -949,14 +990,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \srmon\s(?PhcFallingAlarm) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps rmon hcFallingAlarm", "result": { "traps": { "rmon": { "hcFallingAlarm": "{{ not not hcFallingAlarm }}", - } - } + }, + }, }, }, { @@ -966,14 +1008,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \srmon\s(?PhcRisingAlarm) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps rmon hcRisingAlarm", "result": { "traps": { "rmon": { "hcRisingAlarm": "{{ not not hcRisingAlarm }}", - } - } + }, + }, }, }, { @@ -983,14 +1026,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \srmon\s(?PrisingAlarm) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps rmon risingAlarm", "result": { "traps": { "rmon": { "risingAlarm": "{{ not not risingAlarm }}", - } - } + }, + }, }, }, { @@ -1000,14 +1044,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \ssnmp\s(?Pauthentication) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps snmp authentication", "result": { "traps": { "snmp": { "authentication": "{{ not not authentication }}", - } - } + }, + }, }, }, { @@ -1017,14 +1062,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \sstorm-control\s(?PcpscEventRev1) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps storm-control cpscEventRev1", "result": { "traps": { "storm_control": { "cpscEventRev1n": "{{ not not cpscEventRev1 }}", - } - } + }, + }, }, }, { @@ -1034,14 +1080,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \sstorm-control\s(?Ptrap-rate) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps storm-control trap-rate", "result": { "traps": { "storm_control": { "trap_rate": "{{ not not trap_rate }}", - } - } + }, + }, }, }, { @@ -1051,14 +1098,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \sstpx\s(?Pinconsistency) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps stpx inconsistency", "result": { "traps": { "stpx": { "inconsistency": "{{ not not inconsistency }}", - } - } + }, + }, }, }, { @@ -1068,14 +1116,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \sstpx\s(?Proot-inconsistency) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps stpx root-inconsistency", "result": { "traps": { "stpx": { "root_inconsistency": "{{ not not root_inconsistency }}", - } - } + }, + }, }, }, { @@ -1085,14 +1134,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \sstpx\s(?Ploop-inconsistency) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps stpx loop-inconsistency", "result": { "traps": { "stpx": { "loop_inconsistency": "{{ not not loop_inconsistency }}", - } - } + }, + }, }, }, { @@ -1102,14 +1152,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \ssyslog\s(?Pmessage-generated) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps syslog message-generated", "result": { "traps": { "syslog": { "message_generated": "{{ not not message_generated }}", - } - } + }, + }, }, }, { @@ -1119,14 +1170,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \ssysmgr\s(?PcseFailSwCoreNotifyExtended) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps sysmgr cseFailSwCoreNotifyExtended", "result": { "traps": { "sysmgr": { "cseFailSwCoreNotifyExtended": "{{ not not cseFailSwCoreNotifyExtended }}", - } - } + }, + }, }, }, { @@ -1136,14 +1188,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \ssystem\s(?PClock-change-notification) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps system Clock-change-notification", "result": { "traps": { "system": { "clock_change_notification": "{{ not not clock_change_notification }}", - } - } + }, + }, }, }, { @@ -1153,14 +1206,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \supgrade\s(?PupgradeJobStatusNotify) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps upgrade upgradeJobStatusNotify", "result": { "traps": { "upgrade": { "upgradeJobStatusNotify": "{{ not not upgradeJobStatusNotify }}", - } - } + }, + }, }, }, { @@ -1170,14 +1224,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \supgrade\s(?PupgradeOpNotifyOnCompletion) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps upgrade upgradeOpNotifyOnCompletion", "result": { "traps": { "upgrade": { "upgradeOpNotifyOnCompletion": "{{ not not upgradeOpNotifyOnCompletion }}", - } - } + }, + }, }, }, { @@ -1187,14 +1242,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \svtp\s(?Pnotifs) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps vtp notifs", "result": { "traps": { "vtp": { "notifs": "{{ not not notifs }}", - } - } + }, + }, }, }, { @@ -1204,14 +1260,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \svtp\s(?Pvlancreate) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps vtp vlancreate", "result": { "traps": { "vtp": { "vlancreate": "{{ not not vlancreate }}", - } - } + }, + }, }, }, { @@ -1221,14 +1278,15 @@ def __init__(self, lines=None, module=None): ^snmp-server\senable \straps \svtp\s(?Pvlandelete) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server enable traps vtp vlandelete", "result": { "traps": { "vtp": { "vlandelete": "{{ not not vlandelete }}", - } - } + }, + }, }, }, @@ -1238,12 +1296,13 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server\sengineID \slocal\s(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server engineID local {{ engine_id.local }}", "result": { "engine_id": { "local": "{{ local }}", - } + }, }, }, { @@ -1252,7 +1311,8 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server \s(?PglobalEnforcePriv) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server globalEnforcePriv", "result": { "global_enforce_priv": "{{ not not global_enforce_priv }}", @@ -1268,7 +1328,8 @@ def __init__(self, lines=None, module=None): (\sversion\s(?P\S+))? (\s((auth\s(?P\S+))|(priv\s(?P\S+))|((?P\S+))))? (\sudp-port\s(?P\S+))? - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": _template_hosts, "result": { "hosts": [ @@ -1284,8 +1345,8 @@ def __init__(self, lines=None, module=None): "udp_port": "{{ udp_port }}", "auth": "{{ auth }}", "priv": "{{ priv }}", - } - ] + }, + ], }, }, { @@ -1294,11 +1355,12 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server \slocation\s(?P.+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server location {{ location }}", "result": { "location": "{{ location }}", - } + }, }, { "name": "mib.community_map", @@ -1308,7 +1370,8 @@ def __init__(self, lines=None, module=None): \smib \scommunity-map\s(?P\S+) \scontext\s(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server mib community-map {{ mib.community_map.community }} context {{ mib.community_map.context }}", "result": { "mib": { @@ -1316,9 +1379,9 @@ def __init__(self, lines=None, module=None): "community": "{{ community }}", "context": "{{ context }}", - } - } - } + }, + }, + }, }, { "name": "packetsize", @@ -1326,11 +1389,12 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server \spacketsize\s(?P\d+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server packetsize {{ packetsize }}", "result": { "packetsize": "{{ packetsize }}", - } + }, }, { "name": "protocol.enable", @@ -1338,13 +1402,14 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server \sprotocol\s(?Penable) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server protocol enable", "result": { "protocol": { "enable": "{{ not not enable }}", - } - } + }, + }, }, { "name": "source_interface.informs", @@ -1352,13 +1417,14 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server \ssource-interface\sinforms\s(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server source-interface informs {{ source_interface.informs }}", "result": { "source_interface": { "informs": "{{ informs }}", - } - } + }, + }, }, { "name": "source_interface.traps", @@ -1366,13 +1432,14 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server \ssource-interface\straps\s(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server source-interface traps {{ source_interface.traps }}", "result": { "source_interface": { "traps": "{{ traps }}", - } - } + }, + }, }, { "name": "system_shutdown", @@ -1380,11 +1447,12 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server \s(?Psystem-shutdown) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server system-shutdown", "result": { "system_shutdown": "{{ not not system_shutdown }}", - } + }, }, { "name": "tcp_session", @@ -1393,15 +1461,16 @@ def __init__(self, lines=None, module=None): ^snmp-server \s(?Ptcp-session) (\s(?Pauth))? - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server tcp-session" "{{ ' auth' if tcp_session.auth|d(False) else '' }}", "result": { "tcp_session": { "enable": "{{ True if tcp_session is defined and auth is not defined else None }}", "auth": "{{ not not auth }}", - } - } + }, + }, }, { "name": "users.auth", @@ -1410,12 +1479,15 @@ def __init__(self, lines=None, module=None): ^snmp-server \suser\s(?P\S+) (\s(?P[^auth]\S+))? - (\sauth\s(?Pmd5|sha)\s(?P\S+))? + (\sauth\s(?Pmd5|sha|sha-256)\s(?P\S+))? (\spriv(\s(?Paes-128))?\s(?P\S+))? (\s(?Plocalizedkey))? + (\s(?PlocalizedV2key))? (\sengineID\s(?P\S+))? - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": _tmplt_users_auth, + "remval": "snmp-server user {{ user }}", "result": { "users": { "auth": [ @@ -1427,16 +1499,16 @@ def __init__(self, lines=None, module=None): "password": "'{{ password }}'", "engine_id": "'{{ engine_id }}'", "localized_key": "{{ not not localized_key }}", + "localizedv2_key": "{{ not not localizedv2_key }}", "priv": { "privacy_password": "'{{ privacy_password }}'", "aes_128": "{{ not not aes_128 }}", - } - } - - } - ] - } - } + }, + }, + }, + ], + }, + }, }, { "name": "users.use_acls", @@ -1446,7 +1518,8 @@ def __init__(self, lines=None, module=None): \suser\s(?P\S+) (\suse-ipv4acl\s(?P\S+))? (\suse-ipv6acl\s(?P\S+))? - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "snmp-server user {{ user }}" "{{ (' use-ipv4acl ' + ipv4) if ipv4 is defined else '' }}" "{{ (' use-ipv6acl ' + ipv6) if ipv6 is defined else '' }}", @@ -1457,10 +1530,10 @@ def __init__(self, lines=None, module=None): "user": "{{ user }}", "ipv4": "{{ ipv4 }}", "ipv6": "{{ ipv6 }}", - } - ] - } - } + }, + ], + }, + }, }, ] # fmt: on diff --git a/plugins/module_utils/network/nxos/rm_templates/static_routes.py b/plugins/module_utils/network/nxos/rm_templates/static_routes.py new file mode 100644 index 000000000..a70bc4130 --- /dev/null +++ b/plugins/module_utils/network/nxos/rm_templates/static_routes.py @@ -0,0 +1,126 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 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 + +""" +The Static_routes parser templates file. This contains +a list of parser definitions and associated functions that +facilitates both facts gathering and native command generation for +the given network resource. +""" + +import re + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( + NetworkTemplate, +) + + +class Static_routesTemplate(NetworkTemplate): + def __init__(self, lines=None, module=None): + super(Static_routesTemplate, self).__init__(lines=lines, tmplt=self, module=module) + + # fmt: off + PARSERS = [ + # this parser shared the vrf context names with routes + { + 'name': 'vrf', + 'getval': re.compile( + r''' + ^vrf\scontext\s(?P\S+)$ + ''', re.VERBOSE, + ), + 'setval': 'vrf context {{ namevrf }}', + 'result': {}, + 'shared': True, + }, + { + "name": "ipv4", + "getval": re.compile( + r""" + (^|\s+)ip\sroute + (\s(?P\S+)) + (\s(?P(Ethernet|loopback|mgmt|Null|port-channel)\S+))? + (\s(?P\S+))? + (\svrf\s(?P\S+))? + (\sname\s(?P\S+))? + (\stag\s(?P\d+))? + (\strack\s(?P\d+))? + (\s(?P\d+))? + $""", re.VERBOSE, + ), + "setval": "ip route" + "{{ (' ' + ipv4.dest) if ipv4.dest is defined else '' }}" + "{{ (' ' + ipv4.interface) if ipv4.interface is defined else '' }}" + "{{ (' ' + ipv4.forward_router_address) if ipv4.forward_router_address is defined else '' }}" + "{{ (' vrf ' + ipv4.dest_vrf) if ipv4.dest_vrf is defined else '' }}" + "{{ (' name ' + ipv4.route_name) if ipv4.route_name is defined else '' }}" + "{{ (' tag ' + ipv4.tag|string) if ipv4.tag is defined else '' }}" + "{{ (' track ' + ipv4.track|string) if ipv4.track is defined else '' }}" + "{{ (' ' + ipv4.admin_distance|string) if ipv4.admin_distance is defined else '' }}", + "result": { + "{{ dest }}_{{ namevrf|d() }}_ipv4": [ + { + "_vrf": "{{ namevrf }}", + "_afi": "ipv4", + "_dest": "{{ dest }}", + "interface": "{{ interface }}", + "forward_router_address": "{{ forward_router_address }}", + "admin_distance": "{{ admin_distance }}", + "dest_vrf": "{{ dest_vrf }}", + "tag": "{{ tag }}", + "route_name": "{{ route_name }}", + "track": "{{ track }}", + }, + ], + }, + }, + { + "name": "ipv6", + "getval": re.compile( + r""" + (^|\s+)ipv6\sroute + (\s(?P\S+)) + (\s(?P(Ethernet|loopback|mgmt|Null|port-channel)\S+))? + (\s(?P\S+))? + (\svrf\s(?P\S+))? + (\sname\s(?P\S+))? + (\stag\s(?P\d+))? + (\strack\s(?P\d+))? + (\s(?P\d+))? + $""", re.VERBOSE, + ), + "setval": "ipv6 route" + "{{ (' ' + ipv6.dest) if ipv6.dest is defined else '' }}" + "{{ (' ' + ipv6.interface) if ipv6.interface is defined else '' }}" + "{{ (' ' + ipv6.forward_router_address) if ipv6.forward_router_address is defined else '' }}" + "{{ (' vrf ' + ipv6.dest_vrf) if ipv6.dest_vrf is defined else '' }}" + "{{ (' name ' + ipv6.route_name) if ipv6.route_name is defined else '' }}" + "{{ (' tag ' + ipv6.tag|string) if ipv6.tag is defined else '' }}" + "{{ (' track ' + ipv6.track|string) if ipv6.track is defined else '' }}" + "{{ (' ' + ipv6.admin_distance|string) if ipv6.admin_distance is defined else '' }}", + "result": { + "{{ dest }}_{{ namevrf|d() }}_ipv6": [ + { + "_vrf": "{{ namevrf }}", + "_afi": "ipv6", + "_dest": "{{ dest }}", + "interface": "{{ interface }}", + "forward_router_address": "{{ forward_router_address }}", + "admin_distance": "{{ admin_distance }}", + "dest_vrf": "{{ dest_vrf }}", + "tag": "{{ tag }}", + "route_name": "{{ route_name }}", + "track": "{{ track }}", + }, + ], + }, + }, + ] + # fmt: on diff --git a/plugins/module_utils/network/nxos/utils/telemetry/telemetry.py b/plugins/module_utils/network/nxos/utils/telemetry/telemetry.py index 1a270fead..aa540aded 100644 --- a/plugins/module_utils/network/nxos/utils/telemetry/telemetry.py +++ b/plugins/module_utils/network/nxos/utils/telemetry/telemetry.py @@ -8,9 +8,11 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type import re + from copy import deepcopy @@ -59,16 +61,16 @@ def valiate_input(playvals, type, module): msg = "Invalid playbook value: {0}.".format(playvals) msg += " Parameter under is required" module.fail_json(msg=msg) - if playvals.get("destination") and not isinstance( - playvals["destination"], dict - ): + if playvals.get("destination") and not isinstance(playvals["destination"], dict): msg = "Invalid playbook value: {0}.".format(playvals) msg += " Parameter under must be a dict" module.fail_json(msg=msg) if not playvals.get("destination") and len(playvals) > 1: msg = "Invalid playbook value: {0}.".format(playvals) msg += " Playbook entry contains unrecongnized parameters." - msg += " Make sure keys under are specified as follows:" + msg += ( + " Make sure keys under are specified as follows:" + ) msg += " destination: {ip: , port: , protocol: , encoding: }}" module.fail_json(msg=msg) @@ -79,9 +81,7 @@ def valiate_input(playvals, type, module): module.fail_json(msg=msg) if playvals.get("path") and "name" not in playvals["path"].keys(): msg = "Invalid playbook value: {0}.".format(playvals) - msg += ( - " Parameter under requires key" - ) + msg += " Parameter under requires key" module.fail_json(msg=msg) @@ -97,9 +97,9 @@ def get_instance_data(key, cr_key, cr, existing_key): instance = cr._ref[cr_key]["existing"][existing_key] patterns = { - "destination_groups": r"destination-group (\d+)", - "sensor_groups": r"sensor-group (\d+)", - "subscriptions": r"subscription (\d+)", + "destination_groups": r"destination-group (\S+)", + "sensor_groups": r"sensor-group (\S+)", + "subscriptions": r"subscription (\S+)", } if key in patterns.keys(): m = re.search(patterns[key], cr._ref["_resource_key"]) @@ -147,9 +147,7 @@ def remove_duplicate_context(cmds): """Helper method to remove duplicate telemetry context commands""" if not cmds: return cmds - feature_indices = [ - i for i, x in enumerate(cmds) if x == "feature telemetry" - ] + feature_indices = [i for i, x in enumerate(cmds) if x == "feature telemetry"] telemetry_indices = [i for i, x in enumerate(cmds) if x == "telemetry"] if len(feature_indices) == 1 and len(telemetry_indices) == 1: return cmds @@ -179,9 +177,7 @@ def get_setval_path(module_or_path_data): if isinstance(module_or_path_data, dict): path = module_or_path_data else: - path = module_or_path_data.params["config"]["sensor_groups"][0].get( - "path" - ) + path = module_or_path_data.params["config"]["sensor_groups"][0].get("path") if path is None: return path @@ -226,17 +222,11 @@ def massage_data(have_or_want): else: if item.get("destination"): if item.get("destination").get("port"): - item["destination"]["port"] = str( - item["destination"]["port"] - ) + item["destination"]["port"] = str(item["destination"]["port"]) if item.get("destination").get("protocol"): - item["destination"]["protocol"] = item["destination"][ - "protocol" - ].lower() + item["destination"]["protocol"] = item["destination"]["protocol"].lower() if item.get("destination").get("encoding"): - item["destination"]["encoding"] = item["destination"][ - "encoding" - ].lower() + item["destination"]["encoding"] = item["destination"]["encoding"].lower() if item.get("path"): for key in [ "filter_condition", @@ -251,12 +241,10 @@ def massage_data(have_or_want): item["destination_group"] = str(item["destination_group"]) if item.get("sensor_group"): if item.get("sensor_group").get("id"): - item["sensor_group"]["id"] = str( - item["sensor_group"]["id"] - ) + item["sensor_group"]["id"] = str(item["sensor_group"]["id"]) if item.get("sensor_group").get("sample_interval"): item["sensor_group"]["sample_interval"] = str( - item["sensor_group"]["sample_interval"] + item["sensor_group"]["sample_interval"], ) if item.get("destination_group") and item.get("sensor_group"): item_copy = deepcopy(item) diff --git a/plugins/module_utils/network/nxos/utils/utils.py b/plugins/module_utils/network/nxos/utils/utils.py index 1c2610b8b..01468edd5 100644 --- a/plugins/module_utils/network/nxos/utils/utils.py +++ b/plugins/module_utils/network/nxos/utils/utils.py @@ -1,12 +1,15 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type import socket -from itertools import groupby, count from functools import total_ordering +from itertools import count, groupby + from ansible.module_utils.six import iteritems + LOGGING_SEVMAP = { 0: "emergency", 1: "alert", @@ -121,9 +124,7 @@ def remove_rsvd_interfaces(interfaces): """Exclude reserved interfaces from user management""" if not interfaces: return [] - return [ - i for i in interfaces if get_interface_type(i["name"]) != "management" - ] + return [i for i in interfaces if get_interface_type(i["name"]) != "management"] def vlan_range_to_list(vlans): diff --git a/plugins/modules/nxos_aaa_server.py b/plugins/modules/nxos_aaa_server.py index 98f747afe..9103f931f 100644 --- a/plugins/modules/nxos_aaa_server.py +++ b/plugins/modules/nxos_aaa_server.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -124,14 +125,12 @@ """ import re +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule PARAM_TO_DEFAULT_KEYMAP = { @@ -207,9 +206,7 @@ def config_aaa_server(params, server_type): cmds.append("{0}-server deadtime {1}".format(server_type, deadtime)) if server_timeout is not None: - cmds.append( - "{0}-server timeout {1}".format(server_type, server_timeout) - ) + cmds.append("{0}-server timeout {1}".format(server_type, server_timeout)) if directed_request is not None: if directed_request == "enabled": @@ -218,11 +215,7 @@ def config_aaa_server(params, server_type): cmds.append("no {0}-server directed-request".format(server_type)) if global_key is not None: - cmds.append( - "{0}-server key {1} {2}".format( - server_type, encrypt_type, global_key - ) - ) + cmds.append("{0}-server key {1} {2}".format(server_type, encrypt_type, global_key)) return cmds @@ -236,54 +229,39 @@ def default_aaa_server(existing, params, server_type): global_key = params.get("global_key") existing_key = existing.get("global_key") - if ( - deadtime is not None - and existing.get("deadtime") != PARAM_TO_DEFAULT_KEYMAP["deadtime"] - ): + if deadtime is not None and existing.get("deadtime") != PARAM_TO_DEFAULT_KEYMAP["deadtime"]: cmds.append("no {0}-server deadtime 1".format(server_type)) if ( server_timeout is not None - and existing.get("server_timeout") - != PARAM_TO_DEFAULT_KEYMAP["server_timeout"] + and existing.get("server_timeout") != PARAM_TO_DEFAULT_KEYMAP["server_timeout"] ): cmds.append("no {0}-server timeout 1".format(server_type)) if ( directed_request is not None - and existing.get("directed_request") - != PARAM_TO_DEFAULT_KEYMAP["directed_request"] + and existing.get("directed_request") != PARAM_TO_DEFAULT_KEYMAP["directed_request"] ): cmds.append("no {0}-server directed-request".format(server_type)) if global_key is not None and existing_key is not None: - cmds.append( - "no {0}-server key 7 {1}".format(server_type, existing_key) - ) + cmds.append("no {0}-server key 7 {1}".format(server_type, existing_key)) return cmds def main(): argument_spec = dict( - server_type=dict( - type="str", choices=["radius", "tacacs"], required=True - ), + server_type=dict(type="str", choices=["radius", "tacacs"], required=True), global_key=dict(type="str", no_log=True), encrypt_type=dict(type="str", choices=["0", "7"]), deadtime=dict(type="str"), server_timeout=dict(type="str"), - directed_request=dict( - type="str", choices=["enabled", "disabled", "default"] - ), + directed_request=dict(type="str", choices=["enabled", "disabled", "default"]), state=dict(choices=["default", "present"], default="present"), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() results = {"changed": False, "commands": [], "warnings": warnings} @@ -319,18 +297,14 @@ def main(): if int(deadtime) < 0 or int(deadtime) > 1440: raise ValueError except ValueError: - module.fail_json( - msg="deadtime must be an integer between 0 and 1440" - ) + module.fail_json(msg="deadtime must be an integer between 0 and 1440") if server_timeout: try: if int(server_timeout) < 1 or int(server_timeout) > 60: raise ValueError except ValueError: - module.fail_json( - msg="server_timeout must be an integer between 1 and 60" - ) + module.fail_json(msg="server_timeout must be an integer between 1 and 60") delta = dict(set(proposed.items()).difference(existing.items())) if delta: @@ -341,10 +315,7 @@ def main(): elif state == "default": for key, value in proposed.items(): if key != "server_type" and value != "default": - module.fail_json( - msg='Parameters must be set to "default"' - "when state=default" - ) + module.fail_json(msg='Parameters must be set to "default"' "when state=default") command = default_aaa_server(existing, proposed, server_type) if command: commands.append(command) diff --git a/plugins/modules/nxos_aaa_server_host.py b/plugins/modules/nxos_aaa_server_host.py index 96a9d49a4..192b21ab5 100644 --- a/plugins/modules/nxos_aaa_server_host.py +++ b/plugins/modules/nxos_aaa_server_host.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -113,7 +114,6 @@ tacacs_port: 89 host_timeout: 10 address: 5.6.7.8 - """ RETURN = """ @@ -148,15 +148,13 @@ """ import re +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + get_capabilities, load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_capabilities, - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule def execute_show_command(command, module): @@ -199,24 +197,19 @@ def get_aaa_host_info(module, server_type, address): match = re.search(pattern, body) aaa_host_info["key"] = match.group(1) if aaa_host_info["key"]: - aaa_host_info["key"] = aaa_host_info["key"].replace( - '"', "" - ) + aaa_host_info["key"] = aaa_host_info["key"].replace('"', "") aaa_host_info["encrypt_type"] = "7" aaa_host_info["auth_port"] = match.group(2) aaa_host_info["acct_port"] = match.group(3) aaa_host_info["host_timeout"] = match.group(4) elif "tacacs" in body: pattern = ( - r"\S+ host \S+(?:\s+key 7\s+(\S+))?(?:\s+port (\d+))?" - r"(?:\s+timeout (\d+))?" + r"\S+ host \S+(?:\s+key 7\s+(\S+))?(?:\s+port (\d+))?(?:\s+timeout (\d+))?" ) match = re.search(pattern, body) aaa_host_info["key"] = match.group(1) if aaa_host_info["key"]: - aaa_host_info["key"] = aaa_host_info["key"].replace( - '"', "" - ) + aaa_host_info["key"] = aaa_host_info["key"].replace('"', "") aaa_host_info["encrypt_type"] = "7" aaa_host_info["tacacs_port"] = match.group(2) aaa_host_info["host_timeout"] = match.group(3) @@ -286,11 +279,7 @@ def main(): state=dict(choices=["absent", "present"], default="present"), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() @@ -322,14 +311,11 @@ def main(): module.fail_json(msg="encrypt_type must be used with key") if tacacs_port and server_type != "tacacs": - module.fail_json( - msg="tacacs_port can only be used with server_type=tacacs" - ) + module.fail_json(msg="tacacs_port can only be used with server_type=tacacs") if (auth_port or acct_port) and server_type != "radius": module.fail_json( - msg="auth_port and acct_port can only be used" - "when server_type=radius" + msg="auth_port and acct_port can only be used" "when server_type=radius", ) existing = get_aaa_host_info(module, server_type, address) @@ -356,7 +342,8 @@ def main(): intersect = dict(set(proposed.items()).intersection(existing.items())) if intersect.get("address") and intersect.get("server_type"): command = "no {0}-server host {1}".format( - intersect.get("server_type"), intersect.get("address") + intersect.get("server_type"), + intersect.get("address"), ) commands.append(command) diff --git a/plugins/modules/nxos_acl.py b/plugins/modules/nxos_acl.py deleted file mode 100644 index 36c88f909..000000000 --- a/plugins/modules/nxos_acl.py +++ /dev/null @@ -1,699 +0,0 @@ -#!/usr/bin/python -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - - -DOCUMENTATION = """ -module: nxos_acl -extends_documentation_fragment: -- cisco.nxos.nxos -short_description: (deprecated, removed after 2022-06-01) Manages access - list entries for ACLs. -description: -- Manages access list entries for ACLs. -version_added: 1.0.0 -author: -- Jason Edelman (@jedelman8) -- Gabriele Gerbino (@GGabriele) -deprecated: - alternative: nxos_acls - why: Updated modules released with more functionality - removed_at_date: '2022-06-01' -notes: -- Tested against NXOSv 7.3.(0)D1(1) on VIRL -- Unsupported for Cisco MDS -- C(state=absent) removes the ACE if it exists. -- C(state=delete_acl) deletes the ACL if it exists. -- For idempotency, use port numbers for the src/dest port params like I(src_port1) - and names for the well defined protocols for the I(proto) param. -- Although this module is idempotent in that if the ace as presented in the task is - identical to the one on the switch, no changes will be made. If there is any difference, - what is in Ansible will be pushed (configured options will be overridden). This - is to improve security, but at the same time remember an ACE is removed, then re-added, - so if there is a change, the new ACE will be exactly what parameters you are sending - to the module. -options: - seq: - description: - - Sequence number of the entry (ACE). - type: str - name: - description: - - Case sensitive name of the access list (ACL). - required: true - type: str - action: - description: - - Action of the ACE. - choices: - - permit - - deny - - remark - type: str - remark: - description: - - If action is set to remark, this is the description. - type: str - proto: - description: - - Port number or protocol (as supported by the switch). - type: str - src: - description: - - Source ip and mask using IP/MASK notation and supports keyword 'any'. - type: str - src_port_op: - description: - - Source port operands such as eq, neq, gt, lt, range. - choices: - - any - - eq - - gt - - lt - - neq - - range - type: str - src_port1: - description: - - Port/protocol and also first (lower) port when using range operand. - type: str - src_port2: - description: - - Second (end) port when using range operand. - type: str - dest: - description: - - Destination ip and mask using IP/MASK notation and supports the keyword 'any'. - type: str - dest_port_op: - description: - - Destination port operands such as eq, neq, gt, lt, range. - choices: - - any - - eq - - gt - - lt - - neq - - range - type: str - dest_port1: - description: - - Port/protocol and also first (lower) port when using range operand. - type: str - dest_port2: - description: - - Second (end) port when using range operand. - type: str - log: - description: - - Log matches against this entry. - choices: - - enable - type: str - urg: - description: - - Match on the URG bit. - choices: - - enable - type: str - ack: - description: - - Match on the ACK bit. - choices: - - enable - type: str - psh: - description: - - Match on the PSH bit. - choices: - - enable - type: str - rst: - description: - - Match on the RST bit. - choices: - - enable - type: str - syn: - description: - - Match on the SYN bit. - choices: - - enable - type: str - fin: - description: - - Match on the FIN bit. - choices: - - enable - type: str - established: - description: - - Match established connections. - choices: - - enable - type: str - fragments: - description: - - Check non-initial fragments. - choices: - - enable - type: str - time_range: - description: - - Name of time-range to apply. - type: str - precedence: - description: - - Match packets with given precedence. - choices: - - critical - - flash - - flash-override - - immediate - - internet - - network - - priority - - routine - type: str - dscp: - description: - - Match packets with given dscp value. - choices: - - af11 - - af12 - - af13 - - af21 - - af22 - - af23 - - af31 - - af32 - - af33 - - af41 - - af42 - - af43 - - cs1 - - cs2 - - cs3 - - cs4 - - cs5 - - cs6 - - cs7 - - default - - ef - type: str - state: - description: - - Specify desired state of the resource. - default: present - choices: - - present - - absent - - delete_acl - type: str - - -""" - -EXAMPLES = """ -# configure ACL ANSIBLE -- cisco.nxos.nxos_acl: - name: ANSIBLE - seq: 10 - action: permit - proto: tcp - src: 192.0.2.1/24 - dest: any - state: present -""" - -RETURN = """ -commands: - description: commands sent to the device - returned: always - type: list - sample: ["ip access-list ANSIBLE", "10 permit tcp 192.0.2.1/24 any"] -""" -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - load_config, - run_commands, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule - - -def execute_show_command(command, module, check_rc=True): - command += " | json" - cmds = [command] - body = run_commands(module, cmds, check_rc=check_rc) - return body - - -def get_acl(module, acl_name, seq_number): - command = "show ip access-list" - new_acl = [] - saveme = {} - acl_body = {} - - body = execute_show_command(command, module, check_rc=False) - if "Structured output unsupported" in repr(body): - # Some older versions raise 501 and return a string when no ACLs exist - return {}, [] - - if body and body[0]: - all_acl_body = body[0]["TABLE_ip_ipv6_mac"]["ROW_ip_ipv6_mac"] - else: - # no access-lists configured on the device - return {}, [] - - if isinstance(all_acl_body, dict): - # Only 1 ACL configured. - if all_acl_body.get("acl_name") == acl_name: - acl_body = all_acl_body - else: - for acl in all_acl_body: - if acl.get("acl_name") == acl_name: - acl_body = acl - break - - try: - acl_entries = acl_body["TABLE_seqno"]["ROW_seqno"] - acl_name = acl_body.get("acl_name") - except KeyError: # could be raised if no ACEs are configured for an ACL - return {}, [{"acl": "no_entries"}] - - if isinstance(acl_entries, dict): - acl_entries = [acl_entries] - - for each in acl_entries: - temp = {} - options = {} - remark = each.get("remark") - - temp["name"] = acl_name - temp["seq"] = str(each.get("seqno")) - - if remark: - temp["remark"] = remark - temp["action"] = "remark" - else: - temp["action"] = each.get("permitdeny") - temp["proto"] = str( - each.get("proto", each.get("proto_str", each.get("ip"))) - ) - temp["src"] = each.get("src_any", each.get("src_ip_prefix")) - temp["src_port_op"] = each.get("src_port_op") - temp["src_port1"] = each.get("src_port1_num") - temp["src_port2"] = each.get("src_port2_num") - temp["dest"] = each.get("dest_any", each.get("dest_ip_prefix")) - temp["dest_port_op"] = each.get("dest_port_op") - temp["dest_port1"] = each.get("dest_port1_num") - temp["dest_port2"] = each.get("dest_port2_num") - - options["log"] = each.get("log") - options["urg"] = each.get("urg") - options["ack"] = each.get("ack") - options["psh"] = each.get("psh") - options["rst"] = each.get("rst") - options["syn"] = each.get("syn") - options["fin"] = each.get("fin") - options["established"] = each.get("established") - options["dscp"] = each.get("dscp_str") - options["precedence"] = each.get("precedence_str") - options["fragments"] = each.get("fragments") - options["time_range"] = each.get("timerange") - - keep = {} - for key, value in temp.items(): - if value: - keep[key] = value - - options_no_null = {} - for key, value in options.items(): - if value is not None: - options_no_null[key] = value - keep["options"] = options_no_null - - if keep.get("seq") == seq_number: - saveme = dict(keep) - - new_acl.append(keep) - - return saveme, new_acl - - -def _acl_operand(operand, srcp1, sprcp2): - sub_entry = " " + operand - - if operand == "range": - sub_entry += " " + srcp1 + " " + sprcp2 - else: - sub_entry += " " + srcp1 - - return sub_entry - - -def config_core_acl(proposed): - seq = proposed.get("seq") - action = proposed.get("action") - remark = proposed.get("remark") - proto = proposed.get("proto") - src = proposed.get("src") - src_port_op = proposed.get("src_port_op") - src_port1 = proposed.get("src_port1") - src_port2 = proposed.get("src_port2") - - dest = proposed.get("dest") - dest_port_op = proposed.get("dest_port_op") - dest_port1 = proposed.get("dest_port1") - dest_port2 = proposed.get("dest_port2") - - ace_start_entries = [action, proto, src] - if not remark: - ace = seq + " " + " ".join(ace_start_entries) - if src_port_op: - ace += _acl_operand(src_port_op, src_port1, src_port2) - ace += " " + dest - if dest_port_op: - ace += _acl_operand(dest_port_op, dest_port1, dest_port2) - else: - ace = seq + " remark " + remark - - return ace - - -def config_acl_options(options): - ENABLE_ONLY = [ - "psh", - "urg", - "log", - "ack", - "syn", - "established", - "rst", - "fin", - "fragments", - "log", - ] - - OTHER = ["dscp", "precedence", "time-range"] - # packet-length is the only option not currently supported - - if options.get("time_range"): - options["time-range"] = options.get("time_range") - options.pop("time_range") - - command = "" - for option, value in options.items(): - if option in ENABLE_ONLY: - if value == "enable": - command += " " + option - elif option in OTHER: - command += " " + option + " " + value - if command: - command = command.strip() - return command - - -def flatten_list(command_lists): - flat_command_list = [] - for command in command_lists: - if isinstance(command, list): - flat_command_list.extend(command) - else: - flat_command_list.append(command) - return flat_command_list - - -def main(): - argument_spec = dict( - seq=dict(required=False, type="str"), - name=dict(required=True, type="str"), - action=dict(required=False, choices=["remark", "permit", "deny"]), - remark=dict(required=False, type="str"), - proto=dict(required=False, type="str"), - src=dict(required=False, type="str"), - src_port_op=dict( - required=False, choices=["any", "eq", "gt", "lt", "neq", "range"] - ), - src_port1=dict(required=False, type="str"), - src_port2=dict(required=False, type="str"), - dest=dict(required=False, type="str"), - dest_port_op=dict( - required=False, choices=["any", "eq", "gt", "lt", "neq", "range"] - ), - dest_port1=dict(required=False, type="str"), - dest_port2=dict(required=False, type="str"), - log=dict(required=False, choices=["enable"]), - urg=dict(required=False, choices=["enable"]), - ack=dict(required=False, choices=["enable"]), - psh=dict(required=False, choices=["enable"]), - rst=dict(required=False, choices=["enable"]), - syn=dict(required=False, choices=["enable"]), - fragments=dict(required=False, choices=["enable"]), - fin=dict(required=False, choices=["enable"]), - established=dict(required=False, choices=["enable"]), - time_range=dict(required=False), - precedence=dict( - required=False, - choices=[ - "critical", - "flash", - "flash-override", - "immediate", - "internet", - "network", - "priority", - "routine", - ], - ), - dscp=dict( - required=False, - choices=[ - "af11", - "af12", - "af13", - "af21", - "af22", - "af23", - "af31", - "af32", - "af33", - "af41", - "af42", - "af43", - "cs1", - "cs2", - "cs3", - "cs4", - "cs5", - "cs6", - "cs7", - "default", - "ef", - ], - ), - state=dict( - choices=["absent", "present", "delete_acl"], default="present" - ), - ) - - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) - - warnings = list() - - results = dict(changed=False, warnings=warnings) - - state = module.params["state"] - action = module.params["action"] - remark = module.params["remark"] - dscp = module.params["dscp"] - precedence = module.params["precedence"] - seq = module.params["seq"] - name = module.params["name"] - seq = module.params["seq"] - - if action == "remark" and not remark: - module.fail_json( - msg="when state is action, remark param is also required" - ) - - REQUIRED = ["seq", "name", "action", "proto", "src", "dest"] - ABSENT = ["name", "seq"] - if state == "present": - if action and remark and seq: - pass - else: - for each in REQUIRED: - if module.params[each] is None: - module.fail_json( - msg="req'd params when state is present:", - params=REQUIRED, - ) - elif state == "absent": - for each in ABSENT: - if module.params[each] is None: - module.fail_json( - msg="require params when state is absent", params=ABSENT - ) - elif state == "delete_acl": - if module.params["name"] is None: - module.fail_json(msg="param name req'd when state is delete_acl") - - if dscp and precedence: - module.fail_json( - msg="only one of the params dscp/precedence " "are allowed" - ) - - OPTIONS_NAMES = [ - "log", - "urg", - "ack", - "psh", - "rst", - "syn", - "fin", - "established", - "dscp", - "precedence", - "fragments", - "time_range", - ] - - CORE = [ - "seq", - "name", - "action", - "proto", - "src", - "src_port_op", - "src_port1", - "src_port2", - "dest", - "dest_port_op", - "dest_port1", - "dest_port2", - "remark", - ] - - proposed_core = dict( - (param, value) - for (param, value) in module.params.items() - if param in CORE and value is not None - ) - - proposed_options = dict( - (param, value) - for (param, value) in module.params.items() - if param in OPTIONS_NAMES and value is not None - ) - proposed = {} - proposed.update(proposed_core) - proposed.update(proposed_options) - - existing_options = {} - - # getting existing existing_core=dict, acl=list, seq=list - existing_core, acl = get_acl(module, name, seq) - if existing_core: - existing_options = existing_core.get("options") - existing_core.pop("options") - - commands = [] - delta_core = {} - delta_options = {} - - if not existing_core.get("remark"): - dcore = dict( - set(proposed_core.items()).difference(existing_core.items()) - ) - if not dcore: - # check the diff in the other way just in case - dcore = dict( - set(existing_core.items()).difference(proposed_core.items()) - ) - delta_core = dcore - if delta_core: - delta_options = proposed_options - else: - doptions = dict( - set(proposed_options.items()).difference( - existing_options.items() - ) - ) - # check the diff in the other way just in case - if not doptions: - doptions = dict( - set(existing_options.items()).difference( - proposed_options.items() - ) - ) - delta_options = doptions - else: - delta_core = dict( - set(proposed_core.items()).difference(existing_core.items()) - ) - - if state == "present": - if delta_core or delta_options: - if existing_core: # if the ace exists already - commands.append(["no {0}".format(seq)]) - if delta_options: - myacl_str = config_core_acl(proposed_core) - myacl_str += " " + config_acl_options(proposed_options) - else: - myacl_str = config_core_acl(proposed_core) - command = [myacl_str] - commands.append(command) - elif state == "absent": - if existing_core: - commands.append(["no {0}".format(seq)]) - elif state == "delete_acl": - if acl and acl[0].get("acl") != "no_entries": - commands.append(["no ip access-list {0}".format(name)]) - - cmds = [] - if commands: - preface = [] - if state in ["present", "absent"]: - preface = ["ip access-list {0}".format(name)] - commands.insert(0, preface) - - cmds = flatten_list(commands) - if module.check_mode: - module.exit_json(changed=True, commands=cmds) - else: - load_config(module, cmds) - results["changed"] = True - if "configure" in cmds: - cmds.pop(0) - - results["commands"] = cmds - - module.exit_json(**results) - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/nxos_acl_interface.py b/plugins/modules/nxos_acl_interface.py deleted file mode 100644 index 2a65fa327..000000000 --- a/plugins/modules/nxos_acl_interface.py +++ /dev/null @@ -1,227 +0,0 @@ -#!/usr/bin/python -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - - -DOCUMENTATION = """ -module: nxos_acl_interface -extends_documentation_fragment: -- cisco.nxos.nxos -short_description: (deprecated, removed after 2022-06-01) Manages applying - ACLs to interfaces. -description: -- Manages applying ACLs to interfaces. -version_added: 1.0.0 -deprecated: - alternative: nxos_acl_interfaces - why: Updated modules released with more functionality - removed_at_date: '2022-06-01' -author: -- Jason Edelman (@jedelman8) -- Gabriele Gerbino (@GGabriele) -options: - name: - description: - - Case sensitive name of the access list (ACL). - required: true - type: str - interface: - description: - - Full name of interface, e.g. I(Ethernet1/1). - required: true - type: str - direction: - description: - - Direction ACL to be applied in on the interface. - required: true - choices: - - ingress - - egress - type: str - state: - description: - - Specify desired state of the resource. - required: false - default: present - choices: - - present - - absent - type: str - - -""" - -EXAMPLES = """ -- name: apply egress acl to ethernet1/41 - cisco.nxos.nxos_acl_interface: - name: ANSIBLE - interface: ethernet1/41 - direction: egress - state: present -""" - -RETURN = """ -acl_applied_to: - description: list of interfaces the ACL is applied to - returned: always - type: list - sample: [{"acl_type": "Router ACL", "direction": "egress", - "interface": "Ethernet1/41", "name": "ANSIBLE"}] -commands: - description: commands sent to the device - returned: always - type: list - sample: ["interface ethernet1/41", "ip access-group ANSIBLE out"] -""" -import re - -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - load_config, - run_commands, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule - - -def check_for_acl_int_present(module, name, intf, direction): - # Need to Capitalize the interface name as the nxos - # output has capitalization - command = [ - { - "command": "show running-config aclmgr | section {0}".format( - intf.title() - ), - "output": "text", - } - ] - body = run_commands(module, command) - - if direction == "ingress": - mdir = "in" - elif direction == "egress": - mdir = "out" - - match = re.search( - "ip access-group {0} {1}".format(name, mdir), str(body[0]) - ) - return bool(match) - - -def apply_acl(proposed): - commands = [] - - commands.append("interface " + proposed.get("interface")) - direction = proposed.get("direction") - if direction == "egress": - cmd = "ip access-group {0} {1}".format(proposed.get("name"), "out") - elif direction == "ingress": - cmd = "ip access-group {0} {1}".format(proposed.get("name"), "in") - commands.append(cmd) - - return commands - - -def remove_acl(proposed): - commands = [] - - commands.append("interface " + proposed.get("interface")) - direction = proposed.get("direction") - if direction == "egress": - cmd = "no ip access-group {0} {1}".format(proposed.get("name"), "out") - elif direction == "ingress": - cmd = "no ip access-group {0} {1}".format(proposed.get("name"), "in") - commands.append(cmd) - - return commands - - -def flatten_list(command_lists): - flat_command_list = [] - for command in command_lists: - if isinstance(command, list): - flat_command_list.extend(command) - else: - flat_command_list.append(command) - return flat_command_list - - -def main(): - argument_spec = dict( - name=dict(required=True, type="str"), - interface=dict(required=True), - direction=dict(required=True, choices=["egress", "ingress"]), - state=dict(choices=["absent", "present"], default="present"), - ) - - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) - - warnings = list() - - results = dict(changed=False, warnings=warnings) - - state = module.params["state"] - name = module.params["name"] - interface = module.params["interface"].lower() - direction = module.params["direction"].lower() - - proposed = dict(name=name, interface=interface, direction=direction) - - existing = check_for_acl_int_present(module, name, interface, direction) - - cmds = [] - commands = [] - if state == "present": - if not existing: - command = apply_acl(proposed) - if command: - commands.append(command) - - elif state == "absent": - if existing: - command = remove_acl(proposed) - if command: - commands.append(command) - - if commands: - cmds = flatten_list(commands) - if cmds: - if module.check_mode: - module.exit_json(changed=True, commands=cmds) - else: - load_config(module, cmds) - results["changed"] = True - if "configure" in cmds: - cmds.pop(0) - else: - cmds = [] - - results["commands"] = cmds - - module.exit_json(**results) - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/nxos_acl_interfaces.py b/plugins/modules/nxos_acl_interfaces.py index 11835a873..654fc71e6 100644 --- a/plugins/modules/nxos_acl_interfaces.py +++ b/plugins/modules/nxos_acl_interfaces.py @@ -28,6 +28,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -115,28 +116,28 @@ - name: Merge ACL interfaces configuration cisco.nxos.nxos_acl_interfaces: config: - - name: Ethernet1/2 - access_groups: - - afi: ipv6 - acls: - - name: ACL1v6 - direction: in - - - name: Eth1/5 - access_groups: - - afi: ipv4 - acls: - - name: PortACL - direction: in - port: true - - - name: ACL1v4 - direction: out - - - afi: ipv6 - acls: - - name: ACL1v6 - direction: in + - name: Ethernet1/2 + access_groups: + - afi: ipv6 + acls: + - name: ACL1v6 + direction: in + + - name: Eth1/5 + access_groups: + - afi: ipv4 + acls: + - name: PortACL + direction: in + port: true + + - name: ACL1v4 + direction: out + + - afi: ipv6 + acls: + - name: ACL1v6 + direction: in state: merged # After state: @@ -162,20 +163,20 @@ - name: Replace interface configuration with given configuration cisco.nxos.nxos_acl_interfaces: config: - - name: Eth1/5 - access_groups: - - afi: ipv4 - acls: - - name: NewACLv4 - direction: out - - - name: Ethernet1/3 - access_groups: - - afi: ipv6 - acls: - - name: NewACLv6 - direction: in - port: true + - name: Eth1/5 + access_groups: + - afi: ipv4 + acls: + - name: NewACLv4 + direction: out + + - name: Ethernet1/3 + access_groups: + - afi: ipv6 + acls: + - name: NewACLv6 + direction: in + port: true state: replaced # After state: @@ -201,21 +202,21 @@ - name: Override interface configuration with given configuration cisco.nxos.nxos_acl_interfaces: config: - - name: Ethernet1/3 - access_groups: - - afi: ipv4 - acls: - - name: ACL1v4 - direction: out - - - name: PortACL - port: true - direction: in - - afi: ipv6 - acls: - - name: NewACLv6 - direction: in - port: true + - name: Ethernet1/3 + access_groups: + - afi: ipv4 + acls: + - name: ACL1v4 + direction: out + + - name: PortACL + port: true + direction: in + - afi: ipv6 + acls: + - name: NewACLv6 + direction: in + port: true state: overridden # After state: @@ -241,8 +242,8 @@ - name: Delete ACL configuration on interfaces cisco.nxos.nxos_acl_interfaces: config: - - name: Ethernet1/5 - - name: Ethernet1/2 + - name: Ethernet1/5 + - name: Ethernet1/2 state: deleted # After state: @@ -355,28 +356,28 @@ - name: Render required configuration to be pushed to the device cisco.nxos.nxos_acl_interfaces: config: - - name: Ethernet1/2 - access_groups: - - afi: ipv6 - acls: - - name: ACL1v6 - direction: in - - - name: Ethernet1/5 - access_groups: - - afi: ipv4 - acls: - - name: PortACL - direction: in - port: true - - name: ACL1v4 - direction: out - - afi: ipv6 - acls: - - name: ACL1v6 - direction: in + - name: Ethernet1/2 + access_groups: + - afi: ipv6 + acls: + - name: ACL1v6 + direction: in + - name: Ethernet1/5 + access_groups: + - afi: ipv4 + acls: + - name: PortACL + direction: in + port: true + - name: ACL1v4 + direction: out + - afi: ipv6 + acls: + - name: ACL1v6 + direction: in state: rendered + # returns # rendered: # interface Ethernet1/2 @@ -385,7 +386,6 @@ # ipv6 traffic-filter ACL1v6 in # ip access-group ACL1v4 out # ip port access-group PortACL in - """ RETURN = """ before: @@ -411,6 +411,7 @@ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.acl_interfaces.acl_interfaces import ( Acl_interfacesArgs, ) diff --git a/plugins/modules/nxos_acls.py b/plugins/modules/nxos_acls.py index bb7eb2272..29d610400 100644 --- a/plugins/modules/nxos_acls.py +++ b/plugins/modules/nxos_acls.py @@ -27,6 +27,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -351,6 +352,103 @@ unreachable: description: All unreachables type: bool + icmpv6: + description: ICMPv6 protocol options. + type: dict + suboptions: + beyond_scope: + description: Destination beyond scope. + type: bool + destination_unreachable: + description: Destination address is unreachable. + type: bool + echo_reply: + description: Echo reply. + type: bool + echo_request: + description: Echo request (ping). + type: bool + fragments: + description: Check non-initial fragments. + type: bool + header: + description: Parameter header problem. + type: bool + hop_limit: + description: Hop limit exceeded in transit. + type: bool + mld_query: + description: Multicast Listener Discovery Query. + type: bool + mld_reduction: + description: Multicast Listener Discovery Reduction. + type: bool + mld_report: + description: Multicast Listener Discovery Report. + type: bool + mldv2: + description: Multicast Listener Discovery Protocol. + type: bool + nd_na: + description: Neighbor discovery neighbor advertisements. + type: bool + nd_ns: + description: Neighbor discovery neighbor solicitations. + type: bool + next_header: + description: Parameter next header problems. + type: bool + no_admin: + description: Administration prohibited destination. + type: bool + no_route: + description: No route to destination. + type: bool + packet_too_big: + description: Packet too big. + type: bool + parameter_option: + description: Parameter option problems. + type: bool + parameter_problem: + description: All parameter problems. + type: bool + port_unreachable: + description: Port unreachable. + type: bool + reassembly_timeout: + description: Reassembly timeout. + type: bool + renum_command: + description: Router renumbering command. + type: bool + renum_result: + description: Router renumbering result. + type: bool + renum_seq_number: + description: Router renumbering sequence number reset. + type: bool + router_advertisement: + description: Neighbor discovery router advertisements. + type: bool + router_renumbering: + description: All router renumbering. + type: bool + router_solicitation: + description: Neighbor discovery router solicitations. + type: bool + time_exceeded: + description: All time exceeded. + type: bool + unreachable: + description: All unreachable. + type: bool + telemetry_path: + description: IPT enabled. + type: bool + telemetry_queue: + description: Flow of interest for BDC/HDC. + type: bool tcp: description: TCP flags. type: dict @@ -409,46 +507,89 @@ # Before state: # ------------- -# +# nxos-9k# show running-config | section '^ip(v6)* access-list' -- name: Merge new ACLs configuration +- name: Merge provided ACLs configuration with device configuration cisco.nxos.nxos_acls: - config: - - afi: ipv4 - acls: - - name: ACL1v4 - aces: - - grant: deny - destination: - address: 192.0.2.64 - wildcard_bits: 0.0.0.255 - source: - any: true - port_protocol: - lt: 55 - protocol: tcp - protocol_options: - tcp: - ack: true - fin: true - sequence: 50 - - - afi: ipv6 - acls: - - name: ACL1v6 - aces: - - grant: permit - sequence: 10 - source: - any: true - destination: - prefix: 2001:db8:12::/32 - protocol: sctp state: merged + config: + - afi: ipv4 + acls: + - name: ACL1v4 + aces: + - grant: deny + destination: + address: 192.0.2.64 + wildcard_bits: 0.0.0.255 + source: + any: true + port_protocol: + lt: 55 + protocol: tcp + protocol_options: + tcp: + ack: true + fin: true + sequence: 50 + + - afi: ipv6 + acls: + - name: ACL1v6 + aces: + - grant: permit + sequence: 10 + source: + any: true + destination: + prefix: 2001:db8:12::/32 + protocol: sctp + +# Task Output +# ----------- +# before: [] +# +# commands: +# - ip access-list ACL1v4 +# - 50 deny tcp any lt 55 192.0.2.64 0.0.0.255 ack fin +# - ipv6 access-list ACL1v6 +# - 10 permit sctp any 2001:db8:12::/32 +# +# after: +# - acls: +# - aces: +# - destination: +# prefix: 2001:db8:12::/32 +# grant: permit +# protocol: sctp +# sequence: 10 +# source: +# any: true +# name: ACL1v6 +# afi: ipv6 +# - acls: +# - aces: +# - destination: +# address: 192.0.2.64 +# wildcard_bits: 0.0.0.255 +# grant: deny +# protocol: tcp +# protocol_options: +# tcp: +# ack: true +# fin: true +# sequence: 50 +# source: +# any: true +# port_protocol: +# lt: '55' +# name: ACL1v4 +# afi: ipv4 + # After state: # ------------ # +# nxos-9k# show running-config | section '^ip(v6)* access-list' # ip access-list ACL1v4 # 50 deny tcp any lt 55 192.0.2.64 0.0.0.255 ack fin # ipv6 access-list ACL1v6 @@ -458,94 +599,269 @@ # Before state: # ---------------- -# +# nxos-9k# show running-config | section '^ip(v6)* access-list' # ip access-list ACL1v4 # 10 permit ip any any # 20 deny udp any any # ip access-list ACL2v4 # 10 permit ahp 192.0.2.0 0.0.0.255 any -# ip access-list ACL1v6 +# ipv6 access-list ACL1v6 # 10 permit sctp any any # 20 remark IPv6 ACL -# ip access-list ACL2v6 +# ipv6 access-list ACL2v6 # 10 deny ipv6 any 2001:db8:3000::/36 # 20 permit tcp 2001:db8:2000:2::2/128 2001:db8:2000:ab::2/128 - name: Replace existing ACL configuration with provided configuration cisco.nxos.nxos_acls: config: - - afi: ipv4 - - afi: ipv6 - acls: - - name: ACL1v6 - aces: - - sequence: 20 - grant: permit - source: - any: true - destination: - any: true - protocol: pip - - - remark: Replaced ACE - - - name: ACL2v6 + - afi: ipv4 + - afi: ipv6 + acls: + - name: ACL1v6 + aces: + - sequence: 20 + grant: permit + source: + any: true + destination: + any: true + protocol: pim + + - remark: Replaced ACE + - name: ACL2v6 state: replaced +# Task Output +# ----------- +# before: +# - acls: +# - aces: +# - destination: +# any: true +# grant: permit +# protocol: sctp +# sequence: 10 +# source: +# any: true +# - remark: IPv6 ACL +# sequence: 20 +# name: ACL1v6 +# - aces: +# - destination: +# prefix: 2001:db8:3000::/36 +# grant: deny +# protocol: ipv6 +# sequence: 10 +# source: +# any: true +# - destination: +# host: 2001:db8:2000:ab::2 +# grant: permit +# protocol: tcp +# sequence: 20 +# source: +# host: 2001:db8:2000:2::2 +# name: ACL2v6 +# afi: ipv6 +# - acls: +# - aces: +# - destination: +# any: true +# grant: permit +# protocol: ip +# sequence: 10 +# source: +# any: true +# - destination: +# any: true +# grant: deny +# protocol: udp +# sequence: 20 +# source: +# any: true +# name: ACL1v4 +# - aces: +# - destination: +# any: true +# grant: permit +# protocol: ahp +# sequence: 10 +# source: +# address: 192.0.2.0 +# wildcard_bits: 0.0.0.255 +# name: ACL2v4 +# afi: ipv4 +# +# commands: +# - no ip access-list ACL1v4 +# - no ip access-list ACL2v4 +# - ipv6 access-list ACL1v6 +# - no 10 permit sctp any any +# - no 20 remark IPv6 ACL +# - remark Replaced ACE +# - 20 permit pim any any +# - ipv6 access-list ACL2v6 +# - no 10 deny ipv6 any 2001:db8:3000::/36 +# - no 20 permit tcp host 2001:db8:2000:2::2 host 2001:db8:2000:ab::2 +# +# after: +# - acls: +# - aces: +# - remark: Replaced ACE +# sequence: 10 +# - destination: +# any: true +# grant: permit +# protocol: pim +# sequence: 20 +# source: +# any: true +# name: ACL1v6 +# - name: ACL2v6 +# afi: ipv6 + # After state: # --------------- -# +# nxos-9k# show running-config | section '^ip(v6)* access-list' # ipv6 access-list ACL1v6 -# 20 permit pip any any -# 30 remark Replaced ACE +# 10 remark Replaced ACE +# 20 permit pim any any # ipv6 access-list ACL2v6 # Using overridden # Before state: # ---------------- -# +# nxos-9k# show running-config | section '^ip(v6)* access-list' # ip access-list ACL1v4 # 10 permit ip any any # 20 deny udp any any # ip access-list ACL2v4 # 10 permit ahp 192.0.2.0 0.0.0.255 any -# ip access-list ACL1v6 +# ipv6 access-list ACL1v6 # 10 permit sctp any any # 20 remark IPv6 ACL -# ip access-list ACL2v6 +# ipv6 access-list ACL2v6 # 10 deny ipv6 any 2001:db8:3000::/36 # 20 permit tcp 2001:db8:2000:2::2/128 2001:db8:2000:ab::2/128 - name: Override existing configuration with provided configuration cisco.nxos.nxos_acls: config: - - afi: ipv4 - acls: - - name: NewACL - aces: - - grant: deny - source: - address: 192.0.2.0 - wildcard_bits: 0.0.255.255 - destination: - any: true - protocol: eigrp - - remark: Example for overridden state + - afi: ipv4 + acls: + - name: NewACL + aces: + - grant: deny + source: + address: 192.0.2.0 + wildcard_bits: 0.0.255.255 + destination: + any: true + protocol: eigrp + - remark: Example for overridden state state: overridden +# Task Output +# ----------- +# +# before: +# - acls: +# - aces: +# - destination: +# any: true +# grant: permit +# protocol: sctp +# sequence: 10 +# source: +# any: true +# - remark: IPv6 ACL +# sequence: 20 +# name: ACL1v6 +# - aces: +# - destination: +# prefix: 2001:db8:3000::/36 +# grant: deny +# protocol: ipv6 +# sequence: 10 +# source: +# any: true +# - destination: +# host: 2001:db8:2000:ab::2 +# grant: permit +# protocol: tcp +# sequence: 20 +# source: +# host: 2001:db8:2000:2::2 +# name: ACL2v6 +# afi: ipv6 +# - acls: +# - aces: +# - destination: +# any: true +# grant: permit +# protocol: ip +# sequence: 10 +# source: +# any: true +# - destination: +# any: true +# grant: deny +# protocol: udp +# sequence: 20 +# source: +# any: true +# name: ACL1v4 +# - aces: +# - destination: +# any: true +# grant: permit +# protocol: ahp +# sequence: 10 +# source: +# address: 192.0.2.0 +# wildcard_bits: 0.0.0.255 +# name: ACL2v4 +# afi: ipv4 +# +# commands: +# - no ipv6 access-list ACL1v6 +# - no ipv6 access-list ACL2v6 +# - no ip access-list ACL1v4 +# - no ip access-list ACL2v4 +# - ip access-list NewACL +# - deny eigrp 192.0.2.0 0.0.255.255 any +# - remark Example for overridden state +# +# after: +# - acls: +# - aces: +# - destination: +# any: true +# grant: deny +# protocol: eigrp +# sequence: 10 +# source: +# address: 192.0.2.0 +# wildcard_bits: 0.0.255.255 +# - remark: Example for overridden state +# sequence: 20 +# name: NewACL +# afi: ipv4 + # After state: # ------------ -# +# nxos-9k# show running-config | section '^ip(v6)* access-list' # ip access-list NewACL # 10 deny eigrp 192.0.2.0 0.0.255.255 any # 20 remark Example for overridden state -# Using deleted: +# Using deleted - delete all # # Before state: # ------------- -# +# nxos-9k# show running-config | section '^ip(v6)* access-list' # ip access-list ACL1v4 # 10 permit ip any any # 20 deny udp any any @@ -560,17 +876,89 @@ - name: Delete all ACLs cisco.nxos.nxos_acls: - config: state: deleted +# Task Output +# ----------- +# +# before: +# - acls: +# - aces: +# - destination: +# any: true +# grant: permit +# protocol: sctp +# sequence: 10 +# source: +# any: true +# - remark: IPv6 ACL +# sequence: 20 +# name: ACL1v6 +# - aces: +# - destination: +# prefix: 2001:db8:3000::/36 +# grant: deny +# protocol: ipv6 +# sequence: 10 +# source: +# any: true +# - destination: +# host: 2001:db8:2000:ab::2 +# grant: permit +# protocol: tcp +# sequence: 20 +# source: +# host: 2001:db8:2000:2::2 +# name: ACL2v6 +# afi: ipv6 +# - acls: +# - aces: +# - destination: +# any: true +# grant: permit +# protocol: ip +# sequence: 10 +# source: +# any: true +# - destination: +# any: true +# grant: deny +# protocol: udp +# sequence: 20 +# source: +# any: true +# name: ACL1v4 +# - aces: +# - destination: +# any: true +# grant: permit +# protocol: ahp +# sequence: 10 +# source: +# address: 192.0.2.0 +# wildcard_bits: 0.0.0.255 +# name: ACL2v4 +# afi: ipv4 +# +# commands: +# - no ip access-list ACL1v4 +# - no ip access-list ACL2v4 +# - no ipv6 access-list ACL1v6 +# - no ipv6 access-list ACL2v6 +# +# after: [] + + # After state: # ----------- +# nxos-9k# show running-config | section '^ip(v6)* access-list' # +# Using deleted - delete AFI # Before state: # ------------- -# +# nxos-9k# show running-config | section '^ip(v6)* access-list' # ip access-list ACL1v4 # 10 permit ip any any # 20 deny udp any any @@ -586,12 +974,109 @@ - name: Delete all ACLs in given AFI cisco.nxos.nxos_acls: config: - - afi: ipv4 + - afi: ipv4 state: deleted +# Task Output +# ----------- +# +# before: +# - acls: +# - aces: +# - destination: +# any: true +# grant: permit +# protocol: sctp +# sequence: 10 +# source: +# any: true +# - remark: IPv6 ACL +# sequence: 20 +# name: ACL1v6 +# - aces: +# - destination: +# prefix: 2001:db8:3000::/36 +# grant: deny +# protocol: ipv6 +# sequence: 10 +# source: +# any: true +# - destination: +# host: 2001:db8:2000:ab::2 +# grant: permit +# protocol: tcp +# sequence: 20 +# source: +# host: 2001:db8:2000:2::2 +# name: ACL2v6 +# afi: ipv6 +# - acls: +# - aces: +# - destination: +# any: true +# grant: permit +# protocol: ip +# sequence: 10 +# source: +# any: true +# - destination: +# any: true +# grant: deny +# protocol: udp +# sequence: 20 +# source: +# any: true +# name: ACL1v4 +# - aces: +# - destination: +# any: true +# grant: permit +# protocol: ahp +# sequence: 10 +# source: +# address: 192.0.2.0 +# wildcard_bits: 0.0.0.255 +# name: ACL2v4 +# afi: ipv4 +# +# commands: +# - no ip access-list ACL1v4 +# - no ip access-list ACL2v4 +# +# after: +# - acls: +# - aces: +# - destination: +# any: true +# grant: permit +# protocol: sctp +# sequence: 10 +# source: +# any: true +# - remark: IPv6 ACL +# sequence: 20 +# name: ACL1v6 +# - aces: +# - destination: +# prefix: 2001:db8:3000::/36 +# grant: deny +# protocol: ipv6 +# sequence: 10 +# source: +# any: true +# - destination: +# host: 2001:db8:2000:ab::2 +# grant: permit +# protocol: tcp +# sequence: 20 +# source: +# host: 2001:db8:2000:2::2 +# name: ACL2v6 +# afi: ipv6 + # After state: # ------------ -# +# nxos-9k# show running-config | section '^ip(v6)* access-list' # ip access-list ACL1v6 # 10 permit sctp any any # 20 remark IPv6 ACL @@ -599,11 +1084,11 @@ # 10 deny ipv6 any 2001:db8:3000::/36 # 20 permit tcp 2001:db8:2000:2::2/128 2001:db8:2000:ab::2/128 - +# Using deleted - delete ACLs # Before state: # ------------- -# +# nxos-9k# show running-config | section '^ip(v6)* access-list' # ip access-list ACL1v4 # 10 permit ip any any # 20 deny udp any any @@ -618,18 +1103,106 @@ - name: Delete specific ACLs cisco.nxos.nxos_acls: - config: - - afi: ipv4 - acls: - - name: ACL1v4 - - name: ACL2v4 - - afi: ipv6 - acls: - - name: ACL1v6 state: deleted + config: + - afi: ipv4 + acls: + - name: ACL1v4 + - name: ACL2v4 + - afi: ipv6 + acls: + - name: ACL1v6 + +# Task Output +# ----------- +# +# before: +# - acls: +# - aces: +# - destination: +# any: true +# grant: permit +# protocol: sctp +# sequence: 10 +# source: +# any: true +# - remark: IPv6 ACL +# sequence: 20 +# name: ACL1v6 +# - aces: +# - destination: +# prefix: 2001:db8:3000::/36 +# grant: deny +# protocol: ipv6 +# sequence: 10 +# source: +# any: true +# - destination: +# host: 2001:db8:2000:ab::2 +# grant: permit +# protocol: tcp +# sequence: 20 +# source: +# host: 2001:db8:2000:2::2 +# name: ACL2v6 +# afi: ipv6 +# - acls: +# - aces: +# - destination: +# any: true +# grant: permit +# protocol: ip +# sequence: 10 +# source: +# any: true +# - destination: +# any: true +# grant: deny +# protocol: udp +# sequence: 20 +# source: +# any: true +# name: ACL1v4 +# - aces: +# - destination: +# any: true +# grant: permit +# protocol: ahp +# sequence: 10 +# source: +# address: 192.0.2.0 +# wildcard_bits: 0.0.0.255 +# name: ACL2v4 +# afi: ipv4 +# +# commands: +# - no ip access-list ACL1v4 +# - no ip access-list ACL2v4 +# - no ipv6 access-list ACL1v6 +# +# after: +# - acls: +# - aces: +# - destination: +# prefix: 2001:db8:3000::/36 +# grant: deny +# protocol: ipv6 +# sequence: 10 +# source: +# any: true +# - destination: +# host: 2001:db8:2000:ab::2 +# grant: permit +# protocol: tcp +# sequence: 20 +# source: +# host: 2001:db8:2000:2::2 +# name: ACL2v6 +# afi: ipv6 # After state: # ------------ +# nxos-9k# show running-config | section '^ip(v6)* access-list' # ipv6 access-list ACL2v6 # 10 deny ipv6 any 2001:db8:3000::/36 # 20 permit tcp 2001:db8:2000:2::2/128 2001:db8:2000:ab::2/128 @@ -645,7 +1218,9 @@ 10 permit sctp any any state: parsed -# returns: +# Task Output +# ------------ +# # parsed: # - afi: ipv4 # acls: @@ -683,7 +1258,7 @@ # Before state: # ------------ -# +# nxos-9k# show running-config | section '^ip(v6)* access-list' # ip access-list ACL1v4 # 50 deny tcp any lt 55 192.0.2.64 0.0.0.255 ack fin # ipv6 access-list ACL1v6 @@ -693,7 +1268,9 @@ cisco.nxos.nxos_acls: state: gathered -# returns: +# Task Output +# ----------- +# # gathered: # - afi: ipv4 # acls: @@ -732,39 +1309,41 @@ - name: Render required configuration to be pushed to the device cisco.nxos.nxos_acls: config: - - afi: ipv4 - acls: - - name: ACL1v4 - aces: - - grant: deny - destination: - address: 192.0.2.64 - wildcard_bits: 0.0.0.255 - source: - any: true - port_protocol: - lt: 55 - protocol: tcp - protocol_options: - tcp: - ack: true - fin: true - sequence: 50 - - - afi: ipv6 - acls: - - name: ACL1v6 - aces: - - grant: permit - sequence: 10 - source: - any: true - destination: - prefix: 2001:db8:12::/32 - protocol: sctp + - afi: ipv4 + acls: + - name: ACL1v4 + aces: + - grant: deny + destination: + address: 192.0.2.64 + wildcard_bits: 0.0.0.255 + source: + any: true + port_protocol: + lt: 55 + protocol: tcp + protocol_options: + tcp: + ack: true + fin: true + sequence: 50 + - afi: ipv6 + acls: + - name: ACL1v6 + aces: + - grant: permit + sequence: 10 + source: + any: true + destination: + prefix: '2001:db8:12::/32' + protocol: sctp state: rendered -# returns: + +# Task Output +# ----------- +# # rendered: # ip access-list ACL1v4 # 50 deny tcp any lt 55 192.0.2.64 0.0.0.255 ack fin @@ -790,16 +1369,40 @@ description: The set of commands pushed to the remote device. returned: always type: list - sample: ['ip access-list ACL1v4', '10 permit ip any any precedence critical log', '20 deny tcp any lt smtp host 192.0.2.64 ack fin'] + sample: + - ip access-list ACL1v4 + - 10 permit ip any any precedence critical log + - 20 deny tcp any lt smtp host 192.0.2.64 ack fin +rendered: + description: The provided configuration in the task rendered in device-native format (offline). + returned: when I(state) is C(rendered) + type: list + sample: + - ip access-list ACL1v4 + - 10 permit ip any any precedence critical log + - 20 deny tcp any lt smtp host 192.0.2.64 ack fin +gathered: + description: Facts about the network resource gathered from the remote device as structured data. + returned: when I(state) is C(gathered) + type: list + sample: > + This output will always be in the same format as the + module argspec. +parsed: + description: The device native config provided in I(running_config) option parsed into structured data as per module argspec. + returned: when I(state) is C(parsed) + type: list + sample: > + This output will always be in the same format as the + module argspec. """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.acls.acls import ( AclsArgs, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.acls.acls import ( - Acls, -) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.acls.acls import Acls def main(): @@ -808,9 +1411,7 @@ def main(): :returns: the result form module invocation """ - module = AnsibleModule( - argument_spec=AclsArgs.argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=AclsArgs.argument_spec, supports_check_mode=True) result = Acls(module).execute_module() module.exit_json(**result) diff --git a/plugins/modules/nxos_banner.py b/plugins/modules/nxos_banner.py index b2fe84c61..1a170783a 100644 --- a/plugins/modules/nxos_banner.py +++ b/plugins/modules/nxos_banner.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import, division, print_function + __metaclass__ = type # (c) 2017, Ansible by Red Hat, inc @@ -44,6 +45,10 @@ - exec - motd type: str + multiline_delimiter: + description: Specify the delimiting character than will be used for configuration. + default: "@" + type: str text: description: - The banner text that should be present in the remote device running configuration. @@ -94,16 +99,15 @@ - string """ -from ansible.module_utils.basic import AnsibleModule +import re + from ansible.module_utils._text import to_text +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -import re def execute_show_command(module, command): @@ -126,9 +130,11 @@ def map_obj_to_commands(want, have, module): commands.append("no banner %s" % module.params["banner"]) elif state == "present" and want.get("text") != have.get("text"): - banner_cmd = "banner %s @\n%s\n@" % ( + banner_cmd = "banner %s %s\n%s\n%s" % ( module.params["banner"], + module.params["multiline_delimiter"], want["text"], + module.params["multiline_delimiter"], ) commands.append(banner_cmd) @@ -142,7 +148,7 @@ def map_config_to_obj(module): if "Invalid command" in output: module.fail_json( msg="banner: %s may not be supported on this platform. Possible values are : exec | motd" - % module.params["banner"] + % module.params["banner"], ) if isinstance(output, dict): @@ -181,11 +187,10 @@ def main(): argument_spec = dict( banner=dict(required=True, choices=["exec", "motd"]), text=dict(), + multiline_delimiter=dict(default="@"), state=dict(default="present", choices=["present", "absent"]), ) - argument_spec.update(nxos_argument_spec) - required_if = [("state", "present", ("text",))] module = AnsibleModule( @@ -214,10 +219,7 @@ def main(): err_str = item["clierror"] else: err_str = item - if ( - "more than 40 lines" in err_str - or "buffer overflowed" in err_str - ): + if "more than 40 lines" in err_str or "buffer overflowed" in err_str: load_config(module, commands) result["changed"] = True diff --git a/plugins/modules/nxos_bfd_global.py b/plugins/modules/nxos_bfd_global.py index a8f8acd9d..6ae1a88da 100644 --- a/plugins/modules/nxos_bfd_global.py +++ b/plugins/modules/nxos_bfd_global.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -135,16 +136,14 @@ import re + +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( NxosCmdRef, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( load_config, ) -from ansible.module_utils.basic import AnsibleModule + BFD_CMD_REF = """ # The cmd_ref is a yaml formatted list of module commands. @@ -308,10 +307,7 @@ def main(): fabricpath_slow_timer=dict(required=False, type="int"), fabricpath_vlan=dict(required=False, type="int"), ) - argument_spec.update(nxos_argument_spec) - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() cmd_ref = NxosCmdRef(module, BFD_CMD_REF) diff --git a/plugins/modules/nxos_bfd_interfaces.py b/plugins/modules/nxos_bfd_interfaces.py index 3988648e3..3465d95bb 100644 --- a/plugins/modules/nxos_bfd_interfaces.py +++ b/plugins/modules/nxos_bfd_interfaces.py @@ -28,6 +28,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -103,12 +104,12 @@ - name: Configure interfaces cisco.nxos.nxos_bfd_interfaces: config: - - name: Ethernet1/1 - bfd: enable - echo: enable - - name: Ethernet1/2 - bfd: disable - echo: disable + - name: Ethernet1/1 + bfd: enable + echo: enable + - name: Ethernet1/2 + bfd: disable + echo: disable state: merged @@ -117,12 +118,12 @@ - name: Configure interfaces cisco.nxos.nxos_bfd_interfaces: config: - - name: Ethernet1/1 - bfd: enable - echo: enable - - name: Ethernet1/2 - bfd: disable - echo: disable + - name: Ethernet1/1 + bfd: enable + echo: enable + - name: Ethernet1/2 + bfd: disable + echo: disable state: overridden @@ -131,12 +132,12 @@ - name: Configure interfaces cisco.nxos.nxos_bfd_interfaces: config: - - name: Ethernet1/1 - bfd: enable - echo: enable - - name: Ethernet1/2 - bfd: disable - echo: disable + - name: Ethernet1/1 + bfd: enable + echo: enable + - name: Ethernet1/2 + bfd: disable + echo: disable state: replaced # Using rendered @@ -144,12 +145,12 @@ - name: Use rendered state to convert task input to device specific commands cisco.nxos.nxos_bfd_interfaces: config: - - name: Ethernet1/800 - bfd: enable - echo: enable - - name: Ethernet1/801 - bfd: disable - echo: disable + - name: Ethernet1/800 + bfd: enable + echo: enable + - name: Ethernet1/801 + bfd: disable + echo: disable state: rendered # Task Output (redacted) @@ -262,6 +263,7 @@ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.bfd_interfaces.bfd_interfaces import ( Bfd_interfacesArgs, ) diff --git a/plugins/modules/nxos_bgp.py b/plugins/modules/nxos_bgp.py deleted file mode 100644 index 7c4244d4e..000000000 --- a/plugins/modules/nxos_bgp.py +++ /dev/null @@ -1,787 +0,0 @@ -#!/usr/bin/python -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - - -DOCUMENTATION = """ -module: nxos_bgp -extends_documentation_fragment: -- cisco.nxos.nxos -short_description: (deprecated, removed after 2023-01-27) Manages BGP configuration. -description: -- Manages BGP configurations on NX-OS switches. -version_added: 1.0.0 -author: -- Jason Edelman (@jedelman8) -- Gabriele Gerbino (@GGabriele) -deprecated: - alternative: nxos_bgp_global - why: Updated module released with more functionality. - removed_at_date: '2023-01-27' -notes: -- Tested against NXOSv 7.3.(0)D1(1) on VIRL -- Unsupported for Cisco MDS -- C(state=absent) removes the whole BGP ASN configuration when C(vrf=default) or the - whole VRF instance within the BGP process when using a different VRF. -- Default when supported restores params default value. -- Configuring global params is only permitted if C(vrf=default). -options: - asn: - description: - - BGP autonomous system number. Valid values are String, Integer in ASPLAIN or - ASDOT notation. - required: true - type: str - vrf: - description: - - Name of the VRF. The name 'default' is a valid VRF representing the global BGP. - default: 'default' - type: str - bestpath_always_compare_med: - description: - - Enable/Disable MED comparison on paths from different autonomous systems. - type: bool - bestpath_aspath_multipath_relax: - description: - - Enable/Disable load sharing across the providers with different (but equal-length) - AS paths. - type: bool - bestpath_compare_routerid: - description: - - Enable/Disable comparison of router IDs for identical eBGP paths. - type: bool - bestpath_compare_neighborid: - description: - - Enable/Disable neighborid. Use this when more paths available than max path - config. - type: bool - bestpath_cost_community_ignore: - description: - - Enable/Disable Ignores the cost community for BGP best-path calculations. - type: bool - bestpath_med_confed: - description: - - Enable/Disable enforcement of bestpath to do a MED comparison only between paths - originated within a confederation. - type: bool - bestpath_med_missing_as_worst: - description: - - Enable/Disable assigns the value of infinity to received routes that do not - carry the MED attribute, making these routes the least desirable. - type: bool - bestpath_med_non_deterministic: - description: - - Enable/Disable deterministic selection of the best MED pat from among the paths - from the same autonomous system. - type: bool - cluster_id: - description: - - Route Reflector Cluster-ID. - type: str - confederation_id: - description: - - Routing domain confederation AS. - type: str - confederation_peers: - description: - - AS confederation parameters. - type: list - elements: str - disable_policy_batching: - description: - - Enable/Disable the batching evaluation of prefix advertisement to all peers. - type: bool - disable_policy_batching_ipv4_prefix_list: - description: - - Enable/Disable the batching evaluation of prefix advertisements to all peers - with prefix list. - type: str - disable_policy_batching_ipv6_prefix_list: - description: - - Enable/Disable the batching evaluation of prefix advertisements to all peers - with prefix list. - type: str - enforce_first_as: - description: - - Enable/Disable enforces the neighbor autonomous system to be the first AS number - listed in the AS path attribute for eBGP. On NX-OS, this property is only supported - in the global BGP context. - type: bool - event_history_cli: - description: - - Enable/Disable cli event history buffer. - choices: - - size_small - - size_medium - - size_large - - size_disable - - default - - 'true' - - 'false' - type: str - event_history_detail: - description: - - Enable/Disable detail event history buffer. - choices: - - size_small - - size_medium - - size_large - - size_disable - - default - - 'true' - - 'false' - type: str - event_history_events: - description: - - Enable/Disable event history buffer. - choices: - - size_small - - size_medium - - size_large - - size_disable - - default - - 'true' - - 'false' - type: str - event_history_periodic: - description: - - Enable/Disable periodic event history buffer. - choices: - - size_small - - size_medium - - size_large - - size_disable - - default - - 'true' - - 'false' - type: str - fast_external_fallover: - description: - - Enable/Disable immediately reset the session if the link to a directly connected - BGP peer goes down. Only supported in the global BGP context. - type: bool - flush_routes: - description: - - Enable/Disable flush routes in RIB upon controlled restart. On NX-OS, this property - is only supported in the global BGP context. - type: bool - graceful_restart: - description: - - Enable/Disable graceful restart. - type: bool - graceful_restart_helper: - description: - - Enable/Disable graceful restart helper mode. - type: bool - graceful_restart_timers_restart: - description: - - Set maximum time for a restart sent to the BGP peer. - type: str - graceful_restart_timers_stalepath_time: - description: - - Set maximum time that BGP keeps the stale routes from the restarting BGP peer. - type: str - isolate: - description: - - Enable/Disable isolate this router from BGP perspective. - type: bool - local_as: - description: - - Local AS number to be used within a VRF instance. - type: str - log_neighbor_changes: - description: - - Enable/Disable message logging for neighbor up/down event. - type: bool - maxas_limit: - description: - - Specify Maximum number of AS numbers allowed in the AS-path attribute. Valid - values are between 1 and 512. - type: str - neighbor_down_fib_accelerate: - description: - - Enable/Disable handle BGP neighbor down event, due to various reasons. - type: bool - reconnect_interval: - description: - - The BGP reconnection interval for dropped sessions. Valid values are between - 1 and 60. - type: str - router_id: - description: - - Router Identifier (ID) of the BGP router VRF instance. - type: str - shutdown: - description: - - Administratively shutdown the BGP protocol. - type: bool - suppress_fib_pending: - description: - - Enable/Disable advertise only routes programmed in hardware to peers. - type: bool - timer_bestpath_limit: - description: - - Specify timeout for the first best path after a restart, in seconds. - type: str - timer_bgp_hold: - description: - - Set BGP hold timer. - type: str - timer_bgp_keepalive: - description: - - Set BGP keepalive timer. - type: str - state: - description: - - Determines whether the config should be present or not on the device. - default: present - choices: - - present - - absent - type: str -""" - - -EXAMPLES = """ -- name: Configure a simple ASN - cisco.nxos.nxos_bgp: - asn: 65535 - vrf: test - router_id: 192.0.2.1 - state: present -""" - -RETURN = """ -commands: - description: commands sent to the device - returned: always - type: list - sample: ["router bgp 65535", "vrf test", "router-id 192.0.2.1"] -""" - -import re - -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_config, - load_config, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( - CustomNetworkConfig, -) - - -BOOL_PARAMS = [ - "bestpath_always_compare_med", - "bestpath_aspath_multipath_relax", - "bestpath_compare_neighborid", - "bestpath_compare_routerid", - "bestpath_cost_community_ignore", - "bestpath_med_confed", - "bestpath_med_missing_as_worst", - "bestpath_med_non_deterministic", - "disable_policy_batching", - "enforce_first_as", - "fast_external_fallover", - "flush_routes", - "graceful_restart", - "graceful_restart_helper", - "isolate", - "log_neighbor_changes", - "neighbor_down_fib_accelerate", - "shutdown", - "suppress_fib_pending", -] -GLOBAL_PARAMS = [ - "disable_policy_batching", - "disable_policy_batching_ipv4_prefix_list", - "disable_policy_batching_ipv6_prefix_list", - "enforce_first_as", - "event_history_cli", - "event_history_detail", - "event_history_events", - "event_history_periodic", - "fast_external_fallover", - "flush_routes", - "isolate", - "suppress_fib_pending", - "shutdown", -] -PARAM_TO_DEFAULT_KEYMAP = { - "timer_bgp_keepalive": "60", - "timer_bgp_hold": "180", - "timer_bestpath_limit": "300", - "graceful_restart": True, - "graceful_restart_timers_restart": "120", - "graceful_restart_timers_stalepath_time": "300", - "reconnect_interval": "60", - "suppress_fib_pending": True, - "fast_external_fallover": True, - "enforce_first_as": True, - "event_history_cli": True, - "event_history_detail": False, - "event_history_events": True, - "event_history_periodic": True, - "maxas_limit": "", - "router_id": "", - "cluster_id": "", - "disable_policy_batching_ipv4_prefix_list": "", - "disable_policy_batching_ipv6_prefix_list": "", - "local_as": "", - "confederation_id": "", -} -PARAM_TO_COMMAND_KEYMAP = { - "asn": "router bgp", - "bestpath_always_compare_med": "bestpath always-compare-med", - "bestpath_aspath_multipath_relax": "bestpath as-path multipath-relax", - "bestpath_compare_neighborid": "bestpath compare-neighborid", - "bestpath_compare_routerid": "bestpath compare-routerid", - "bestpath_cost_community_ignore": "bestpath cost-community ignore", - "bestpath_med_confed": "bestpath med confed", - "bestpath_med_missing_as_worst": "bestpath med missing-as-worst", - "bestpath_med_non_deterministic": "bestpath med non-deterministic", - "cluster_id": "cluster-id", - "confederation_id": "confederation identifier", - "confederation_peers": "confederation peers", - "disable_policy_batching": "disable-policy-batching", - "disable_policy_batching_ipv4_prefix_list": "disable-policy-batching ipv4 prefix-list", - "disable_policy_batching_ipv6_prefix_list": "disable-policy-batching ipv6 prefix-list", - "enforce_first_as": "enforce-first-as", - "event_history_cli": "event-history cli", - "event_history_detail": "event-history detail", - "event_history_events": "event-history events", - "event_history_periodic": "event-history periodic", - "fast_external_fallover": "fast-external-fallover", - "flush_routes": "flush-routes", - "graceful_restart": "graceful-restart", - "graceful_restart_helper": "graceful-restart-helper", - "graceful_restart_timers_restart": "graceful-restart restart-time", - "graceful_restart_timers_stalepath_time": "graceful-restart stalepath-time", - "isolate": "isolate", - "local_as": "local-as", - "log_neighbor_changes": "log-neighbor-changes", - "maxas_limit": "maxas-limit", - "neighbor_down_fib_accelerate": "neighbor-down fib-accelerate", - "reconnect_interval": "reconnect-interval", - "router_id": "router-id", - "shutdown": "shutdown", - "suppress_fib_pending": "suppress-fib-pending", - "timer_bestpath_limit": "timers bestpath-limit", - "timer_bgp_hold": "timers bgp", - "timer_bgp_keepalive": "timers bgp", - "vrf": "vrf", -} - - -def get_value(arg, config): - command = PARAM_TO_COMMAND_KEYMAP.get(arg) - - if command.split()[0] == "event-history": - has_size = re.search( - r"^\s+{0} size\s(?P.*)$".format(command), config, re.M - ) - - if command == "event-history detail": - value = False - else: - value = "size_small" - - if has_size: - value = "size_%s" % has_size.group("value") - - elif arg in ["enforce_first_as", "fast_external_fallover"]: - no_command_re = re.compile(r"no\s+{0}\s*".format(command), re.M) - value = True - - if no_command_re.search(config): - value = False - - elif arg in BOOL_PARAMS: - has_command = re.search(r"^\s+{0}\s*$".format(command), config, re.M) - value = False - - if has_command: - value = True - else: - command_val_re = re.compile( - r"(?:{0}\s)(?P.*)".format(command), re.M - ) - value = "" - - has_command = command_val_re.search(config) - if has_command: - found_value = has_command.group("value") - - if arg == "confederation_peers": - value = found_value.split() - elif arg == "timer_bgp_keepalive": - value = found_value.split()[0] - elif arg == "timer_bgp_hold": - split_values = found_value.split() - if len(split_values) == 2: - value = split_values[1] - elif found_value: - value = found_value - - return value - - -def get_existing(module, args, warnings): - existing = {} - netcfg = CustomNetworkConfig( - indent=2, contents=get_config(module, flags=["bgp all"]) - ) - - asn_re = re.compile( - r".*router\sbgp\s(?P\d+(\.\d+)?).*", re.S - ) - asn_match = asn_re.match(str(netcfg)) - - if asn_match: - existing_asn = asn_match.group("existing_asn") - bgp_parent = "router bgp {0}".format(existing_asn) - - if module.params["vrf"] != "default": - parents = [bgp_parent, "vrf {0}".format(module.params["vrf"])] - else: - parents = [bgp_parent] - - config = netcfg.get_section(parents) - if config: - for arg in args: - if arg != "asn" and ( - module.params["vrf"] == "default" - or arg not in GLOBAL_PARAMS - ): - existing[arg] = get_value(arg, config) - - existing["asn"] = existing_asn - if module.params["vrf"] == "default": - existing["vrf"] = "default" - - if ( - not existing - and module.params["vrf"] != "default" - and module.params["state"] == "present" - ): - msg = "VRF {0} doesn't exist.".format(module.params["vrf"]) - warnings.append(msg) - - return existing - - -def apply_key_map(key_map, table): - new_dict = {} - for key in table: - new_key = key_map.get(key) - if new_key: - new_dict[new_key] = table.get(key) - - return new_dict - - -def state_present(module, existing, proposed, candidate): - commands = list() - proposed_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, proposed) - existing_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, existing) - - for key, value in proposed_commands.items(): - if value is True: - commands.append(key) - elif value is False: - commands.append("no {0}".format(key)) - elif value == "default": - default_value = PARAM_TO_DEFAULT_KEYMAP.get(key) - existing_value = existing_commands.get(key) - - if default_value: - commands.append("{0} {1}".format(key, default_value)) - elif existing_value: - if key == "confederation peers": - existing_value = " ".join(existing_value) - commands.append("no {0} {1}".format(key, existing_value)) - elif not value: - existing_value = existing_commands.get(key) - if existing_value: - commands.append("no {0} {1}".format(key, existing_value)) - elif key == "confederation peers": - commands.append("{0} {1}".format(key, value)) - elif key.startswith("timers bgp"): - command = "timers bgp {0} {1}".format( - proposed["timer_bgp_keepalive"], proposed["timer_bgp_hold"] - ) - if command not in commands: - commands.append(command) - else: - if value.startswith("size"): - value = value.replace("_", " ") - command = "{0} {1}".format(key, value) - commands.append(command) - - parents = [] - if commands: - commands = fix_commands(commands) - parents = ["router bgp {0}".format(module.params["asn"])] - if module.params["vrf"] != "default": - parents.append("vrf {0}".format(module.params["vrf"])) - elif proposed: - if module.params["vrf"] != "default": - commands.append("vrf {0}".format(module.params["vrf"])) - parents = ["router bgp {0}".format(module.params["asn"])] - else: - commands.append("router bgp {0}".format(module.params["asn"])) - - candidate.add(commands, parents=parents) - - -def state_absent(module, existing, candidate): - commands = [] - parents = [] - if module.params["vrf"] == "default": - commands.append("no router bgp {0}".format(module.params["asn"])) - elif existing.get("vrf") == module.params["vrf"]: - commands.append("no vrf {0}".format(module.params["vrf"])) - parents = ["router bgp {0}".format(module.params["asn"])] - - candidate.add(commands, parents=parents) - - -def fix_commands(commands): - local_as_command = "" - confederation_id_command = "" - confederation_peers_command = "" - - for command in commands: - if "local-as" in command: - local_as_command = command - elif "confederation identifier" in command: - confederation_id_command = command - elif "confederation peers" in command: - confederation_peers_command = command - - if local_as_command and confederation_id_command: - if "no" in confederation_id_command: - commands.pop(commands.index(local_as_command)) - commands.pop(commands.index(confederation_id_command)) - commands.append(confederation_id_command) - commands.append(local_as_command) - else: - commands.pop(commands.index(local_as_command)) - commands.pop(commands.index(confederation_id_command)) - commands.append(local_as_command) - commands.append(confederation_id_command) - - if confederation_peers_command and confederation_id_command: - if local_as_command: - if "no" in local_as_command: - commands.pop(commands.index(local_as_command)) - commands.pop(commands.index(confederation_id_command)) - commands.pop(commands.index(confederation_peers_command)) - commands.append(confederation_id_command) - commands.append(confederation_peers_command) - commands.append(local_as_command) - else: - commands.pop(commands.index(local_as_command)) - commands.pop(commands.index(confederation_id_command)) - commands.pop(commands.index(confederation_peers_command)) - commands.append(local_as_command) - commands.append(confederation_id_command) - commands.append(confederation_peers_command) - else: - commands.pop(commands.index(confederation_peers_command)) - commands.pop(commands.index(confederation_id_command)) - commands.append(confederation_id_command) - commands.append(confederation_peers_command) - - return commands - - -def main(): - argument_spec = dict( - asn=dict(required=True, type="str"), - vrf=dict(required=False, type="str", default="default"), - bestpath_always_compare_med=dict(required=False, type="bool"), - bestpath_aspath_multipath_relax=dict(required=False, type="bool"), - bestpath_compare_neighborid=dict(required=False, type="bool"), - bestpath_compare_routerid=dict(required=False, type="bool"), - bestpath_cost_community_ignore=dict(required=False, type="bool"), - bestpath_med_confed=dict(required=False, type="bool"), - bestpath_med_missing_as_worst=dict(required=False, type="bool"), - bestpath_med_non_deterministic=dict(required=False, type="bool"), - cluster_id=dict(required=False, type="str"), - confederation_id=dict(required=False, type="str"), - confederation_peers=dict(required=False, type="list", elements="str"), - disable_policy_batching=dict(required=False, type="bool"), - disable_policy_batching_ipv4_prefix_list=dict( - required=False, type="str" - ), - disable_policy_batching_ipv6_prefix_list=dict( - required=False, type="str" - ), - enforce_first_as=dict(required=False, type="bool"), - event_history_cli=dict( - required=False, - choices=[ - "true", - "false", - "default", - "size_small", - "size_medium", - "size_large", - "size_disable", - ], - ), - event_history_detail=dict( - required=False, - choices=[ - "true", - "false", - "default", - "size_small", - "size_medium", - "size_large", - "size_disable", - ], - ), - event_history_events=dict( - required=False, - choices=[ - "true", - "false", - "default", - "size_small", - "size_medium", - "size_large", - "size_disable", - ], - ), - event_history_periodic=dict( - required=False, - choices=[ - "true", - "false", - "default", - "size_small", - "size_medium", - "size_large", - "size_disable", - ], - ), - fast_external_fallover=dict(required=False, type="bool"), - flush_routes=dict(required=False, type="bool"), - graceful_restart=dict(required=False, type="bool"), - graceful_restart_helper=dict(required=False, type="bool"), - graceful_restart_timers_restart=dict(required=False, type="str"), - graceful_restart_timers_stalepath_time=dict( - required=False, type="str" - ), - isolate=dict(required=False, type="bool"), - local_as=dict(required=False, type="str"), - log_neighbor_changes=dict(required=False, type="bool"), - maxas_limit=dict(required=False, type="str"), - neighbor_down_fib_accelerate=dict(required=False, type="bool"), - reconnect_interval=dict(required=False, type="str"), - router_id=dict(required=False, type="str"), - shutdown=dict(required=False, type="bool"), - suppress_fib_pending=dict(required=False, type="bool"), - timer_bestpath_limit=dict(required=False, type="str"), - timer_bgp_hold=dict(required=False, type="str"), - timer_bgp_keepalive=dict(required=False, type="str"), - state=dict( - choices=["present", "absent"], default="present", required=False - ), - ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, - required_together=[["timer_bgp_hold", "timer_bgp_keepalive"]], - supports_check_mode=True, - ) - - warnings = list() - result = dict(changed=False, warnings=warnings) - - state = module.params["state"] - - if module.params["vrf"] != "default": - for param in GLOBAL_PARAMS: - if module.params[param]: - module.fail_json( - msg='Global params can be modified only under "default" VRF.', - vrf=module.params["vrf"], - global_param=param, - ) - - args = PARAM_TO_COMMAND_KEYMAP.keys() - existing = get_existing(module, args, warnings) - - if existing.get("asn") and state == "present": - if existing.get("asn") != module.params["asn"]: - module.fail_json( - msg="Another BGP ASN already exists.", - proposed_asn=module.params["asn"], - existing_asn=existing.get("asn"), - ) - - proposed_args = dict( - (k, v) for k, v in module.params.items() if v is not None and k in args - ) - proposed = {} - for key, value in proposed_args.items(): - if key not in ["asn", "vrf"]: - if str(value).lower() == "default": - value = PARAM_TO_DEFAULT_KEYMAP.get(key, "default") - if key == "confederation_peers": - if value[0] == "default": - if existing.get(key): - proposed[key] = "default" - else: - v = set([int(i) for i in value]) - ex = set([int(i) for i in existing.get(key)]) - if v != ex: - proposed[key] = " ".join(str(s) for s in v) - else: - if existing.get(key) != value: - proposed[key] = value - - candidate = CustomNetworkConfig(indent=3) - if state == "present": - state_present(module, existing, proposed, candidate) - elif existing.get("asn") == module.params["asn"]: - state_absent(module, existing, candidate) - - if candidate: - candidate = candidate.items_text() - if not module.check_mode: - load_config(module, candidate) - result["changed"] = True - result["commands"] = candidate - else: - result["commands"] = [] - - module.exit_json(**result) - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/nxos_bgp_address_family.py b/plugins/modules/nxos_bgp_address_family.py index b117d0045..489b6fa30 100644 --- a/plugins/modules/nxos_bgp_address_family.py +++ b/plugins/modules/nxos_bgp_address_family.py @@ -10,6 +10,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type DOCUMENTATION = """ @@ -51,7 +52,7 @@ description: Address Family indicator. type: str choices: ["ipv4", "ipv6", "link-state", "vpnv4", "vpnv6", "l2vpn"] - required: True + required: true safi: description: Sub Address Family indicator. type: str @@ -366,11 +367,11 @@ safi: unicast vrf: site-1 default_information: - originate: True + originate: true aggregate_address: - prefix: 203.0.113.0/24 - as_set: True - summary_only: True + as_set: true + summary_only: true - afi: ipv6 safi: multicast vrf: site-1 @@ -382,8 +383,8 @@ id: 101 route_map: rmap-eigrp-1 -# Task output -# ------------- +# Task output: +# ------------ # before: {} # # commands: @@ -419,11 +420,11 @@ # safi: unicast # vrf: site-1 # default_information: -# originate: True +# originate: true # aggregate_address: # - prefix: 203.0.113.0/24 -# as_set: True -# summary_only: True +# as_set: true +# summary_only: true # - afi: ipv6 # safi: multicast # vrf: site-1 @@ -436,7 +437,7 @@ # route_map: rmap-eigrp-1 # After state: -# ------------- +# ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65536 # address-family ipv4 multicast @@ -489,15 +490,15 @@ non_critical_delay: 180 aggregate_address: - prefix: 203.0.113.0/24 - as_set: True - summary_only: True + as_set: true + summary_only: true - afi: ipv4 safi: unicast vrf: site-1 state: replaced -# Task output -# ------------- +# Task output: +# ------------ # before: # as_number: "65536" # address_family: @@ -516,11 +517,11 @@ # safi: unicast # vrf: site-1 # default_information: -# originate: True +# originate: true # aggregate_address: # - prefix: 203.0.113.0/24 -# as_set: True -# summary_only: True +# as_set: true +# summary_only: true # - afi: ipv6 # safi: multicast # vrf: site-1 @@ -557,8 +558,8 @@ # non_critical_delay: 180 # aggregate_address: # - prefix: 203.0.113.0/24 -# as_set: True -# summary_only: True +# as_set: true +# summary_only: true # # - afi: ipv4 # safi: unicast @@ -576,7 +577,7 @@ # route_map: rmap-eigrp-1 # After state: -# ------------- +# ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65536 # address-family ipv4 multicast @@ -621,15 +622,15 @@ route_map: rmap1 aggregate_address: - prefix: 203.0.113.0/24 - as_set: True - summary_only: True + as_set: true + summary_only: true - afi: ipv4 safi: unicast vrf: site-1 state: overridden -# Task output -# ------------- +# Task output: +# ------------ # before: # as_number: "65536" # address_family: @@ -648,11 +649,11 @@ # safi: unicast # vrf: site-1 # default_information: -# originate: True +# originate: true # aggregate_address: # - prefix: 203.0.113.0/24 -# as_set: True -# summary_only: True +# as_set: true +# summary_only: true # - afi: ipv6 # safi: multicast # vrf: site-1 @@ -689,15 +690,15 @@ # route_map: rmap1 # aggregate_address: # - prefix: 203.0.113.0/24 -# as_set: True -# summary_only: True +# as_set: true +# summary_only: true # - afi: ipv4 # safi: unicast # vrf: site-1 # # After state: -# ------------- +# ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65536 # address-family ipv4 multicast @@ -738,8 +739,8 @@ safi: multicast state: deleted -# Task output -# ------------- +# Task output: +# ------------ # before: # as_number: "65536" # address_family: @@ -758,11 +759,11 @@ # safi: unicast # vrf: site-1 # default_information: -# originate: True +# originate: true # aggregate_address: # - prefix: 203.0.113.0/24 -# as_set: True -# summary_only: True +# as_set: true +# summary_only: true # - afi: ipv6 # safi: multicast # vrf: site-1 @@ -787,14 +788,14 @@ # safi: unicast # vrf: site-1 # default_information: -# originate: True +# originate: true # aggregate_address: # - prefix: 203.0.113.0/24 -# as_set: True -# summary_only: True +# as_set: true +# summary_only: true # After state: -# ------------- +# ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65536 # vrf site-1 @@ -825,8 +826,8 @@ cisco.nxos.nxos_bgp_address_family: state: deleted -# Task output -# ------------- +# Task output: +# ------------ # before: # as_number: "65536" # address_family: @@ -845,11 +846,11 @@ # safi: unicast # vrf: site-1 # default_information: -# originate: True +# originate: true # aggregate_address: # - prefix: 203.0.113.0/24 -# as_set: True -# summary_only: True +# as_set: true +# summary_only: true # - afi: ipv6 # safi: multicast # vrf: site-1 @@ -872,7 +873,7 @@ # as_number: "65536" # After state: -# ------------- +# ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65536 # Nexus9000v# @@ -899,11 +900,11 @@ safi: unicast vrf: site-1 default_information: - originate: True + originate: true aggregate_address: - prefix: 203.0.113.0/24 - as_set: True - summary_only: True + as_set: true + summary_only: true - afi: ipv6 safi: multicast vrf: site-1 @@ -916,8 +917,8 @@ route_map: rmap-eigrp-1 state: rendered -# Task Output (redacted) -# ----------------------- +# Task Output: +# ------------ # rendered: # - router bgp 65536 # - address-family ipv4 multicast @@ -956,8 +957,8 @@ running_config: "{{ lookup('file', 'parsed.cfg') }}" state: parsed -# Task output (redacted) -# ----------------------- +# Task output: +# ------------ # parsed: # as_number: "65536" # address_family: @@ -976,11 +977,11 @@ # safi: unicast # vrf: site-1 # default_information: -# originate: True +# originate: true # aggregate_address: # - prefix: 203.0.113.0/24 -# as_set: True -# summary_only: True +# as_set: true +# summary_only: true # - afi: ipv6 # safi: multicast # vrf: site-1 @@ -992,8 +993,55 @@ # protocol: eigrp # route_map: rmap-eigrp-1 """ +RETURN = """ +before: + description: The configuration prior to the module execution. + returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) + type: dict + sample: > + This output will always be in the same format as the + module argspec. +after: + description: The resulting configuration after module execution. + returned: when changed + type: dict + sample: > + This output will always be in the same format as the + module argspec. +commands: + description: The set of commands pushed to the remote device. + returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) + type: list + sample: + - router bgp 65536 + - address-family ipv4 multicast + - nexthop route-map rmap2 +rendered: + description: The provided configuration in the task rendered in device-native format (offline). + returned: when I(state) is C(rendered) + type: list + sample: + - router bgp 65536 + - address-family ipv4 multicast + - nexthop route-map rmap2 +gathered: + description: Facts about the network resource gathered from the remote device as structured data. + returned: when I(state) is C(gathered) + type: dict + sample: > + This output will always be in the same format as the + module argspec. +parsed: + description: The device native config provided in I(running_config) option parsed into structured data as per module argspec. + returned: when I(state) is C(parsed) + type: dict + sample: > + This output will always be in the same format as the + module argspec. +""" from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.bgp_address_family.bgp_address_family import ( Bgp_address_familyArgs, ) diff --git a/plugins/modules/nxos_bgp_af.py b/plugins/modules/nxos_bgp_af.py deleted file mode 100644 index d00ce318f..000000000 --- a/plugins/modules/nxos_bgp_af.py +++ /dev/null @@ -1,940 +0,0 @@ -#!/usr/bin/python -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - - -DOCUMENTATION = """ -module: nxos_bgp_af -extends_documentation_fragment: -- cisco.nxos.nxos -short_description: (deprecated, removed after 2023-02-24) Manages BGP Address-family configuration. -description: -- Manages BGP Address-family configurations on NX-OS switches. -version_added: 1.0.0 -author: Gabriele Gerbino (@GGabriele) -deprecated: - alternative: nxos_bgp_address_family - why: Updated module released with more functionality. - removed_at_date: '2023-02-24' -notes: -- Tested against NXOSv 7.3.(0)D1(1) on VIRL -- Unsupported for Cisco MDS -- C(state=absent) removes the whole BGP ASN configuration -- Default, where supported, restores params default value. -options: - asn: - description: - - BGP autonomous system number. Valid values are String, Integer in ASPLAIN or - ASDOT notation. - required: true - type: str - vrf: - description: - - Name of the VRF. The name 'default' is a valid VRF representing the global bgp. - default: 'default' - type: str - afi: - description: - - Address Family Identifier. - required: true - choices: - - ipv4 - - ipv6 - - vpnv4 - - vpnv6 - - l2vpn - type: str - safi: - description: - - Sub Address Family Identifier. - required: true - choices: - - unicast - - multicast - - evpn - type: str - additional_paths_install: - description: - - Install a backup path into the forwarding table and provide prefix independent - convergence (PIC) in case of a PE-CE link failure. - type: bool - additional_paths_receive: - description: - - Enables the receive capability of additional paths for all of the neighbors - under this address family for which the capability has not been disabled. - type: bool - additional_paths_selection: - description: - - Configures the capability of selecting additional paths for a prefix. Valid - values are a string defining the name of the route-map. - type: str - additional_paths_send: - description: - - Enables the send capability of additional paths for all of the neighbors under - this address family for which the capability has not been disabled. - type: bool - advertise_l2vpn_evpn: - description: - - Advertise evpn routes. - type: bool - client_to_client: - description: - - Configure client-to-client route reflection. - type: bool - dampen_igp_metric: - description: - - Specify dampen value for IGP metric-related changes, in seconds. Valid values - are integer and keyword 'default'. - type: str - dampening_state: - description: - - Enable/disable route-flap dampening. - type: bool - dampening_half_time: - description: - - Specify decay half-life in minutes for route-flap dampening. Valid values are - integer and keyword 'default'. - type: str - dampening_max_suppress_time: - description: - - Specify max suppress time for route-flap dampening stable route. Valid values - are integer and keyword 'default'. - type: str - dampening_reuse_time: - description: - - Specify route reuse time for route-flap dampening. Valid values are integer - and keyword 'default'. - type: str - dampening_routemap: - description: - - Specify route-map for route-flap dampening. Valid values are a string defining - the name of the route-map. - type: str - dampening_suppress_time: - description: - - Specify route suppress time for route-flap dampening. Valid values are integer - and keyword 'default'. - type: str - default_information_originate: - description: - - Default information originate. - type: bool - default_metric: - description: - - Sets default metrics for routes redistributed into BGP. Valid values are Integer - or keyword 'default' - type: str - distance_ebgp: - description: - - Sets the administrative distance for eBGP routes. Valid values are Integer or - keyword 'default'. - type: str - distance_ibgp: - description: - - Sets the administrative distance for iBGP routes. Valid values are Integer or - keyword 'default'. - type: str - distance_local: - description: - - Sets the administrative distance for local BGP routes. Valid values are Integer - or keyword 'default'. - type: str - inject_map: - description: - - An array of route-map names which will specify prefixes to inject. Each array - entry must first specify the inject-map name, secondly an exist-map name, and - optionally the copy-attributes keyword which indicates that attributes should - be copied from the aggregate. For example [['lax_inject_map', 'lax_exist_map'], - ['nyc_inject_map', 'nyc_exist_map', 'copy-attributes'], ['fsd_inject_map', 'fsd_exist_map']]. - type: list - elements: list - maximum_paths: - description: - - Configures the maximum number of equal-cost paths for load sharing. Valid value - is an integer in the range 1-64. - type: str - maximum_paths_ibgp: - description: - - Configures the maximum number of ibgp equal-cost paths for load sharing. Valid - value is an integer in the range 1-64. - type: str - networks: - description: - - Networks to configure. Valid value is a list of network prefixes to advertise. - The list must be in the form of an array. Each entry in the array must include - a prefix address and an optional route-map. For example [['10.0.0.0/16', 'routemap_LA'], - ['192.168.1.1', 'Chicago'], ['192.168.2.0/24'], ['192.168.3.0/24', 'routemap_NYC']]. - type: list - elements: list - next_hop_route_map: - description: - - Configure a route-map for valid nexthops. Valid values are a string defining - the name of the route-map. - type: str - redistribute: - description: - - A list of redistribute directives. Multiple redistribute entries are allowed. - The list must be in the form of a nested array. the first entry of each array - defines the source-protocol to redistribute from; the second entry defines a - route-map name. A route-map is highly advised but may be optional on some platforms, - in which case it may be omitted from the array list. For example [['direct', - 'rm_direct'], ['lisp', 'rm_lisp']]. - type: list - elements: list - suppress_inactive: - description: - - Advertises only active routes to peers. - type: bool - table_map: - description: - - Apply table-map to filter routes downloaded into URIB. Valid values are a string. - type: str - table_map_filter: - description: - - Filters routes rejected by the route-map and does not download them to the RIB. - type: bool - state: - description: - - Determines whether the config should be present or not on the device. - default: present - choices: - - present - - absent - type: str - retain_route_target: - description: - - Retains all of the routes or the routes which are part of configured route-map. - Valid values are route-map names or keyword C(all) or keyword C(default). C(all) - retains all the routes regardless of Target-VPN community. C(default) will disable - the retain route target option. If you are using route-map name please ensure - that the name is not same as C(all) and C(default). - type: str - version_added: 1.1.0 -""" -EXAMPLES = """ -# configure a simple address-family -- cisco.nxos.nxos_bgp_af: - asn: 65535 - vrf: TESTING - afi: ipv4 - safi: unicast - advertise_l2vpn_evpn: true - state: present - retain_route_target: all -""" - -RETURN = """ -commands: - description: commands sent to the device - returned: always - type: list - sample: ["router bgp 65535", "vrf TESTING", - "address-family ipv4 unicast", "advertise l2vpn evpn", - "retain route-target all"] -""" - -import re - -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_config, - load_config, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( - CustomNetworkConfig, -) - - -BOOL_PARAMS = [ - "additional_paths_install", - "additional_paths_receive", - "additional_paths_send", - "advertise_l2vpn_evpn", - "dampening_state", - "default_information_originate", - "suppress_inactive", -] -PARAM_TO_DEFAULT_KEYMAP = { - "maximum_paths": "1", - "maximum_paths_ibgp": "1", - "client_to_client": True, - "distance_ebgp": "20", - "distance_ibgp": "200", - "distance_local": "220", - "dampen_igp_metric": "600", -} -PARAM_TO_COMMAND_KEYMAP = { - "asn": "router bgp", - "afi": "address-family", - "safi": "address-family", - "additional_paths_install": "additional-paths install backup", - "additional_paths_receive": "additional-paths receive", - "additional_paths_selection": "additional-paths selection route-map", - "additional_paths_send": "additional-paths send", - "advertise_l2vpn_evpn": "advertise l2vpn evpn", - "client_to_client": "client-to-client reflection", - "dampen_igp_metric": "dampen-igp-metric", - "dampening_state": "dampening", - "dampening_half_time": "dampening", - "dampening_max_suppress_time": "dampening", - "dampening_reuse_time": "dampening", - "dampening_routemap": "dampening route-map", - "dampening_suppress_time": "dampening", - "default_information_originate": "default-information originate", - "default_metric": "default-metric", - "distance_ebgp": "distance", - "distance_ibgp": "distance", - "distance_local": "distance", - "inject_map": "inject-map", - "maximum_paths": "maximum-paths", - "maximum_paths_ibgp": "maximum-paths ibgp", - "networks": "network", - "redistribute": "redistribute", - "next_hop_route_map": "nexthop route-map", - "suppress_inactive": "suppress-inactive", - "table_map": "table-map", - "table_map_filter": "table-map-filter", - "vrf": "vrf", - "retain_route_target": "retain route-target", -} -DAMPENING_PARAMS = [ - "dampening_half_time", - "dampening_suppress_time", - "dampening_reuse_time", - "dampening_max_suppress_time", -] - - -def get_value(arg, config, module): - command = PARAM_TO_COMMAND_KEYMAP[arg] - command_val_re = re.compile( - r"(?:{0}\s)(?P.*)$".format(command), re.M - ) - has_command_val = command_val_re.search(config) - - if arg in ["networks", "redistribute", "inject_map"]: - value = [] - for ele in command_val_re.findall(config): - tl = ele.split() - if "exist-map" in tl: - tl.remove("exist-map") - elif "route-map" in tl: - tl.remove("route-map") - value.append(tl) - - elif command == "distance": - distance_re = ( - r".*distance\s(?P\w+)\s(?P\w+)\s(?P\w+)" - ) - match_distance = re.match(distance_re, config, re.DOTALL) - - value = "" - if match_distance: - distance_group = match_distance.groupdict() - - if arg == "distance_ebgp": - value = distance_group["d_ebgp"] - elif arg == "distance_ibgp": - value = distance_group["d_ibgp"] - elif arg == "distance_local": - value = distance_group["d_local"] - - elif command.split()[0] == "dampening": - value = "" - if arg == "dampen_igp_metric" or arg == "dampening_routemap": - if command in config: - value = has_command_val.group("value") - else: - dampening_re = r".*dampening\s(?P\w+)\s(?P\w+)\s(?P\w+)\s(?P\w+)" - match_dampening = re.match(dampening_re, config, re.DOTALL) - if match_dampening: - dampening_group = match_dampening.groupdict() - - if arg == "dampening_half_time": - value = dampening_group["half"] - elif arg == "dampening_reuse_time": - value = dampening_group["reuse"] - elif arg == "dampening_suppress_time": - value = dampening_group["suppress"] - elif arg == "dampening_max_suppress_time": - value = dampening_group["max_suppress"] - else: - if arg == "dampening_state": - value = True if "dampening" in config else False - elif arg == "table_map_filter": - tmf_regex = re.compile(r"\s+table-map.*filter$", re.M) - value = False - if tmf_regex.search(config): - value = True - - elif arg == "table_map": - tm_regex = re.compile( - r"(?:table-map\s)(?P\S+)(\sfilter)?$", re.M - ) - has_tablemap = tm_regex.search(config) - value = "" - if has_tablemap: - value = has_tablemap.group("value") - - elif arg == "client_to_client": - no_command_re = re.compile(r"^\s+no\s{0}\s*$".format(command), re.M) - value = True - - if no_command_re.search(config): - value = False - - elif arg == "retain_route_target": - value = "" - if command in config: - route_target = has_command_val.group("value") - if route_target: - if route_target == "all": - value = "all" - elif "route-map" in route_target: - value = route_target.replace("route-map ", "") - - elif arg in BOOL_PARAMS: - command_re = re.compile(r"^\s+{0}\s*$".format(command), re.M) - value = False - - if command_re.search(config): - value = True - - else: - value = "" - - if has_command_val: - value = has_command_val.group("value") - - return value - - -def get_existing(module, args, warnings): - existing = {} - netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) - - asn_regex = re.compile( - r".*router\sbgp\s(?P\d+(\.\d+)?).*", re.DOTALL - ) - match_asn = asn_regex.match(str(netcfg)) - - if match_asn: - existing_asn = match_asn.group("existing_asn") - parents = ["router bgp {0}".format(existing_asn)] - if module.params["vrf"] != "default": - parents.append("vrf {0}".format(module.params["vrf"])) - - parents.append( - "address-family {0} {1}".format( - module.params["afi"], module.params["safi"] - ) - ) - config = netcfg.get_section(parents) - - if config: - for arg in args: - if arg not in ["asn", "afi", "safi", "vrf"]: - gv = get_value(arg, config, module) - if gv: - existing[arg] = gv - else: - if ( - arg != "client_to_client" - and arg in PARAM_TO_DEFAULT_KEYMAP.keys() - ): - existing[arg] = PARAM_TO_DEFAULT_KEYMAP.get(arg) - else: - existing[arg] = gv - - existing["asn"] = existing_asn - existing["afi"] = module.params["afi"] - existing["safi"] = module.params["safi"] - existing["vrf"] = module.params["vrf"] - else: - warnings.append( - "The BGP process {0} didn't exist but the task just created it.".format( - module.params["asn"] - ) - ) - - return existing - - -def apply_key_map(key_map, table): - new_dict = {} - for key, value in table.items(): - new_key = key_map.get(key) - if new_key: - new_dict[new_key] = value - - return new_dict - - -def fix_proposed(module, proposed, existing): - commands = list() - command = "" - fixed_proposed = {} - for key, value in proposed.items(): - if key in DAMPENING_PARAMS: - if value != "default": - command = "dampening {0} {1} {2} {3}".format( - proposed.get("dampening_half_time"), - proposed.get("dampening_reuse_time"), - proposed.get("dampening_suppress_time"), - proposed.get("dampening_max_suppress_time"), - ) - else: - if existing.get(key): - command = "no dampening {0} {1} {2} {3}".format( - existing["dampening_half_time"], - existing["dampening_reuse_time"], - existing["dampening_suppress_time"], - existing["dampening_max_suppress_time"], - ) - if "default" in command: - command = "" - elif key.startswith("distance"): - command = "distance {0} {1} {2}".format( - proposed.get("distance_ebgp"), - proposed.get("distance_ibgp"), - proposed.get("distance_local"), - ) - else: - fixed_proposed[key] = value - - if command: - if command not in commands: - commands.append(command) - - return fixed_proposed, commands - - -def default_existing(existing_value, key, value): - commands = [] - if key == "network": - for network in existing_value: - if len(network) == 2: - commands.append( - "no network {0} route-map {1}".format( - network[0], network[1] - ) - ) - elif len(network) == 1: - commands.append("no network {0}".format(network[0])) - - elif key == "inject-map": - for maps in existing_value: - if len(maps) == 2: - commands.append( - "no inject-map {0} exist-map {1}".format(maps[0], maps[1]) - ) - elif len(maps) == 3: - commands.append( - "no inject-map {0} exist-map {1} " - "copy-attributes".format(maps[0], maps[1]) - ) - - elif key == "redistribute": - for maps in existing_value: - commands.append( - "no redistribute {0} route-map {1}".format(maps[0], maps[1]) - ) - - elif key == "retain route-target": - if existing_value == "all": - commands.append("no {0} {1}".format(key, existing_value)) - elif existing_value != "default": - commands.append("no {0} route-map {1}".format(key, existing_value)) - - else: - commands.append("no {0} {1}".format(key, existing_value)) - return commands - - -def get_network_command(existing, key, value): - commands = [] - existing_networks = existing.get("networks", []) - for inet in value: - if not isinstance(inet, list): - inet = [inet] - if inet not in existing_networks: - if len(inet) == 1: - command = "{0} {1}".format(key, inet[0]) - elif len(inet) == 2: - command = "{0} {1} route-map {2}".format(key, inet[0], inet[1]) - if command: - commands.append(command) - for enet in existing_networks: - if enet not in value: - if len(enet) == 1: - command = "no {0} {1}".format(key, enet[0]) - elif len(enet) == 2: - command = "no {0} {1} route-map {2}".format( - key, enet[0], enet[1] - ) - if command: - commands.append(command) - return commands - - -def get_inject_map_command(existing, key, value): - commands = [] - existing_maps = existing.get("inject_map", []) - for maps in value: - if not isinstance(maps, list): - maps = [maps] - if maps not in existing_maps: - if len(maps) == 2: - command = "inject-map {0} exist-map {1}".format( - maps[0], maps[1] - ) - elif len(maps) == 3: - command = ( - "inject-map {0} exist-map {1} " - "copy-attributes".format(maps[0], maps[1]) - ) - if command: - commands.append(command) - for emaps in existing_maps: - if emaps not in value: - if len(emaps) == 2: - command = "no inject-map {0} exist-map {1}".format( - emaps[0], emaps[1] - ) - elif len(emaps) == 3: - command = ( - "no inject-map {0} exist-map {1} " - "copy-attributes".format(emaps[0], emaps[1]) - ) - if command: - commands.append(command) - return commands - - -def get_redistribute_command(existing, key, value): - commands = [] - existing_rules = existing.get("redistribute", []) - for rule in value: - if not isinstance(rule, list): - rule = [rule] - if rule not in existing_rules: - command = "redistribute {0} route-map {1}".format(rule[0], rule[1]) - commands.append(command) - for erule in existing_rules: - if erule not in value: - command = "no redistribute {0} route-map {1}".format( - erule[0], erule[1] - ) - commands.append(command) - return commands - - -def get_table_map_command(module, existing, key, value): - commands = [] - if key == "table-map": - if value != "default": - command = "{0} {1}".format(key, module.params["table_map"]) - if ( - module.params["table_map_filter"] is not None - and module.params["table_map_filter"] != "default" - ): - command += " filter" - commands.append(command) - else: - if existing.get("table_map"): - command = "no {0} {1}".format(key, existing.get("table_map")) - commands.append(command) - return commands - - -def get_retain_route_target_command(existing, key, value): - commands = [] - if key == "retain route-target": - if value != "default": - if value == "all": - command = "{0} {1}".format(key, value) - else: - command = "{0} route-map {1}".format(key, value) - else: - existing_value = existing.get("retain_route_target") - if existing_value == "all": - command = "no {0} {1}".format(key, existing_value) - else: - command = "no {0} route-map {1}".format(key, existing_value) - commands.append(command) - return commands - - -def get_default_table_map_filter(existing): - commands = [] - existing_table_map_filter = existing.get("table_map_filter") - if existing_table_map_filter: - existing_table_map = existing.get("table_map") - if existing_table_map: - command = "table-map {0}".format(existing_table_map) - commands.append(command) - return commands - - -def state_present(module, existing, proposed, candidate): - fixed_proposed, commands = fix_proposed(module, proposed, existing) - proposed_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, fixed_proposed) - existing_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, existing) - for key, value in proposed_commands.items(): - if key == "address-family": - addr_family_command = "address-family {0} {1}".format( - module.params["afi"], module.params["safi"] - ) - if addr_family_command not in commands: - commands.append(addr_family_command) - - elif key.startswith("table-map"): - table_map_commands = get_table_map_command( - module, existing, key, value - ) - if table_map_commands: - commands.extend(table_map_commands) - - elif value is True: - commands.append(key) - - elif value is False: - commands.append("no {0}".format(key)) - - elif value == "default": - if key in PARAM_TO_DEFAULT_KEYMAP: - commands.append( - "{0} {1}".format(key, PARAM_TO_DEFAULT_KEYMAP[key]) - ) - - elif existing_commands.get(key): - if key == "table-map-filter": - default_tmf_command = get_default_table_map_filter( - existing - ) - - if default_tmf_command: - commands.extend(default_tmf_command) - else: - existing_value = existing_commands.get(key) - default_command = default_existing( - existing_value, key, value - ) - if default_command: - commands.extend(default_command) - else: - if key == "network": - network_commands = get_network_command(existing, key, value) - if network_commands: - commands.extend(network_commands) - - elif key == "inject-map": - inject_map_commands = get_inject_map_command( - existing, key, value - ) - if inject_map_commands: - commands.extend(inject_map_commands) - - elif key == "redistribute": - redistribute_commands = get_redistribute_command( - existing, key, value - ) - if redistribute_commands: - commands.extend(redistribute_commands) - - elif key == "retain route-target": - retain_route_target_commands = get_retain_route_target_command( - existing, key, value - ) - if retain_route_target_commands: - commands.extend(retain_route_target_commands) - - else: - command = "{0} {1}".format(key, value) - commands.append(command) - - if commands: - parents = ["router bgp {0}".format(module.params["asn"])] - if module.params["vrf"] != "default": - parents.append("vrf {0}".format(module.params["vrf"])) - - addr_family_command = "address-family {0} {1}".format( - module.params["afi"], module.params["safi"] - ) - parents.append(addr_family_command) - if addr_family_command in commands: - commands.remove(addr_family_command) - candidate.add(commands, parents=parents) - - -def state_absent(module, candidate): - commands = [] - parents = ["router bgp {0}".format(module.params["asn"])] - if module.params["vrf"] != "default": - parents.append("vrf {0}".format(module.params["vrf"])) - - commands.append( - "no address-family {0} {1}".format( - module.params["afi"], module.params["safi"] - ) - ) - candidate.add(commands, parents=parents) - - -def main(): - argument_spec = dict( - asn=dict(required=True, type="str"), - vrf=dict(required=False, type="str", default="default"), - safi=dict( - required=True, type="str", choices=["unicast", "multicast", "evpn"] - ), - afi=dict( - required=True, - type="str", - choices=["ipv4", "ipv6", "vpnv4", "vpnv6", "l2vpn"], - ), - additional_paths_install=dict(required=False, type="bool"), - additional_paths_receive=dict(required=False, type="bool"), - additional_paths_selection=dict(required=False, type="str"), - additional_paths_send=dict(required=False, type="bool"), - advertise_l2vpn_evpn=dict(required=False, type="bool"), - client_to_client=dict(required=False, type="bool"), - dampen_igp_metric=dict(required=False, type="str"), - dampening_state=dict(required=False, type="bool"), - dampening_half_time=dict(required=False, type="str"), - dampening_max_suppress_time=dict(required=False, type="str"), - dampening_reuse_time=dict(required=False, type="str"), - dampening_routemap=dict(required=False, type="str"), - dampening_suppress_time=dict(required=False, type="str"), - default_information_originate=dict(required=False, type="bool"), - default_metric=dict(required=False, type="str"), - distance_ebgp=dict(required=False, type="str"), - distance_ibgp=dict(required=False, type="str"), - distance_local=dict(required=False, type="str"), - inject_map=dict(required=False, type="list", elements="list"), - maximum_paths=dict(required=False, type="str"), - maximum_paths_ibgp=dict(required=False, type="str"), - networks=dict(required=False, type="list", elements="list"), - next_hop_route_map=dict(required=False, type="str"), - redistribute=dict(required=False, type="list", elements="list"), - suppress_inactive=dict(required=False, type="bool"), - table_map=dict(required=False, type="str"), - table_map_filter=dict(required=False, type="bool"), - state=dict( - choices=["present", "absent"], default="present", required=False - ), - retain_route_target=dict(required=False, type="str"), - ) - - argument_spec.update(nxos_argument_spec) - - mutually_exclusive = [ - ("dampening_state", "dampening_routemap"), - ("dampening_state", "dampening_half_time"), - ("dampening_state", "dampening_suppress_time"), - ("dampening_state", "dampening_reuse_time"), - ("dampening_state", "dampening_max_suppress_time"), - ("dampening_routemap", "dampening_half_time"), - ("dampening_routemap", "dampening_suppress_time"), - ("dampening_routemap", "dampening_reuse_time"), - ("dampening_routemap", "dampening_max_suppress_time"), - ] - - module = AnsibleModule( - argument_spec=argument_spec, - mutually_exclusive=mutually_exclusive, - required_together=[ - DAMPENING_PARAMS, - ["distance_ibgp", "distance_ebgp", "distance_local"], - ], - supports_check_mode=True, - ) - - warnings = list() - result = dict(changed=False, warnings=warnings) - - state = module.params["state"] - - if module.params["advertise_l2vpn_evpn"]: - if module.params["vrf"] == "default": - module.fail_json( - msg="It is not possible to advertise L2VPN " - "EVPN in the default VRF. Please specify " - "another one.", - vrf=module.params["vrf"], - ) - - if module.params["table_map_filter"] and not module.params["table_map"]: - module.fail_json( - msg="table_map param is needed when using" - " table_map_filter filter." - ) - - args = PARAM_TO_COMMAND_KEYMAP.keys() - existing = get_existing(module, args, warnings) - - if existing.get("asn") and state == "present": - if existing.get("asn") != module.params["asn"]: - module.fail_json( - msg="Another BGP ASN already exists.", - proposed_asn=module.params["asn"], - existing_asn=existing.get("asn"), - ) - - proposed_args = dict( - (k, v) for k, v in module.params.items() if v is not None and k in args - ) - - for arg in ["networks", "inject_map", "redistribute"]: - if proposed_args.get(arg): - if proposed_args[arg][0] == "default": - proposed_args[arg] = "default" - - proposed = {} - for key, value in proposed_args.items(): - if key not in ["asn", "vrf"]: - if str(value).lower() == "default": - value = PARAM_TO_DEFAULT_KEYMAP.get(key, "default") - if existing.get(key) != value: - proposed[key] = value - - candidate = CustomNetworkConfig(indent=3) - if state == "present": - state_present(module, existing, proposed, candidate) - elif state == "absent" and existing: - state_absent(module, candidate) - - if candidate: - candidate = candidate.items_text() - if not module.check_mode: - load_config(module, candidate) - result["changed"] = True - result["commands"] = candidate - else: - result["commands"] = [] - - module.exit_json(**result) - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/nxos_bgp_global.py b/plugins/modules/nxos_bgp_global.py index f6d0c1f83..59e7eefd7 100644 --- a/plugins/modules/nxos_bgp_global.py +++ b/plugins/modules/nxos_bgp_global.py @@ -10,6 +10,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type DOCUMENTATION = """ @@ -202,7 +203,7 @@ neighbor_address: description: IP address/Prefix of the neighbor or interface. type: str - required: True + required: true bfd: description: Bidirectional Fast Detection for the neighbor. type: dict @@ -356,6 +357,9 @@ remote_as: description: Specify Autonomous System Number of the neighbor. type: str + remote_as_route_map: + description: Route-map to match prefix peer AS number. + type: str remove_private_as: description: Remove private AS number from outbound updates. type: dict @@ -507,14 +511,16 @@ or a vrf context that is to be removed. Please use the M(cisco.nxos.nxos_bgp_af) or M(cisco.nxos.nxos_bgp_neighbor_af) modules for prior cleanup. - - States I(merged) and I(replaced) will result in a failure if BGP is already configured + - States C(merged) and C(replaced) will result in a failure if BGP is already configured with a different ASN than what is provided in the task. In such cases, please use - state I(purged) to remove the existing BGP process and proceed further. + state C(purged) to remove the existing BGP process and proceed further. + - States C(replaced) and C(overridden) have the same behaviour for this module. - Refer to examples for more details. type: str choices: - merged - replaced + - overridden - deleted - purged - parsed @@ -537,16 +543,16 @@ router_id: 192.168.1.1 bestpath: as_path: - multipath_relax: True - compare_neighborid: True - cost_community_ignore: True + multipath_relax: true + compare_neighborid: true + cost_community_ignore: true confederation: identifier: 42 peers: - 65020 - 65030 - 65040 - log_neighbor_changes: True + log_neighbor_changes: true maxas_limit: 20 neighbors: - neighbor_address: 192.168.1.100 @@ -556,19 +562,19 @@ remote_as: 65563 description: NBR-1 low_memory: - exempt: True + exempt: true - neighbor_address: 192.168.1.101 remote_as: 65563 password: encryption: 7 key: 12090404011C03162E neighbor_down: - fib_accelerate: True + fib_accelerate: true vrfs: - vrf: site-1 allocate_index: 5000 local_as: 200 - log_neighbor_changes: True + log_neighbor_changes: true neighbors: - neighbor_address: 198.51.100.1 description: site-1-nbr-1 @@ -581,7 +587,7 @@ description: site-1-nbr-2 - vrf: site-2 local_as: 300 - log_neighbor_changes: True + log_neighbor_changes: true neighbors: - neighbor_address: 203.0.113.2 description: site-2-nbr-1 @@ -590,10 +596,10 @@ key: AF92F4C16A0A0EC5BDF56CF58BC030F6 remote_as: 65568 neighbor_down: - fib_accelerate: True + fib_accelerate: true -# Task output -# ------------- +# Task output: +# ------------ # before: {} # # commands: @@ -698,7 +704,7 @@ # After state: -# ------------- +# ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65563 # router-id 192.168.1.1 @@ -789,8 +795,8 @@ as_number: 65563 router_id: 192.168.1.1 bestpath: - compare_neighborid: True - cost_community_ignore: True + compare_neighborid: true + cost_community_ignore: true confederation: identifier: 42 peers: @@ -806,24 +812,24 @@ remote_as: 65563 description: NBR-1 low_memory: - exempt: True + exempt: true neighbor_down: - fib_accelerate: True + fib_accelerate: true vrfs: - vrf: site-2 local_as: 300 - log_neighbor_changes: True + log_neighbor_changes: true neighbors: - neighbor_address: 203.0.113.2 password: encryption: 7 key: 12090404011C03162E neighbor_down: - fib_accelerate: True + fib_accelerate: true state: replaced -# Task output -# ------------- +# Task output: +# ------------ # before: # as_number: '65563' # bestpath: @@ -936,7 +942,7 @@ # vrf: site-2 # # After state: -# ------------- +# ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65563 # router-id 192.168.1.1 @@ -1017,8 +1023,8 @@ cisco.nxos.nxos_bgp_global: state: deleted -# Task output -# ------------- +# Task output: +# ------------ # before: # as_number: '65563' @@ -1100,7 +1106,7 @@ # as_number: '65563' # # After state: -# ------------- +# ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65563 # address-family ipv4 unicast @@ -1170,8 +1176,8 @@ cisco.nxos.nxos_bgp_global: state: purged -# Task output -# ------------- +# Task output: +# ------------ # before: # as_number: '65563' @@ -1239,7 +1245,7 @@ # after: {} # # After state: -# ------------- +# ------------ # Nexus9000v# show running-config | section "^router bgp" # Nexus9000v# @@ -1252,16 +1258,16 @@ router_id: 192.168.1.1 bestpath: as_path: - multipath_relax: True - compare_neighborid: True - cost_community_ignore: True + multipath_relax: true + compare_neighborid: true + cost_community_ignore: true confederation: identifier: 42 peers: - 65020 - 65030 - 65040 - log_neighbor_changes: True + log_neighbor_changes: true maxas_limit: 20 neighbors: - neighbor_address: 192.168.1.100 @@ -1271,19 +1277,19 @@ remote_as: 65563 description: NBR-1 low_memory: - exempt: True + exempt: true - neighbor_address: 192.168.1.101 remote_as: 65563 password: encryption: 7 key: 12090404011C03162E neighbor_down: - fib_accelerate: True + fib_accelerate: true vrfs: - vrf: site-1 allocate_index: 5000 local_as: 200 - log_neighbor_changes: True + log_neighbor_changes: true neighbors: - neighbor_address: 198.51.100.1 description: site-1-nbr-1 @@ -1296,7 +1302,7 @@ description: site-1-nbr-2 - vrf: site-2 local_as: 300 - log_neighbor_changes: True + log_neighbor_changes: true neighbors: - neighbor_address: 203.0.113.2 description: site-1-nbr-1 @@ -1305,10 +1311,10 @@ key: AF92F4C16A0A0EC5BDF56CF58BC030F6 remote_as: 65568 neighbor_down: - fib_accelerate: True + fib_accelerate: true -# Task Output (redacted) -# ----------------------- +# Task output: +# ------------ # rendered: # - router bgp 65563 # - bestpath as-path multipath-relax @@ -1397,8 +1403,8 @@ running_config: "{{ lookup('file', 'parsed.cfg') }}" state: parsed -# Task output (redacted) -# ----------------------- +# Task output: +# ------------ # parsed: # as_number: '65563' # bestpath: @@ -1490,8 +1496,8 @@ cisco.nxos.nxos_bgp_global: state: gathered -# Task output (redacted) -# ----------------------- +# Task output: +# ------------ # gathered: # as_number: '65563' # bestpath: @@ -1555,7 +1561,7 @@ as_number: 65536 router_id: 198.51.100.2 maxas_limit: 20 - log_neighbor_changes: True + log_neighbor_changes: true neighbors: - neighbor_address: 192.0.2.1 remote_as: 65537 @@ -1564,8 +1570,8 @@ key: 12090404011C03162E state: replaced -# Task output (redacted) -# ----------------------- +# Task output: +# ------------ # fatal: [Nexus9000v]: FAILED! => changed=false # msg: Neighbor 203.0.113.2 has address-family configurations. # Please use the nxos_bgp_neighbor_af module to remove those first. @@ -1599,7 +1605,7 @@ as_number: 65536 router_id: 198.51.100.2 maxas_limit: 20 - log_neighbor_changes: True + log_neighbor_changes: true neighbors: - neighbor_address: 192.0.2.1 remote_as: 65537 @@ -1609,11 +1615,11 @@ vrfs: - vrf: site-2 neighbor_down: - fib_accelerate: True + fib_accelerate: true state: replaced -# Task output (redacted) -# ----------------------- +# Task output: +# ------------ # fatal: [Nexus9000v]: FAILED! => changed=false # msg: VRF site-1 has address-family configurations. # Please use the nxos_bgp_af module to remove those first. @@ -1655,9 +1661,32 @@ - remote-as 65562 - description site-1-nbr-1 - password 3 13D4D3549493D2877B1DC116EE27A6BE +rendered: + description: The provided configuration in the task rendered in device-native format (offline). + returned: when I(state) is C(rendered) + type: list + sample: + - router bgp 65563 + - maxas-limit 20 + - router-id 192.168.1.1 +gathered: + description: Facts about the network resource gathered from the remote device as structured data. + returned: when I(state) is C(gathered) + type: dict + sample: > + This output will always be in the same format as the + module argspec. +parsed: + description: The device native config provided in I(running_config) option parsed into structured data as per module argspec. + returned: when I(state) is C(parsed) + type: dict + sample: > + This output will always be in the same format as the + module argspec. """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.bgp_global.bgp_global import ( Bgp_globalArgs, ) diff --git a/plugins/modules/nxos_bgp_neighbor.py b/plugins/modules/nxos_bgp_neighbor.py deleted file mode 100644 index 5c4c39f56..000000000 --- a/plugins/modules/nxos_bgp_neighbor.py +++ /dev/null @@ -1,589 +0,0 @@ -#!/usr/bin/python -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - - -DOCUMENTATION = """ -module: nxos_bgp_neighbor -extends_documentation_fragment: -- cisco.nxos.nxos -short_description: (deprecated, removed after 2023-01-27) Manages BGP neighbors configurations. -description: -- Manages BGP neighbors configurations on NX-OS switches. -version_added: 1.0.0 -author: Gabriele Gerbino (@GGabriele) -deprecated: - alternative: nxos_bgp_global - why: Updated module released with more functionality. - removed_at_date: '2023-01-27' -notes: -- Tested against NXOSv 7.3.(0)D1(1) on VIRL -- Unsupported for Cisco MDS -- C(state=absent) removes the whole BGP neighbor configuration. -- Default, where supported, restores params default value. -options: - asn: - description: - - BGP autonomous system number. Valid values are string, Integer in ASPLAIN or - ASDOT notation. - required: true - type: str - vrf: - description: - - Name of the VRF. The name 'default' is a valid VRF representing the global bgp. - default: default - type: str - neighbor: - description: - - Neighbor Identifier. Valid values are string. Neighbors may use IPv4 or IPv6 - notation, with or without prefix length. - required: true - type: str - description: - description: - - Description of the neighbor. - type: str - bfd: - description: - - Enables/Disables BFD for a given neighbor. - - "Dependency: ''feature bfd''" - type: str - choices: - - enable - - disable - connected_check: - description: - - Configure whether or not to check for directly connected peer. - type: bool - capability_negotiation: - description: - - Configure whether or not to negotiate capability with this neighbor. - type: bool - dynamic_capability: - description: - - Configure whether or not to enable dynamic capability. - type: bool - ebgp_multihop: - description: - - Specify multihop TTL for a remote peer. Valid values are integers between 2 - and 255, or keyword 'default' to disable this property. - type: str - local_as: - description: - - Specify the local-as number for the eBGP neighbor. Valid values are String or - Integer in ASPLAIN or ASDOT notation, or 'default', which means not to configure - it. - type: str - log_neighbor_changes: - description: - - Specify whether or not to enable log messages for neighbor up/down event. - choices: - - enable - - disable - - inherit - type: str - low_memory_exempt: - description: - - Specify whether or not to shut down this neighbor under memory pressure. - type: bool - maximum_peers: - description: - - Specify Maximum number of peers for this neighbor prefix Valid values are between - 1 and 1000, or 'default', which does not impose the limit. Note that this parameter - is accepted only on neighbors with address/prefix. - type: str - pwd: - description: - - Specify the password for neighbor. Valid value is string. - type: str - pwd_type: - description: - - Specify the encryption type the password will use. Valid values are '3des' or - 'cisco_type_7' encryption or keyword 'default'. - choices: - - 3des - - cisco_type_7 - - default - type: str - remote_as: - description: - - Specify Autonomous System Number of the neighbor. Valid values are String or - Integer in ASPLAIN or ASDOT notation, or 'default', which means not to configure - it. - type: str - remove_private_as: - description: - - Specify the config to remove private AS number from outbound updates. Valid - values are 'enable' to enable this config, 'disable' to disable this config, - 'all' to remove all private AS number, or 'replace-as', to replace the private - AS number. - choices: - - enable - - disable - - all - - replace-as - type: str - shutdown: - description: - - Configure to administratively shutdown this neighbor. - type: bool - suppress_4_byte_as: - description: - - Configure to suppress 4-byte AS Capability. - type: bool - timers_keepalive: - description: - - Specify keepalive timer value. Valid values are integers between 0 and 3600 - in terms of seconds, or 'default', which is 60. - type: str - timers_holdtime: - description: - - Specify holdtime timer value. Valid values are integers between 0 and 3600 in - terms of seconds, or 'default', which is 180. - type: str - transport_passive_only: - description: - - Specify whether or not to only allow passive connection setup. Valid values - are 'true', 'false', and 'default', which defaults to 'false'. This property - can only be configured when the neighbor is in 'ip' address format without prefix - length. - type: bool - update_source: - description: - - Specify source interface of BGP session and updates. - type: str - state: - description: - - Determines whether the config should be present or not on the device. - default: present - choices: - - present - - absent - type: str - peer_type: - description: - - Specify the peer type for BGP session. - choices: - - fabric_border_leaf - - fabric_external - - disable - type: str - version_added: 1.1.0 -""" -EXAMPLES = """ -# create a new neighbor -- cisco.nxos.nxos_bgp_neighbor: - asn: 65535 - neighbor: 192.0.2.3 - local_as: 20 - remote_as: 30 - bfd: enable - description: just a description - update_source: Ethernet1/3 - state: present - peer_type: fabric_external -""" - -RETURN = """ -commands: - description: commands sent to the device - returned: always - type: list - sample: ["router bgp 65535", "neighbor 192.0.2.3", - "remote-as 30", "update-source Ethernet1/3", - "description just a description", "local-as 20", "peer-type fabric-external"] -""" - -import re - -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_config, - load_config, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( - CustomNetworkConfig, -) - - -BOOL_PARAMS = [ - "capability_negotiation", - "shutdown", - "connected_check", - "dynamic_capability", - "low_memory_exempt", - "suppress_4_byte_as", - "transport_passive_only", -] -PARAM_TO_COMMAND_KEYMAP = { - "asn": "router bgp", - "bfd": "bfd", - "capability_negotiation": "dont-capability-negotiate", - "connected_check": "disable-connected-check", - "description": "description", - "dynamic_capability": "dynamic-capability", - "ebgp_multihop": "ebgp-multihop", - "local_as": "local-as", - "log_neighbor_changes": "log-neighbor-changes", - "low_memory_exempt": "low-memory exempt", - "maximum_peers": "maximum-peers", - "neighbor": "neighbor", - "pwd": "password", - "pwd_type": "password", - "remote_as": "remote-as", - "remove_private_as": "remove-private-as", - "shutdown": "shutdown", - "suppress_4_byte_as": "capability suppress 4-byte-as", - "timers_keepalive": "timers", - "timers_holdtime": "timers", - "transport_passive_only": "transport connection-mode passive", - "update_source": "update-source", - "vrf": "vrf", - "peer_type": "peer-type", -} -PARAM_TO_DEFAULT_KEYMAP = { - "bfd": "disable", - "shutdown": False, - "dynamic_capability": True, - "timers_keepalive": 60, - "timers_holdtime": 180, - "peer_type": "disable", -} - - -def get_value(arg, config): - command = PARAM_TO_COMMAND_KEYMAP[arg] - has_command = re.search(r"^\s+{0}$".format(command), config, re.M) - has_command_val = re.search( - r"(?:\s+{0}\s*)(?P.*)$".format(command), config, re.M - ) - - if arg == "dynamic_capability": - has_no_command = re.search( - r"\s+no\s{0}\s*$".format(command), config, re.M - ) - value = True - if has_no_command: - value = False - elif arg in BOOL_PARAMS: - value = False - if has_command: - value = True - elif arg == "log_neighbor_changes": - value = "" - if has_command: - value = "enable" - elif has_command_val: - value = "disable" - - elif arg == "remove_private_as": - value = "disable" - if has_command: - value = "enable" - elif has_command_val: - value = has_command_val.group("value") - elif arg == "bfd": - value = "enable" if has_command else "disable" - - elif arg == "peer_type": - value = "disable" - if has_command_val: - value = has_command_val.group("value").replace("-", "_") - else: - value = "" - - if has_command_val: - value = has_command_val.group("value") - - if command in ["timers", "password"]: - split_value = value.split() - value = "" - - if arg in ["timers_keepalive", "pwd_type"]: - value = split_value[0] - elif ( - arg in ["timers_holdtime", "pwd"] and len(split_value) == 2 - ): - value = split_value[1] - - return value - - -def get_existing(module, args, warnings): - existing = {} - netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) - - asn_regex = re.compile( - r".*router\sbgp\s(?P\d+(\.\d+)?).*", re.S - ) - match_asn = asn_regex.match(str(netcfg)) - - if match_asn: - existing_asn = match_asn.group("existing_asn") - parents = ["router bgp {0}".format(existing_asn)] - - if module.params["vrf"] != "default": - parents.append("vrf {0}".format(module.params["vrf"])) - - parents.append("neighbor {0}".format(module.params["neighbor"])) - config = netcfg.get_section(parents) - if config: - for arg in args: - if arg not in ["asn", "vrf", "neighbor"]: - existing[arg] = get_value(arg, config) - - existing["asn"] = existing_asn - existing["neighbor"] = module.params["neighbor"] - existing["vrf"] = module.params["vrf"] - else: - warnings.append( - "The BGP process didn't exist but the task" " just created it." - ) - return existing - - -def apply_key_map(key_map, table): - new_dict = {} - for key in table: - new_key = key_map.get(key) - if new_key: - new_dict[new_key] = table.get(key) - - return new_dict - - -def state_present(module, existing, proposed, candidate): - commands = list() - proposed_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, proposed) - existing_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, existing) - - for key, value in proposed_commands.items(): - if value is True: - commands.append(key) - elif value is False: - commands.append("no {0}".format(key)) - elif value == "default": - if existing_commands.get(key): - if key == "password": - commands.append("no password") - else: - existing_value = existing_commands.get(key) - commands.append("no {0} {1}".format(key, existing_value)) - else: - if key == "log-neighbor-changes": - if value == "enable": - commands.append("{0}".format(key)) - elif value == "disable": - commands.append("{0} {1}".format(key, value)) - elif value == "inherit": - if existing_commands.get(key): - commands.append("no {0}".format(key)) - elif key == "password": - pwd_type = module.params["pwd_type"] - if pwd_type == "3des": - pwd_type = 3 - else: - pwd_type = 7 - command = "{0} {1} {2}".format(key, pwd_type, value) - if command not in commands: - commands.append(command) - elif key == "remove-private-as": - if value == "enable": - command = "{0}".format(key) - commands.append(command) - elif value == "disable": - if existing_commands.get(key) != "disable": - command = "no {0}".format(key) - commands.append(command) - else: - command = "{0} {1}".format(key, value) - commands.append(command) - elif key == "timers": - if proposed["timers_keepalive"] != PARAM_TO_DEFAULT_KEYMAP.get( - "timers_keepalive" - ) or proposed[ - "timers_holdtime" - ] != PARAM_TO_DEFAULT_KEYMAP.get( - "timers_holdtime" - ): - command = "timers {0} {1}".format( - proposed["timers_keepalive"], - proposed["timers_holdtime"], - ) - if command not in commands: - commands.append(command) - elif key == "bfd": - no_cmd = "no " if value == "disable" else "" - commands.append(no_cmd + key) - elif key == "peer-type": - if value == "disable": - if existing_commands.get(key) != "disable": - command = "no {0}".format(key) - commands.append(command) - elif value == "fabric_external": - ptype = "fabric-external" - command = "{0} {1}".format(key, ptype) - commands.append(command) - elif value == "fabric_border_leaf": - ptype = "fabric-border-leaf" - command = "{0} {1}".format(key, ptype) - commands.append(command) - else: - command = "{0} {1}".format(key, value) - commands.append(command) - - if commands: - parents = ["router bgp {0}".format(module.params["asn"])] - if module.params["vrf"] != "default": - parents.append("vrf {0}".format(module.params["vrf"])) - - parents.append("neighbor {0}".format(module.params["neighbor"])) - - # make sure that local-as is the last command in the list. - local_as_command = "local-as {0}".format(module.params["local_as"]) - if local_as_command in commands: - commands.remove(local_as_command) - commands.append(local_as_command) - candidate.add(commands, parents=parents) - - -def state_absent(module, existing, proposed, candidate): - commands = [] - parents = ["router bgp {0}".format(module.params["asn"])] - if module.params["vrf"] != "default": - parents.append("vrf {0}".format(module.params["vrf"])) - - commands.append("no neighbor {0}".format(module.params["neighbor"])) - candidate.add(commands, parents=parents) - - -def main(): - argument_spec = dict( - asn=dict(required=True, type="str"), - vrf=dict(required=False, type="str", default="default"), - neighbor=dict(required=True, type="str"), - description=dict(required=False, type="str"), - bfd=dict(required=False, type="str", choices=["enable", "disable"]), - capability_negotiation=dict(required=False, type="bool"), - connected_check=dict(required=False, type="bool"), - dynamic_capability=dict(required=False, type="bool"), - ebgp_multihop=dict(required=False, type="str"), - local_as=dict(required=False, type="str"), - log_neighbor_changes=dict( - required=False, - type="str", - choices=["enable", "disable", "inherit"], - ), - low_memory_exempt=dict(required=False, type="bool"), - maximum_peers=dict(required=False, type="str"), - pwd=dict(required=False, type="str"), - pwd_type=dict( - required=False, - type="str", - choices=["3des", "cisco_type_7", "default"], - ), - remote_as=dict(required=False, type="str"), - remove_private_as=dict( - required=False, - type="str", - choices=["enable", "disable", "all", "replace-as"], - ), - shutdown=dict(required=False, type="bool"), - suppress_4_byte_as=dict(required=False, type="bool"), - timers_keepalive=dict(required=False, type="str"), - timers_holdtime=dict(required=False, type="str"), - transport_passive_only=dict(required=False, type="bool"), - update_source=dict(required=False, type="str"), - state=dict( - choices=["present", "absent"], default="present", required=False - ), - peer_type=dict( - required=False, - type="str", - choices=["disable", "fabric_border_leaf", "fabric_external"], - ), - ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, - required_together=[ - ["timers_holdtime", "timers_keepalive"], - ["pwd", "pwd_type"], - ], - supports_check_mode=True, - ) - - warnings = list() - result = dict(changed=False, warnings=warnings) - - state = module.params["state"] - - if module.params["pwd_type"] == "default": - module.params["pwd_type"] = "0" - - args = PARAM_TO_COMMAND_KEYMAP.keys() - existing = get_existing(module, args, warnings) - - if existing.get("asn") and state == "present": - if existing["asn"] != module.params["asn"]: - module.fail_json( - msg="Another BGP ASN already exists.", - proposed_asn=module.params["asn"], - existing_asn=existing.get("asn"), - ) - - proposed_args = dict( - (k, v) for k, v in module.params.items() if v is not None and k in args - ) - proposed = {} - for key, value in proposed_args.items(): - if key not in ["asn", "vrf", "neighbor", "pwd_type"]: - if str(value).lower() == "default": - value = PARAM_TO_DEFAULT_KEYMAP.get(key, "default") - if key == "bfd": - if existing.get("bfd", "disable") != value: - proposed[key] = value - elif existing.get(key) != value: - proposed[key] = value - - candidate = CustomNetworkConfig(indent=3) - if state == "present": - state_present(module, existing, proposed, candidate) - elif state == "absent" and existing: - state_absent(module, existing, proposed, candidate) - - if candidate: - candidate = candidate.items_text() - if not module.check_mode: - load_config(module, candidate) - result["changed"] = True - result["commands"] = candidate - else: - result["commands"] = [] - - module.exit_json(**result) - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/nxos_bgp_neighbor_address_family.py b/plugins/modules/nxos_bgp_neighbor_address_family.py index d55199719..de41a9bf1 100644 --- a/plugins/modules/nxos_bgp_neighbor_address_family.py +++ b/plugins/modules/nxos_bgp_neighbor_address_family.py @@ -10,6 +10,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type DOCUMENTATION = """ @@ -50,7 +51,7 @@ neighbor_address: description: IP/IPv6 address of the neighbor. type: str - required: True + required: true address_family: description: BGP Neighbor Address Family related configurations. type: list @@ -60,7 +61,7 @@ description: Address Family indicator. type: str choices: ["ipv4", "ipv6", "link-state", "vpnv4", "vpnv6", "l2vpn"] - required: True + required: true safi: description: Sub Address Family indicator. type: str @@ -72,7 +73,7 @@ route_map: description: Route-map name. type: str - required: True + required: true exist_map: description: Condition route-map to advertise only when prefix in condition exists. type: str @@ -186,6 +187,9 @@ rewrite_evpn_rt_asn: description: Auto generate RTs for EBGP neighbor. type: bool + rewrite_rt_asn: + description: Auto generate RTs for EBGP neighbor. + type: bool route_map: description: Apply route-map to neighbor. type: dict @@ -303,9 +307,9 @@ address_family: - afi: ipv4 safi: unicast - suppress_inactive: True + suppress_inactive: true next_hop_self: - set: True + set: true - neighbor_address: 203.0.113.2 address_family: - afi: ipv6 @@ -313,10 +317,10 @@ - afi: ipv4 safi: multicast send_community: - set: True + set: true -# Task output -# ------------- +# Task output: +# ------------ # before: {} # # commands: @@ -379,12 +383,12 @@ # - afi: ipv4 # safi: multicast # send_community: -# set: True +# set: true # - afi: ipv6 # safi: unicast # After state: -# ------------- +# ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65536 # neighbor 192.0.2.32 @@ -468,11 +472,11 @@ - afi: ipv4 safi: multicast send_community: - set: True + set: true state: replaced -# Task output -# ------------- +# Task output: +# ------------ # before: # as_number: "65536" # neighbors: @@ -511,7 +515,7 @@ # - afi: ipv4 # safi: multicast # send_community: -# set: True +# set: true # - afi: ipv6 # safi: unicast # @@ -558,12 +562,12 @@ # - afi: ipv4 # safi: multicast # send_community: -# set: True +# set: true # - afi: ipv6 # safi: unicast # After state: -# ------------- +# ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65536 # neighbor 192.0.2.32 @@ -625,13 +629,13 @@ address_family: - afi: ipv4 safi: unicast - suppress_inactive: True + suppress_inactive: true next_hop_self: - set: True + set: true state: overridden -# Task output -# ------------- +# Task output: +# ------------ # before: # as_number: "65536" # neighbors: @@ -670,7 +674,7 @@ # - afi: ipv4 # safi: multicast # send_community: -# set: True +# set: true # - afi: ipv6 # safi: unicast # @@ -704,12 +708,12 @@ # address_family: # - afi: ipv4 # safi: unicast -# suppress_inactive: True +# suppress_inactive: true # next_hop_self: -# set: True +# set: true # After state: -# ------------- +# ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65536 # neighbor 192.0.2.32 @@ -765,8 +769,8 @@ safi: unicast state: deleted -# Task output -# ------------- +# Task output: +# ------------ # before: # as_number: "65536" # neighbors: @@ -805,7 +809,7 @@ # - afi: ipv4 # safi: multicast # send_community: -# set: True +# set: true # - afi: ipv6 # safi: unicast # @@ -846,10 +850,10 @@ # - afi: ipv4 # safi: multicast # send_community: -# set: True +# set: true # # After state: -# ------------- +# ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65536 # neighbor 192.0.2.32 @@ -898,8 +902,8 @@ cisco.nxos.nxos_bgp_neighbor_address_family: state: deleted -# Task output -# ------------- +# Task output: +# ------------ # before: # as_number: "65536" # neighbors: @@ -938,7 +942,7 @@ # - afi: ipv4 # safi: multicast # send_community: -# set: True +# set: true # - afi: ipv6 # safi: unicast # @@ -960,7 +964,7 @@ # as_number: "65536" # # After state: -# ------------- +# ------------ # Nexus9000v# show running-config | section "^router bgp" # router bgp 65536 # neighbor 192.0.2.32 @@ -1004,9 +1008,9 @@ address_family: - afi: ipv4 safi: unicast - suppress_inactive: True + suppress_inactive: true next_hop_self: - set: True + set: true - neighbor_address: 203.0.113.2 address_family: - afi: ipv6 @@ -1014,11 +1018,11 @@ - afi: ipv4 safi: multicast send_community: - set: True + set: true state: rendered -# Task Output (redacted) -# ----------------------- +# Task output: +# ------------ # rendered: # - router bgp 65536 # - neighbor 192.0.2.32 @@ -1072,8 +1076,8 @@ running_config: "{{ lookup('file', 'parsed.cfg') }}" state: parsed -# Task output (redacted) -# ----------------------- +# Task output: +# ------------ # parsed: # as_number: "65536" # neighbors: @@ -1112,12 +1116,59 @@ # - afi: ipv4 # safi: multicast # send_community: -# set: True +# set: true # - afi: ipv6 # safi: unicast """ +RETURN = """ +before: + description: The configuration prior to the module execution. + returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) + type: dict + sample: > + This output will always be in the same format as the + module argspec. +after: + description: The resulting configuration after module execution. + returned: when changed + type: dict + sample: > + This output will always be in the same format as the + module argspec. +commands: + description: The set of commands pushed to the remote device. + returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) + type: list + sample: + - router bgp 65536 + - neighbor 192.0.2.32 + - address-family ipv4 unicast +rendered: + description: The provided configuration in the task rendered in device-native format (offline). + returned: when I(state) is C(rendered) + type: list + sample: + - router bgp 65536 + - neighbor 192.0.2.32 + - address-family ipv4 unicast +gathered: + description: Facts about the network resource gathered from the remote device as structured data. + returned: when I(state) is C(gathered) + type: dict + sample: > + This output will always be in the same format as the + module argspec. +parsed: + description: The device native config provided in I(running_config) option parsed into structured data as per module argspec. + returned: when I(state) is C(parsed) + type: dict + sample: > + This output will always be in the same format as the + module argspec. +""" from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.bgp_neighbor_address_family.bgp_neighbor_address_family import ( Bgp_neighbor_address_familyArgs, ) diff --git a/plugins/modules/nxos_bgp_neighbor_af.py b/plugins/modules/nxos_bgp_neighbor_af.py deleted file mode 100644 index 4fdfbb181..000000000 --- a/plugins/modules/nxos_bgp_neighbor_af.py +++ /dev/null @@ -1,820 +0,0 @@ -#!/usr/bin/python -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - - -DOCUMENTATION = """ -module: nxos_bgp_neighbor_af -extends_documentation_fragment: -- cisco.nxos.nxos -short_description: (deprecated, removed after 2023-02-24) Manages BGP address-family's neighbors configuration. -description: -- Manages BGP address-family's neighbors configurations on NX-OS switches. -version_added: 1.0.0 -author: Gabriele Gerbino (@GGabriele) -deprecated: - alternative: nxos_bgp_neighbor_address_family - why: Updated module released with more functionality. - removed_at_date: '2023-02-24' -notes: -- Tested against NXOSv 7.3.(0)D1(1) on VIRL -- Unsupported for Cisco MDS -- C(state=absent) removes the whole BGP address-family's neighbor configuration. -- Default, when supported, removes properties -- In order to default maximum-prefix configuration, only C(max_prefix_limit=default) - is needed. -options: - asn: - description: - - BGP autonomous system number. Valid values are String, Integer in ASPLAIN or - ASDOT notation. - required: true - type: str - vrf: - description: - - Name of the VRF. The name 'default' is a valid VRF representing the global bgp. - default: default - type: str - neighbor: - description: - - Neighbor Identifier. Valid values are string. Neighbors may use IPv4 or IPv6 - notation, with or without prefix length. - required: true - type: str - afi: - description: - - Address Family Identifier. - required: true - choices: - - ipv4 - - ipv6 - - vpnv4 - - vpnv6 - - l2vpn - type: str - safi: - description: - - Sub Address Family Identifier. - required: true - choices: - - unicast - - multicast - - evpn - type: str - additional_paths_receive: - description: - - Valid values are enable for basic command enablement; disable for disabling - the command at the neighbor af level (it adds the disable keyword to the basic - command); and inherit to remove the command at this level (the command value - is inherited from a higher BGP layer). - choices: - - enable - - disable - - inherit - type: str - additional_paths_send: - description: - - Valid values are enable for basic command enablement; disable for disabling - the command at the neighbor af level (it adds the disable keyword to the basic - command); and inherit to remove the command at this level (the command value - is inherited from a higher BGP layer). - choices: - - enable - - disable - - inherit - type: str - advertise_map_exist: - description: - - Conditional route advertisement. This property requires two route maps, an advertise-map - and an exist-map. Valid values are an array specifying both the advertise-map - name and the exist-map name, or simply 'default' e.g. ['my_advertise_map', 'my_exist_map']. - This command is mutually exclusive with the advertise_map_non_exist property. - type: list - elements: str - advertise_map_non_exist: - description: - - Conditional route advertisement. This property requires two route maps, an advertise-map - and an exist-map. Valid values are an array specifying both the advertise-map - name and the non-exist-map name, or simply 'default' e.g. ['my_advertise_map', - 'my_non_exist_map']. This command is mutually exclusive with the advertise_map_exist - property. - type: list - elements: str - allowas_in: - description: - - Activate allowas-in property - type: bool - allowas_in_max: - description: - - Max-occurrences value for allowas_in. Valid values are an integer value or 'default'. - This is mutually exclusive with allowas_in. - type: str - as_override: - description: - - Activate the as-override feature. - type: bool - default_originate: - description: - - Activate the default-originate feature. - type: bool - default_originate_route_map: - description: - - Route-map for the default_originate property. Valid values are a string defining - a route-map name, or 'default'. This is mutually exclusive with default_originate. - type: str - disable_peer_as_check: - description: - - Disable checking of peer AS-number while advertising - type: bool - filter_list_in: - description: - - Valid values are a string defining a filter-list name, or 'default'. - type: str - filter_list_out: - description: - - Valid values are a string defining a filter-list name, or 'default'. - type: str - max_prefix_limit: - description: - - maximum-prefix limit value. Valid values are an integer value or 'default'. - type: str - max_prefix_interval: - description: - - Optional restart interval. Valid values are an integer. Requires max_prefix_limit. - May not be combined with max_prefix_warning. - type: str - max_prefix_threshold: - description: - - Optional threshold percentage at which to generate a warning. Valid values are - an integer value. Requires max_prefix_limit. - type: str - max_prefix_warning: - description: - - Optional warning-only keyword. Requires max_prefix_limit. May not be combined - with max_prefix_interval. - type: bool - next_hop_self: - description: - - Activate the next-hop-self feature. - type: bool - next_hop_third_party: - description: - - Activate the next-hop-third-party feature. - type: bool - prefix_list_in: - description: - - Valid values are a string defining a prefix-list name, or 'default'. - type: str - prefix_list_out: - description: - - Valid values are a string defining a prefix-list name, or 'default'. - type: str - route_map_in: - description: - - Valid values are a string defining a route-map name, or 'default'. - type: str - route_map_out: - description: - - Valid values are a string defining a route-map name, or 'default'. - type: str - route_reflector_client: - description: - - Router reflector client. - type: bool - send_community: - description: - - send-community attribute. - choices: - - none - - both - - extended - - standard - - default - type: str - soft_reconfiguration_in: - description: - - Valid values are 'enable' for basic command enablement; 'always' to add the - always keyword to the basic command; and 'inherit' to remove the command at - this level (the command value is inherited from a higher BGP layer). - choices: - - enable - - always - - inherit - type: str - soo: - description: - - Site-of-origin. Valid values are a string defining a VPN extcommunity or 'default'. - type: str - suppress_inactive: - description: - - suppress-inactive feature. - type: bool - unsuppress_map: - description: - - unsuppress-map. Valid values are a string defining a route-map name or 'default'. - type: str - weight: - description: - - Weight value. Valid values are an integer value or 'default'. - type: str - state: - description: - - Determines whether the config should be present or not on the device. - default: present - choices: - - present - - absent - type: str - rewrite_evpn_rt_asn: - description: - - Auto generate route targets for EBGP neighbor. - type: bool - version_added: 1.1.0 -""" -EXAMPLES = """ -- name: configure RR client - cisco.nxos.nxos_bgp_neighbor_af: - asn: 65535 - neighbor: 192.0.2.3 - afi: ipv4 - safi: unicast - route_reflector_client: true - state: present - rewrite_evpn_rt_asn: true -""" - -RETURN = """ -commands: - description: commands sent to the device - returned: always - type: list - sample: ["router bgp 65535", "neighbor 192.0.2.3", - "address-family ipv4 unicast", "route-reflector-client", - "rewrite-evpn-rt-asn"] -""" - -import re - -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_config, - load_config, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( - CustomNetworkConfig, -) - - -BOOL_PARAMS = [ - "allowas_in", - "as_override", - "default_originate", - "disable_peer_as_check", - "next_hop_self", - "next_hop_third_party", - "route_reflector_client", - "suppress_inactive", - "rewrite_evpn_rt_asn", -] -PARAM_TO_COMMAND_KEYMAP = { - "afi": "address-family", - "asn": "router bgp", - "neighbor": "neighbor", - "additional_paths_receive": "capability additional-paths receive", - "additional_paths_send": "capability additional-paths send", - "advertise_map_exist": "advertise-map exist-map", - "advertise_map_non_exist": "advertise-map non-exist-map", - "allowas_in": "allowas-in", - "allowas_in_max": "allowas-in", - "as_override": "as-override", - "default_originate": "default-originate", - "default_originate_route_map": "default-originate route-map", - "disable_peer_as_check": "disable-peer-as-check", - "filter_list_in": "filter-list in", - "filter_list_out": "filter-list out", - "max_prefix_limit": "maximum-prefix", - "max_prefix_interval": "maximum-prefix interval", - "max_prefix_threshold": "maximum-prefix threshold", - "max_prefix_warning": "maximum-prefix warning", - "next_hop_self": "next-hop-self", - "next_hop_third_party": "next-hop-third-party", - "prefix_list_in": "prefix-list in", - "prefix_list_out": "prefix-list out", - "route_map_in": "route-map in", - "route_map_out": "route-map out", - "route_reflector_client": "route-reflector-client", - "safi": "address-family", - "send_community": "send-community", - "soft_reconfiguration_in": "soft-reconfiguration inbound", - "soo": "soo", - "suppress_inactive": "suppress-inactive", - "unsuppress_map": "unsuppress-map", - "weight": "weight", - "vrf": "vrf", - "rewrite_evpn_rt_asn": "rewrite-evpn-rt-asn", -} - - -def get_value(arg, config, module): - custom = [ - "additional_paths_send", - "additional_paths_receive", - "max_prefix_limit", - "max_prefix_interval", - "max_prefix_threshold", - "max_prefix_warning", - "send_community", - "soft_reconfiguration_in", - ] - command = PARAM_TO_COMMAND_KEYMAP[arg] - has_command = re.search(r"^\s+{0}\s*".format(command), config, re.M) - has_command_val = re.search( - r"(?:{0}\s)(?P.*)$".format(command), config, re.M - ) - value = "" - - if arg in custom: - value = get_custom_value(arg, config, module) - - elif arg == "next_hop_third_party": - has_no_command = re.search( - r"^\s+no\s+{0}\s*$".format(command), config, re.M - ) - value = False - if not has_no_command: - value = True - - elif arg in BOOL_PARAMS: - value = False - if has_command: - value = True - - elif command.startswith("advertise-map"): - value = [] - has_adv_map = re.search( - r"{0}\s(?P.*)\s{1}\s(?P.*)$".format( - *command.split() - ), - config, - re.M, - ) - if has_adv_map: - value = list(has_adv_map.groups()) - - elif command.split()[0] in ["filter-list", "prefix-list", "route-map"]: - has_cmd_direction_val = re.search( - r"{0}\s(?P.*)\s{1}$".format(*command.split()), config, re.M - ) - if has_cmd_direction_val: - value = has_cmd_direction_val.group("value") - - elif has_command_val: - value = has_command_val.group("value") - - return value - - -def get_custom_value(arg, config, module): - command = PARAM_TO_COMMAND_KEYMAP.get(arg) - splitted_config = config.splitlines() - value = "" - - if arg.startswith("additional_paths"): - value = "inherit" - for line in splitted_config: - if command in line: - if "disable" in line: - value = "disable" - else: - value = "enable" - elif arg.startswith("max_prefix"): - for line in splitted_config: - if "maximum-prefix" in line: - splitted_line = line.split() - if arg == "max_prefix_limit": - value = splitted_line[1] - elif arg == "max_prefix_interval" and "restart" in line: - value = splitted_line[-1] - elif arg == "max_prefix_threshold" and len(splitted_line) > 2: - try: - int(splitted_line[2]) - value = splitted_line[2] - except ValueError: - value = "" - elif arg == "max_prefix_warning": - value = "warning-only" in line - elif arg == "soft_reconfiguration_in": - value = "inherit" - for line in splitted_config: - if command in line: - if "always" in line: - value = "always" - else: - value = "enable" - - elif arg == "send_community": - value = "none" - for line in splitted_config: - if command in line: - if "extended" in line: - if value == "standard": - value = "both" - else: - value = "extended" - elif "both" in line: - value = "both" - else: - value = "standard" - - return value - - -def get_existing(module, args, warnings): - existing = {} - netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) - - asn_regex = re.compile( - r".*router\sbgp\s(?P\d+(\.\d+)?).*", re.S - ) - match_asn = asn_regex.match(str(netcfg)) - - if match_asn: - existing_asn = match_asn.group("existing_asn") - parents = ["router bgp {0}".format(existing_asn)] - - if module.params["vrf"] != "default": - parents.append("vrf {0}".format(module.params["vrf"])) - - parents.append("neighbor {0}".format(module.params["neighbor"])) - parents.append( - "address-family {0} {1}".format( - module.params["afi"], module.params["safi"] - ) - ) - config = netcfg.get_section(parents) - - if config: - for arg in args: - if arg not in ["asn", "vrf", "neighbor", "afi", "safi"]: - existing[arg] = get_value(arg, config, module) - - existing["asn"] = existing_asn - existing["neighbor"] = module.params["neighbor"] - existing["vrf"] = module.params["vrf"] - existing["afi"] = module.params["afi"] - existing["safi"] = module.params["safi"] - else: - warnings.append( - "The BGP process didn't exist but the task just created it." - ) - - return existing - - -def apply_key_map(key_map, table): - new_dict = {} - for key in table: - new_key = key_map.get(key) - if new_key: - new_dict[new_key] = table.get(key) - - return new_dict - - -def get_default_command(key, value, existing_commands): - command = "" - if existing_commands.get(key): - existing_value = existing_commands.get(key) - if value == "inherit": - if existing_value != "inherit": - command = "no {0}".format(key) - else: - if key == "advertise-map exist-map": - command = "no advertise-map {0} exist-map {1}".format( - existing_value[0], existing_value[1] - ) - elif key == "advertise-map non-exist-map": - command = "no advertise-map {0} non-exist-map {1}".format( - existing_value[0], existing_value[1] - ) - elif key == "filter-list in": - command = "no filter-list {0} in".format(existing_value) - elif key == "filter-list out": - command = "no filter-list {0} out".format(existing_value) - elif key == "prefix-list in": - command = "no prefix-list {0} in".format(existing_value) - elif key == "prefix-list out": - command = "no prefix-list {0} out".format(existing_value) - elif key == "route-map in": - command = "no route-map {0} in".format(existing_value) - elif key == "route-map out": - command = "no route-map {0} out".format(existing_value) - elif key.startswith("maximum-prefix"): - command = "no maximum-prefix" - elif key == "allowas-in max": - command = ["no allowas-in {0}".format(existing_value)] - command.append("allowas-in") - else: - command = "no {0} {1}".format(key, existing_value) - else: - if key.replace(" ", "_").replace("-", "_") in BOOL_PARAMS: - command = "no {0}".format(key) - return command - - -def fix_proposed(module, existing, proposed): - allowas_in = proposed.get("allowas_in") - allowas_in_max = proposed.get("allowas_in_max") - - if allowas_in_max and not allowas_in: - proposed.pop("allowas_in_max") - elif allowas_in and allowas_in_max: - proposed.pop("allowas_in") - - if ( - existing.get("send_community") == "none" - and proposed.get("send_community") == "default" - ): - proposed.pop("send_community") - return proposed - - -def state_present(module, existing, proposed, candidate): - commands = list() - proposed = fix_proposed(module, existing, proposed) - - proposed_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, proposed) - existing_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, existing) - for key, value in proposed_commands.items(): - if value in ["inherit", "default"]: - command = get_default_command(key, value, existing_commands) - - if isinstance(command, str): - if command and command not in commands: - commands.append(command) - elif isinstance(command, list): - for cmd in command: - if cmd not in commands: - commands.append(cmd) - - elif key.startswith("maximum-prefix"): - if module.params["max_prefix_limit"] != "default": - command = "maximum-prefix {0}".format( - module.params["max_prefix_limit"] - ) - if module.params["max_prefix_threshold"]: - command += " {0}".format( - module.params["max_prefix_threshold"] - ) - if module.params["max_prefix_interval"]: - command += " restart {0}".format( - module.params["max_prefix_interval"] - ) - elif module.params["max_prefix_warning"]: - command += " warning-only" - commands.append(command) - - elif value is True: - commands.append(key) - elif value is False: - commands.append("no {0}".format(key)) - elif key == "address-family": - commands.append( - "address-family {0} {1}".format( - module.params["afi"], module.params["safi"] - ) - ) - elif key.startswith("capability additional-paths"): - command = key - if value == "disable": - command += " disable" - commands.append(command) - elif key.startswith("advertise-map"): - direction = key.split()[1] - commands.append( - "advertise-map {1} {0} {2}".format(direction, *value) - ) - elif key.split()[0] in ["filter-list", "prefix-list", "route-map"]: - commands.append("{1} {0} {2}".format(value, *key.split())) - - elif key == "soft-reconfiguration inbound": - command = "" - if value == "enable": - command = key - elif value == "always": - command = "{0} {1}".format(key, value) - commands.append(command) - elif key == "send-community": - command = key - if value in ["standard", "extended"]: - commands.append("no " + key + " both") - command += " {0}".format(value) - commands.append(command) - else: - command = "{0} {1}".format(key, value) - commands.append(command) - - if commands: - parents = ["router bgp {0}".format(module.params["asn"])] - if module.params["vrf"] != "default": - parents.append("vrf {0}".format(module.params["vrf"])) - - parents.append("neighbor {0}".format(module.params["neighbor"])) - - af_command = "address-family {0} {1}".format( - module.params["afi"], module.params["safi"] - ) - parents.append(af_command) - if af_command in commands: - commands.remove(af_command) - candidate.add(commands, parents=parents) - - -def state_absent(module, existing, candidate): - commands = [] - parents = ["router bgp {0}".format(module.params["asn"])] - if module.params["vrf"] != "default": - parents.append("vrf {0}".format(module.params["vrf"])) - - parents.append("neighbor {0}".format(module.params["neighbor"])) - commands.append( - "no address-family {0} {1}".format( - module.params["afi"], module.params["safi"] - ) - ) - candidate.add(commands, parents=parents) - - -def main(): - argument_spec = dict( - asn=dict(required=True, type="str"), - vrf=dict(required=False, type="str", default="default"), - neighbor=dict(required=True, type="str"), - afi=dict( - required=True, - type="str", - choices=["ipv4", "ipv6", "vpnv4", "vpnv6", "l2vpn"], - ), - safi=dict( - required=True, type="str", choices=["unicast", "multicast", "evpn"] - ), - additional_paths_receive=dict( - required=False, - type="str", - choices=["enable", "disable", "inherit"], - ), - additional_paths_send=dict( - required=False, - type="str", - choices=["enable", "disable", "inherit"], - ), - advertise_map_exist=dict(required=False, type="list", elements="str"), - advertise_map_non_exist=dict( - required=False, type="list", elements="str" - ), - allowas_in=dict(required=False, type="bool"), - allowas_in_max=dict(required=False, type="str"), - as_override=dict(required=False, type="bool"), - default_originate=dict(required=False, type="bool"), - default_originate_route_map=dict(required=False, type="str"), - disable_peer_as_check=dict(required=False, type="bool"), - filter_list_in=dict(required=False, type="str"), - filter_list_out=dict(required=False, type="str"), - max_prefix_limit=dict(required=False, type="str"), - max_prefix_interval=dict(required=False, type="str"), - max_prefix_threshold=dict(required=False, type="str"), - max_prefix_warning=dict(required=False, type="bool"), - next_hop_self=dict(required=False, type="bool"), - next_hop_third_party=dict(required=False, type="bool"), - prefix_list_in=dict(required=False, type="str"), - prefix_list_out=dict(required=False, type="str"), - route_map_in=dict(required=False, type="str"), - route_map_out=dict(required=False, type="str"), - route_reflector_client=dict(required=False, type="bool"), - send_community=dict( - required=False, - choices=["none", "both", "extended", "standard", "default"], - ), - soft_reconfiguration_in=dict( - required=False, type="str", choices=["enable", "always", "inherit"] - ), - soo=dict(required=False, type="str"), - suppress_inactive=dict(required=False, type="bool"), - unsuppress_map=dict(required=False, type="str"), - weight=dict(required=False, type="str"), - state=dict( - choices=["present", "absent"], default="present", required=False - ), - rewrite_evpn_rt_asn=dict(required=False, type="bool"), - ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, - mutually_exclusive=[ - ["advertise_map_exist", "advertise_map_non_exist"], - ["max_prefix_interval", "max_prefix_warning"], - ["default_originate", "default_originate_route_map"], - ["allowas_in", "allowas_in_max"], - ], - supports_check_mode=True, - ) - - warnings = list() - result = dict(changed=False, warnings=warnings) - - state = module.params["state"] - for key in [ - "max_prefix_interval", - "max_prefix_warning", - "max_prefix_threshold", - ]: - if module.params[key] and not module.params["max_prefix_limit"]: - module.fail_json( - msg="max_prefix_limit is required when using %s" % key - ) - if module.params["vrf"] == "default" and module.params["soo"]: - module.fail_json(msg="SOO is only allowed in non-default VRF") - - args = PARAM_TO_COMMAND_KEYMAP.keys() - existing = get_existing(module, args, warnings) - - if existing.get("asn") and state == "present": - if existing.get("asn") != module.params["asn"]: - module.fail_json( - msg="Another BGP ASN already exists.", - proposed_asn=module.params["asn"], - existing_asn=existing.get("asn"), - ) - - for param in ["advertise_map_exist", "advertise_map_non_exist"]: - if module.params[param] == ["default"]: - module.params[param] = "default" - - proposed_args = dict( - (k, v) for k, v in module.params.items() if v is not None and k in args - ) - - proposed = {} - for key, value in proposed_args.items(): - if key not in ["asn", "vrf", "neighbor"]: - if not isinstance(value, list): - if str(value).lower() == "true": - value = True - elif str(value).lower() == "false": - value = False - elif str(value).lower() == "default": - if key in BOOL_PARAMS: - value = False - else: - value = "default" - elif key == "send_community" and str(value).lower() == "none": - value = "default" - if existing.get(key) != value: - proposed[key] = value - - candidate = CustomNetworkConfig(indent=3) - if state == "present": - state_present(module, existing, proposed, candidate) - elif state == "absent" and existing: - state_absent(module, existing, candidate) - - if candidate: - candidate = candidate.items_text() - if not module.check_mode: - responses = load_config(module, candidate) - if responses: - for resp in responses: - if resp: - if resp.endswith("is valid only for EBGP peers"): - module.fail_json(msg=resp) - result["changed"] = True - result["commands"] = candidate - else: - result["commands"] = [] - - module.exit_json(**result) - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/nxos_bgp_templates.py b/plugins/modules/nxos_bgp_templates.py new file mode 100644 index 000000000..9ad53e348 --- /dev/null +++ b/plugins/modules/nxos_bgp_templates.py @@ -0,0 +1,1015 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Copyright 2023 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +""" +The module file for nxos_bgp_templates +""" + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +DOCUMENTATION = """ +module: nxos_bgp_templates +short_description: BGP Templates resource module. +description: +- This module manages BGP templates on devices running Cisco NX-OS. +version_added: 4.2.0 +notes: +- Tested against NX-OS 9.3.6. +- Unsupported for Cisco MDS +- This module works with connection C(network_cli) and C(httpapi). +author: Nilashish Chakraborty (@NilashishC) +options: + running_config: + description: + - This option is used only with state I(parsed). + - The value of this option should be the output received from the NX-OS device + by executing the command B(show running-config bgp | section 'template'). + - The state I(parsed) reads the configuration from C(running_config) option and + transforms it into Ansible structured data as per the resource module's argspec + and the value is then returned in the I(parsed) key within the result. + type: str + config: + description: A list of BGP templates. + type: dict + suboptions: + as_number: + description: Autonomous System Number of the router. + type: str + neighbor: + description: Configure BGP peer templates. + type: list + elements: dict + suboptions: + name: + description: Name of the BGP peer template. + type: str + address_family: + description: Configure an address-family for peer. + type: list + elements: dict + suboptions: + afi: + description: Address Family indicator. + type: str + choices: ["ipv4", "ipv6", "link-state", "l2vpn"] + required: True + safi: + description: Sub Address Family indicator. + type: str + choices: ["unicast", "multicast", "mvpn", "evpn"] + advertise_map: + description: Specify route-map for conditional advertisement. + type: dict + suboptions: + route_map: + description: Route-map name. + type: str + required: True + exist_map: + description: Condition route-map to advertise only when prefix in condition exists. + type: str + non_exist_map: + description: Condition route-map to advertise only when prefix in condition does not exist. + type: str + advertisement_interval: + description: Minimum interval between sending BGP routing updates. + type: int + allowas_in: + description: Accept as-path with my AS present in it. + type: dict + suboptions: + set: + description: Activate allowas-in property. + type: bool + max_occurences: + description: Number of occurrences of AS number, default is 3. + type: int + as_override: + description: Override matching AS-number while sending update. + type: bool + capability: + description: Advertise capability to the peer. + type: dict + suboptions: + additional_paths: + description: Additional paths capability. + type: dict + suboptions: + receive: + description: Additional paths Receive capability. + type: str + choices: ["enable", "disable"] + send: + description: Additional paths Send capability. + type: str + choices: ["enable", "disable"] + default_originate: + description: Originate a default toward this peer. + type: dict + suboptions: + set: + description: Set default-originate attribute. + type: bool + route_map: + description: Route-map to specify criteria for originating default. + type: str + disable_peer_as_check: + description: Disable checking of peer AS-number while advertising. + type: bool + filter_list: + description: Name of filter-list. + type: dict + suboptions: + inbound: + description: Apply policy to incoming routes. + type: str + outbound: + description: Apply policy to outgoing routes. + type: str + inherit: + description: Inherit a peer-policy template. + type: dict + suboptions: + peer_policy: + description: Peer-policy template to inherit. + type: str + maximum_prefix: + description: Maximum number of prefixes from this neighbor. + type: dict + suboptions: + max_prefix_limit: + description: Maximum prefix limit. + type: int + generate_warning_threshold: + description: Threshold percentage at which to generate a warning. + type: int + restart_interval: + description: Restart bgp connection after limit is exceeded. + type: int + warning_only: + description: Only give a warning message when limit is exceeded. + type: bool + next_hop_self: + description: Set our address as nexthop (non-reflected). + type: dict + suboptions: + set: + description: Set next-hop-self attribute. + type: bool + all_routes: + description: Set our address as nexthop for all routes. + type: bool + next_hop_third_party: + description: Compute a third-party nexthop if possible. + type: bool + prefix_list: + description: Apply prefix-list. + type: dict + suboptions: + inbound: + description: Apply policy to incoming routes. + type: str + outbound: + description: Apply policy to outgoing routes. + type: str + route_map: + description: Apply route-map to neighbor. + type: dict + suboptions: + inbound: + description: Name of policy to apply to incoming routes. + type: str + outbound: + description: Name of policy to apply to outgoing routes. + type: str + route_reflector_client: + description: Configure a neighbor as Route reflector client. + type: bool + send_community: + description: Send Community attribute to this neighbor. + type: str + choices: ["standard", "extended", "both"] + soft_reconfiguration_inbound: + description: Soft reconfiguration. + type: dict + suboptions: + set: + description: Set soft-reconfiguration inbound attribute. + type: bool + always: + description: Always perform inbound soft reconfiguration. + type: bool + soo: + description: Specify Site-of-origin extcommunity. + type: str + suppress_inactive: + description: Advertise only active routes to peer. + type: bool + unsuppress_map: + description: Route-map to selectively unsuppress suppressed routes. + type: str + weight: + description: Set default weight for routes from this neighbor. + type: int + bfd: + description: Bidirectional Fast Detection for the neighbor. + type: dict + suboptions: + set: + description: Set BFD for this neighbor. + type: bool + singlehop: + description: Single-hop session. + type: bool + multihop: + description: Multihop session. + type: dict + suboptions: + set: + description: Set BFD multihop. + type: bool + interval: + description: Configure BFD session interval parameters. + type: dict + suboptions: + tx_interval: + description: TX interval in milliseconds. + type: int + required: true + min_rx_interval: + description: Minimum RX interval. + type: int + required: true + multiplier: + description: Detect Multiplier. + type: int + required: true + bmp_activate_server: + description: Specify server ID for activating BMP monitoring for the peer. + type: int + capability: + description: Capability. + type: dict + suboptions: + suppress_4_byte_as: + description: Suppress 4-byte AS Capability. + type: bool + description: + description: Neighbor specific descripion. + type: str + disable_connected_check: + description: Disable check for directly connected peer. + type: bool + dont_capability_negotiate: + description: Don't negotiate capability with this neighbor. + type: bool + dscp: + description: Set dscp value for tcp transport. + type: str + dynamic_capability: + description: Dynamic Capability + type: bool + ebgp_multihop: + description: Specify multihop TTL for remote peer. + type: int + graceful_shutdown: + description: Graceful-shutdown for this neighbor. + type: dict + suboptions: + activate: + description: Send graceful-shutdown community. + type: dict + suboptions: + set: + description: Set activate. + type: bool + route_map: + description: Apply route-map to modify attributes for outbound. + type: str + inherit: + description: Inherit a template. + type: dict + suboptions: + peer_session: + description: Peer-session template to inherit. + type: str + local_as: + description: Specify the local-as number for the eBGP neighbor. + type: str + log_neighbor_changes: + description: Log message for neighbor up/down event. + type: dict + suboptions: + set: + description: + - Set log-neighbor-changes. + type: bool + disable: + description: + - Disable logging of neighbor up/down event. + type: bool + low_memory: + description: Behaviour in low memory situations. + type: dict + suboptions: + exempt: + description: Do not shutdown this peer when under memory pressure. + type: bool + password: + description: Configure a password for neighbor. + type: dict + suboptions: + encryption: + description: + - 0 specifies an UNENCRYPTED neighbor password. + - 3 specifies an 3DES ENCRYPTED neighbor password will follow. + - 7 specifies a Cisco type 7 ENCRYPTED neighbor password will follow. + type: int + key: + description: Authentication password. + type: str + path_attribute: + description: BGP path attribute optional filtering. + type: list + elements: dict + suboptions: + action: + description: Action. + type: str + choices: ["discard", "treat-as-withdraw"] + type: + description: Path attribute type + type: int + range: + description: Path attribute range. + type: dict + suboptions: + start: + description: Path attribute range start value. + type: int + end: + description: Path attribute range end value. + type: int + remote_as: + description: Specify Autonomous System Number of the neighbor. + type: str + remove_private_as: + description: Remove private AS number from outbound updates. + type: dict + suboptions: + set: + description: Remove private AS. + type: bool + replace_as: + description: Replace. + type: bool + all: + description: All. + type: bool + shutdown: + description: Administratively shutdown this neighbor. + type: bool + timers: + description: Configure keepalive and hold timers. + type: dict + suboptions: + keepalive: + description: Keepalive interval (seconds). + type: int + holdtime: + description: Holdtime (seconds). + type: int + transport: + description: BGP transport connection. + type: dict + suboptions: + connection_mode: + description: Specify type of connection. + type: dict + suboptions: + passive: + description: Allow passive connection setup only. + type: bool + ttl_security: + description: Enable TTL Security Mechanism. + type: dict + suboptions: + hops: + description: Specify hop count for remote peer. + type: int + update_source: + description: Specify source of BGP session and updates. + type: str + state: + description: + - The state the configuration should be left in. + - Refer to examples for more details. + type: str + choices: + - merged + - replaced + - overridden + - deleted + - parsed + - gathered + - rendered + default: merged +""" + +EXAMPLES = """ +# Using merged + +# Before state: +# -------------- +# +# nxos9k# show running-config | section "^router bgp" +# nxos9k# + +- name: Merge the provided configuration with the existing running configuration + cisco.nxos.nxos_bgp_templates: + config: + as_number: 65536 + neighbor: + - name: neighbor_tmplt_1 + address_family: + - afi: ipv4 + safi: unicast + advertise_map: + route_map: rmap1 + non_exist_map: nemap1 + advertisement_interval: 60 + disable_peer_as_check: true + bmp_activate_server: 2 + capability: + suppress_4_byte_as: true + description: Test_BGP_PEER_TEMPLATE_1 + local_as: 65536 + remote_as: 65001 + + - name: neighbor_tmplt_2 + description: Test_BGP_PEER_TEMPLATE_2 + address_family: + - afi: ipv4 + safi: multicast + advertise_map: + route_map: rmap1 + exist_map: emap1 + as_override: true + filter_list: + inbound: flist1 + outbound: flist2 + inherit: + peer_session: psession1 + timers: + holdtime: 100 + keepalive: 45 +# Task Output: +# ------------ +# before: {} +# +# commands: +# - router bgp 65536 +# - template peer neighbor_tmplt_1 +# - bmp-activate-server 2 +# - capability suppress 4-byte-as +# - description Test_BGP_PEER_TEMPLATE_1 +# - local-as 65536 +# - remote-as 65001 +# - address-family ipv4 unicast +# - advertise-map rmap1 non-exist-map nemap1 +# - advertisement-interval 60 +# - disable-peer-as-check +# - template peer neighbor_tmplt_2 +# - description Test_BGP_PEER_TEMPLATE_2 +# - inherit peer-session psession1 +# - timers 45 100 +# - address-family ipv4 multicast +# - advertise-map rmap1 exist-map emap1 +# - as-override +# - filter-list flist1 in +# - filter-list flist2 out +# +# after: +# as_number: "65536" +# neighbor: +# - name: neighbor_tmplt_1 +# address_family: +# - afi: ipv4 +# safi: unicast +# advertise_map: +# non_exist_map: nemap1 +# route_map: rmap1 +# advertisement_interval: 60 +# disable_peer_as_check: true +# bmp_activate_server: 2 +# capability: +# suppress_4_byte_as: true +# description: Test_BGP_PEER_TEMPLATE_1 +# local_as: "65536" +# remote_as: "65001" +# +# - name: neighbor_tmplt_2 +# description: Test_BGP_PEER_TEMPLATE_2 +# address_family: +# - afi: ipv4 +# safi: multicast +# advertise_map: +# exist_map: emap1 +# route_map: rmap1 +# as_override: true +# filter_list: +# inbound: flist1 +# outbound: flist2 +# inherit: +# peer_session: psession1 +# timers: +# holdtime: 100 +# keepalive: 45 + +# After state: +# -------------- +# +# nxos9k# show running-config | section "^router bgp" +# router bgp 65536 +# template peer neighbor_tmplt_1 +# capability suppress 4-byte-as +# bmp-activate-server 2 +# description Test_BGP_PEER_TEMPLATE_1 +# local-as 65536 +# remote-as 65001 +# address-family ipv4 unicast +# advertise-map rmap1 non-exist-map nemap1 +# advertisement-interval 60 +# disable-peer-as-check +# template peer neighbor_tmplt_2 +# description Test_BGP_PEER_TEMPLATE_2 +# inherit peer-session psession1 +# timers 45 100 +# address-family ipv4 multicast +# advertise-map rmap1 exist-map emap1 +# as-override +# filter-list flist1 in +# filter-list flist2 out + +# Using replaced + +# Before state: +# ------------- +# +# nxos9k# show running-config | section "^router bgp" +# router bgp 65536 +# template peer neighbor_tmplt_1 +# capability suppress 4-byte-as +# description Test_BGP_PEER_TEMPLATE_1 +# bmp-activate-server 2 +# local-as 65536 +# remote-as 65001 +# address-family ipv4 unicast +# advertise-map rmap1 non-exist-map nemap1 +# advertisement-interval 60 +# disable-peer-as-check +# template peer neighbor_tmplt_2 +# description Test_BGP_PEER_TEMPLATE_2 +# inherit peer-session psession1 +# timers 45 100 +# address-family ipv4 multicast +# advertise-map rmap1 exist-map emap1 +# as-override +# filter-list flist1 in +# filter-list flist2 out + +- name: Replace BGP templates configuration with provided configuration + cisco.nxos.nxos_bgp_templates: + config: + as_number: 65536 + neighbor: + - name: neighbor_tmplt_1 + address_family: + - afi: ipv4 + safi: unicast + advertise_map: + route_map: rmap1 + non_exist_map: nemap1 + advertisement_interval: 60 + disable_peer_as_check: true + inherit: + peer_session: psession1 + description: Test_BGP_PEER_TEMPLATE_1 + local_as: 65537 + state: replaced + +# Task output: +# ------------ +# +# before: +# as_number: "65536" +# neighbor: +# - name: neighbor_tmplt_1 +# address_family: +# - afi: ipv4 +# safi: unicast +# advertise_map: +# non_exist_map: nemap1 +# route_map: rmap1 +# advertisement_interval: 60 +# disable_peer_as_check: true +# bmp_activate_server: 2 +# capability: +# suppress_4_byte_as: true +# description: Test_BGP_PEER_TEMPLATE_1 +# local_as: "65536" +# remote_as: "65001" +# +# - name: neighbor_tmplt_2 +# description: Test_BGP_PEER_TEMPLATE_2 +# address_family: +# - afi: ipv4 +# safi: multicast +# advertise_map: +# exist_map: emap1 +# route_map: rmap1 +# as_override: true +# filter_list: +# inbound: flist1 +# outbound: flist2 +# inherit: +# peer_session: psession1 +# timers: +# holdtime: 100 +# keepalive: 45 +# +# commands: +# - router bgp 65536 +# - template peer neighbor_tmplt_1 +# - no bmp-activate-server 2 +# - no capability suppress 4-byte-as +# - inherit peer-session psession1 +# - local-as 65537 +# - no remote-as 65001 +# +# after: +# as_number: "65536" +# neighbor: +# - name: neighbor_tmplt_1 +# address_family: +# - afi: ipv4 +# safi: unicast +# advertise_map: +# non_exist_map: nemap1 +# route_map: rmap1 +# advertisement_interval: 60 +# disable_peer_as_check: true +# description: Test_BGP_PEER_TEMPLATE_1 +# inherit: +# peer_session: psession1 +# local_as: "65537" +# +# - name: neighbor_tmplt_2 +# description: Test_BGP_PEER_TEMPLATE_2 +# address_family: +# - afi: ipv4 +# safi: multicast +# advertise_map: +# exist_map: emap1 +# route_map: rmap1 +# as_override: true +# filter_list: +# inbound: flist1 +# outbound: flist2 +# inherit: +# peer_session: psession1 +# timers: +# holdtime: 100 +# keepalive: 45 + +# After state: +# ------------ +# +# nxos9k# show running-config | section "^router bgp" +# router bgp 65536 +# template peer neighbor_tmplt_1 +# inherit peer-session psession1 +# description Test_BGP_PEER_TEMPLATE_1 +# local-as 65537 +# address-family ipv4 unicast +# advertise-map rmap1 non-exist-map nemap1 +# advertisement-interval 60 +# disable-peer-as-check +# template peer neighbor_tmplt_2 +# description Test_BGP_PEER_TEMPLATE_2 +# inherit peer-session psession1 +# bmp-activate-server 2 +# timers 45 100 +# address-family ipv4 multicast +# advertise-map rmap1 exist-map emap1 +# as-override +# filter-list flist1 in +# filter-list flist2 out + +# Using overridden +# +# Before state: +# ------------- +# +# nxos9k# show running-config | section "^router bgp" +# router bgp 65536 +# template peer neighbor_tmplt_1 +# capability suppress 4-byte-as +# description Test_BGP_PEER_TEMPLATE_1 +# bmp-activate-server 2 +# local-as 65536 +# remote-as 65001 +# address-family ipv4 unicast +# advertise-map rmap1 non-exist-map nemap1 +# advertisement-interval 60 +# disable-peer-as-check +# template peer neighbor_tmplt_2 +# description Test_BGP_PEER_TEMPLATE_2 +# inherit peer-session psession1 +# timers 45 100 +# address-family ipv4 multicast +# advertise-map rmap1 exist-map emap1 +# as-override +# filter-list flist1 in +# filter-list flist2 out + +- name: Override BGP templates configuration with provided configuration + cisco.nxos.nxos_bgp_templates: + config: + as_number: 65536 + neighbor: + - name: neighbor_tmplt_1 + address_family: + - afi: ipv4 + safi: unicast + advertise_map: + route_map: rmap1 + non_exist_map: nemap1 + advertisement_interval: 60 + disable_peer_as_check: true + inherit: + peer_session: psession1 + description: Test_BGP_PEER_TEMPLATE_1 + local_as: 65537 + state: overridden + +# Task output: +# ------------ +# +# before: +# as_number: "65536" +# neighbor: +# - name: neighbor_tmplt_1 +# address_family: +# - afi: ipv4 +# safi: unicast +# advertise_map: +# non_exist_map: nemap1 +# route_map: rmap1 +# advertisement_interval: 60 +# disable_peer_as_check: true +# bmp_activate_server: 2 +# capability: +# suppress_4_byte_as: true +# description: Test_BGP_PEER_TEMPLATE_1 +# local_as: "65536" +# remote_as: "65001" +# +# - name: neighbor_tmplt_2 +# description: Test_BGP_PEER_TEMPLATE_2 +# address_family: +# - afi: ipv4 +# safi: multicast +# advertise_map: +# exist_map: emap1 +# route_map: rmap1 +# as_override: true +# filter_list: +# inbound: flist1 +# outbound: flist2 +# inherit: +# peer_session: psession1 +# timers: +# holdtime: 100 +# keepalive: 45 +# +# commands: +# - router bgp 65536 +# - template peer neighbor_tmplt_1 +# - no bmp-activate-server 2 +# - no capability suppress 4-byte-as +# - inherit peer-session psession1 +# - local-as 65537 +# - no remote-as 65001 +# - no template peer neighbor_tmplt_2 +# +# after: +# as_number: "65536" +# neighbor: +# - name: neighbor_tmplt_1 +# address_family: +# - afi: ipv4 +# safi: unicast +# advertise_map: +# non_exist_map: nemap1 +# route_map: rmap1 +# advertisement_interval: 60 +# disable_peer_as_check: true +# description: Test_BGP_PEER_TEMPLATE_1 +# inherit: +# peer_session: psession1 +# local_as: "65537" + +# After state: +# ------------ +# +# nxos9k# show running-config | section "^router bgp" +# router bgp 65536 +# template peer neighbor_tmplt_1 +# inherit peer-session psession1 +# description Test_BGP_PEER_TEMPLATE_1 +# local-as 65537 +# address-family ipv4 unicast +# advertise-map rmap1 non-exist-map nemap1 +# advertisement-interval 60 +# disable-peer-as-check + +# Using deleted + +# Before state: +# -------------- +# +# nxos9k# show running-config | section "^router bgp" +# router bgp 65536 +# template peer neighbor_tmplt_1 +# capability suppress 4-byte-as +# description Test_BGP_PEER_TEMPLATE_1 +# bmp-activate-server 2 +# local-as 65536 +# remote-as 65001 +# address-family ipv4 unicast +# advertise-map rmap1 non-exist-map nemap1 +# advertisement-interval 60 +# disable-peer-as-check +# template peer neighbor_tmplt_2 +# description Test_BGP_PEER_TEMPLATE_2 +# inherit peer-session psession1 +# timers 45 100 +# address-family ipv4 multicast +# advertise-map rmap1 exist-map emap1 +# as-override +# filter-list flist1 in +# filter-list flist2 out + +- name: Delete BGP configs handled by this module + cisco.nxos.nxos_bgp_templates: + state: deleted + +# Task output: +# ------------ +# +# before: +# as_number: "65536" +# neighbor: +# - name: neighbor_tmplt_1 +# address_family: +# - afi: ipv4 +# safi: unicast +# advertise_map: +# non_exist_map: nemap1 +# route_map: rmap1 +# advertisement_interval: 60 +# disable_peer_as_check: true +# bmp_activate_server: 2 +# capability: +# suppress_4_byte_as: true +# description: Test_BGP_PEER_TEMPLATE_1 +# local_as: "65536" +# remote_as: "65001" +# +# - name: neighbor_tmplt_2 +# description: Test_BGP_PEER_TEMPLATE_2 +# address_family: +# - afi: ipv4 +# safi: multicast +# advertise_map: +# exist_map: emap1 +# route_map: rmap1 +# as_override: true +# filter_list: +# inbound: flist1 +# outbound: flist2 +# inherit: +# peer_session: psession1 +# timers: +# holdtime: 100 +# keepalive: 45 +# +# commands: +# - router bgp 65536 +# - no template peer neighbor_tmplt_1 +# - no template peer neighbor_tmplt_2 +# +# after: {} + +# After state: +# ------------- +# nxos9k# show running-config | section "^router bgp" +# nxos9k# +""" + +RETURN = """ +before: + description: The configuration prior to the module execution. + returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) + type: dict + sample: > + This output will always be in the same format as the + module argspec. +after: + description: The resulting configuration after module execution. + returned: when changed + type: dict + sample: > + This output will always be in the same format as the + module argspec. +commands: + description: The set of commands pushed to the remote device. + returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) + type: list + sample: + - router bgp 65536 + - template peer neighbor_tmplt_1 + - no bmp-activate-server 2 + - no capability suppress 4-byte-as + - inherit peer-session psession1 + - local-as 65537 + - no remote-as 65001 + - no template peer neighbor_tmplt_2 +rendered: + description: The provided configuration in the task rendered in device-native format (offline). + returned: when I(state) is C(rendered) + type: list + sample: + - router bgp 65536 + - template peer neighbor_tmplt_1 + - bmp-activate-server 2 + - no capability suppress 4-byte-as + - no template peer neighbor_tmplt_2 +gathered: + description: Facts about the network resource gathered from the remote device as structured data. + returned: when I(state) is C(gathered) + type: dict + sample: > + This output will always be in the same format as the + module argspec. +parsed: + description: The device native config provided in I(running_config) option parsed into structured data as per module argspec. + returned: when I(state) is C(parsed) + type: dict + sample: > + This output will always be in the same format as the + module argspec. +""" + +from ansible.module_utils.basic import AnsibleModule + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.bgp_templates.bgp_templates import ( + Bgp_templatesArgs, +) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.bgp_templates.bgp_templates import ( + Bgp_templates, +) + + +def main(): + """ + Main entry point for module execution + + :returns: the result form module invocation + """ + module = AnsibleModule( + argument_spec=Bgp_templatesArgs.argument_spec, + mutually_exclusive=[["config", "running_config"]], + required_if=[ + ["state", "merged", ["config"]], + ["state", "replaced", ["config"]], + ["state", "overridden", ["config"]], + ["state", "rendered", ["config"]], + ["state", "parsed", ["running_config"]], + ], + supports_check_mode=True, + ) + + result = Bgp_templates(module).execute_module() + module.exit_json(**result) + + +if __name__ == "__main__": + main() diff --git a/plugins/modules/nxos_command.py b/plugins/modules/nxos_command.py index 6cabf9b7a..6c3c2c384 100644 --- a/plugins/modules/nxos_command.py +++ b/plugins/modules/nxos_command.py @@ -4,6 +4,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -59,9 +60,10 @@ retries: description: - Specifies the number of retries a command should by tried before it is considered - failed. The command is run on the target device every retry and evaluated against + failed. The command is run on the target device every retry and evaluated against the I(wait_for) conditionals. - default: 10 + - The commands are run once when I(retries) is set to C(0). + default: 9 type: int interval: description: @@ -85,32 +87,31 @@ - name: run multiple commands on remote nodes cisco.nxos.nxos_command: commands: - - show version - - show interfaces + - show version + - show interfaces - name: run multiple commands and evaluate the output cisco.nxos.nxos_command: commands: - - show version - - show interfaces + - show version + - show interfaces wait_for: - - result[0] contains Cisco - - result[1] contains loopback0 + - result[0] contains Cisco + - result[1] contains loopback0 - name: run commands and specify the output format cisco.nxos.nxos_command: commands: - - command: show version - output: json + - command: show version + output: json - name: run commands that require answering a prompt cisco.nxos.nxos_command: commands: - - configure terminal - - command: no feature npv - prompt: Do you want to continue - answer: y - + - configure terminal + - command: no feature npv + prompt: Do you want to continue + answer: y """ RETURN = """ @@ -139,14 +140,12 @@ FailedConditionalError, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - transform_commands, to_lines, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, - run_commands, + transform_commands, ) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import run_commands + def parse_commands(module, warnings): commands = transform_commands(module) @@ -156,7 +155,7 @@ def parse_commands(module, warnings): if not item["command"].startswith("show"): warnings.append( "Only show commands are supported when using check mode, not " - "executing %s" % item["command"] + "executing %s" % item["command"], ) commands.remove(item) @@ -177,20 +176,17 @@ def main(): commands=dict(type="list", required=True, elements="raw"), wait_for=dict(type="list", aliases=["waitfor"], elements="str"), match=dict(default="all", choices=["any", "all"]), - retries=dict(default=10, type="int"), + retries=dict(default=9, type="int"), interval=dict(default=1, type="int"), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() result = {"changed": False, "warnings": warnings} commands = parse_commands(module, warnings) wait_for = module.params["wait_for"] or list() + conditionals = [] try: conditionals = [Conditional(c) for c in wait_for] @@ -201,7 +197,7 @@ def main(): interval = module.params["interval"] match = module.params["match"] - while retries > 0: + while retries >= 0: responses = run_commands(module, commands) for item in list(conditionals): @@ -225,9 +221,7 @@ def main(): msg = "One or more conditional statements have not been satisfied" module.fail_json(msg=msg, failed_conditions=failed_conditions) - result.update( - {"stdout": responses, "stdout_lines": list(to_lines(responses))} - ) + result.update({"stdout": responses, "stdout_lines": list(to_lines(responses))}) module.exit_json(**result) diff --git a/plugins/modules/nxos_config.py b/plugins/modules/nxos_config.py index 5727c9e9a..84be30a02 100644 --- a/plugins/modules/nxos_config.py +++ b/plugins/modules/nxos_config.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -124,7 +125,7 @@ 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 + default: false running_config: description: - The module, by default, will connect to the remote device and retrieve the current @@ -145,7 +146,7 @@ the running-config is append with the all keyword. When the value is set to false, the command is issued without the all keyword type: bool - default: no + default: false save_when: description: - When changes are made to the device running-configuration, the changes are not @@ -245,21 +246,21 @@ - cisco.nxos.nxos_config: lines: - - 10 permit ip 192.0.2.1/32 any log - - 20 permit ip 192.0.2.2/32 any log - - 30 permit ip 192.0.2.3/32 any log - - 40 permit ip 192.0.2.4/32 any log - - 50 permit ip 192.0.2.5/32 any log + - 10 permit ip 192.0.2.1/32 any log + - 20 permit ip 192.0.2.2/32 any log + - 30 permit ip 192.0.2.3/32 any log + - 40 permit ip 192.0.2.4/32 any log + - 50 permit ip 192.0.2.5/32 any log parents: ip access-list test before: no ip access-list test match: exact - cisco.nxos.nxos_config: lines: - - 10 permit ip 192.0.2.1/32 any log - - 20 permit ip 192.0.2.2/32 any log - - 30 permit ip 192.0.2.3/32 any log - - 40 permit ip 192.0.2.4/32 any log + - 10 permit ip 192.0.2.1/32 any log + - 20 permit ip 192.0.2.2/32 any log + - 30 permit ip 192.0.2.3/32 any log + - 40 permit ip 192.0.2.4/32 any log parents: ip access-list test before: no ip access-list test replace: block @@ -273,13 +274,13 @@ cisco.nxos.nxos_config: lines: # - shut - - shutdown + - shutdown # parents: int eth1/1 parents: interface Ethernet1/1 - name: configurable backup path cisco.nxos.nxos_config: - backup: yes + backup: true backup_options: filename: backup.cfg dir_path: /home/user @@ -329,17 +330,13 @@ NetworkConfig, dumps, ) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import to_list + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( get_config, + get_connection, load_config, run_commands, - get_connection, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, ) @@ -389,7 +386,7 @@ def save_config(module, result): module.warn( "Skipping command `copy running-config startup-config` " "due to check_mode. Configuration not copied to " - "non-volatile storage" + "non-volatile storage", ) @@ -403,9 +400,7 @@ def main(): parents=dict(type="list", elements="str"), before=dict(type="list", elements="str"), after=dict(type="list", elements="str"), - match=dict( - default="line", choices=["line", "strict", "exact", "none"] - ), + match=dict(default="line", choices=["line", "strict", "exact", "none"]), replace=dict(default="line", choices=["line", "block", "config"]), running_config=dict(aliases=["config"]), intended_config=dict(), @@ -413,20 +408,19 @@ def main(): backup=dict(type="bool", default=False), backup_options=dict(type="dict", options=backup_spec), save_when=dict( - choices=["always", "never", "modified", "changed"], default="never" + choices=["always", "never", "modified", "changed"], + default="never", ), diff_against=dict(choices=["running", "startup", "intended"]), diff_ignore_lines=dict(type="list", elements="str"), ) - argument_spec.update(nxos_argument_spec) - mutually_exclusive = [("lines", "src", "replace_src"), ("parents", "src")] required_if = [ - ("match", "strict", ["lines"]), - ("match", "exact", ["lines"]), - ("replace", "block", ["lines"]), + ("match", "strict", ["lines", "src"], True), + ("match", "exact", ["lines", "src"], True), + ("replace", "block", ["lines", "src"], True), ("replace", "config", ["replace_src"]), ("diff_against", "intended", ["intended_config"]), ] @@ -452,13 +446,9 @@ def main(): replace_src = module.params["replace_src"] if replace_src: if module.params["replace"] != "config": - module.fail_json( - msg="replace: config is required with replace_src" - ) + module.fail_json(msg="replace: config is required with replace_src") - if module.params["backup"] or ( - module._diff and module.params["diff_against"] == "running" - ): + if module.params["backup"] or (module._diff and module.params["diff_against"] == "running"): contents = get_config(module, flags=flags) config = NetworkConfig(indent=2, contents=contents) if module.params["backup"]: @@ -489,9 +479,7 @@ def main(): diff_replace=replace, ) except ConnectionError as exc: - module.fail_json( - msg=to_text(exc, errors="surrogate_then_replace") - ) + module.fail_json(msg=to_text(exc, errors="surrogate_then_replace")) config_diff = response["config_diff"] if config_diff: @@ -518,14 +506,19 @@ def main(): save_config(module, result) elif module.params["save_when"] == "modified": output = execute_show_commands( - module, ["show running-config", "show startup-config"] + module, + ["show running-config", "show startup-config"], ) running_config = NetworkConfig( - indent=2, contents=output[0], ignore_lines=diff_ignore_lines + indent=2, + contents=output[0], + ignore_lines=diff_ignore_lines, ) startup_config = NetworkConfig( - indent=2, contents=output[1], ignore_lines=diff_ignore_lines + indent=2, + contents=output[1], + ignore_lines=diff_ignore_lines, ) if running_config.sha1 != startup_config.sha1: @@ -542,13 +535,15 @@ def main(): # recreate the object in order to process diff_ignore_lines running_config = NetworkConfig( - indent=2, contents=contents, ignore_lines=diff_ignore_lines + indent=2, + contents=contents, + ignore_lines=diff_ignore_lines, ) if module.params["diff_against"] == "running": if module.check_mode: module.warn( - "unable to perform diff against running-config due to check mode" + "unable to perform diff against running-config due to check mode", ) contents = None else: @@ -566,10 +561,14 @@ def main(): if contents is not None: base_config = NetworkConfig( - indent=2, contents=contents, ignore_lines=diff_ignore_lines + indent=2, + contents=contents, + ignore_lines=diff_ignore_lines, ) if running_config.sha1 != base_config.sha1: + before = "" + after = "" if module.params["diff_against"] == "intended": before = running_config after = base_config @@ -581,12 +580,10 @@ def main(): { "changed": True, "diff": {"before": str(before), "after": str(after)}, - } + }, ) - if result.get("changed") and any( - (module.params["src"], module.params["lines"]) - ): + if result.get("changed") and any((module.params["src"], module.params["lines"])): msg = ( "To ensure idempotency and correct diff the input configuration lines should be" " similar to how they appear if present in" diff --git a/plugins/modules/nxos_devicealias.py b/plugins/modules/nxos_devicealias.py deleted file mode 120000 index 94e80bde3..000000000 --- a/plugins/modules/nxos_devicealias.py +++ /dev/null @@ -1 +0,0 @@ -storage/nxos_devicealias.py \ No newline at end of file diff --git a/plugins/modules/nxos_devicealias.py b/plugins/modules/nxos_devicealias.py new file mode 100644 index 000000000..1aa4c9d75 --- /dev/null +++ b/plugins/modules/nxos_devicealias.py @@ -0,0 +1,564 @@ +#!/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 + + +DOCUMENTATION = """ +module: nxos_devicealias +short_description: Configuration of device alias for Cisco NXOS MDS Switches. +description: +- Configuration of device alias for Cisco MDS NXOS. +version_added: 1.0.0 +author: +- Suhas Bharadwaj (@srbharadwaj) (subharad@cisco.com) +notes: +- Tested against Cisco MDS NX-OS 8.4(1) +options: + distribute: + description: + - Enable/Disable device-alias distribution + type: bool + mode: + description: + - Mode of devices-alias, basic or enhanced + choices: + - basic + - enhanced + type: str + da: + description: + - List of device-alias to be added or removed + type: list + elements: dict + suboptions: + name: + description: + - Name of the device-alias to be added or removed + required: true + type: str + pwwn: + description: + - pwwn to which the name needs to be associated with + type: str + remove: + description: + - Removes the device-alias if set to True + type: bool + default: false + rename: + description: + - List of device-alias to be renamed + type: list + elements: dict + suboptions: + old_name: + description: + - Old name of the device-alias that needs to be renamed + required: true + type: str + new_name: + description: + - New name of the device-alias + required: true + type: str +""" + +EXAMPLES = """ +- name: Test that device alias module works + cisco.nxos.nxos_devicealias: + da: + - name: test1_add + pwwn: 56:2:22:11:22:88:11:67 + - name: test2_add + pwwn: 65:22:22:11:22:22:11:d + - name: dev1 + remove: true + - name: dev2 + remove: true + distribute: true + mode: enhanced + rename: + - new_name: bcd + old_name: abc + - new_name: bcd1 + old_name: abc1 +""" + +RETURN = """ +commands: + description: commands sent to the device + returned: always + type: list + sample: + - terminal dont-ask + - device-alias database + - device-alias name somename pwwn 10:00:00:00:89:a1:01:03 + - device-alias name somename1 pwwn 10:00:00:00:89:a1:02:03 + - device-alias commit + - no terminal dont-ask +""" + +import string + +from ansible.module_utils.basic import AnsibleModule + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + load_config, + run_commands, +) + + +__metaclass__ = type + +VALID_DA_CHARS = ("-", "_", "$", "^") + + +class showDeviceAliasStatus(object): + """docstring for showDeviceAliasStatus""" + + def __init__(self, module): + self.module = module + self.distribute = "" + self.mode = "" + self.locked = False + self.update() + + def execute_show_cmd(self, cmd): + output = execute_show_command(cmd, self.module)[0] + return output + + def update(self): + command = "show device-alias status" + output = self.execute_show_cmd(command).split("\n") + for o in output: + if "Fabric Distribution" in o: + self.distribute = o.split(":")[1].strip().lower() + if "Mode" in o: + self.mode = o.split("Mode:")[1].strip().lower() + if "Locked" in o: + self.locked = True + + def isLocked(self): + return self.locked + + def getDistribute(self): + return self.distribute + + def getMode(self): + return self.mode + + +class showDeviceAliasDatabase(object): + """docstring for showDeviceAliasDatabase""" + + def __init__(self, module): + self.module = module + self.da_dict = {} + self.update() + + def execute_show_cmd(self, cmd): + output = execute_show_command(cmd, self.module)[0] + return output + + def update(self): + command = "show device-alias database" + # output = execute_show_command(command, self.module)[0].split("\n") + output = self.execute_show_cmd(command) + self.da_list = output.split("\n") + for eachline in self.da_list: + if "device-alias" in eachline: + sv = eachline.strip().split() + self.da_dict[sv[2]] = sv[4] + + def isNameInDaDatabase(self, name): + return name in self.da_dict.keys() + + def isPwwnInDaDatabase(self, pwwn): + newpwwn = ":".join( + ["0" + str(ep) if len(ep) == 1 else ep for ep in pwwn.split(":")], + ) + return newpwwn in self.da_dict.values() + + def isNamePwwnPresentInDatabase(self, name, pwwn): + newpwwn = ":".join( + ["0" + str(ep) if len(ep) == 1 else ep for ep in pwwn.split(":")], + ) + if name in self.da_dict.keys(): + if newpwwn == self.da_dict[name]: + return True + return False + + def getPwwnByName(self, name): + if name in self.da_dict.keys(): + return self.da_dict[name] + else: + return None + + def getNameByPwwn(self, pwwn): + newpwwn = ":".join( + ["0" + str(ep) if len(ep) == 1 else ep for ep in pwwn.split(":")], + ) + for n, p in self.da_dict.items(): + if p == newpwwn: + return n + return None + + +def isPwwnValid(pwwn): + pwwnsplit = pwwn.split(":") + if len(pwwnsplit) != 8: + return False + for eachpwwnsplit in pwwnsplit: + if len(eachpwwnsplit) > 2 or len(eachpwwnsplit) < 1: + return False + if not all(c in string.hexdigits for c in eachpwwnsplit): + return False + return True + + +def isNameValid(name): + if not name[0].isalpha(): + # Illegal first character. Name must start with a letter + return False + if len(name) > 64: + return False + for character in name: + if not character.isalnum() and character not in VALID_DA_CHARS: + return False + return True + + +def execute_show_command(command, module, command_type="cli_show"): + output = "text" + commands = [{"command": command, "output": output}] + out = run_commands(module, commands) + return out + + +def flatten_list(command_lists): + flat_command_list = [] + for command in command_lists: + if isinstance(command, list): + flat_command_list.extend(command) + else: + flat_command_list.append(command) + return flat_command_list + + +def main(): + element_spec = dict( + name=dict(required=True, type="str"), + pwwn=dict(type="str"), + remove=dict(type="bool", default=False), + ) + + element_spec_rename = dict( + old_name=dict(required=True, type="str"), + new_name=dict(required=True, type="str"), + ) + + argument_spec = dict( + distribute=dict(type="bool"), + mode=dict(type="str", choices=["enhanced", "basic"]), + da=dict(type="list", elements="dict", options=element_spec), + rename=dict(type="list", elements="dict", options=element_spec_rename), + ) + + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) + + warnings = list() + messages = list() + commands_to_execute = list() + result = {"changed": False} + + distribute = module.params["distribute"] + mode = module.params["mode"] + da = module.params["da"] + rename = module.params["rename"] + + # Step 0.0: Validate syntax of name and pwwn + # Also validate syntax of rename arguments + if da is not None: + for eachdict in da: + name = eachdict["name"] + pwwn = eachdict["pwwn"] + remove = eachdict["remove"] + if pwwn is not None: + pwwn = pwwn.lower() + if not remove: + if pwwn is None: + module.fail_json( + msg="This device alias name " + + str(name) + + " which needs to be added, does not have pwwn specified. Please specify a valid pwwn", + ) + if not isNameValid(name): + module.fail_json( + msg="This pwwn name is invalid : " + + str(name) + + ". Note that name cannot be more than 64 alphanumeric chars, " + + "it must start with a letter, and can only contain these characters: " + + ", ".join(["'{0}'".format(c) for c in VALID_DA_CHARS]), + ) + if not isPwwnValid(pwwn): + module.fail_json( + msg="This pwwn is invalid : " + + str(pwwn) + + ". Please check that its a valid pwwn", + ) + if rename is not None: + for eachdict in rename: + oldname = eachdict["old_name"] + newname = eachdict["new_name"] + if not isNameValid(oldname): + module.fail_json( + msg="This pwwn name is invalid : " + + str(oldname) + + ". Note that name cannot be more than 64 alphanumeric chars, " + + "it must start with a letter, and can only contain these characters: " + + ", ".join(["'{0}'".format(c) for c in VALID_DA_CHARS]), + ) + if not isNameValid(newname): + module.fail_json( + msg="This pwwn name is invalid : " + + str(newname) + + ". Note that name cannot be more than 64 alphanumeric chars, " + + "it must start with a letter, and can only contain these characters: " + + ", ".join(["'{0}'".format(c) for c in VALID_DA_CHARS]), + ) + + # Step 0.1: Check DA status + shDAStausObj = showDeviceAliasStatus(module) + d = shDAStausObj.getDistribute() + m = shDAStausObj.getMode() + if shDAStausObj.isLocked(): + module.fail_json( + msg="device-alias has acquired lock on the switch. Hence cannot procced.", + ) + + # Step 1: Process distribute + commands = [] + if distribute is not None: + if distribute: + # playbook has distribute as True(enabled) + if d == "disabled": + # but switch distribute is disabled(false), so set it to + # true(enabled) + commands.append("device-alias distribute") + messages.append( + "device-alias distribute changed from disabled to enabled", + ) + else: + messages.append( + "device-alias distribute remains unchanged. current distribution mode is enabled", + ) + else: + # playbook has distribute as False(disabled) + if d == "enabled": + # but switch distribute is enabled(true), so set it to + # false(disabled) + commands.append("no device-alias distribute") + messages.append( + "device-alias distribute changed from enabled to disabled", + ) + else: + messages.append( + "device-alias distribute remains unchanged. current distribution mode is disabled", + ) + + cmds = flatten_list(commands) + if cmds: + commands_to_execute = commands_to_execute + cmds + if module.check_mode: + # Check mode implemented at the da_add/da_remove stage + pass + else: + result["changed"] = True + load_config(module, cmds) + + # Step 2: Process mode + commands = [] + if mode is not None: + if mode == "basic": + # playbook has mode as basic + if m == "enhanced": + # but switch mode is enhanced, so set it to basic + commands.append("no device-alias mode enhanced") + messages.append("device-alias mode changed from enhanced to basic") + else: + messages.append( + "device-alias mode remains unchanged. current mode is basic", + ) + + else: + # playbook has mode as enhanced + if m == "basic": + # but switch mode is basic, so set it to enhanced + commands.append("device-alias mode enhanced") + messages.append("device-alias mode changed from basic to enhanced") + else: + messages.append( + "device-alias mode remains unchanged. current mode is enhanced", + ) + + if commands: + if distribute: + commands.append("device-alias commit") + commands = ["terminal dont-ask"] + commands + ["no terminal dont-ask"] + else: + if distribute is None and d == "enabled": + commands.append("device-alias commit") + commands = ["terminal dont-ask"] + commands + ["no terminal dont-ask"] + + cmds = flatten_list(commands) + + if cmds: + commands_to_execute = commands_to_execute + cmds + if module.check_mode: + # Check mode implemented at the end + pass + else: + result["changed"] = True + load_config(module, cmds) + + # Step 3: Process da + commands = [] + shDADatabaseObj = showDeviceAliasDatabase(module) + if da is not None: + da_remove_list = [] + da_add_list = [] + for eachdict in da: + name = eachdict["name"] + pwwn = eachdict["pwwn"] + remove = eachdict["remove"] + if pwwn is not None: + pwwn = pwwn.lower() + if remove: + if shDADatabaseObj.isNameInDaDatabase(name): + commands.append("no device-alias name " + name) + da_remove_list.append(name) + else: + messages.append( + name + + " - This device alias name is not in switch device-alias database, hence cannot be removed.", + ) + else: + if shDADatabaseObj.isNamePwwnPresentInDatabase(name, pwwn): + messages.append( + name + + " : " + + pwwn + + " - This device alias name,pwwn is already in switch device-alias database, hence nothing to configure", + ) + else: + if shDADatabaseObj.isNameInDaDatabase(name): + module.fail_json( + msg=name + + " - This device alias name is already present in switch device-alias database but assigned to another pwwn (" + + shDADatabaseObj.getPwwnByName(name) + + ") hence cannot be added", + ) + + elif shDADatabaseObj.isPwwnInDaDatabase(pwwn): + module.fail_json( + msg=pwwn + + " - This device alias pwwn is already present in switch device-alias database but assigned to another name (" + + shDADatabaseObj.getNameByPwwn(pwwn) + + ") hence cannot be added", + ) + + else: + commands.append("device-alias name " + name + " pwwn " + pwwn) + da_add_list.append(name) + + if len(da_add_list) != 0 or len(da_remove_list) != 0: + commands = ["device-alias database"] + commands + if distribute: + commands.append("device-alias commit") + commands = ["terminal dont-ask"] + commands + ["no terminal dont-ask"] + else: + if distribute is None and d == "enabled": + commands.append("device-alias commit") + commands = ["terminal dont-ask"] + commands + ["no terminal dont-ask"] + + cmds = flatten_list(commands) + if cmds: + commands_to_execute = commands_to_execute + cmds + if module.check_mode: + # Check mode implemented at the end + pass + else: + result["changed"] = True + load_config(module, cmds) + if len(da_remove_list) != 0: + messages.append( + "the required device-alias were removed. " + ",".join(da_remove_list), + ) + if len(da_add_list) != 0: + messages.append( + "the required device-alias were added. " + ",".join(da_add_list), + ) + + # Step 5: Process rename + commands = [] + if rename is not None: + for eachdict in rename: + oldname = eachdict["old_name"] + newname = eachdict["new_name"] + if shDADatabaseObj.isNameInDaDatabase(newname): + module.fail_json( + changed=False, + commands=cmds, + msg=newname + + " - this name is already present in the device-alias database, hence we cannot rename " + + oldname + + " with this one", + ) + if shDADatabaseObj.isNameInDaDatabase(oldname): + commands.append("device-alias rename " + oldname + " " + newname) + else: + module.fail_json( + changed=False, + commands=cmds, + msg=oldname + + " - this name is not present in the device-alias database, hence we cannot rename.", + ) + + if len(commands) != 0: + commands = ["device-alias database"] + commands + if distribute: + commands.append("device-alias commit") + commands = ["terminal dont-ask"] + commands + ["no terminal dont-ask"] + else: + if distribute is None and d == "enabled": + commands.append("device-alias commit") + commands = ["terminal dont-ask"] + commands + ["no terminal dont-ask"] + cmds = flatten_list(commands) + if cmds: + commands_to_execute = commands_to_execute + cmds + if module.check_mode: + # Check mode implemented at the end + pass + else: + result["changed"] = True + load_config(module, cmds) + + # Step END: check for 'check' mode + if module.check_mode: + module.exit_json( + changed=False, + commands=commands_to_execute, + msg="Check Mode: No cmds issued to the hosts", + ) + + result["messages"] = messages + result["commands"] = commands_to_execute + result["warnings"] = warnings + module.exit_json(**result) + + +if __name__ == "__main__": + main() diff --git a/plugins/modules/nxos_evpn_global.py b/plugins/modules/nxos_evpn_global.py index 15b8cc59a..83ef78392 100644 --- a/plugins/modules/nxos_evpn_global.py +++ b/plugins/modules/nxos_evpn_global.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -54,24 +55,18 @@ """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + get_capabilities, get_config, load_config, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_capabilities, - nxos_argument_spec, -) def main(): argument_spec = dict(nv_overlay_evpn=dict(required=True, type="bool")) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) result = {"changed": False} @@ -86,9 +81,7 @@ def main(): os_platform = info.get("network_os_platform", "") if "3K" in os_platform: - module.fail_json( - msg="This module is not supported on Nexus 3000 series" - ) + module.fail_json(msg="This module is not supported on Nexus 3000 series") if module.params["nv_overlay_evpn"] is True: if "nv overlay evpn" not in config: diff --git a/plugins/modules/nxos_evpn_vni.py b/plugins/modules/nxos_evpn_vni.py index 023507758..89771f374 100644 --- a/plugins/modules/nxos_evpn_vni.py +++ b/plugins/modules/nxos_evpn_vni.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -88,8 +89,8 @@ vni: 6000 route_distinguisher: 60:10 route_target_import: - - 5000:10 - - 4100:100 + - "5000:10" + - "4100:100" route_target_export: auto route_target_both: default """ @@ -103,18 +104,17 @@ """ import re -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_config, - load_config, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) + from ansible.module_utils.basic import AnsibleModule from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( CustomNetworkConfig, ) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + get_config, + load_config, +) + PARAM_TO_COMMAND_KEYMAP = { "vni": "vni", @@ -216,16 +216,14 @@ def state_present(module, existing, proposed): continue if existing: if target not in existing.get( - key.replace("-", "_").replace(" ", "_") + key.replace("-", "_").replace(" ", "_"), ): commands.append("{0} {1}".format(key, target)) else: commands.append("{0} {1}".format(key, target)) if existing.get(key.replace("-", "_").replace(" ", "_")): - for exi in existing.get( - key.replace("-", "_").replace(" ", "_") - ): + for exi in existing.get(key.replace("-", "_").replace(" ", "_")): if exi not in value: commands.append("no {0} {1}".format(key, exi)) @@ -256,16 +254,10 @@ def main(): route_target_both=dict(required=False, type="list", elements="str"), route_target_import=dict(required=False, type="list", elements="str"), route_target_export=dict(required=False, type="list", elements="str"), - state=dict( - choices=["present", "absent"], default="present", required=False - ), + state=dict(choices=["present", "absent"], default="present", required=False), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() results = dict(changed=False, warnings=warnings) @@ -273,9 +265,7 @@ def main(): state = module.params["state"] args = PARAM_TO_COMMAND_KEYMAP.keys() existing = get_existing(module, args) - proposed_args = dict( - (k, v) for k, v in module.params.items() if v is not None and k in args - ) + proposed_args = dict((k, v) for k, v in module.params.items() if v is not None and k in args) commands = [] parents = [] diff --git a/plugins/modules/nxos_facts.py b/plugins/modules/nxos_facts.py index e484222dc..77ca123d5 100644 --- a/plugins/modules/nxos_facts.py +++ b/plugins/modules/nxos_facts.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -27,8 +28,8 @@ short_description: Gets facts about NX-OS switches description: - Collects facts from Cisco Nexus devices running the NX-OS operating system. Fact - collection is supported over both Cli and Nxapi transports. This module prepends - all of the base network fact keys with C(ansible_net_). The facts module + collection is supported over both C(network_cli) and C(httpapi). This module prepends + all of the base network fact keys with C(ansible_net_). The facts module will always collect a base set of facts from the device and can enable or disable collection of additional facts. version_added: 1.0.0 @@ -41,7 +42,7 @@ options: gather_subset: description: - - When supplied, this argument will restrict the facts collected to a given subset. Possible + - When supplied, this argument will gather operational facts only for the given subset. Possible values for this argument include C(all), C(hardware), C(config), C(legacy), C(interfaces), and C(min). Can specify a list of values to include a larger subset. Values can also be used with an initial C(!) to specify that a specific subset should not be collected. @@ -51,19 +52,20 @@ elements: str gather_network_resources: description: - - When supplied, this argument will restrict the facts collected to a given subset. - Possible values for this argument include all and the resources like interfaces, - vlans etc. Can specify a list of values to include a larger subset. Values can + - When supplied, this argument will gather configuration facts only for the given subset. + Can specify a list of values to include a larger subset. Values can also be used with an initial C(!) to specify that a specific subset should - not be collected. Valid subsets are C(all), C(bfd_interfaces), C(lag_interfaces), + not be collected. + - Valid subsets are C(all), C(bfd_interfaces), C(lag_interfaces), C(telemetry), C(vlans), C(lacp), C(lacp_interfaces), C(interfaces), C(l3_interfaces), C(l2_interfaces), C(lldp_global), C(acls), C(acl_interfaces), C(ospfv2), C(ospfv3), C(ospf_interfaces), - C(bgp_global), C(bgp_address_family), C(route_maps), C(prefix_lists), C(logging_global), C(ntp_global), C(snmp_server). + C(bgp_global), C(bgp_address_family), C(route_maps), C(prefix_lists), C(logging_global), C(ntp_global), + C(snmp_server), C(hostname). required: false type: list elements: str available_network_resources: - description: When 'True' a list of network resources for which resource modules are available will be provided. + description: When set to C(true) a list of network resources for which resource modules are available will be provided. type: bool default: false """ @@ -75,11 +77,11 @@ - name: Gather only the config and default facts cisco.nxos.nxos_facts: gather_subset: - - config + - config - name: Do not gather hardware facts cisco.nxos.nxos_facts: gather_subset: - - '!hardware' + - '!hardware' - name: Gather legacy and resource facts cisco.nxos.nxos_facts: gather_subset: all @@ -87,10 +89,10 @@ - name: Gather only the interfaces resource facts and no legacy facts cisco.nxos.nxos_facts: gather_subset: - - '!all' - - '!min' + - '!all' + - '!min' gather_network_resources: - - interfaces + - interfaces - name: Gather interfaces resource and minimal legacy facts cisco.nxos.nxos_facts: gather_subset: min @@ -212,16 +214,28 @@ """ from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.connection import Connection + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.facts.facts import ( FactsArgs, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, - FACT_RESOURCE_SUBSETS, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts + + +def get_chassis_type(connection): + """Return facts resource subsets based on + chassis model. + """ + target_type = "nexus" + + device_info = connection.get_device_info() + model = device_info.get("network_os_model", "") + platform = device_info.get("network_os_platform", "") + + if platform.startswith("DS-") and "MDS" in model: + target_type = "mds" + + return target_type def main(): @@ -231,20 +245,18 @@ def main(): :returns: ansible_facts """ argument_spec = FactsArgs.argument_spec - argument_spec.update(nxos_argument_spec) - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) + connection = Connection(module._socket_path) + facts = Facts(module, chassis_type=get_chassis_type(connection)) warnings = [] ansible_facts = {} if module.params.get("available_network_resources"): - ansible_facts["available_network_resources"] = sorted( - FACT_RESOURCE_SUBSETS.keys() - ) - result = Facts(module).get_facts() + ansible_facts["available_network_resources"] = sorted(facts.get_resource_subsets().keys()) + + result = facts.get_facts() additional_facts, additional_warnings = result ansible_facts.update(additional_facts) warnings.extend(additional_warnings) diff --git a/plugins/modules/nxos_fc_interfaces.py b/plugins/modules/nxos_fc_interfaces.py new file mode 100644 index 000000000..a77deffdb --- /dev/null +++ b/plugins/modules/nxos_fc_interfaces.py @@ -0,0 +1,580 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Copyright 2023 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +""" +The module file for nxos_fc_interfaces +""" + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +DOCUMENTATION = """ +--- +module: nxos_fc_interfaces +short_description: Fc Interfaces resource module +description: This module manages the interface attributes of NX-OS fc interfaces. +version_added: 5.2.0 +author: Suhas Bharadwaj (@srbharadwaj) +notes: + - Tested against NXOS 9.3(2) on Cisco MDS Switches +options: + running_config: + description: + - This option is used only with state I(parsed). + - The value of this option should be the output received from the NX-OS + device by executing the command B(show running-config interface) + - The state I(parsed) reads the configuration from C(running_config) + option and transforms it into Ansible structured data as per the + resource module's argspec and the value is then returned in the + I(parsed) key within the result. + type: str + config: + description: A dictionary of interface options + type: list + elements: dict + suboptions: + name: + description: + - Full name of interface, e.g. fc1/1, fc18/48 + type: str + required: true + description: + description: + - Interface description. + type: str + enabled: + description: + - Administrative state of the interface. Set the value to C(true) to + administratively enable the interface or C(true) to disable it + type: bool + speed: + description: + - Interface link speed. + choices: + - 'auto' + - '1000' + - '2000' + - '4000' + - '8000' + - '10000' + - '16000' + - '32000' + - '64000' + - 'auto max 2000' + - 'auto max 4000' + - 'auto max 8000' + - 'auto max 16000' + - 'auto max 32000' + - 'auto max 64000' + type: str + mode: + description: + - Port mode of the fc interface + choices: + - 'auto' + - 'E' + - 'F' + - 'Fx' + - 'NP' + - 'SD' + type: str + trunk_mode: + description: + - Trunk mode of the fc interface + choices: + - 'auto' + - 'on' + - 'off' + type: str + analytics: + description: + - Analytics type on the fc interface + choices: + - 'fc-scsi' + - 'fc-nvme' + - 'fc-all' + type: str + state: + description: + - The state of the configuration after module completion + type: str + choices: + - merged + - replaced + - overridden + - deleted + - gathered + - rendered + - parsed + default: merged +""" +EXAMPLES = """ +# Using merged + +# Before state: +# ------------- +# +# switch# show running-config interface all +# interface fc18/10 +# analytics type fc-nvme +# switchport speed auto max 16000 +# switchport mode auto +# switchport description $ +# switchport trunk mode on +# shutdown + +- name: Merge provided configuration with device configuration + cisco.nxos.nxos_fc_interfaces: + config: + - name: fc18/10 + analytics: fc-scsi + state: merged + +# Task Output +# ----------- +# +# before: +# - name: fc18/10 +# speed: auto max 16000 +# mode: auto +# trunk_mode: on +# enabled: true +# description: $ +# analytics: fc-nvme +# commands: +# - interface fc18/10 +# - analytics type fc-scsi +# after: +# - name: fc18/10 +# speed: auto max 16000 +# mode: auto +# trunk_mode: on +# enabled: true +# description: $ +# analytics: fc-all + +# After state: +# ------------ +# +# switch# show running-config interface all +# interface fc18/10 +# analytics type fc-scsi +# analytics type fc-nvme +# switchport speed auto max 16000 +# switchport mode auto +# switchport description $ +# switchport trunk mode on +# shutdown + +# Using replaced + +# Before state: +# ------------- +# +# switch# show running-config interface all +# interface fc18/12 +# analytics type fc-scsi +# analytics type fc-nvme +# switchport speed auto max 64000 +# switchport mode auto +# switchport description 1 +# switchport trunk mode on +# no shutdown + +- name: Replaces device configuration of listed interfaces with provided configuration + cisco.nxos.nxos_fc_interfaces: + config: + - name: fc18/12 + speed: auto max 64000 + mode: auto + trunk_mode: "on" + enabled: true + description: 1 + analytics: fc-scsi + state: replaced + +# Task Output +# ----------- +# +# before: +# - name: fc18/12 +# speed: auto max 64000 +# mode: auto +# trunk_mode: on +# enabled: true +# description: 1 +# analytics: fc-all +# commands: +# - interface fc18/12 +# - no analytics type fc-all +# - analytics type fc-scsi +# after: +# - name: fc18/12 +# speed: auto max 64000 +# mode: auto +# trunk_mode: on +# enabled: true +# description: 1 +# analytics: fc-scsi + +# After state: +# ------------ +# +# switch# show running-config interface all +# interface fc18/12 +# analytics type fc-scsi +# switchport speed auto max 64000 +# switchport mode auto +# switchport description 1 +# switchport trunk mode on +# no shutdown + + +# Using deleted + +# Before state: +# ------------- +# +# switch# show running-config interface all +# interface fc1/2 +# switchport speed 1000 +# switchport mode E +# no switchport description +# switchport trunk mode off +# no shutdown + +- name: Delete or return interface parameters to default settings + cisco.nxos.nxos_fc_interfaces: + config: + - name: fc1/2 + state: deleted + +# Task Output +# ----------- +# +# before: +# - name: fc1/2 +# speed: 1000 +# mode: E +# trunk_mode: off +# enabled: true +# commands: +# - interface fc1/2 +# - no switchport speed 1000 +# - no switchport mode E +# - switchport trunk mode on +# - shutdown +# after: +# - name: fc1/2 +# speed: auto +# mode: auto +# trunk_mode: on +# enabled: true + +# After state: +# ------------ +# +# switch# show running-config interface all +# interface fc1/2 +# switchport speed auto +# switchport mode auto +# no switchport description +# switchport trunk mode on +# shutdown + +# Using overridden + +# Before state: +# ------------- +# +# switch# show running-config interface all +# interface fc18/12 +# analytics type fc-scsi +# analytics type fc-nvme +# switchport speed auto max 64000 +# switchport mode auto +# switchport description 1 +# switchport trunk mode on +# no shutdown +# interface fc18/13 +# analytics type fc-scsi +# analytics type fc-nvme +# switchport speed auto max 64000 +# switchport mode auto +# switchport description 1 +# switchport trunk mode on +# no shutdown + +- name: Replaces device configuration of listed interfaces with provided configuration + cisco.nxos.nxos_fc_interfaces: + config: + - name: fc18/12 + speed: auto max 64000 + mode: auto + trunk_mode: "on" + enabled: true + description: 1 + analytics: fc-scsi + state: overridden + +# Task Output +# ----------- +# +# before: +# - name: fc18/12 +# speed: auto max 64000 +# mode: auto +# trunk_mode: on +# enabled: true +# description: 1 +# analytics: fc-all +# - name: fc18/13 +# speed: auto max 64000 +# mode: auto +# trunk_mode: on +# enabled: true +# description: 1 +# analytics: fc-all +# commands: +# - interface fc18/12 +# no analytics type fc-all +# analytics type fc-scsi +# - interface fc18/13 +# no switchport description +# no switchport speed auto max 64000 +# no switchport mode auto +# switchport trunk mode on +# shutdown +# after: +# - name: fc18/12 +# speed: auto max 64000 +# mode: auto +# trunk_mode: on +# enabled: true +# description: 1 +# analytics: fc-scsi +# - name: fc18/13 +# speed: auto max 64000 +# mode: auto +# trunk_mode: on +# enabled: true + +# After state: +# ------------ +# +# switch# show running-config interface all +# interface fc18/12 +# analytics type fc-scsi +# switchport speed auto max 64000 +# switchport mode auto +# switchport description 1 +# switchport trunk mode on +# no shutdown +# interface fc18/13 +# switchport mode auto +# switchport trunk mode on +# shutdown + +# Using rendered + +- name: Use rendered state to convert task input to device specific commands + cisco.nxos.nxos_fc_interfaces: + config: + - name: fc1/1 + speed: auto + mode: auto + trunk_mode: "on" + enabled: true + description: This is a sample line + - name: fc1/2 + speed: 1000 + mode: E + trunk_mode: "off" + enabled: true + state: rendered + +# Task Output +# ----------- +# +# rendered: +# interface fc1/1 +# switchport speed auto +# switchport mode auto +# switchport description This is a sample line +# switchport trunk mode on +# no shutdown +# +# interface fc1/2 +# switchport speed 1000 +# switchport mode E +# no switchport description +# switchport trunk mode off +# no shutdown + +# Using parsed + +# parsed.cfg +# ------------ +# +# interface fc1/1 +# switchport speed auto +# switchport mode auto +# switchport description This is a sample line +# switchport trunk mode on +# no shutdown +# +# interface fc1/2 +# switchport speed 1000 +# switchport mode E +# no switchport description +# switchport trunk mode off +# no shutdown + +- name: Use parsed state to convert externally supplied config to structured format + cisco.nxos.nxos_fc_interfaces: + running_config: "{{ lookup('file', 'parsed.cfg') }}" + state: parsed + +# Task output +# ----------- +# +# parsed: +# - name: fc1/1 +# speed: auto +# mode: auto +# trunk_mode: on +# enabled: true +# description: This is a sample line +# - name: fc1/2 +# speed: 1000 +# mode: E +# trunk_mode: off +# enabled: true + +# Using gathered + +# Before state: +# ------------- +# +# switch# show running-config | section interface +# interface fc1/1 +# switchport speed auto +# switchport mode auto +# switchport description This is a sample line +# switchport trunk mode on +# no shutdown +# +# interface fc1/2 +# switchport speed 1000 +# switchport mode E +# no switchport description +# switchport trunk mode off +# no shutdown +# +- name: Gather interfaces facts from the device using nxos_fc_interfaces + cisco.nxos.nxos_fc_interfaces: + state: gathered +# +# Task output +# ----------- +# +# - name: fc1/1 +# speed: auto +# mode: auto +# trunk_mode: on +# enabled: true +# description: This is a sample line +# - name: fc1/2 +# speed: 1000 +# mode: E +# trunk_mode: off +# enabled: true +""" + +RETURN = """ +before: + description: The configuration prior to the module execution. + returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) + type: dict + sample: > + This output will always be in the same format as the + module argspec. +after: + description: The resulting configuration after module execution. + returned: when changed + type: dict + sample: > + This output will always be in the same format as the + module argspec. +commands: + description: The set of commands pushed to the remote device. + returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) + type: list + sample: + - interface fc1/1 + - description sample description + - shutdown +rendered: + description: The provided configuration in the task rendered in device-native format (offline). + returned: when I(state) is C(rendered) + type: list + sample: + - interface fc1/1 + - description sample description + - shutdown +gathered: + description: Facts about the network resource gathered from the remote device as structured data. + returned: when I(state) is C(gathered) + type: list + sample: > + This output will always be in the same format as the + module argspec. +parsed: + description: The device native config provided in I(running_config) option parsed into structured data as per module argspec. + returned: when I(state) is C(parsed) + type: list + sample: > + This output will always be in the same format as the + module argspec. +""" + +from ansible.module_utils.basic import AnsibleModule + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.fc_interfaces.fc_interfaces import ( + Fc_interfacesArgs, +) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.fc_interfaces.fc_interfaces import ( + Fc_interfaces, +) + + +def main(): + """ + Main entry point for module execution + + :returns: the result form module invocation + """ + module = AnsibleModule( + argument_spec=Fc_interfacesArgs.argument_spec, + mutually_exclusive=[["config", "running_config"]], + required_if=[ + ["state", "merged", ["config"]], + ["state", "replaced", ["config"]], + ["state", "overridden", ["config"]], + ["state", "rendered", ["config"]], + ["state", "parsed", ["running_config"]], + ], + supports_check_mode=True, + ) + + result = Fc_interfaces(module).execute_module() + module.exit_json(**result) + + +if __name__ == "__main__": + main() diff --git a/plugins/modules/nxos_feature.py b/plugins/modules/nxos_feature.py index 4a42d120f..c9229c4d5 100644 --- a/plugins/modules/nxos_feature.py +++ b/plugins/modules/nxos_feature.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type DOCUMENTATION = """ @@ -79,14 +80,12 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.connection import ConnectionError + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + get_capabilities, + get_config, load_config, run_commands, - get_config, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_capabilities, - nxos_argument_spec, ) @@ -118,10 +117,7 @@ def get_available_features(feature, module): if feature not in available_features: available_features[feature] = state else: - if ( - available_features[feature] == "disabled" - and state == "enabled" - ): + if available_features[feature] == "disabled" and state == "enabled": available_features[feature] = state # certain configurable features do not @@ -272,11 +268,7 @@ def main(): state=dict(choices=["enabled", "disabled"], default="enabled"), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() results = dict(changed=False, warnings=warnings) diff --git a/plugins/modules/nxos_file_copy.py b/plugins/modules/nxos_file_copy.py index af689c121..4847a446e 100644 --- a/plugins/modules/nxos_file_copy.py +++ b/plugins/modules/nxos_file_copy.py @@ -18,6 +18,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type DOCUMENTATION = """ @@ -156,7 +157,8 @@ type: str vrf: description: - - The VRF used to pull the file. Useful when no vrf management is defined + - The VRF used to pull the file. Useful when no vrf management is defined. + - This option is not applicable for MDS switches. default: management type: str """ @@ -222,41 +224,42 @@ sample: true """ -import re -import os import hashlib +import os +import re -from ansible.module_utils._text import to_text, to_bytes +from ansible.module_utils._text import to_bytes, to_text from ansible.module_utils.basic import AnsibleModule -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network import ( get_resource_connection, ) -class FilePush: +class FileCopy: def __init__(self, module): self._module = module self._connection = get_resource_connection(self._module) + device_info = self._connection.get_device_info() + self._model = device_info.get("network_os_model", "") + self._platform = device_info.get("network_os_platform", "") + + +class FilePush(FileCopy): + def __init__(self, module): + super(FilePush, self).__init__(module) self.result = {} def md5sum_check(self, dst, file_system): command = "show file {0}{1} md5sum".format(file_system, dst) remote_filehash = self._connection.run_commands(command)[0] - remote_filehash = to_bytes( - remote_filehash, errors="surrogate_or_strict" - ) + remote_filehash = to_bytes(remote_filehash, errors="surrogate_or_strict") local_file = self._module.params["local_file"] try: with open(local_file, "rb") as f: filecontent = f.read() except (OSError, IOError) as exc: - self._module.fail_json( - "Error reading the file: {0}".format(to_text(exc)) - ) + self._module.fail_json("Error reading the file: {0}".format(to_text(exc))) filecontent = to_bytes(filecontent, errors="surrogate_or_strict") local_filehash = hashlib.md5(filecontent).hexdigest() @@ -288,15 +291,9 @@ def get_flash_size(self, file_system): match = re.search(r"No such file or directory", body) if match: - self._module.fail_json( - "Invalid nxos filesystem {0}".format(file_system) - ) + self._module.fail_json("Invalid nxos filesystem {0}".format(file_system)) else: - self._module.fail_json( - "Unable to determine size of filesystem {0}".format( - file_system - ) - ) + self._module.fail_json("Unable to determine size of filesystem {0}".format(file_system)) def enough_space(self, file, file_system): flash_size = self.get_flash_size(file_system) @@ -311,40 +308,33 @@ def transfer_file_to_device(self, remote_file): file_system = self._module.params["file_system"] if not self.enough_space(local_file, file_system): - self._module.fail_json( - "Could not transfer file. Not enough space on device." - ) + self._module.fail_json("Could not transfer file. Not enough space on device.") # frp = full_remote_path, flp = full_local_path - frp = "{0}{1}".format(file_system, remote_file) + frp = remote_file + if not file_system.startswith("bootflash:"): + frp = "{0}{1}".format(file_system, remote_file) flp = os.path.join(os.path.abspath(local_file)) + try: self._connection.copy_file( source=flp, destination=frp, proto="scp", - timeout=self._connection.get_option( - "persistent_command_timeout" - ), + timeout=self._connection.get_option("persistent_command_timeout"), ) - self.result[ - "transfer_status" - ] = "Sent: File copied to remote device." + self.result["transfer_status"] = "Sent: File copied to remote device." except Exception as exc: self.result["failed"] = True self.result["msg"] = "Exception received : %s" % exc def run(self): local_file = self._module.params["local_file"] - remote_file = self._module.params["remote_file"] or os.path.basename( - local_file - ) + remote_file = self._module.params["remote_file"] or os.path.basename(local_file) file_system = self._module.params["file_system"] if not os.path.isfile(local_file): - self._module.fail_json( - "Local file {0} not found".format(local_file) - ) + self._module.fail_json("Local file {0} not found".format(local_file)) remote_file = remote_file or os.path.basename(local_file) remote_exists = self.remote_file_exists(remote_file, file_system) @@ -353,9 +343,7 @@ def run(self): self.result["changed"] = True file_exists = False else: - self.result[ - "transfer_status" - ] = "No Transfer: File already copied to remote device." + self.result["transfer_status"] = "No Transfer: File already copied to remote device." file_exists = True if not self._module.check_mode and not file_exists: @@ -370,10 +358,9 @@ def run(self): return self.result -class FilePull: +class FilePull(FileCopy): def __init__(self, module): - self._module = module - self._connection = get_resource_connection(self._module) + super(FilePull, self).__init__(module) self.result = {} def mkdir(self, directory): @@ -395,7 +382,11 @@ def copy_file_from_remote(self, local, local_file_directory, file_system): rfile = self._module.params["remote_file"] + " " if not rfile.startswith("/"): rfile = "/" + rfile - vrf = " vrf " + self._module.params["vrf"] + + if not self._platform.startswith("DS-") and "MDS" not in self._model: + vrf = " vrf " + self._module.params["vrf"] + else: + vrf = "" if self._module.params["file_pull_compact"]: compact = " compact " else: @@ -425,9 +416,7 @@ def copy_file_from_remote(self, local, local_file_directory, file_system): ) self.result["copy_cmd"] = copy_cmd - pulled = self._connection.pull_file( - command=copy_cmd, remotepassword=rserverpassword - ) + pulled = self._connection.pull_file(command=copy_cmd, remotepassword=rserverpassword) if pulled: self.result[ "transfer_status" @@ -438,9 +427,7 @@ def copy_file_from_remote(self, local, local_file_directory, file_system): def run(self): self.result["failed"] = False remote_file = self._module.params["remote_file"] - local_file = ( - self._module.params["local_file"] or remote_file.split("/")[-1] - ) + local_file = self._module.params["local_file"] or remote_file.split("/")[-1] file_system = self._module.params["file_system"] # Note: This is the local file directory on the remote nxos device. local_file_dir = self._module.params["local_file_directory"] @@ -454,9 +441,7 @@ def run(self): else: dir = "" self.result["local_file"] = file_system + dir + "/" + local_file - self.result["remote_scp_server"] = self._module.params[ - "remote_scp_server" - ] + self.result["remote_scp_server"] = self._module.params["remote_scp_server"] self.result["file_system"] = self._module.params["file_system"] if not self.result["failed"]: @@ -487,13 +472,9 @@ def main(): remote_scp_server_password=dict(no_log=True), ) - argument_spec.update(nxos_argument_spec) - module = AnsibleModule( argument_spec=argument_spec, - required_if=[ - ("file_pull", True, ("remote_file", "remote_scp_server")) - ], + required_if=[("file_pull", True, ("remote_file", "remote_scp_server"))], required_together=[("remote_scp_server", "remote_scp_server_user")], supports_check_mode=True, ) diff --git a/plugins/modules/nxos_gir.py b/plugins/modules/nxos_gir.py index 693bf73a3..c473ff5ac 100644 --- a/plugins/modules/nxos_gir.py +++ b/plugins/modules/nxos_gir.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -164,14 +165,12 @@ sample: true """ +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule def get_system_mode(module): @@ -204,15 +203,11 @@ def get_commands(module, state, mode): commands = list() if module.params["system_mode_maintenance"] is True and mode == "normal": commands.append("system mode maintenance") - elif ( - module.params["system_mode_maintenance"] is False - and mode == "maintenance" - ): + elif module.params["system_mode_maintenance"] is False and mode == "maintenance": commands.append("no system mode maintenance") elif ( - module.params["system_mode_maintenance_dont_generate_profile"] is True - and mode == "normal" + module.params["system_mode_maintenance_dont_generate_profile"] is True and mode == "normal" ): commands.append("system mode maintenance dont-generate-profile") elif ( @@ -223,66 +218,47 @@ def get_commands(module, state, mode): elif module.params["system_mode_maintenance_timeout"]: timeout = get_maintenance_timeout(module) - if ( - state == "present" - and timeout != module.params["system_mode_maintenance_timeout"] - ): + if state == "present" and timeout != module.params["system_mode_maintenance_timeout"]: commands.append( "system mode maintenance timeout {0}".format( - module.params["system_mode_maintenance_timeout"] - ) + module.params["system_mode_maintenance_timeout"], + ), ) - elif ( - state == "absent" - and timeout == module.params["system_mode_maintenance_timeout"] - ): + elif state == "absent" and timeout == module.params["system_mode_maintenance_timeout"]: commands.append( "no system mode maintenance timeout {0}".format( - module.params["system_mode_maintenance_timeout"] - ) + module.params["system_mode_maintenance_timeout"], + ), ) - elif ( - module.params["system_mode_maintenance_shutdown"] and mode == "normal" - ): + elif module.params["system_mode_maintenance_shutdown"] and mode == "normal": commands.append("system mode maintenance shutdown") - elif ( - module.params["system_mode_maintenance_shutdown"] is False - and mode == "maintenance" - ): + elif module.params["system_mode_maintenance_shutdown"] is False and mode == "maintenance": commands.append("no system mode maintenance") elif module.params["system_mode_maintenance_on_reload_reset_reason"]: reset_reasons = get_reset_reasons(module) if ( state == "present" - and module.params[ - "system_mode_maintenance_on_reload_reset_reason" - ].lower() + and module.params["system_mode_maintenance_on_reload_reset_reason"].lower() not in reset_reasons.lower() ): commands.append( "system mode maintenance on-reload " "reset-reason {0}".format( - module.params[ - "system_mode_maintenance_on_reload_reset_reason" - ] - ) + module.params["system_mode_maintenance_on_reload_reset_reason"], + ), ) elif ( state == "absent" - and module.params[ - "system_mode_maintenance_on_reload_reset_reason" - ].lower() + and module.params["system_mode_maintenance_on_reload_reset_reason"].lower() in reset_reasons.lower() ): commands.append( "no system mode maintenance on-reload " "reset-reason {0}".format( - module.params[ - "system_mode_maintenance_on_reload_reset_reason" - ] - ) + module.params["system_mode_maintenance_on_reload_reset_reason"], + ), ) if commands: @@ -293,9 +269,7 @@ def get_commands(module, state, mode): def main(): argument_spec = dict( system_mode_maintenance=dict(required=False, type="bool"), - system_mode_maintenance_dont_generate_profile=dict( - required=False, type="bool" - ), + system_mode_maintenance_dont_generate_profile=dict(required=False, type="bool"), system_mode_maintenance_timeout=dict(required=False, type="str"), system_mode_maintenance_shutdown=dict(required=False, type="bool"), system_mode_maintenance_on_reload_reset_reason=dict( @@ -313,13 +287,9 @@ def main(): "maintenance", ], ), - state=dict( - choices=["absent", "present"], default="present", required=False - ), + state=dict(choices=["absent", "present"], default="present", required=False), ) - argument_spec.update(nxos_argument_spec) - module = AnsibleModule( argument_spec=argument_spec, mutually_exclusive=[ @@ -329,7 +299,7 @@ def main(): "system_mode_maintenance_timeout", "system_mode_maintenance_shutdown", "system_mode_maintenance_on_reload_reset_reason", - ] + ], ], required_one_of=[ [ @@ -338,7 +308,7 @@ def main(): "system_mode_maintenance_timeout", "system_mode_maintenance_shutdown", "system_mode_maintenance_on_reload_reset_reason", - ] + ], ], supports_check_mode=True, ) diff --git a/plugins/modules/nxos_gir_profile_management.py b/plugins/modules/nxos_gir_profile_management.py index 7c3f092af..2ddf2ce60 100644 --- a/plugins/modules/nxos_gir_profile_management.py +++ b/plugins/modules/nxos_gir_profile_management.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -64,8 +65,8 @@ - cisco.nxos.nxos_gir_profile_management: mode: maintenance commands: - - router eigrp 11 - - isolate + - router eigrp 11 + - isolate # Remove the maintenance-mode profile - cisco.nxos.nxos_gir_profile_management: @@ -105,18 +106,16 @@ """ -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_config, - load_config, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) from ansible.module_utils.basic import AnsibleModule from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( CustomNetworkConfig, ) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + get_config, + load_config, +) + def get_existing(module): existing = [] @@ -171,11 +170,7 @@ def main(): state=dict(choices=["absent", "present"], default="present"), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() diff --git a/plugins/modules/nxos_hostname.py b/plugins/modules/nxos_hostname.py index 122c49f11..3f141562c 100644 --- a/plugins/modules/nxos_hostname.py +++ b/plugins/modules/nxos_hostname.py @@ -10,6 +10,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type DOCUMENTATION = """ @@ -145,7 +146,6 @@ # ----------------------- # parsed: # hostname: NXOSv-9k - """ RETURN = """ @@ -192,6 +192,7 @@ """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.hostname.hostname import ( HostnameArgs, ) diff --git a/plugins/modules/nxos_hsrp.py b/plugins/modules/nxos_hsrp.py index 1ecee4478..ee59b7ddc 100644 --- a/plugins/modules/nxos_hsrp.py +++ b/plugins/modules/nxos_hsrp.py @@ -1,6 +1,7 @@ #!/usr/bin/python from __future__ import absolute_import, division, print_function + __metaclass__ = type # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) @@ -142,18 +143,14 @@ sample: ["interface vlan10", "hsrp version 2", "hsrp 30", "ip 10.30.1.1"] """ -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - load_config, - run_commands, -) +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( get_capabilities, - nxos_argument_spec, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( get_interface_type, + load_config, + run_commands, ) -from ansible.module_utils.basic import AnsibleModule PARAM_TO_DEFAULT_KEYMAP = { @@ -218,9 +215,7 @@ def get_hsrp_group(group, interface, module): if "sh_keystring_attr" not in hsrp_table: del hsrp_key["sh_keystring_attr"] if "unknown enum:" in str(hsrp_table): - hsrp_table = get_hsrp_group_unknown_enum( - module, command, hsrp_table - ) + hsrp_table = get_hsrp_group_unknown_enum(module, command, hsrp_table) except (AttributeError, IndexError, TypeError, KeyError): return {} @@ -258,9 +253,7 @@ def get_hsrp_group_unknown_enum(module, command, hsrp_table): if "unknown enum:" in hsrp_table["sh_preempt"]: cmd = {"output": "text", "command": command.split("|")[0]} out = run_commands(module, cmd)[0] - hsrp_table["sh_preempt"] = ( - "enabled" if ("may preempt" in out) else "disabled" - ) + hsrp_table["sh_preempt"] = "enabled" if ("may preempt" in out) else "disabled" return hsrp_table @@ -292,9 +285,7 @@ def get_commands_config_hsrp(delta, interface, args, existing): if priority: if priority == "default": - if existing and existing.get( - "priority" - ) != PARAM_TO_DEFAULT_KEYMAP.get("priority"): + if existing and existing.get("priority") != PARAM_TO_DEFAULT_KEYMAP.get("priority"): delta["priority"] = "no priority" else: del delta["priority"] @@ -303,9 +294,7 @@ def get_commands_config_hsrp(delta, interface, args, existing): if vip: if vip == "default": - if existing and existing.get("vip") != PARAM_TO_DEFAULT_KEYMAP.get( - "vip" - ): + if existing and existing.get("vip") != PARAM_TO_DEFAULT_KEYMAP.get("vip"): delta["vip"] = "no ip" else: del delta["vip"] @@ -331,17 +320,15 @@ def get_commands_config_hsrp(delta, interface, args, existing): auth_string = args["auth_string"] if auth_string != "default": if auth_type == "md5": - command = "authentication md5 key-string {0} {1}".format( - auth_enc, auth_string - ) + command = "authentication md5 key-string {0} {1}".format(auth_enc, auth_string) commands.append(command) elif auth_type == "text": command = "authentication text {0}".format(auth_string) commands.append(command) else: - if existing and existing.get( - "auth_string" - ) != PARAM_TO_DEFAULT_KEYMAP.get("auth_string"): + if existing and existing.get("auth_string") != PARAM_TO_DEFAULT_KEYMAP.get( + "auth_string", + ): commands.append("no authentication") if commands and not group: @@ -376,16 +363,14 @@ def is_default(interface, module): return True else: return False - except (KeyError): + except KeyError: return "DNE" def validate_config(body, vip, module): new_body = "".join(body) if "invalid ip address" in new_body.lower(): - module.fail_json( - msg="Invalid VIP. Possible duplicate IP address.", vip=vip - ) + module.fail_json(msg="Invalid VIP. Possible duplicate IP address.", vip=vip) def main(): @@ -394,22 +379,14 @@ def main(): interface=dict(required=True), version=dict(choices=["1", "2"], default="1", required=False), priority=dict(type="str", required=False), - preempt=dict( - type="str", choices=["disabled", "enabled"], required=False - ), + preempt=dict(type="str", choices=["disabled", "enabled"], required=False), vip=dict(type="str", required=False), auth_type=dict(choices=["text", "md5"], required=False), auth_string=dict(type="str", required=False), - state=dict( - choices=["absent", "present"], required=False, default="present" - ), + state=dict(choices=["absent", "present"], required=False, default="present"), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() results = dict(changed=False, warnings=warnings) @@ -456,16 +433,14 @@ def main(): mode = get_interface_mode(interface, intf_type, module) if mode == "layer2": module.fail_json( - msg="That interface is a layer2 port.\nMake it " - "a layer 3 port first.", + msg="That interface is a layer2 port.\nMake it " "a layer 3 port first.", interface=interface, ) if auth_type or auth_string: if not (auth_type and auth_string): module.fail_json( - msg="When using auth parameters, you need BOTH " - "auth_type AND auth_string." + msg="When using auth parameters, you need BOTH " "auth_type AND auth_string.", ) args = dict( @@ -486,26 +461,19 @@ def main(): # This will enforce better practice with md5 and hsrp version. if proposed.get("auth_type", None) == "md5": if proposed["version"] == "1": - module.fail_json( - msg="It's recommended to use HSRP v2 " "when auth_type=md5" - ) + module.fail_json(msg="It's recommended to use HSRP v2 " "when auth_type=md5") elif not proposed.get("auth_type", None) and existing: - if ( - proposed["version"] == "1" and existing["auth_type"] == "md5" - ) and state == "present": + if (proposed["version"] == "1" and existing["auth_type"] == "md5") and state == "present": module.fail_json( - msg="Existing auth_type is md5. It's recommended " - "to use HSRP v2 when using md5" + msg="Existing auth_type is md5. It's recommended " "to use HSRP v2 when using md5", ) commands = [] if state == "present": delta = dict(set(proposed.items()).difference(existing.items())) if delta: - command = get_commands_config_hsrp( - delta, interface, args, existing - ) + command = get_commands_config_hsrp(delta, interface, args, existing) commands.extend(command) elif state == "absent": diff --git a/plugins/modules/nxos_hsrp_interfaces.py b/plugins/modules/nxos_hsrp_interfaces.py index d425ba61d..3e11949dc 100644 --- a/plugins/modules/nxos_hsrp_interfaces.py +++ b/plugins/modules/nxos_hsrp_interfaces.py @@ -28,6 +28,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -87,8 +88,8 @@ - name: Configure hsrp attributes on interfaces cisco.nxos.nxos_hsrp_interfaces: config: - - name: Ethernet1/1 - - name: Ethernet1/2 + - name: Ethernet1/1 + - name: Ethernet1/2 operation: deleted @@ -97,10 +98,10 @@ - name: Configure hsrp attributes on interfaces cisco.nxos.nxos_hsrp_interfaces: config: - - name: Ethernet1/1 - bfd: enable - - name: Ethernet1/2 - bfd: disable + - name: Ethernet1/1 + bfd: enable + - name: Ethernet1/2 + bfd: disable operation: merged @@ -109,10 +110,10 @@ - name: Configure hsrp attributes on interfaces cisco.nxos.nxos_hsrp_interfaces: config: - - name: Ethernet1/1 - bfd: enable - - name: Ethernet1/2 - bfd: disable + - name: Ethernet1/1 + bfd: enable + - name: Ethernet1/2 + bfd: disable operation: overridden @@ -121,10 +122,10 @@ - name: Configure hsrp attributes on interfaces cisco.nxos.nxos_hsrp_interfaces: config: - - name: Ethernet1/1 - bfd: enable - - name: Ethernet1/2 - bfd: disable + - name: Ethernet1/1 + bfd: enable + - name: Ethernet1/2 + bfd: disable operation: replaced # Using rendered @@ -132,10 +133,10 @@ - name: Use rendered state to convert task input to device specific commands cisco.nxos.nxos_hsrp_interfaces: config: - - name: Ethernet1/800 - bfd: enable - - name: Ethernet1/801 - bfd: enable + - name: Ethernet1/800 + bfd: enable + - name: Ethernet1/801 + bfd: enable state: rendered # Task Output (redacted) @@ -198,7 +199,6 @@ # bfd: enable # - name: Ethernet1/2 # bfd: enable - """ RETURN = """ before: @@ -224,6 +224,7 @@ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.hsrp_interfaces.hsrp_interfaces import ( Hsrp_interfacesArgs, ) diff --git a/plugins/modules/nxos_igmp.py b/plugins/modules/nxos_igmp.py index 46b5cd9df..937706162 100644 --- a/plugins/modules/nxos_igmp.py +++ b/plugins/modules/nxos_igmp.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -84,20 +85,16 @@ type: list sample: ["ip igmp flush-routes"] """ +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule def get_current(module): - output = run_commands( - module, {"command": "show running-config", "output": "text"} - ) + output = run_commands(module, {"command": "show running-config", "output": "text"}) return { "flush_routes": "ip igmp flush-routes" in output[0], "enforce_rtr_alert": "ip igmp enforce-router-alert" in output[0], @@ -119,11 +116,7 @@ def main(): state=dict(choices=["present", "default"], default="present"), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() diff --git a/plugins/modules/nxos_igmp_interface.py b/plugins/modules/nxos_igmp_interface.py index fd688fd1b..66a2a495e 100644 --- a/plugins/modules/nxos_igmp_interface.py +++ b/plugins/modules/nxos_igmp_interface.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -153,8 +154,8 @@ interface: ethernet1/32 startup_query_interval: 30 oif_ps: - - {prefix: 238.2.2.6} - - {source: 192.168.0.1, prefix: 238.2.2.5} + - {prefix: 238.2.2.6} + - {source: 192.168.0.1, prefix: 238.2.2.5} state: present """ RETURN = """ @@ -188,19 +189,15 @@ sample: true """ +import re + +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + get_interface_type, load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_interface_type, -) -from ansible.module_utils.basic import AnsibleModule - -import re def execute_show_command(command, module, command_type="cli_show"): @@ -281,9 +278,7 @@ def get_igmp_interface(module, interface): elif report_llg == "false": igmp["report_llg"] = False - immediate_leave = str( - resource["ImmediateLeave"] - ).lower() # returns en or dis + immediate_leave = str(resource["ImmediateLeave"]).lower() # returns en or dis if re.search(r"^en|^true|^enabled", immediate_leave): igmp["immediate_leave"] = True elif re.search(r"^dis|^false|^disabled", immediate_leave): @@ -294,16 +289,12 @@ def get_igmp_interface(module, interface): # or PREFIX source , etc. command = "show run interface {0} | inc oif".format(interface) - body = execute_show_command( - command, module, command_type="cli_show_ascii" - )[0] + body = execute_show_command(command, module, command_type="cli_show_ascii")[0] staticoif = [] if body: split_body = body.split("\n") - route_map_regex = ( - r".*ip igmp static-oif route-map\s+(?P\S+).*" - ) + route_map_regex = r".*ip igmp static-oif route-map\s+(?P\S+).*" prefix_source_regex = ( r".*ip igmp static-oif\s+(?P" r"((\d+.){3}\d+))(\ssource\s" @@ -319,9 +310,7 @@ def get_igmp_interface(module, interface): route_map = "" try: - match_prefix_source = re.match( - prefix_source_regex, line, re.DOTALL - ) + match_prefix_source = re.match(prefix_source_regex, line, re.DOTALL) prefix_source_group = match_prefix_source.groupdict() prefix = prefix_source_group["prefix"] source = prefix_source_group["source"] @@ -385,9 +374,7 @@ def config_igmp_interface(delta, existing, existing_oif_prefix_source): if "source" in each.keys(): src = each["source"] if src: - commands.append( - CMDS.get("oif_prefix_source").format(pf, src) - ) + commands.append(CMDS.get("oif_prefix_source").format(pf, src)) else: commands.append(CMDS.get("oif_prefix").format(pf)) if existing_oif_prefix_source: @@ -399,13 +386,10 @@ def config_igmp_interface(delta, existing, existing_oif_prefix_source): src = each["source"] if src: commands.append( - "no " - + CMDS.get("oif_prefix_source").format(pf, src) + "no " + CMDS.get("oif_prefix_source").format(pf, src), ) else: - commands.append( - "no " + CMDS.get("oif_prefix").format(pf) - ) + commands.append("no " + CMDS.get("oif_prefix").format(pf)) elif key == "oif_routemap": if value == "default": if existing.get(key): @@ -458,9 +442,7 @@ def get_igmp_interface_defaults(): immediate_leave=immediate_leave, ) - default = dict( - (param, value) for (param, value) in args.items() if value is not None - ) + default = dict((param, value) for (param, value) in args.items() if value is not None) return default @@ -471,7 +453,9 @@ def config_default_igmp_interface(existing, delta): delta = dict(set(proposed.items()).difference(existing.items())) if delta: command = config_igmp_interface( - delta, existing, existing_oif_prefix_source=None + delta, + existing, + existing_oif_prefix_source=None, ) if command: @@ -486,20 +470,17 @@ def config_remove_oif(existing, existing_oif_prefix_source): command = None if existing.get("oif_routemap"): commands.append( - "no ip igmp static-oif route-map {0}".format( - existing.get("oif_routemap") - ) + "no ip igmp static-oif route-map {0}".format(existing.get("oif_routemap")), ) elif existing_oif_prefix_source: for each in existing_oif_prefix_source: if each.get("prefix") and each.get("source"): command = "no ip igmp static-oif {0} source {1} ".format( - each.get("prefix"), each.get("source") + each.get("prefix"), + each.get("source"), ) elif each.get("prefix"): - command = "no ip igmp static-oif {0}".format( - each.get("prefix") - ) + command = "no ip igmp static-oif {0}".format(each.get("prefix")) if command: commands.append(command) command = None @@ -510,9 +491,7 @@ def config_remove_oif(existing, existing_oif_prefix_source): def main(): argument_spec = dict( interface=dict(required=True, type="str"), - version=dict( - required=False, type="str", choices=["2", "3", "default"] - ), + version=dict(required=False, type="str", choices=["2", "3", "default"]), startup_query_interval=dict(required=False, type="str"), startup_query_count=dict(required=False, type="str"), robustness=dict(required=False, type="str"), @@ -527,12 +506,9 @@ def main(): oif_routemap=dict(required=False, type="str"), oif_ps=dict(required=False, type="raw"), restart=dict(type="bool", default=False), - state=dict( - choices=["present", "absent", "default"], default="present" - ), + state=dict(choices=["present", "absent", "default"], default="present"), ) - argument_spec.update(nxos_argument_spec) mutually_exclusive = [("oif_ps", "oif_routemap")] module = AnsibleModule( @@ -566,14 +542,14 @@ def main(): if oif_routemap and existing_oif_prefix_source: module.fail_json( msg="Delete static-oif configurations on this " - "interface if you want to use a routemap" + "interface if you want to use a routemap", ) if oif_ps and existing.get("oif_routemap"): module.fail_json( msg="Delete static-oif route-map configuration " "on this interface if you want to config " - "static entries" + "static entries", ) args = [ @@ -594,9 +570,7 @@ def main(): changed = False commands = [] - proposed = dict( - (k, v) for k, v in module.params.items() if v is not None and k in args - ) + proposed = dict((k, v) for k, v in module.params.items() if v is not None and k in args) CANNOT_ABSENT = [ "version", @@ -617,9 +591,7 @@ def main(): for each in CANNOT_ABSENT: if each in proposed: module.fail_json( - msg="only params: " - "oif_ps, oif_routemap can be used when " - "state=absent" + msg="only params: " "oif_ps, oif_routemap can be used when " "state=absent", ) # delta check for all params except oif_ps @@ -633,9 +605,7 @@ def main(): if state == "present": if delta: - command = config_igmp_interface( - delta, existing, existing_oif_prefix_source - ) + command = config_igmp_interface(delta, existing, existing_oif_prefix_source) if command: commands.append(command) diff --git a/plugins/modules/nxos_igmp_snooping.py b/plugins/modules/nxos_igmp_snooping.py index 5f6dfafdb..6d14ba17b 100644 --- a/plugins/modules/nxos_igmp_snooping.py +++ b/plugins/modules/nxos_igmp_snooping.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -98,14 +99,12 @@ import re +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule def execute_show_command(command, module, output="text"): @@ -161,9 +160,7 @@ def get_igmp_snooping(module): link_local_grp_supp = str(body.get("glinklocalgrpsup")).lower() if "none" in link_local_grp_supp: - link_local_grp_supp = str( - body.get("GlobalLinkLocalGroupSupression") - ).lower() + link_local_grp_supp = str(body.get("GlobalLinkLocalGroupSupression")).lower() if link_local_grp_supp == "true" or link_local_grp_supp == "enabled": existing["link_local_grp_supp"] = True else: @@ -201,9 +198,7 @@ def config_igmp_snooping(delta, existing, default=False): if value: if default and key == "group_timeout": if existing.get(key): - gt_command = "no " + CMDS.get(key).format( - existing.get(key) - ) + gt_command = "no " + CMDS.get(key).format(existing.get(key)) elif value == "default" and key == "group_timeout": if existing.get(key): command = "no " + CMDS.get(key).format(existing.get(key)) @@ -237,9 +232,7 @@ def get_igmp_snooping_defaults(): group_timeout=group_timeout, ) - default = dict( - (param, value) for (param, value) in args.items() if value is not None - ) + default = dict((param, value) for (param, value) in args.items() if value is not None) return default @@ -269,11 +262,7 @@ def main(): state=dict(choices=["present", "default"], default="present"), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() results = {"changed": False, "commands": [], "warnings": warnings} @@ -293,9 +282,7 @@ def main(): group_timeout=group_timeout, ) - proposed = dict( - (param, value) for (param, value) in args.items() if value is not None - ) + proposed = dict((param, value) for (param, value) in args.items() if value is not None) existing = get_igmp_snooping(module) diff --git a/plugins/modules/nxos_install_os.py b/plugins/modules/nxos_install_os.py index acd7f3847..9b64a8989 100644 --- a/plugins/modules/nxos_install_os.py +++ b/plugins/modules/nxos_install_os.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -77,7 +78,7 @@ EXAMPLES = """ - name: Install OS on N9k - check_mode: no + check_mode: false cisco.nxos.nxos_install_os: system_image_file: nxos.7.0.3.I6.1.bin issu: desired @@ -93,11 +94,11 @@ - name: Check installed OS for newly installed version nxos_command: commands: [show version | json] - provider: '{{ connection }}' register: output + - assert: that: - - output['stdout'][0]['kickstart_ver_str'] == '7.0(3)I6(1)' + - output['stdout'][0]['kickstart_ver_str'] == '7.0(3)I6(1)' """ RETURN = """ @@ -122,15 +123,15 @@ import re + from time import sleep + +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule # Output options are 'text' or 'json' @@ -391,7 +392,7 @@ def build_install_cmd_set(issu, image, kick, type, force=True): commands.append("%s nxos %s %s" % (rootcmd, image, issu_cmd)) else: commands.append( - "%s %s system %s kickstart %s" % (rootcmd, issu_cmd, image, kick) + "%s %s system %s kickstart %s" % (rootcmd, issu_cmd, image, kick), ) return commands @@ -430,10 +431,7 @@ def check_mode_legacy(module, issu, image, kick=None): if target_image["error"]: data["error"] = True data["raw"] = target_image["raw"] - if ( - current["kickstart_ver_str"] != target_image["version"] - and not data["error"] - ): + if current["kickstart_ver_str"] != target_image["version"] and not data["error"]: data["upgrade_needed"] = True data["disruptive"] = True upgrade_msg = "Switch upgraded: system: %s" % tsver @@ -446,10 +444,7 @@ def check_mode_legacy(module, issu, image, kick=None): if target_kick["error"]: data["error"] = True data["raw"] = target_kick["raw"] - if ( - current["kickstart_ver_str"] != target_kick["version"] - and not data["error"] - ): + if current["kickstart_ver_str"] != target_kick["version"] and not data["error"]: data["upgrade_needed"] = True data["disruptive"] = True upgrade_msg = upgrade_msg + " kickstart: %s" % tkver @@ -539,9 +534,7 @@ def do_install_all(module, issu, image, kick=None): if upgrade["invalid_command"] and "force" in commands[1]: # Not all platforms support the 'force' keyword. Check for this # condition and re-try without the 'force' keyword if needed. - commands = build_install_cmd_set( - issu, image, kick, "install", False - ) + commands = build_install_cmd_set(issu, image, kick, "install", False) upgrade = check_install_in_progress(module, commands, opts) upgrade["upgrade_cmd"] = commands @@ -573,11 +566,7 @@ def main(): issu=dict(choices=["required", "desired", "no", "yes"], default="no"), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() diff --git a/plugins/modules/nxos_interface.py b/plugins/modules/nxos_interface.py deleted file mode 100644 index 6e745cf80..000000000 --- a/plugins/modules/nxos_interface.py +++ /dev/null @@ -1,993 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# 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: nxos_interface -extends_documentation_fragment: -- cisco.nxos.nxos -short_description: (deprecated, removed after 2022-06-01) Manages physical - attributes of interfaces. -description: -- Manages physical attributes of interfaces of NX-OS switches. -version_added: 1.0.0 -deprecated: - alternative: nxos_interfaces - why: Updated modules released with more functionality - removed_at_date: '2022-06-01' -author: -- Jason Edelman (@jedelman8) -- Trishna Guha (@trishnaguha) -notes: -- Tested against NXOSv 7.3.(0)D1(1) on VIRL -- Unsupported for Cisco MDS -- This module is also used to create logical interfaces such as svis and loopbacks. -- Be cautious of platform specific idiosyncrasies. For example, when you default a - loopback interface, the admin state toggles on certain versions of NX-OS. -- The M(cisco.nxos.nxos_overlay_global) C(anycast_gateway_mac) attribute must be set before setting - the C(fabric_forwarding_anycast_gateway) property. -options: - name: - description: - - Full name of interface, i.e. Ethernet1/1, port-channel10. - aliases: - - interface - type: str - interface_type: - description: - - Interface type to be unconfigured from the device. - choices: - - loopback - - portchannel - - svi - - nve - type: str - speed: - description: - - Interface link speed. Applicable for ethernet interface only. - type: str - admin_state: - description: - - Administrative state of the interface. - default: up - choices: - - up - - down - type: str - description: - description: - - Interface description. - type: str - mode: - description: - - Manage Layer 2 or Layer 3 state of the interface. This option is supported for - ethernet and portchannel interface. Applicable for ethernet and portchannel - interface only. - choices: - - layer2 - - layer3 - type: str - mtu: - description: - - MTU for a specific interface. Must be an even number between 576 and 9216. Applicable - for ethernet interface only. - type: str - ip_forward: - description: - - Enable/Disable ip forward feature on SVIs. - choices: - - enable - - disable - type: str - fabric_forwarding_anycast_gateway: - description: - - Associate SVI with anycast gateway under VLAN configuration mode. Applicable - for SVI interface only. - type: bool - duplex: - description: - - Interface link status. Applicable for ethernet interface only. - choices: - - full - - half - - auto - type: str - tx_rate: - description: - - Transmit rate in bits per second (bps). - - This is state check parameter only. - - Supports conditionals, see - U(https://docs.ansible.com/ansible/latest/network/user_guide/network_working_with_command_output.html#conditionals-in-networking-modules) - type: str - rx_rate: - description: - - Receiver rate in bits per second (bps). - - This is state check parameter only. - - Supports conditionals, see - U(https://docs.ansible.com/ansible/latest/network/user_guide/network_working_with_command_output.html#conditionals-in-networking-modules) - type: str - neighbors: - description: - - Check the operational state of given interface C(name) for LLDP neighbor. - - The following suboptions are available. This is state check parameter only. - type: list - elements: dict - suboptions: - host: - description: - - LLDP neighbor host for given interface C(name). - type: str - port: - description: - - LLDP neighbor port to which given interface C(name) is connected. - type: str - aggregate: - description: List of Interfaces definitions. - type: list - elements: dict - suboptions: - name: - description: - - Full name of interface, i.e. Ethernet1/1, port-channel10. - required: true - type: str - interface_type: - description: - - Interface type to be unconfigured from the device. - choices: - - loopback - - portchannel - - svi - - nve - type: str - speed: - description: - - Interface link speed. Applicable for ethernet interface only. - type: str - admin_state: - description: - - Administrative state of the interface. - choices: - - up - - down - type: str - description: - description: - - Interface description. - type: str - mode: - description: - - Manage Layer 2 or Layer 3 state of the interface. This option is supported for - ethernet and portchannel interface. Applicable for ethernet and portchannel - interface only. - choices: - - layer2 - - layer3 - type: str - mtu: - description: - - MTU for a specific interface. Must be an even number between 576 and 9216. Applicable - for ethernet interface only. - type: str - ip_forward: - description: - - Enable/Disable ip forward feature on SVIs. - choices: - - enable - - disable - type: str - fabric_forwarding_anycast_gateway: - description: - - Associate SVI with anycast gateway under VLAN configuration mode. Applicable - for SVI interface only. - type: bool - duplex: - description: - - Interface link status. Applicable for ethernet interface only. - choices: - - full - - half - - auto - type: str - tx_rate: - description: - - Transmit rate in bits per second (bps). - - This is state check parameter only. - - Supports conditionals, see - U(https://docs.ansible.com/ansible/latest/network/user_guide/network_working_with_command_output.html#conditionals-in-networking-modules) - type: str - rx_rate: - description: - - Receiver rate in bits per second (bps). - - This is state check parameter only. - - Supports conditionals, see - U(https://docs.ansible.com/ansible/latest/network/user_guide/network_working_with_command_output.html#conditionals-in-networking-modules) - type: str - neighbors: - description: - - Check the operational state of given interface C(name) for LLDP neighbor. - - The following suboptions are available. This is state check parameter only. - type: list - elements: dict - suboptions: - host: - description: - - LLDP neighbor host for given interface C(name). - type: str - port: - description: - - LLDP neighbor port to which given interface C(name) is connected. - type: str - state: - description: - - Specify desired state of the resource. - choices: - - present - - absent - - default - type: str - delay: - description: - - Time in seconds to wait before checking for the operational state on remote - device. This wait is applicable for operational state arguments. - type: int - state: - description: - - Specify desired state of the resource. - default: present - choices: - - present - - absent - - default - type: str - delay: - description: - - Time in seconds to wait before checking for the operational state on remote - device. This wait is applicable for operational state arguments. - default: 10 - type: int - - -""" - -EXAMPLES = """ -- name: Ensure an interface is a Layer 3 port and that it has the proper description - cisco.nxos.nxos_interface: - name: Ethernet1/1 - description: Configured by Ansible - mode: layer3 - -- name: Admin down an interface - cisco.nxos.nxos_interface: - name: Ethernet2/1 - admin_state: down - -- name: Remove all loopback interfaces - cisco.nxos.nxos_interface: - name: loopback - state: absent - -- name: Remove all logical interfaces - cisco.nxos.nxos_interface: - interface_type: '{{ item }} ' - state: absent - loop: - - loopback - - portchannel - - svi - - nve - -- name: Admin up all loopback interfaces - cisco.nxos.nxos_interface: - name: loopback 0-1023 - admin_state: up - -- name: Admin down all loopback interfaces - cisco.nxos.nxos_interface: - name: loopback 0-1023 - admin_state: down - -- name: Check neighbors intent arguments - cisco.nxos.nxos_interface: - name: Ethernet2/3 - neighbors: - - port: Ethernet2/3 - host: abc.mycompany.com - -- name: Add interface using aggregate - cisco.nxos.nxos_interface: - aggregate: - - {name: Ethernet0/1, mtu: 256, description: test-interface-1} - - {name: Ethernet0/2, mtu: 516, description: test-interface-2} - duplex: full - speed: 100 - state: present - -- name: Delete interface using aggregate - cisco.nxos.nxos_interface: - aggregate: - - name: Loopback9 - - name: Loopback10 - state: absent - -- name: Check intent arguments - cisco.nxos.nxos_interface: - name: Ethernet0/2 - state: up - tx_rate: ge(0) - rx_rate: le(0) -""" - -RETURN = """ -commands: - description: command list sent to the device - returned: always - type: list - sample: - - interface Ethernet2/3 - - mtu 1500 - - speed 10 -""" - -import re -import time - -from copy import deepcopy - -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - load_config, - run_commands, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, - normalize_interface, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_interface_type, -) -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - conditional, - remove_default_spec, -) - - -def execute_show_command(command, module): - if "show run" not in command: - output = "json" - else: - output = "text" - cmds = [{"command": command, "output": output}] - body = run_commands(module, cmds, check_rc=False) - if body and "Invalid" in body[0]: - return [] - else: - return body - - -def search_obj_in_list(name, lst): - for o in lst: - if o["name"] == name: - return o - - return None - - -def get_interfaces_dict(module): - """Gets all active interfaces on a given switch""" - try: - body = execute_show_command("show interface", module)[0] - except IndexError: - return {} - - interfaces = { - "ethernet": [], - "svi": [], - "loopback": [], - "management": [], - "portchannel": [], - "nve": [], - "unknown": [], - } - - if body: - interface_list = body["TABLE_interface"]["ROW_interface"] - for index in interface_list: - intf = index["interface"] - intf_type = get_interface_type(intf) - interfaces[intf_type].append(intf) - - return interfaces - - -def get_vlan_interface_attributes(name, intf_type, module): - """Returns dictionary that has two k/v pairs: - admin_state & description if not an svi, returns None - """ - command = "show run interface {0} all".format(name) - try: - body = execute_show_command(command, module)[0] - except (IndexError, TypeError): - return None - if body: - command_list = body.split("\n") - desc = None - admin_state = "down" - for each in command_list: - if "description" in each: - desc = each.lstrip().split("description")[1].lstrip() - elif "no shutdown" in each: - admin_state = "up" - return dict(description=desc, admin_state=admin_state) - else: - return None - - -def get_interface_type_removed_cmds(interfaces): - commands = [] - - for interface in interfaces: - if interface != "Vlan1": - commands.append("no interface {0}".format(interface)) - - return commands - - -def get_admin_state(admin_state): - command = "" - if admin_state == "up": - command = "no shutdown" - elif admin_state == "down": - command = "shutdown" - return command - - -def is_default_interface(name, module): - """Checks to see if interface exists and if it is a default config""" - command = "show run interface {0}".format(name) - - try: - body = execute_show_command(command, module)[0] - except (IndexError, TypeError): - body = "" - - if body: - raw_list = body.split("\n") - found = False - for line in raw_list: - if line.startswith("interface"): - found = True - if found and line and not line.startswith("interface"): - return False - return True - - else: - return "DNE" - - -def add_command_to_interface(interface, cmd, commands): - if interface not in commands: - commands.append(interface) - commands.append(cmd) - - -def map_obj_to_commands(updates, module): - commands = list() - commands2 = list() - want, have = updates - - args = ("speed", "description", "duplex", "mtu") - for w in want: - name = w["name"] - mode = w["mode"] - ip_forward = w["ip_forward"] - fabric_forwarding_anycast_gateway = w[ - "fabric_forwarding_anycast_gateway" - ] - admin_state = w["admin_state"] - state = w["state"] - interface_type = w["interface_type"] - del w["state"] - if name: - w["interface_type"] = None - - if interface_type: - obj_in_have = {} - if state in ("present", "default"): - module.fail_json( - msg="The interface_type param can be used only with state absent." - ) - else: - obj_in_have = search_obj_in_list(name, have) - is_default = is_default_interface(name, module) - - if name: - interface = "interface " + name - - if state == "absent": - if obj_in_have: - commands.append("no interface {0}".format(name)) - elif interface_type and not obj_in_have: - intfs = get_interfaces_dict(module)[interface_type] - cmds = get_interface_type_removed_cmds(intfs) - commands.extend(cmds) - - elif state == "present": - if obj_in_have: - # Don't run switchport command for loopback and svi interfaces - if get_interface_type(name) in ("ethernet", "portchannel"): - if mode == "layer2" and mode != obj_in_have.get("mode"): - add_command_to_interface( - interface, "switchport", commands - ) - elif mode == "layer3" and mode != obj_in_have.get("mode"): - add_command_to_interface( - interface, "no switchport", commands - ) - - if admin_state == "up" and admin_state != obj_in_have.get( - "admin_state" - ): - add_command_to_interface( - interface, "no shutdown", commands - ) - elif admin_state == "down" and admin_state != obj_in_have.get( - "admin_state" - ): - add_command_to_interface(interface, "shutdown", commands) - - if ip_forward == "enable" and ip_forward != obj_in_have.get( - "ip_forward" - ): - add_command_to_interface(interface, "ip forward", commands) - elif ip_forward == "disable" and ip_forward != obj_in_have.get( - "ip forward" - ): - add_command_to_interface( - interface, "no ip forward", commands - ) - - if ( - fabric_forwarding_anycast_gateway is True - and obj_in_have.get("fabric_forwarding_anycast_gateway") - is False - ): - add_command_to_interface( - interface, - "fabric forwarding mode anycast-gateway", - commands, - ) - - elif ( - fabric_forwarding_anycast_gateway is False - and obj_in_have.get("fabric_forwarding_anycast_gateway") - is True - ): - add_command_to_interface( - interface, - "no fabric forwarding mode anycast-gateway", - commands, - ) - - for item in args: - candidate = w.get(item) - if candidate and candidate != obj_in_have.get(item): - cmd = item + " " + str(candidate) - add_command_to_interface(interface, cmd, commands) - - if name and get_interface_type(name) == "ethernet": - if mode != obj_in_have.get("mode"): - admin_state = w.get("admin_state") or obj_in_have.get( - "admin_state" - ) - if admin_state: - c1 = "interface {0}".format( - normalize_interface(w["name"]) - ) - c2 = get_admin_state(admin_state) - commands2.append(c1) - commands2.append(c2) - - else: - commands.append(interface) - # Don't run switchport command for loopback and svi interfaces - if get_interface_type(name) in ("ethernet", "portchannel"): - if mode == "layer2": - commands.append("switchport") - elif mode == "layer3": - commands.append("no switchport") - - if admin_state == "up": - commands.append("no shutdown") - elif admin_state == "down": - commands.append("shutdown") - - if ip_forward == "enable": - commands.append("ip forward") - elif ip_forward == "disable": - commands.append("no ip forward") - - if fabric_forwarding_anycast_gateway is True: - commands.append("fabric forwarding mode anycast-gateway") - - elif fabric_forwarding_anycast_gateway is False: - commands.append( - "no fabric forwarding mode anycast-gateway" - ) - - for item in args: - candidate = w.get(item) - if candidate: - commands.append(item + " " + str(candidate)) - - elif state == "default": - if is_default is False: - commands.append("default interface {0}".format(name)) - elif is_default == "DNE": - module.exit_json( - msg="interface you are trying to default does not exist" - ) - - return commands, commands2 - - -def map_params_to_obj(module): - obj = [] - aggregate = module.params.get("aggregate") - if aggregate: - for item in aggregate: - for key in item: - if item.get(key) is None: - item[key] = module.params[key] - - d = item.copy() - name = d["name"] - d["name"] = normalize_interface(name) - obj.append(d) - - else: - obj.append( - { - "name": normalize_interface(module.params["name"]), - "description": module.params["description"], - "speed": module.params["speed"], - "mode": module.params["mode"], - "mtu": module.params["mtu"], - "duplex": module.params["duplex"], - "ip_forward": module.params["ip_forward"], - "fabric_forwarding_anycast_gateway": module.params[ - "fabric_forwarding_anycast_gateway" - ], - "admin_state": module.params["admin_state"], - "state": module.params["state"], - "interface_type": module.params["interface_type"], - "tx_rate": module.params["tx_rate"], - "rx_rate": module.params["rx_rate"], - "neighbors": module.params["neighbors"], - } - ) - - return obj - - -def map_config_to_obj(want, module): - objs = list() - - for w in want: - obj = dict( - name=None, - description=None, - admin_state=None, - speed=None, - mtu=None, - mode=None, - duplex=None, - interface_type=None, - ip_forward=None, - fabric_forwarding_anycast_gateway=None, - ) - - if not w["name"]: - return obj - - command = "show interface {0}".format(w["name"]) - try: - body = execute_show_command(command, module)[0] - except IndexError: - return list() - if body: - try: - interface_table = body["TABLE_interface"]["ROW_interface"] - except (KeyError, TypeError): - return list() - - if interface_table: - if interface_table.get("eth_mode") == "fex-fabric": - module.fail_json( - msg='nxos_interface does not support interfaces with mode "fex-fabric"' - ) - - intf_type = get_interface_type(w["name"]) - - if intf_type in ["portchannel", "ethernet"]: - mode = interface_table.get("eth_mode") - if mode in ("access", "trunk", "dot1q-tunnel"): - obj["mode"] = "layer2" - elif mode in ("routed", "layer3"): - obj["mode"] = "layer3" - else: - obj["mode"] = "layer3" - - if intf_type == "ethernet": - obj["name"] = normalize_interface( - interface_table.get("interface") - ) - obj["admin_state"] = interface_table.get("admin_state") - obj["description"] = interface_table.get("desc") - obj["mtu"] = interface_table.get("eth_mtu") - obj["duplex"] = interface_table.get("eth_duplex") - - command = "show run interface {0}".format(obj["name"]) - body = execute_show_command(command, module)[0] - - speed_match = re.search(r"speed (\d+)", body) - if speed_match is None: - obj["speed"] = "auto" - else: - obj["speed"] = speed_match.group(1) - - duplex_match = re.search(r"duplex (\S+)", body) - if duplex_match is None: - obj["duplex"] = "auto" - else: - obj["duplex"] = duplex_match.group(1) - - if "ip forward" in body: - obj["ip_forward"] = "enable" - else: - obj["ip_forward"] = "disable" - - elif intf_type == "svi": - obj["name"] = normalize_interface( - interface_table.get("interface") - ) - attributes = get_vlan_interface_attributes( - obj["name"], intf_type, module - ) - obj["admin_state"] = str( - attributes.get("admin_state", "nxapibug") - ) - obj["description"] = str( - attributes.get("description", "nxapi_bug") - ) - obj["mtu"] = interface_table.get("svi_mtu") - - command = "show run interface {0}".format(obj["name"]) - body = execute_show_command(command, module)[0] - if "ip forward" in body: - obj["ip_forward"] = "enable" - else: - obj["ip_forward"] = "disable" - if "fabric forwarding mode anycast-gateway" in body: - obj["fabric_forwarding_anycast_gateway"] = True - else: - obj["fabric_forwarding_anycast_gateway"] = False - - elif intf_type in ("loopback", "management", "nve"): - obj["name"] = normalize_interface( - interface_table.get("interface") - ) - obj["admin_state"] = interface_table.get("admin_state") - if obj["admin_state"] is None and intf_type == "loopback": - # Some platforms don't have the 'admin_state' key. - # For loopback interfaces it's safe to use the - # 'state' key instead. - obj["admin_state"] = interface_table.get("state") - obj["description"] = interface_table.get("desc") - - elif intf_type == "portchannel": - obj["name"] = normalize_interface( - interface_table.get("interface") - ) - obj["admin_state"] = interface_table.get("admin_state") - obj["description"] = interface_table.get("desc") - obj["mtu"] = interface_table.get("eth_mtu") - - if obj["admin_state"] is None: - # Some nxos platforms do not have the 'admin_state' key. - # Use the 'state_rsn_desc' key instead to determine the - # admin state of the interface. - state_description = interface_table.get("state_rsn_desc") - if state_description == "Administratively down": - obj["admin_state"] = "down" - elif state_description is not None: - obj["admin_state"] = "up" - - objs.append(obj) - - return objs - - -def check_declarative_intent_params(module, want): - failed_conditions = [] - have_neighbors = None - for w in want: - if w["interface_type"]: - continue - want_tx_rate = w.get("tx_rate") - want_rx_rate = w.get("rx_rate") - want_neighbors = w.get("neighbors") - if not (want_tx_rate or want_rx_rate or want_neighbors): - continue - - time.sleep(module.params["delay"]) - - cmd = [ - { - "command": "show interface {0}".format(w["name"]), - "output": "text", - } - ] - - try: - out = run_commands(module, cmd, check_rc=False)[0] - except (AttributeError, IndexError, TypeError): - out = "" - - if want_tx_rate: - match = re.search(r"output rate (\d+)", out, re.M) - have_tx_rate = None - - if match: - have_tx_rate = match.group(1) - - if have_tx_rate is None or not conditional( - want_tx_rate, have_tx_rate.strip(), cast=int - ): - failed_conditions.append("tx_rate " + want_tx_rate) - - if want_rx_rate: - match = re.search(r"input rate (\d+)", out, re.M) - have_rx_rate = None - - if match: - have_rx_rate = match.group(1) - - if have_rx_rate is None or not conditional( - want_rx_rate, have_rx_rate.strip(), cast=int - ): - failed_conditions.append("rx_rate " + want_rx_rate) - - if want_neighbors: - have_host = [] - have_port = [] - if have_neighbors is None: - cmd = [ - { - "command": "show lldp neighbors interface {0} detail".format( - w["name"] - ), - "output": "text", - } - ] - output = run_commands(module, cmd, check_rc=False) - if output: - have_neighbors = output[0] - else: - have_neighbors = "" - if ( - have_neighbors - and "Total entries displayed: 0" not in have_neighbors - ): - for line in have_neighbors.strip().split("\n"): - if line.startswith("Port Description"): - have_port.append(line.split(": ")[1]) - if line.startswith("System Name"): - have_host.append(line.split(": ")[1]) - - for item in want_neighbors: - host = item.get("host") - port = item.get("port") - if host and host not in have_host: - failed_conditions.append("host " + host) - if port and port not in have_port: - failed_conditions.append("port " + port) - - return failed_conditions - - -def main(): - """main entry point for module execution""" - neighbors_spec = dict(host=dict(), port=dict()) - - element_spec = dict( - name=dict(aliases=["interface"]), - admin_state=dict(default="up", choices=["up", "down"]), - description=dict(), - speed=dict(), - mode=dict(choices=["layer2", "layer3"]), - mtu=dict(), - duplex=dict(choices=["full", "half", "auto"]), - interface_type=dict(choices=["loopback", "portchannel", "svi", "nve"]), - ip_forward=dict(choices=["enable", "disable"]), - fabric_forwarding_anycast_gateway=dict(type="bool"), - tx_rate=dict(), - rx_rate=dict(), - neighbors=dict(type="list", elements="dict", options=neighbors_spec), - delay=dict(default=10, type="int"), - state=dict( - choices=["absent", "present", "default"], default="present" - ), - ) - - aggregate_spec = deepcopy(element_spec) - aggregate_spec["name"] = dict(required=True) - - # remove default in aggregate spec, to handle common arguments - remove_default_spec(aggregate_spec) - - argument_spec = dict( - aggregate=dict( - type="list", - elements="dict", - options=aggregate_spec, - mutually_exclusive=[["name", "interface_type"]], - ) - ) - - argument_spec.update(element_spec) - argument_spec.update(nxos_argument_spec) - - required_one_of = [["name", "aggregate", "interface_type"]] - mutually_exclusive = [["name", "aggregate"], ["name", "interface_type"]] - - module = AnsibleModule( - argument_spec=argument_spec, - required_one_of=required_one_of, - mutually_exclusive=mutually_exclusive, - supports_check_mode=True, - ) - warnings = list() - - result = {"changed": False} - if warnings: - result["warnings"] = warnings - - want = map_params_to_obj(module) - have = map_config_to_obj(want, module) - - commands = [] - commands1, commands2 = map_obj_to_commands((want, have), module) - commands.extend(commands1) - - if commands: - if not module.check_mode: - load_config(module, commands) - result["changed"] = True - # if the mode changes from L2 to L3, the admin state - # seems to change after the API call, so adding a second API - # call to ensure it's in the desired state. - if commands2: - load_config(module, commands2) - commands.extend(commands2) - commands = [cmd for cmd in commands if cmd != "configure"] - result["commands"] = commands - - if result["changed"]: - failed_conditions = check_declarative_intent_params(module, want) - - if failed_conditions: - msg = "One or more conditional statements have not been satisfied" - module.fail_json(msg=msg, failed_conditions=failed_conditions) - - module.exit_json(**result) - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/nxos_interface_ospf.py b/plugins/modules/nxos_interface_ospf.py deleted file mode 100644 index 6e170c9e1..000000000 --- a/plugins/modules/nxos_interface_ospf.py +++ /dev/null @@ -1,615 +0,0 @@ -#!/usr/bin/python -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - - -DOCUMENTATION = """ -module: nxos_interface_ospf -extends_documentation_fragment: -- cisco.nxos.nxos -short_description: (deprecated, removed after 2022-10-26) Manages configuration of an OSPF interface instance. -description: -- Manages configuration of an OSPF interface instance. -version_added: 1.0.0 -deprecated: - alternative: nxos_ospf_interfaces - why: Updated modules released with more functionality - removed_at_date: '2022-10-26' -author: Gabriele Gerbino (@GGabriele) -notes: -- Tested against NXOSv 7.3.(0)D1(1) on VIRL -- Unsupported for Cisco MDS -- Default, where supported, restores params default value. -- To remove an existing authentication configuration you should use C(message_digest_key_id=default) - plus all other options matching their existing values. -- Loopback interfaces only support ospf network type 'point-to-point'. -- C(state=absent) removes the whole OSPF interface configuration. -options: - interface: - description: - - Name of this cisco_interface resource. Valid value is a string. - required: true - type: str - ospf: - description: - - Name of the ospf instance. - required: true - type: str - area: - description: - - Ospf area associated with this cisco_interface_ospf instance. Valid values are - a string, formatted as an IP address (i.e. "0.0.0.0") or as an integer. - required: true - type: str - bfd: - description: - - Enables bfd at interface level. This overrides the bfd variable set at the ospf - router level. - - Valid values are 'enable', 'disable' or 'default'. - - "Dependency: ''feature bfd''" - type: str - choices: - - enable - - disable - - default - cost: - description: - - The cost associated with this cisco_interface_ospf instance. - type: str - hello_interval: - description: - - Time between sending successive hello packets. Valid values are an integer or - the keyword 'default'. - type: str - dead_interval: - description: - - Time interval an ospf neighbor waits for a hello packet before tearing down - adjacencies. Valid values are an integer or the keyword 'default'. - type: str - passive_interface: - description: - - Enable or disable passive-interface state on this interface. true - (enable) - Prevent OSPF from establishing an adjacency or sending routing updates on this - interface. false - (disable) Override global 'passive-interface default' for - this interface. - type: bool - network: - description: - - Specifies interface ospf network type. Valid values are 'point-to-point' or - 'broadcast'. - choices: - - point-to-point - - broadcast - type: str - message_digest: - description: - - Enables or disables the usage of message digest authentication. - type: bool - message_digest_key_id: - description: - - Md5 authentication key-id associated with the ospf instance. If this is present, - message_digest_encryption_type, message_digest_algorithm_type and message_digest_password - are mandatory. Valid value is an integer and 'default'. - type: str - message_digest_algorithm_type: - description: - - Algorithm used for authentication among neighboring routers within an area. - Valid values are 'md5' and 'default'. - choices: - - md5 - - default - type: str - message_digest_encryption_type: - description: - - Specifies the scheme used for encrypting message_digest_password. Valid values - are '3des' or 'cisco_type_7' encryption or 'default'. - choices: - - cisco_type_7 - - 3des - - default - type: str - message_digest_password: - description: - - Specifies the message_digest password. Valid value is a string. - type: str - state: - description: - - Determines whether the config should be present or not on the device. - default: present - choices: - - present - - absent - type: str -""" -EXAMPLES = """ -- cisco.nxos.nxos_interface_ospf: - interface: ethernet1/32 - ospf: 1 - area: 1 - bfd: disable - cost: default - -- cisco.nxos.nxos_interface_ospf: - interface: loopback0 - ospf: prod - area: 0.0.0.0 - bfd: enable - network: point-to-point - state: present -""" - -RETURN = """ -commands: - description: commands sent to the device - returned: always - type: list - sample: ["interface Ethernet1/32", "ip router ospf 1 area 0.0.0.1", "ip ospf bfd disable"] -""" - - -import re -import struct -import socket -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_config, - load_config, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( - CustomNetworkConfig, -) - -BOOL_PARAMS = ["passive_interface", "message_digest"] -PARAM_TO_COMMAND_KEYMAP = { - "interface": "", - "cost": "ip ospf cost", - "ospf": "ip router ospf", - "area": "ip router ospf", - "bfd": "ip ospf bfd", - "hello_interval": "ip ospf hello-interval", - "dead_interval": "ip ospf dead-interval", - "passive_interface": "ip ospf passive-interface", - "message_digest": "ip ospf authentication message-digest", - "message_digest_key_id": "ip ospf message-digest-key", - "message_digest_algorithm_type": "ip ospf message-digest-key", - "message_digest_encryption_type": "ip ospf message-digest-key", - "message_digest_password": "ip ospf message-digest-key", - "network": "ip ospf network", -} - - -def get_value(arg, config, module): - command = PARAM_TO_COMMAND_KEYMAP[arg] - has_command = re.search(r"\s+{0}\s*$".format(command), config, re.M) - has_command_val = re.search( - r"(?:{0}\s)(?P.*)$".format(command), config, re.M - ) - - if command == "ip router ospf": - value = "" - if has_command_val: - value_list = has_command_val.group("value").split() - if arg == "ospf": - value = value_list[0] - elif arg == "area": - value = value_list[2] - value = normalize_area(value, module) - elif command == "ip ospf message-digest-key": - value = "" - if has_command_val: - value_list = has_command_val.group("value").split() - if arg == "message_digest_key_id": - value = value_list[0] - elif arg == "message_digest_algorithm_type": - value = value_list[1] - elif arg == "message_digest_encryption_type": - value = value_list[2] - if value == "3": - value = "3des" - elif value == "7": - value = "cisco_type_7" - elif arg == "message_digest_password": - value = value_list[3] - elif arg == "passive_interface": - has_no_command = re.search( - r"\s+no\s+{0}\s*$".format(command), config, re.M - ) - if has_no_command: - value = False - elif has_command: - value = True - else: - value = None - elif arg == "bfd": - m = re.search(r"\s*ip ospf bfd(?P disable)?", config) - if m: - value = "disable" if m.group("disable") else "enable" - else: - value = "default" - elif arg in BOOL_PARAMS: - value = bool(has_command) - else: - value = "" - if has_command_val: - value = has_command_val.group("value") - return value - - -def get_existing(module, args): - existing = {} - netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) - if module.params["interface"].startswith("loopback") or module.params[ - "interface" - ].startswith("port-channel"): - parents = ["interface {0}".format(module.params["interface"])] - else: - parents = [ - "interface {0}".format(module.params["interface"].capitalize()) - ] - config = netcfg.get_section(parents) - if "ospf" in config: - for arg in args: - if arg not in ["interface"]: - existing[arg] = get_value(arg, config, module) - existing["interface"] = module.params["interface"] - return existing - - -def apply_key_map(key_map, table): - new_dict = {} - for key, value in table.items(): - new_key = key_map.get(key) - if new_key: - new_dict[new_key] = value - return new_dict - - -def get_default_commands(existing, proposed, existing_commands, key, module): - commands = list() - existing_value = existing_commands.get(key) - if key.startswith("ip ospf message-digest-key"): - check = False - for param in [ - "message_digest_encryption_type", - "message_digest_algorithm_type", - "message_digest_password", - ]: - if existing[param] == proposed[param]: - check = True - if check: - if existing["message_digest_encryption_type"] == "3des": - encryption_type = "3" - elif existing["message_digest_encryption_type"] == "cisco_type_7": - encryption_type = "7" - command = "no {0} {1} {2} {3} {4}".format( - key, - existing["message_digest_key_id"], - existing["message_digest_algorithm_type"], - encryption_type, - existing["message_digest_password"], - ) - commands.append(command) - elif "ip ospf bfd" in key: - commands.append("no {0}".format(key)) - elif "passive-interface" in key: - commands.append("default ip ospf passive-interface") - else: - commands.append("no {0} {1}".format(key, existing_value)) - return commands - - -def get_custom_command(existing_cmd, proposed, key, module): - commands = list() - - if key == "ip router ospf": - command = "{0} {1} area {2}".format( - key, proposed["ospf"], proposed["area"] - ) - if command not in existing_cmd: - commands.append(command) - - if key == "ip ospf network": - command = "{0} {1}".format(key, proposed["network"]) - - if command not in existing_cmd: - commands.append(command) - - elif key.startswith("ip ospf message-digest-key"): - if ( - proposed["message_digest_key_id"] != "default" - and "options" not in key - ): - if proposed["message_digest_encryption_type"] == "3des": - encryption_type = "3" - elif proposed["message_digest_encryption_type"] == "cisco_type_7": - encryption_type = "7" - command = "{0} {1} {2} {3} {4}".format( - key, - proposed["message_digest_key_id"], - proposed["message_digest_algorithm_type"], - encryption_type, - proposed["message_digest_password"], - ) - commands.append(command) - return commands - - -def state_present(module, existing, proposed, candidate): - commands = list() - proposed_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, proposed) - existing_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, existing) - - for key, value in proposed_commands.items(): - if existing_commands.get(key): - if key == "ip router ospf": - if proposed["area"] == existing["area"]: - continue - if existing_commands[key] == value: - continue - - if key == "ip ospf passive-interface" and module.params.get( - "interface" - ).upper().startswith("LO"): - module.fail_json( - msg="loopback interface does not support passive_interface" - ) - if ( - key == "ip ospf network" - and value == "broadcast" - and module.params.get("interface").upper().startswith("LO") - ): - module.fail_json( - msg="loopback interface does not support ospf network type broadcast" - ) - - if key == "ip ospf bfd": - cmd = key - if "disable" in value: - cmd += " disable" - elif "default" in value and existing.get("bfd") is not None: - cmd = "no " + cmd - commands.append(cmd) - continue - - if value is True: - commands.append(key) - elif value is False: - commands.append("no {0}".format(key)) - elif value == "default": - if existing_commands.get(key): - commands.extend( - get_default_commands( - existing, proposed, existing_commands, key, module - ) - ) - else: - if key == "ip router ospf" or key.startswith( - "ip ospf message-digest-key" - ): - commands.extend( - get_custom_command(commands, proposed, key, module) - ) - else: - command = "{0} {1}".format(key, value.lower()) - commands.append(command) - - if commands: - parents = [ - "interface {0}".format(module.params["interface"].capitalize()) - ] - candidate.add(commands, parents=parents) - - -def state_absent(module, existing, proposed, candidate): - commands = [] - parents = ["interface {0}".format(module.params["interface"].capitalize())] - existing_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, existing) - - for key, value in existing_commands.items(): - if "ip ospf bfd" in key: - if "default" not in value: - # cli is present when enabled or disabled; this removes either case - commands.append("no ip ospf bfd") - continue - if "ip ospf passive-interface" in key and value is not None: - # cli is present for both enabled or disabled; 'no' will not remove - commands.append("default ip ospf passive-interface") - continue - - if value: - if key.startswith("ip ospf message-digest-key"): - if "options" not in key: - if existing["message_digest_encryption_type"] == "3des": - encryption_type = "3" - elif ( - existing["message_digest_encryption_type"] - == "cisco_type_7" - ): - encryption_type = "7" - command = "no {0} {1} {2} {3} {4}".format( - key, - existing["message_digest_key_id"], - existing["message_digest_algorithm_type"], - encryption_type, - existing["message_digest_password"], - ) - commands.append(command) - elif key in [ - "ip ospf authentication message-digest", - "ip ospf network", - ]: - if value: - commands.append("no {0}".format(key)) - elif key == "ip router ospf": - command = "no {0} {1} area {2}".format( - key, proposed["ospf"], proposed["area"] - ) - if command not in commands: - commands.append(command) - else: - existing_value = existing_commands.get(key) - commands.append("no {0} {1}".format(key, existing_value)) - - candidate.add(commands, parents=parents) - - -def normalize_area(area, module): - try: - area = int(area) - area = socket.inet_ntoa(struct.pack("!L", area)) - except ValueError: - splitted_area = area.split(".") - if len(splitted_area) != 4: - module.fail_json(msg="Incorrect Area ID format", area=area) - return area - - -def main(): - argument_spec = dict( - interface=dict(required=True, type="str"), - ospf=dict(required=True, type="str"), - area=dict(required=True, type="str"), - bfd=dict( - choices=["enable", "disable", "default"], - required=False, - type="str", - ), - cost=dict(required=False, type="str"), - hello_interval=dict(required=False, type="str"), - dead_interval=dict(required=False, type="str"), - passive_interface=dict(required=False, type="bool"), - network=dict( - required=False, type="str", choices=["broadcast", "point-to-point"] - ), - message_digest=dict(required=False, type="bool"), - message_digest_key_id=dict(required=False, type="str"), - message_digest_algorithm_type=dict( - required=False, type="str", choices=["md5", "default"] - ), - message_digest_encryption_type=dict( - required=False, - type="str", - choices=["cisco_type_7", "3des", "default"], - ), - message_digest_password=dict(required=False, type="str", no_log=True), - state=dict( - choices=["present", "absent"], default="present", required=False - ), - ) - - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, - required_together=[ - [ - "message_digest_key_id", - "message_digest_algorithm_type", - "message_digest_encryption_type", - "message_digest_password", - ] - ], - supports_check_mode=True, - ) - - # Normalize interface input data. - # - # * For port-channel and loopback interfaces expection is all lower case names. - # * All other interfaces the expectation is an uppercase leading character - # followed by lower case characters. - # - if re.match(r"(port-channel|loopback)", module.params["interface"], re.I): - module.params["interface"] = module.params["interface"].lower() - else: - module.params["interface"] = module.params["interface"].capitalize() - - warnings = list() - result = {"changed": False, "commands": [], "warnings": warnings} - - for param in [ - "message_digest_encryption_type", - "message_digest_algorithm_type", - "message_digest_password", - ]: - if ( - module.params[param] == "default" - and module.params["message_digest_key_id"] != "default" - ): - module.exit_json( - msg="Use message_digest_key_id=default to remove an existing authentication configuration" - ) - - state = module.params["state"] - args = PARAM_TO_COMMAND_KEYMAP.keys() - - existing = get_existing(module, args) - proposed_args = dict( - (k, v) for k, v in module.params.items() if v is not None and k in args - ) - - proposed = {} - for key, value in proposed_args.items(): - if key != "interface": - if str(value).lower() == "true": - value = True - elif str(value).lower() == "false": - value = False - elif str(value).lower() == "default": - value = "default" - elif key == "bfd": - value = str(value).lower() - if existing.get(key) or (not existing.get(key) and value): - proposed[key] = value - elif ( - "passive_interface" in key - and existing.get(key) is None - and value is False - ): - proposed[key] = value - - proposed["area"] = normalize_area(proposed["area"], module) - if "hello_interval" in proposed and proposed["hello_interval"] == "10": - proposed["hello_interval"] = "default" - - candidate = CustomNetworkConfig(indent=3) - if state == "present": - state_present(module, existing, proposed, candidate) - elif ( - state == "absent" - and existing.get("ospf") == proposed["ospf"] - and existing.get("area") == proposed["area"] - ): - state_absent(module, existing, proposed, candidate) - - if candidate: - candidate = candidate.items_text() - if not module.check_mode: - load_config(module, candidate) - result["changed"] = True - result["commands"] = candidate - - module.exit_json(**result) - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/nxos_interfaces.py b/plugins/modules/nxos_interfaces.py index c67ba84b5..30045188d 100644 --- a/plugins/modules/nxos_interfaces.py +++ b/plugins/modules/nxos_interfaces.py @@ -28,6 +28,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -66,8 +67,8 @@ type: str enabled: description: - - Administrative state of the interface. Set the value to C(true) to administratively - enable the interface or C(false) to disable it + - Administrative state of the interface. Set the value to C(true) to + administratively enable the interface or C(false) to disable it type: bool speed: description: @@ -130,146 +131,265 @@ # Before state: # ------------- # +# switch# show running-config | section interface # interface Ethernet1/1 # description testing -# mtu 1800 +# interface mgmt0 +# description mgmt interface +# ip address dhcp +# vrf member management - name: Merge provided configuration with device configuration cisco.nxos.nxos_interfaces: config: - - name: Ethernet1/1 - description: Configured by Ansible - enabled: true - - name: Ethernet1/2 - description: Configured by Ansible Network - enabled: false + - name: Ethernet1/1 + description: Configured by Ansible + enabled: true + - name: Ethernet1/2 + description: Configured by Ansible Network + enabled: false state: merged +# Task Output +# ----------- +# +# before: +# - description: testing +# name: Ethernet1/1 +# - description: mgmt interface +# name: mgmt0 +# commands: +# - interface Ethernet1/1 +# - description Configured by Ansible +# - interface Ethernet1/2 +# - description Configured by Ansible Network +# - shutdown +# after: +# - description: Configured by Ansible +# name: Ethernet1/1 +# - description: Configured by Ansible Network +# enabled: false +# name: Ethernet1/2 +# - description: mgmt interface +# name: mgmt0 + # After state: # ------------ # +# switch# show running-config | section interface # interface Ethernet1/1 -# description Configured by Ansible -# no shutdown -# mtu 1800 -# interface Ethernet2 -# description Configured by Ansible Network -# shutdown - +# description Configured by Ansible +# interface Ethernet1/2 +# description Configured by Ansible Network +# shutdown +# interface mgmt0 +# description mgmt interface +# ip address dhcp +# vrf member management # Using replaced # Before state: # ------------- # +# switch# show running-config | section interface # interface Ethernet1/1 -# description Interface 1/1 +# description Updated by Ansible # interface Ethernet1/2 +# description Configured by Ansible Network +# shutdown +# interface mgmt0 +# description mgmt interface +# ip address dhcp +# vrf member management - name: Replaces device configuration of listed interfaces with provided configuration cisco.nxos.nxos_interfaces: config: - - name: Ethernet1/1 - description: Configured by Ansible - enabled: true - mtu: 2000 - - name: Ethernet1/2 - description: Configured by Ansible Network - enabled: false - mode: layer2 + - name: Ethernet1/1 + description: Configured by Ansible + enabled: true + mtu: 9000 + - name: Ethernet1/2 + description: Configured by Ansible Network + enabled: false + mode: layer2 state: replaced +# Task Output +# ----------- +# +# before: +# - description: Updated by Ansible +# name: Ethernet1/1 +# - description: Configured by Ansible Network +# enabled: false +# name: Ethernet1/2 +# - description: mgmt interface +# name: mgmt0 +# commands: +# - interface Ethernet1/1 +# - mtu 1500 +# - interface Ethernet1/2 +# - description Updated by Ansible +# after: +# - description: Updated by Ansible +# name: Ethernet1/1 +# - description: Updated by Ansible +# enabled: false +# name: Ethernet1/2 +# - description: mgmt interface +# name: mgmt0 + # After state: # ------------ # +# switch# show running-config | section interface # interface Ethernet1/1 -# description Configured by Ansible -# no shutdown -# mtu 1500 -# interface Ethernet2/2 -# description Configured by Ansible Network -# shutdown -# switchport - +# description Updated by Ansible +# interface Ethernet1/2 +# description Updated by Ansible +# shutdown +# interface mgmt0 +# description mgmt interface +# ip address dhcp +# vrf member management # Using overridden # Before state: # ------------- # +# switch# show running-config | section interface # interface Ethernet1/1 -# description Interface Ethernet1/1 +# description Updated by Ansible # interface Ethernet1/2 +# description Updated by Ansible +# shutdown # interface mgmt0 -# description Management interface -# ip address dhcp +# description mgmt interface +# ip address dhcp +# vrf member management - name: Override device configuration of all interfaces with provided configuration cisco.nxos.nxos_interfaces: config: - - name: Ethernet1/1 - enabled: true - - name: Ethernet1/2 - description: Configured by Ansible Network - enabled: false + - name: Ethernet1/1 + enabled: true + - name: Ethernet1/2 + description: Configured by Ansible Network + enabled: false + - description: mgmt interface + name: mgmt0 state: overridden +# Task Output +# ----------- +# +# before: +# - description: Updated by Ansible +# name: Ethernet1/1 +# - description: Updated by Ansible +# enabled: false +# name: Ethernet1/2 +# - description: mgmt interface +# name: mgmt0 +# commands: +# - interface Ethernet1/1 +# - no description +# - interface Ethernet1/2 +# - description Configured by Ansible Network +# after: +# - name: Ethernet1/1 +# - description: Configured by Ansible Network +# enabled: false +# name: Ethernet1/2 +# - description: mgmt interface +# name: mgmt0 + # After state: # ------------ # +# switch# show running-config | section interface # interface Ethernet1/1 # interface Ethernet1/2 -# description Configured by Ansible Network -# shutdown +# description Configured by Ansible Network +# shutdown # interface mgmt0 -# ip address dhcp - +# description mgmt interface +# ip address dhcp +# vrf member management # Using deleted # Before state: # ------------- # +# switch# show running-config | section interface # interface Ethernet1/1 -# description Interface Ethernet1/1 # interface Ethernet1/2 +# description Configured by Ansible Network +# shutdown # interface mgmt0 -# description Management interface -# ip address dhcp +# description mgmt interface +# ip address dhcp +# vrf member management - name: Delete or return interface parameters to default settings cisco.nxos.nxos_interfaces: config: - - name: Ethernet1/1 + - name: Ethernet1/2 state: deleted +# Task Output +# ----------- +# +# before: +# - name: Ethernet1/1 +# - description: Configured by Ansible Network +# enabled: false +# name: Ethernet1/2 +# - description: mgmt interface +# name: mgmt0 +# commands: +# - interface Ethernet1/2 +# - no description +# - no shutdown +# after: +# - name: Ethernet1/1 +# - name: Ethernet1/2 +# - description: mgmt interface +# name: mgmt0 + # After state: # ------------ # +# switch# show running-config | section interface # interface Ethernet1/1 # interface Ethernet1/2 # interface mgmt0 -# description Management interface -# ip address dhcp +# description mgmt interface +# ip address dhcp +# vrf member management # Using rendered - name: Use rendered state to convert task input to device specific commands cisco.nxos.nxos_interfaces: config: - - name: Ethernet1/1 - description: outbound-intf - mode: layer3 - speed: 100 - - name: Ethernet1/2 - mode: layer2 - enabled: true - duplex: full + - name: Ethernet1/1 + description: outbound-intf + mode: layer3 + speed: 100 + - name: Ethernet1/2 + mode: layer2 + enabled: true + duplex: full state: rendered -# Task Output (redacted) -# ----------------------- - +# Task Output +# ----------- +# # rendered: # - "interface Ethernet1/1" # - "description outbound-intf" @@ -283,6 +403,7 @@ # parsed.cfg # ------------ +# # interface Ethernet1/800 # description test-1 # speed 1000 @@ -300,8 +421,9 @@ running_config: "{{ lookup('file', 'parsed.cfg') }}" state: parsed -# Task output (redacted) -# ----------------------- +# Task output +# ----------- +# # parsed: # - description: "test-1" # duplex: "half" @@ -309,7 +431,6 @@ # mode: "layer3" # name: "Ethernet1/800" # speed: "1000" -# # - description: "test-2" # enabled: true # mode: "layer2" @@ -318,8 +439,10 @@ # Using gathered -# Existing device config state -# ----------------------------- +# Before state: +# ------------- +# +# switch# show running-config | section interface # interface Ethernet1/1 # description outbound-intf # switchport @@ -335,8 +458,9 @@ cisco.nxos.nxos_interfaces: state: gathered -# Task output (redacted) -# ----------------------- +# Task output +# ----------- +# # - name: Ethernet1/1 # description: outbound-intf # mode: layer2 @@ -347,8 +471,10 @@ # Using purged -# Existing device config state -# ----------------------------- +# Before state: +# ------------- +# +# switch# show running-config | section interface # interface Vlan1 # interface Vlan42 # mtu 1800 @@ -369,6 +495,7 @@ # Task output # ------------ +# # before: # - name: Vlan1 # - mtu: '1800' @@ -379,17 +506,24 @@ # - name: Ethernet1/2 # - description: sub-intf # name: Ethernet1/2.100 -# # commands: # - no interface port-channel10 # - no interface Ethernet1/2.100 # - no interface Vlan42 -# # after: # - name: Vlan1 # - name: port-channel11 # - name: Ethernet1/1 # - name: Ethernet1/2 + +# After state: +# ------------- +# +# switch# show running-config | section interface +# interface Vlan1 +# interface port-channel11 +# interface Ethernet1/1 +# interface Ethernet1/2 """ RETURN = """ before: @@ -415,6 +549,7 @@ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.interfaces.interfaces import ( InterfacesArgs, ) diff --git a/plugins/modules/nxos_l2_interface.py b/plugins/modules/nxos_l2_interface.py deleted file mode 100644 index 6e88238cf..000000000 --- a/plugins/modules/nxos_l2_interface.py +++ /dev/null @@ -1,700 +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: nxos_l2_interface -extends_documentation_fragment: -- cisco.nxos.nxos -short_description: (deprecated, removed after 2022-06-01) Manage Layer-2 - interface on Cisco NXOS devices. -description: -- This module provides declarative management of Layer-2 interface on Cisco NXOS devices. -version_added: 1.0.0 -deprecated: - alternative: nxos_l2_interfaces - why: Updated modules released with more functionality - removed_at_date: '2022-06-01' -author: -- Trishna Guha (@trishnaguha) -notes: -- Tested against NXOSv 7.0(3)I5(1). -- Unsupported for Cisco MDS -options: - name: - description: - - Full name of the interface excluding any logical unit number, i.e. Ethernet1/1. - aliases: - - interface - type: str - mode: - description: - - Mode in which interface needs to be configured. - choices: - - access - - trunk - type: str - access_vlan: - description: - - Configure given VLAN in access port. If C(mode=access), used as the access VLAN - ID. - type: str - native_vlan: - description: - - Native VLAN to be configured in trunk port. If C(mode=trunk), used as the trunk - native VLAN ID. - type: str - trunk_vlans: - description: - - List of VLANs to be configured in trunk port. If C(mode=trunk), used as the - VLAN range to ADD or REMOVE from the trunk. - aliases: - - trunk_add_vlans - type: str - trunk_allowed_vlans: - description: - - List of allowed VLANs in a given trunk port. If C(mode=trunk), these are the - only VLANs that will be configured on the trunk, i.e. "2-10,15". - type: str - aggregate: - description: - - List of Layer-2 interface definitions. - type: list - elements: dict - suboptions: - name: - description: - - Full name of the interface excluding any logical unit number, i.e. Ethernet1/1. - aliases: - - interface - type: str - mode: - description: - - Mode in which interface needs to be configured. - choices: - - access - - trunk - type: str - access_vlan: - description: - - Configure given VLAN in access port. If C(mode=access), used as the access VLAN - ID. - type: str - native_vlan: - description: - - Native VLAN to be configured in trunk port. If C(mode=trunk), used as the trunk - native VLAN ID. - type: str - trunk_vlans: - description: - - List of VLANs to be configured in trunk port. If C(mode=trunk), used as the - VLAN range to ADD or REMOVE from the trunk. - aliases: - - trunk_add_vlans - type: str - trunk_allowed_vlans: - description: - - List of allowed VLANs in a given trunk port. If C(mode=trunk), these are the - only VLANs that will be configured on the trunk, i.e. "2-10,15". - type: str - state: - description: - - Manage the state of the Layer-2 Interface configuration. - choices: - - present - - absent - - unconfigured - type: str - - state: - description: - - Manage the state of the Layer-2 Interface configuration. - default: present - choices: - - present - - absent - - unconfigured - type: str - - -""" - -EXAMPLES = """ -- name: Ensure Eth1/5 is in its default l2 interface state - cisco.nxos.nxos_l2_interface: - name: Ethernet1/5 - state: unconfigured - -- name: Ensure Eth1/5 is configured for access vlan 20 - cisco.nxos.nxos_l2_interface: - name: Ethernet1/5 - mode: access - access_vlan: 20 - -- name: Ensure Eth1/5 only has vlans 5-10 as trunk vlans - cisco.nxos.nxos_l2_interface: - name: Ethernet1/5 - mode: trunk - native_vlan: 10 - trunk_vlans: 5-10 - -- name: Ensure eth1/5 is a trunk port and ensure 2-50 are being tagged (doesn't mean - others aren't also being tagged) - cisco.nxos.nxos_l2_interface: - name: Ethernet1/5 - mode: trunk - native_vlan: 10 - trunk_vlans: 2-50 - -- name: Ensure these VLANs are not being tagged on the trunk - cisco.nxos.nxos_l2_interface: - name: Ethernet1/5 - mode: trunk - trunk_vlans: 51-4094 - state: absent - -- name: Aggregate Configure interfaces for access_vlan with aggregate - cisco.nxos.nxos_l2_interface: - aggregate: - - {name: Ethernet1/2, access_vlan: 6} - - {name: Ethernet1/7, access_vlan: 15} - mode: access -""" - -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 eth1/5 - - switchport access vlan 20 -""" - -from copy import deepcopy - -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - load_config, - run_commands, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, - get_interface_type, -) -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - remove_default_spec, -) - - -def get_interface_mode(name, module): - """Gets current mode of interface: layer2 or layer3 - Args: - device (Device): This is the device object of an NX-API enabled device - using the Device class within device.py - interface (string): full name of interface, i.e. Ethernet1/1, - loopback10, port-channel20, vlan20 - Returns: - str: 'layer2' or 'layer3' - """ - command = "show interface {0} | json".format(name) - intf_type = get_interface_type(name) - mode = "unknown" - interface_table = {} - - try: - body = run_commands(module, [command])[0] - interface_table = body["TABLE_interface"]["ROW_interface"] - except (KeyError, AttributeError, IndexError): - return mode - - if interface_table: - # HACK FOR NOW - if intf_type in ["ethernet", "portchannel"]: - mode = str(interface_table.get("eth_mode", "layer3")) - if mode in ["access", "trunk"]: - mode = "layer2" - if mode == "routed": - mode = "layer3" - elif intf_type == "loopback" or intf_type == "svi": - mode = "layer3" - return mode - - -def interface_is_portchannel(name, module): - """Checks to see if an interface is part of portchannel bundle - Args: - interface (str): full name of interface, i.e. Ethernet1/1 - Returns: - True/False based on if interface is a member of a portchannel bundle - """ - intf_type = get_interface_type(name) - - if intf_type == "ethernet": - command = "show interface {0} | json".format(name) - try: - body = run_commands(module, [command])[0] - interface_table = body["TABLE_interface"]["ROW_interface"] - except (KeyError, AttributeError, IndexError): - interface_table = None - - if interface_table: - state = interface_table.get("eth_bundle") - if state: - return True - else: - return False - - return False - - -def get_switchport(port, module): - """Gets current config of L2 switchport - Args: - device (Device): This is the device object of an NX-API enabled device - using the Device class within device.py - port (str): full name of interface, i.e. Ethernet1/1 - Returns: - dictionary with k/v pairs for L2 vlan config - """ - - command = "show interface {0} switchport | json".format(port) - - try: - body = run_commands(module, [command])[0] - sp_table = body["TABLE_interface"]["ROW_interface"] - except (KeyError, AttributeError, IndexError): - sp_table = None - - if sp_table: - key_map = { - "interface": "name", - "oper_mode": "mode", - "switchport": "switchport", - "access_vlan": "access_vlan", - "access_vlan_name": "access_vlan_name", - "native_vlan": "native_vlan", - "native_vlan_name": "native_vlan_name", - "trunk_vlans": "trunk_vlans", - } - sp = apply_key_map(key_map, sp_table) - return sp - - else: - return {} - - -def remove_switchport_config_commands(name, existing, proposed, module): - mode = proposed.get("mode") - commands = [] - command = None - - if mode == "access": - av_check = existing.get("access_vlan") == proposed.get("access_vlan") - if av_check: - command = "no switchport access vlan {0}".format( - existing.get("access_vlan") - ) - commands.append(command) - - elif mode == "trunk": - existing_vlans = existing.get("trunk_vlans_list") - proposed_vlans = proposed.get("trunk_vlans_list") - vlans_to_remove = set(proposed_vlans).intersection(existing_vlans) - - if vlans_to_remove: - proposed_allowed_vlans = proposed.get("trunk_allowed_vlans") - remove_trunk_allowed_vlans = proposed.get( - "trunk_vlans", proposed_allowed_vlans - ) - command = "switchport trunk allowed vlan remove {0}".format( - remove_trunk_allowed_vlans - ) - commands.append(command) - - native_check = existing.get("native_vlan") == proposed.get( - "native_vlan" - ) - if native_check and proposed.get("native_vlan"): - command = "no switchport trunk native vlan {0}".format( - existing.get("native_vlan") - ) - commands.append(command) - - if commands: - commands.insert(0, "interface " + name) - return commands - - -def get_switchport_config_commands(name, existing, proposed, module): - """Gets commands required to config a given switchport interface""" - - proposed_mode = proposed.get("mode") - existing_mode = existing.get("mode") - commands = [] - command = None - - if proposed_mode != existing_mode: - if proposed_mode == "trunk": - command = "switchport mode trunk" - elif proposed_mode == "access": - command = "switchport mode access" - - if command: - commands.append(command) - - if proposed_mode == "access": - av_check = str(existing.get("access_vlan")) == str( - proposed.get("access_vlan") - ) - if not av_check: - command = "switchport access vlan {0}".format( - proposed.get("access_vlan") - ) - commands.append(command) - - elif proposed_mode == "trunk": - tv_check = existing.get("trunk_vlans_list") == proposed.get( - "trunk_vlans_list" - ) - - if not tv_check: - if proposed.get("allowed"): - command = "switchport trunk allowed vlan {0}".format( - proposed.get("trunk_allowed_vlans") - ) - commands.append(command) - - else: - existing_vlans = existing.get("trunk_vlans_list") - proposed_vlans = proposed.get("trunk_vlans_list") - vlans_to_add = set(proposed_vlans).difference(existing_vlans) - if vlans_to_add: - command = "switchport trunk allowed vlan add {0}".format( - proposed.get("trunk_vlans") - ) - commands.append(command) - - native_check = str(existing.get("native_vlan")) == str( - proposed.get("native_vlan") - ) - if not native_check and proposed.get("native_vlan"): - command = "switchport trunk native vlan {0}".format( - proposed.get("native_vlan") - ) - commands.append(command) - - if commands: - commands.insert(0, "interface " + name) - return commands - - -def is_switchport_default(existing): - """Determines if switchport has a default config based on mode - Args: - existing (dict): existing switchport configuration from Ansible mod - Returns: - boolean: True if switchport has OOB Layer 2 config, i.e. - vlan 1 and trunk all and mode is access - """ - - c1 = str(existing["access_vlan"]) == "1" - c2 = str(existing["native_vlan"]) == "1" - c3 = existing["trunk_vlans"] == "1-4094" - c4 = existing["mode"] == "access" - - default = c1 and c2 and c3 and c4 - - return default - - -def default_switchport_config(name): - commands = [] - commands.append("interface " + name) - commands.append("switchport mode access") - commands.append("switch access vlan 1") - commands.append("switchport trunk native vlan 1") - commands.append("switchport trunk allowed vlan all") - return commands - - -def vlan_range_to_list(vlans): - result = [] - if vlans: - for part in vlans.split(","): - if part == "none": - break - if "-" in part: - a, b = part.split("-") - a, b = int(a), int(b) - result.extend(range(a, b + 1)) - else: - a = int(part) - result.append(a) - return numerical_sort(result) - return result - - -def get_list_of_vlans(module): - - command = "show vlan | json" - vlan_list = [] - - try: - body = run_commands(module, [command])[0] - vlan_table = body["TABLE_vlanbrief"]["ROW_vlanbrief"] - except (KeyError, AttributeError, IndexError): - return [] - - if isinstance(vlan_table, list): - for vlan in vlan_table: - vlan_list.append(str(vlan["vlanshowbr-vlanid-utf"])) - else: - vlan_list.append("1") - - return vlan_list - - -def numerical_sort(string_int_list): - """Sorts list of strings/integers that are digits in numerical order.""" - - as_int_list = [] - as_str_list = [] - for vlan in string_int_list: - as_int_list.append(int(vlan)) - as_int_list.sort() - for vlan in as_int_list: - as_str_list.append(str(vlan)) - return as_str_list - - -def apply_key_map(key_map, table): - new_dict = {} - for key, value in table.items(): - new_key = key_map.get(key) - if new_key: - new_dict[new_key] = str(value) - return new_dict - - -def apply_value_map(value_map, resource): - for key, value in value_map.items(): - resource[key] = value[resource.get(key)] - return resource - - -def flatten_list(command_lists): - flat_command_list = [] - for command in command_lists: - if isinstance(command, list): - flat_command_list.extend(command) - else: - flat_command_list.append(command) - return flat_command_list - - -def map_params_to_obj(module): - obj = [] - aggregate = module.params.get("aggregate") - if aggregate: - for item in aggregate: - for key in item: - if item.get(key) is None: - item[key] = module.params[key] - - d = item.copy() - obj.append(d) - else: - obj.append( - { - "name": module.params["name"], - "mode": module.params["mode"], - "access_vlan": module.params["access_vlan"], - "native_vlan": module.params["native_vlan"], - "trunk_vlans": module.params["trunk_vlans"], - "trunk_allowed_vlans": module.params["trunk_allowed_vlans"], - "state": module.params["state"], - } - ) - - return obj - - -def main(): - """main entry point for module execution""" - element_spec = dict( - name=dict(type="str", aliases=["interface"]), - mode=dict(choices=["access", "trunk"]), - access_vlan=dict(type="str"), - native_vlan=dict(type="str"), - trunk_vlans=dict(type="str", aliases=["trunk_add_vlans"]), - trunk_allowed_vlans=dict(type="str"), - state=dict( - choices=["absent", "present", "unconfigured"], default="present" - ), - ) - - aggregate_spec = deepcopy(element_spec) - - # remove default in aggregate spec, to handle common arguments - remove_default_spec(aggregate_spec) - - argument_spec = dict( - aggregate=dict(type="list", elements="dict", options=aggregate_spec) - ) - - argument_spec.update(element_spec) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, - mutually_exclusive=[ - ["access_vlan", "trunk_vlans"], - ["access_vlan", "native_vlan"], - ["access_vlan", "trunk_allowed_vlans"], - ], - supports_check_mode=True, - ) - - warnings = list() - commands = [] - result = {"changed": False} - if warnings: - result["warnings"] = warnings - - want = map_params_to_obj(module) - for w in want: - name = w["name"] - mode = w["mode"] - access_vlan = w["access_vlan"] - state = w["state"] - trunk_vlans = w["trunk_vlans"] - native_vlan = w["native_vlan"] - trunk_allowed_vlans = w["trunk_allowed_vlans"] - - args = dict( - name=name, - mode=mode, - access_vlan=access_vlan, - native_vlan=native_vlan, - trunk_vlans=trunk_vlans, - trunk_allowed_vlans=trunk_allowed_vlans, - ) - - proposed = dict((k, v) for k, v in args.items() if v is not None) - - name = name.lower() - - if mode == "access" and state == "present" and not access_vlan: - module.fail_json( - msg="access_vlan param is required when mode=access && state=present" - ) - - if mode == "trunk" and access_vlan: - module.fail_json( - msg="access_vlan param not supported when using mode=trunk" - ) - - current_mode = get_interface_mode(name, module) - - # Current mode will return layer3, layer2, or unknown - if current_mode == "unknown" or current_mode == "layer3": - module.fail_json( - msg="Ensure interface is configured to be a L2" - "\nport first before using this module. You can use" - "\nthe nxos_interface module for this." - ) - - if interface_is_portchannel(name, module): - module.fail_json( - msg="Cannot change L2 config on physical " - "\nport because it is in a portchannel. " - "\nYou should update the portchannel config." - ) - - # existing will never be null for Eth intfs as there is always a default - existing = get_switchport(name, module) - - # Safeguard check - # If there isn't an existing, something is wrong per previous comment - if not existing: - module.fail_json( - msg="Make sure you are using the FULL interface name" - ) - - if trunk_vlans or trunk_allowed_vlans: - if trunk_vlans: - trunk_vlans_list = vlan_range_to_list(trunk_vlans) - elif trunk_allowed_vlans: - trunk_vlans_list = vlan_range_to_list(trunk_allowed_vlans) - proposed["allowed"] = True - - existing_trunks_list = vlan_range_to_list( - (existing["trunk_vlans"]) - ) - - existing["trunk_vlans_list"] = existing_trunks_list - proposed["trunk_vlans_list"] = trunk_vlans_list - - current_vlans = get_list_of_vlans(module) - - if state == "present": - if access_vlan and access_vlan not in current_vlans: - module.fail_json( - msg="You are trying to configure a VLAN" - " on an interface that\ndoes not exist on the " - " switch yet!", - vlan=access_vlan, - ) - elif native_vlan and native_vlan not in current_vlans: - module.fail_json( - msg="You are trying to configure a VLAN" - " on an interface that\ndoes not exist on the " - " switch yet!", - vlan=native_vlan, - ) - else: - command = get_switchport_config_commands( - name, existing, proposed, module - ) - commands.append(command) - elif state == "unconfigured": - is_default = is_switchport_default(existing) - if not is_default: - command = default_switchport_config(name) - commands.append(command) - elif state == "absent": - command = remove_switchport_config_commands( - name, existing, proposed, module - ) - commands.append(command) - - if trunk_vlans or trunk_allowed_vlans: - existing.pop("trunk_vlans_list") - proposed.pop("trunk_vlans_list") - - cmds = flatten_list(commands) - if cmds: - if module.check_mode: - module.exit_json(changed=True, commands=cmds) - else: - result["changed"] = True - load_config(module, cmds) - if "configure" in cmds: - cmds.pop(0) - - result["commands"] = cmds - result["warnings"] = warnings - - module.exit_json(**result) - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/nxos_l2_interfaces.py b/plugins/modules/nxos_l2_interfaces.py index c4cdc871a..c490d65ed 100644 --- a/plugins/modules/nxos_l2_interfaces.py +++ b/plugins/modules/nxos_l2_interfaces.py @@ -28,6 +28,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -92,6 +93,7 @@ as changed=True. type: str choices: + - dot1q-tunnel - access - trunk - fex-fabric @@ -109,37 +111,63 @@ - rendered - parsed default: merged - """ + EXAMPLES = """ # Using merged # Before state: # ------------- # +# switch# show running-config | section interface # interface Ethernet1/1 -# switchport access vlan 20 # interface Ethernet1/2 # switchport trunk native vlan 20 # interface mgmt0 # ip address dhcp # ipv6 address auto-config -- name: Merge provided configuration with device configuration. +- name: Merge provided configuration with device configuration cisco.nxos.nxos_l2_interfaces: config: - - name: Ethernet1/1 - trunk: - native_vlan: 10 - allowed_vlans: 2,4,15 - - name: Ethernet1/2 - access: - vlan: 30 + - name: Ethernet1/1 + trunk: + native_vlan: 10 + allowed_vlans: 2,4,15 + - name: Ethernet1/2 + access: + vlan: 30 state: merged +# Task Output +# ----------- +# +# before: +# - name: Loopback999 +# - name: Ethernet1/2 +# - name: mgmt0 +# - name: Ethernet1/1 +# commands: +# - interface Ethernet1/1 +# - switchport trunk allowed vlan 2,4,15 +# - switchport trunk native vlan 10 +# - interface Ethernet1/2 +# - switchport access vlan 30 +# after: +# - name: Ethernet1/1 +# trunk: +# allowed_vlans: 2,4,15 +# native_vlan: 10 +# - access: +# vlan: 30 +# name: Ethernet1/2 +# - name: mgmt0 +# - name: Loopback999 + # After state: # ------------ # +# switch# show running-config | section interface # interface Ethernet1/1 # switchport trunk native vlan 10 # switchport trunk allowed vlans 2,4,15 @@ -149,16 +177,17 @@ # ip address dhcp # ipv6 address auto-config - # Using replaced # Before state: # ------------- # +# switch# show running-config | section interface # interface Ethernet1/1 -# switchport access vlan 20 +# switchport trunk native vlan 10 +# switchport trunk allowed vlans 2,4,15 # interface Ethernet1/2 -# switchport trunk native vlan 20 +# switchport access vlan 30 # interface mgmt0 # ip address dhcp # ipv6 address auto-config @@ -166,15 +195,43 @@ - name: Replace device configuration of specified L2 interfaces with provided configuration. cisco.nxos.nxos_l2_interfaces: config: - - name: Ethernet1/1 - trunk: - native_vlan: 20 - allowed_vlans: 5-10, 15 + - name: Ethernet1/1 + trunk: + native_vlan: 20 + allowed_vlans: 5-10, 15 state: replaced +# Task Output +# ----------- +# +# before: +# - name: Ethernet1/1 +# trunk: +# allowed_vlans: 2,4,15 +# native_vlan: 10 +# - access: +# vlan: 30 +# name: Ethernet1/2 +# - name: mgmt0 +# commands: +# - interface Ethernet1/1 +# - no switchport trunk native vlan +# - switchport trunk allowed vlan 5-10,15 +# - switchport trunk native vlan 20 +# after: +# - name: Ethernet1/1 +# trunk: +# allowed_vlans: 5-10,15 +# native_vlan: 20 +# - access: +# vlan: 30 +# name: Ethernet1/2 +# - name: mgmt0 + # After state: # ------------ # +# switch# show running-config | section interface # interface Ethernet1/1 # switchport trunk native vlan 20 # switchport trunk allowed vlan 5-10,15 @@ -185,32 +242,57 @@ # ip address dhcp # ipv6 address auto-config - # Using overridden # Before state: # ------------- # +# switch# show running-config | section interface # interface Ethernet1/1 -# switchport access vlan 20 +# switchport trunk native vlan 20 +# switchport trunk allowed vlan 5-10,15 # interface Ethernet1/2 # switchport trunk native vlan 20 +# switchport mode trunk # interface mgmt0 # ip address dhcp # ipv6 address auto-config -- name: Override device configuration of all L2 interfaces on device with provided - configuration. +- name: Override device configuration with provided configuration. cisco.nxos.nxos_l2_interfaces: config: - - name: Ethernet1/2 - access: - vlan: 30 + - name: Ethernet1/2 + access: + vlan: 30 state: overridden +# Task Output +# ----------- +# +# before: +# - name: Ethernet1/1 +# trunk: +# allowed_vlans: 5,6,7,8,9,10,15 +# native_vlan: 20 +# - access: +# vlan: 30 +# name: Ethernet1/2 +# - name: mgmt0 +# commands: +# - interface Ethernet1/1 +# - no switchport trunk allowed vlan +# - no switchport trunk native vlan +# after: +# - name: Ethernet1/1 +# - access: +# vlan: 30 +# name: Ethernet1/2 +# - name: mgmt0 + # After state: # ------------ # +# switch# show running-config | section interface # interface Ethernet1/1 # interface Ethernet1/2 # switchport access vlan 30 @@ -224,10 +306,12 @@ # Before state: # ------------- # +# switch# show running-config | section interface # interface Ethernet1/1 -# switchport access vlan 20 +# switchport trunk native vlan 10 +# switchport trunk allowed vlan 2,4,15 # interface Ethernet1/2 -# switchport trunk native vlan 20 +# switchport access vlan 30 # interface mgmt0 # ip address dhcp # ipv6 address auto-config @@ -236,13 +320,37 @@ itself). cisco.nxos.nxos_l2_interfaces: config: - - name: Ethernet1/1 - - name: Ethernet1/2 + - name: Ethernet1/1 + - name: Ethernet1/2 state: deleted +# Task Output +# ----------- +# +# before: +# - name: Ethernet1/1 +# trunk: +# allowed_vlans: 2,4,15 +# native_vlan: 10 +# - access: +# vlan: 30 +# name: Ethernet1/2 +# - name: mgmt0 +# commands: +# - interface Ethernet1/1 +# - no switchport trunk allowed vlan +# - no switchport trunk native vlan +# - interface Ethernet1/2 +# - no switchport access vlan +# after: +# - name: Ethernet1/1 +# - name: Ethernet1/2 +# - name: mgmt0 + # After state: # ------------ # +# switch# show running-config | section interface # interface Ethernet1/1 # interface Ethernet1/2 # interface mgmt0 @@ -254,36 +362,37 @@ - name: Render platform specific configuration lines (without connecting to the device) cisco.nxos.nxos_l2_interfaces: config: - - name: Ethernet1/1 - trunk: - native_vlan: 10 - allowed_vlans: 2,4,15 - - name: Ethernet1/2 - access: - vlan: 30 - - name: Ethernet1/3 - trunk: - native_vlan: 20 - allowed_vlans: 5-10, 15 + - name: Ethernet1/1 + trunk: + native_vlan: 10 + allowed_vlans: 2,4,15 + - name: Ethernet1/2 + access: + vlan: 30 + - name: Ethernet1/3 + trunk: + native_vlan: 20 + allowed_vlans: 5-10, 15 state: rendered -# Task Output (redacted) -# ----------------------- - +# Task Output +# ----------- +# # rendered: -# - "interface Ethernet1/1" -# - "switchport trunk allowed vlan 2,4,15" -# - "switchport trunk native vlan 10" -# - "interface Ethernet1/2" -# - "switchport access vlan 30" -# - "interface Ethernet1/3" -# - "switchport trunk allowed vlan 5,6,7,8,9,10,15" -# - "switchport trunk native vlan 20" +# - interface Ethernet1/1 +# - switchport trunk allowed vlan 2,4,15 +# - switchport trunk native vlan 10 +# - interface Ethernet1/2 +# - switchport access vlan 30 +# - interface Ethernet1/3 +# - switchport trunk allowed vlan 5-10,15 +# - switchport trunk native vlan 20 # Using parsed # parsed.cfg # ------------ +# # interface Ethernet1/800 # switchport access vlan 18 # switchport trunk allowed vlan 210 @@ -295,8 +404,9 @@ running_config: "{{ lookup('file', 'parsed.cfg') }}" state: parsed -# Task output (redacted) -# ----------------------- +# Task output +# ----------- +# # parsed: # - name: Ethernet1/800 # access: @@ -309,9 +419,10 @@ # Using gathered -# Existing device config state -# ------------------------------- -# Nexus9kvI5# sh running-config | section ^interface +# Before state: +# ------------- +# +# switch# sh running-config | section ^interface # interface Ethernet1/1 # switchport access vlan 6 # switchport trunk allowed vlan 200 @@ -322,19 +433,20 @@ cisco.nxos.nxos_l2_interfaces: state: gathered -# Task output (redacted) -# ----------------------- +# Task output +# ----------- +# # gathered: # - name: "Ethernet1/1" # access: # vlan: 6 # trunk: # allowed_vlans: "200" -# # - name: "Ethernet1/2" # trunk: # native_vlan: 10 """ + RETURN = """ before: description: The configuration as structured data prior to module invocation. @@ -367,6 +479,7 @@ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.l2_interfaces.l2_interfaces import ( L2_interfacesArgs, ) diff --git a/plugins/modules/nxos_l3_interface.py b/plugins/modules/nxos_l3_interface.py deleted file mode 100644 index 499cbf13b..000000000 --- a/plugins/modules/nxos_l3_interface.py +++ /dev/null @@ -1,290 +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: nxos_l3_interface -author: Trishna Guha (@trishnaguha) -short_description: (deprecated, removed after 2022-06-01) Manage L3 interfaces - on Cisco NXOS network devices -description: -- This module provides declarative management of L3 interfaces on Cisco NXOS network - devices. -version_added: 1.0.0 -deprecated: - alternative: nxos_l3_interfaces - why: Updated modules released with more functionality - removed_at_date: '2022-06-01' -notes: -- Tested against NXOSv 7.0(3)I5(1). -- Unsupported for Cisco MDS -options: - name: - description: - - Name of the L3 interface. - type: str - ipv4: - description: - - IPv4 of the L3 interface. - type: str - ipv6: - description: - - IPv6 of the L3 interface. - type: str - aggregate: - description: List of L3 interfaces definitions. - type: list - elements: dict - suboptions: - name: - description: - - Name of the L3 interface. - type: str - ipv4: - description: - - IPv4 of the L3 interface. - type: str - ipv6: - description: - - IPv6 of the L3 interface. - type: str - state: - description: - - State of the L3 interface configuration. - choices: - - present - - absent - type: str - state: - description: - - State of the L3 interface configuration. - default: present - choices: - - present - - absent - type: str -extends_documentation_fragment: -- cisco.nxos.nxos -""" - -EXAMPLES = """ -- name: Set interface IPv4 address - cisco.nxos.nxos_l3_interface: - name: Ethernet2/3 - ipv4: 192.168.0.1/24 - -- name: Remove interface IPv4 address - cisco.nxos.nxos_l3_interface: - name: Ethernet2/3 - state: absent - -- name: Set IP addresses on aggregate - cisco.nxos.nxos_l3_interface: - aggregate: - - {name: "Ethernet2/1", ipv4: "192.168.2.10/24"} - - {name: "Ethernet2/5", ipv4: "192.168.3.10/24", ipv6: "fd5d:12c9:2201:1::1/64"} - -- name: Remove IP addresses on aggregate - cisco.nxos.nxos_l3_interface: - aggregate: - - {name: "Ethernet2/1", ipv4: "192.168.2.10/24"} - - {name: "Ethernet2/5", 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: - - interface ethernet2/3 - - no switchport - - ip address 192.168.22.1/24 - - ipv6 address "fd5d:12c9:2201:1::1/64" - - no ip address 192.168.22.1/24 -""" - -import re - -from copy import deepcopy - -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( - CustomNetworkConfig, -) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - remove_default_spec, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_config, - load_config, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, - normalize_interface, -) - - -def search_obj_in_list(name, lst): - for o in lst: - if o["name"] == name: - return o - - -def map_obj_to_commands(updates, module, warnings): - commands = list() - want, have = updates - - for w in want: - name = w["name"] - ipv4 = w["ipv4"] - ipv6 = w["ipv6"] - state = w["state"] - del w["state"] - - obj_in_have = search_obj_in_list(name, have) - - if not obj_in_have: - warnings.append("Unknown interface {0}".format(name)) - elif state == "absent": - command = [] - if obj_in_have["name"] == name: - if ipv4 and ipv4 == obj_in_have["ipv4"]: - command.append("no ip address {0}".format(ipv4)) - if ipv6 and ipv6 in obj_in_have["ipv6"]: - command.append("no ipv6 address {0}".format(ipv6)) - if command: - command.append("exit") - command.insert(0, "interface {0}".format(name)) - commands.extend(command) - - elif state == "present": - command = [] - if obj_in_have["name"] == name: - if ipv4 and ipv4 != obj_in_have["ipv4"]: - command.append("ip address {0}".format(ipv4)) - if ipv6 and ipv6 not in obj_in_have["ipv6"]: - command.append("ipv6 address {0}".format(ipv6)) - if command: - command.append("exit") - command.insert(0, "interface {0}".format(name)) - elif not ipv4 and not ipv6: - command.append("interface {0}".format(name)) - commands.extend(command) - - return commands - - -def map_params_to_obj(module): - obj = [] - - aggregate = module.params.get("aggregate") - if aggregate: - for item in aggregate: - for key in item: - if item.get(key) is None: - item[key] = module.params[key] - - d = item.copy() - name = d["name"] - d["name"] = normalize_interface(name) - obj.append(d) - - else: - obj.append( - { - "name": normalize_interface(module.params["name"]), - "ipv4": module.params["ipv4"], - "ipv6": module.params["ipv6"], - "state": module.params["state"], - } - ) - - return obj - - -def map_config_to_obj(want, module): - objs = list() - netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) - - for w in want: - parents = ["interface {0}".format(w["name"])] - config = netcfg.get_section(parents) - obj = dict(name=None, ipv4=None, ipv6=[]) - - if config: - match_name = re.findall(r"interface (\S+)", config, re.M) - if match_name: - obj["name"] = normalize_interface(match_name[0]) - - match_ipv4 = re.findall(r"ip address (\S+)", config, re.M) - if match_ipv4: - obj["ipv4"] = match_ipv4[0] - - match_ipv6 = re.findall(r"ipv6 address (\S+)", config, re.M) - if match_ipv6: - obj["ipv6"] = match_ipv6 - - objs.append(obj) - return objs - - -def main(): - """main entry point for module execution""" - element_spec = dict( - name=dict(), - ipv4=dict(), - ipv6=dict(), - state=dict(default="present", choices=["present", "absent"]), - ) - - aggregate_spec = deepcopy(element_spec) - - # remove default in aggregate spec, to handle common arguments - remove_default_spec(aggregate_spec) - - argument_spec = dict( - aggregate=dict(type="list", elements="dict", options=aggregate_spec) - ) - - argument_spec.update(element_spec) - argument_spec.update(nxos_argument_spec) - - required_one_of = [["name", "aggregate"]] - mutually_exclusive = [["name", "aggregate"]] - module = AnsibleModule( - argument_spec=argument_spec, - required_one_of=required_one_of, - mutually_exclusive=mutually_exclusive, - supports_check_mode=True, - ) - - warnings = list() - result = {"changed": False} - - want = map_params_to_obj(module) - have = map_config_to_obj(want, module) - - commands = map_obj_to_commands((want, have), module, warnings) - result["commands"] = commands - - if warnings: - result["warnings"] = warnings - if commands: - if not module.check_mode: - load_config(module, commands) - result["changed"] = True - - module.exit_json(**result) - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/nxos_l3_interfaces.py b/plugins/modules/nxos_l3_interfaces.py index cd5b34050..5dc3d05a9 100644 --- a/plugins/modules/nxos_l3_interfaces.py +++ b/plugins/modules/nxos_l3_interfaces.py @@ -28,6 +28,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -98,11 +99,15 @@ type: int redirects: description: - - Enables/disables ip redirects + - Enables/disables ipv4 redirects. + type: bool + ipv6_redirects: + description: + - Enables/disables ipv6 redirects. type: bool unreachables: description: - - Enables/disables ip redirects + - Enables/disables ip redirects. type: bool evpn_multisite_tracking: description: @@ -137,39 +142,93 @@ # Before state: # ------------- # +# router# show running-config | section interface # interface Ethernet1/6 +# description Configured by Ansible Network +# no switchport +# no shutdown +# interface Ethernet1/7 +# description Configured by Ansible +# no switchport +# no shutdown +# interface mgmt0 +# description mgmt interface +# ip address dhcp +# vrf member management - name: Merge provided configuration with device configuration. cisco.nxos.nxos_l3_interfaces: config: - - name: Ethernet1/6 - ipv4: - - address: 192.168.1.1/24 - tag: 5 - - address: 10.1.1.1/24 - secondary: true - tag: 10 - ipv6: - - address: fd5d:12c9:2201:2::1/64 - tag: 6 - - name: Ethernet1/7.42 - dot1q: 42 - redirects: false - unreachables: false + - name: Ethernet1/6 + ipv4: + - address: 192.168.1.1/24 + tag: 5 + - address: 10.1.1.1/24 + secondary: true + tag: 10 + ipv6: + - address: fd5d:12c9:2201:2::1/64 + tag: 6 + - name: Ethernet1/7.42 + redirects: false + unreachables: false state: merged +# Task Output +# ----------- +# +# before: +# - name: Ethernet1/6 +# - name: Ethernet1/7 +# - ipv4: +# - address: dhcp +# name: mgmt0 +# commands: +# - interface Ethernet1/6 +# - ip address 192.168.1.1/24 tag 5 +# - ip address 10.1.1.1/24 secondary tag 10 +# - ipv6 address fd5d:12c9:2201:2::1/64 tag 6 +# - interface Ethernet1/7 +# - no ip redirects +# after: +# - ipv4: +# - address: 192.168.1.1/24 +# tag: 5 +# - address: 10.1.1.1/24 +# secondary: true +# tag: 10 +# ipv6: +# - address: fd5d:12c9:2201:2::1/64 +# tag: 6 +# name: Ethernet1/6 +# redirects: false +# - name: Ethernet1/7 +# redirects: false +# - ipv4: +# - address: dhcp +# name: mgmt0 + # After state: # ------------ # +# router# show running-config | section interface # interface Ethernet1/6 -# ip address 192.168.22.1/24 tag 5 +# description Configured by Ansible Network +# no switchport +# no ip redirects +# ip address 192.168.1.1/24 tag 5 # ip address 10.1.1.1/24 secondary tag 10 -# interface Ethernet1/6 # ipv6 address fd5d:12c9:2201:2::1/64 tag 6 -# interface Ethernet1/7.42 -# encapsulation dot1q 42 +# no shutdown +# interface Ethernet1/7 +# description Configured by Ansible +# no switchport # no ip redirects -# no ip unreachables +# no shutdown +# interface mgmt0 +# description mgmt interface +# ip address dhcp +# vrf member management # Using replaced @@ -177,107 +236,295 @@ # Before state: # ------------- # +# router# show running-config | section interface # interface Ethernet1/6 -# ip address 192.168.22.1/24 -# ipv6 address "fd5d:12c9:2201:1::1/64" +# description Configured by Ansible Network +# no switchport +# no ip redirects +# ip address 192.168.1.1/24 tag 5 +# ip address 10.1.1.1/24 secondary tag 10 +# ipv6 address fd5d:12c9:2201:2::1/64 tag 6 +# no shutdown +# interface Ethernet1/7 +# description Configured by Ansible +# no switchport +# no ip redirects +# no shutdown +# interface mgmt0 +# description mgmt interface +# ip address dhcp +# vrf member management - name: Replace device configuration of specified L3 interfaces with provided configuration. cisco.nxos.nxos_l3_interfaces: config: - - name: Ethernet1/6 - ipv4: - - address: 192.168.22.3/24 + - name: Ethernet1/6 + ipv4: + - address: 192.168.22.3/24 state: replaced +# Task Output +# ----------- +# +# before: +# - ipv4: +# - address: 192.168.1.1/24 +# tag: 5 +# - address: 10.1.1.1/24 +# secondary: true +# tag: 10 +# ipv6: +# - address: fd5d:12c9:2201:2::1/64 +# tag: 6 +# name: Ethernet1/6 +# redirects: false +# - name: Ethernet1/7 +# redirects: false +# - ipv4: +# - address: dhcp +# name: mgmt0 +# commands: +# - interface Ethernet1/6 +# - ip address 192.168.22.3/24 +# - no ipv6 address fd5d:12c9:2201:2::1/64 +# - ip redirects +# after: +# - ipv4: +# - address: 192.168.22.3/24 +# - address: 10.1.1.1/24 +# secondary: true +# tag: 10 +# name: Ethernet1/6 +# redirects: false +# - name: Ethernet1/7 +# redirects: false +# - ipv4: +# - address: dhcp +# name: mgmt0 + # After state: # ------------ # +# router# show running-config | section interface # interface Ethernet1/6 +# description Configured by Ansible Network +# no switchport +# no ip redirects # ip address 192.168.22.3/24 - +# ip address 10.1.1.1/24 secondary tag 10 +# no shutdown +# interface Ethernet1/7 +# description Configured by Ansible +# no switchport +# no ip redirects +# no shutdown +# interface mgmt0 +# description mgmt interface +# ip address dhcp +# vrf member management # Using overridden # Before state: # ------------- # -# interface Ethernet1/2 -# ip address 192.168.22.1/24 +# router# show running-config | section interface # interface Ethernet1/6 -# ipv6 address "fd5d:12c9:2201:1::1/64" +# description Configured by Ansible Network +# no switchport +# no ip redirects +# ip address 192.168.1.1/24 tag 5 +# ip address 10.1.1.1/24 secondary tag 10 +# ipv6 address fd5d:12c9:2201:2::1/64 tag 6 +# no shutdown +# interface Ethernet1/7 +# description Configured by Ansible +# no switchport +# no ip redirects +# no shutdown +# interface Ethernet1/7.42 +# no ip redirects +# interface mgmt0 +# description mgmt interface +# ip address dhcp +# vrf member management -- name: Override device configuration of all L3 interfaces on device with provided - configuration. +- name: Override device configuration with provided configuration. cisco.nxos.nxos_l3_interfaces: config: - - name: Ethernet1/2 - ipv4: 192.168.22.3/4 + - ipv4: + - address: dhcp + name: mgmt0 + - name: Ethernet1/6 + ipv4: + - address: 192.168.22.3/24 state: overridden +# Task Output +# ----------- +# +# before: +# - ipv4: +# - address: 192.168.1.1/24 +# tag: 5 +# - address: 10.1.1.1/24 +# secondary: true +# tag: 10 +# ipv6: +# - address: fd5d:12c9:2201:2::1/64 +# tag: 6 +# name: Ethernet1/6 +# redirects: false +# - name: Ethernet1/7 +# redirects: false +# - name: Ethernet1/7.42 +# redirects: false +# - ipv4: +# - address: dhcp +# name: mgmt0 +# commands: +# - interface Ethernet1/6 +# - no ipv6 address fd5d:12c9:2201:2::1/64 +# - no ip address 10.1.1.1/24 secondary +# - ip address 192.168.22.3/24 +# - ip redirects +# - interface Ethernet1/7 +# - ip redirects +# - interface Ethernet1/7.42 +# - ip redirects +# after: +# - ipv4: +# - address: 192.168.22.3/24 +# name: Ethernet1/6 +# - name: Ethernet1/7 +# - name: Ethernet1/7.42 +# - ipv4: +# - address: dhcp +# name: mgmt0 + # After state: # ------------ # -# interface Ethernet1/2 -# ipv4 address 192.168.22.3/24 +# router# show running-config | section interface # interface Ethernet1/6 - +# description Configured by Ansible Network +# no switchport +# ip address 192.168.22.3/24 +# no shutdown +# interface Ethernet1/7 +# description Configured by Ansible +# no switchport +# no shutdown +# interface Ethernet1/7.42 +# interface mgmt0 +# description mgmt interface +# ip address dhcp +# vrf member management # Using deleted # Before state: # ------------- # +# router# show running-config | section interface # interface Ethernet1/6 -# ip address 192.168.22.1/24 -# interface Ethernet1/2 -# ipv6 address "fd5d:12c9:2201:1::1/64" +# description Configured by Ansible Network +# no switchport +# ip address 192.168.22.3/24 +# no shutdown +# interface Ethernet1/7 +# description Configured by Ansible +# no switchport +# no shutdown +# interface Ethernet1/7.42 +# interface mgmt0 +# description mgmt interface +# ip address dhcp +# vrf member management - name: Delete L3 attributes of given interfaces (This won't delete the interface itself). cisco.nxos.nxos_l3_interfaces: config: - - name: Ethernet1/6 - - name: Ethernet1/2 + - name: Ethernet1/6 + - name: Ethernet1/2 state: deleted +# Task Output +# ----------- +# +# before: +# - name: Ethernet1/2 +# - ipv4: +# - address: 192.168.22.3/24 +# name: Ethernet1/6 +# - name: Ethernet1/7 +# - name: Ethernet1/7.42 +# - ipv4: +# - address: dhcp +# name: mgmt0 +# commands: +# - interface Ethernet1/6 +# - no ip address +# after: +# - name: Ethernet1/2 +# - name: Ethernet1/7 +# - name: Ethernet1/7.42 +# - ipv4: +# - address: dhcp +# name: mgmt0 + # After state: # ------------ # +# router# show running-config | section interface # interface Ethernet1/6 -# interface Ethernet1/2 +# description Configured by Ansible Network +# no switchport +# no shutdown +# interface Ethernet1/7 +# description Configured by Ansible +# no switchport +# no shutdown +# interface Ethernet1/7.42 +# interface mgmt0 +# description mgmt interface +# ip address dhcp +# vrf member management # Using rendered - name: Use rendered state to convert task input to device specific commands cisco.nxos.nxos_l3_interfaces: config: - - name: Ethernet1/800 - ipv4: - - address: 192.168.1.100/24 - tag: 5 - - address: 10.1.1.1/24 - secondary: true - tag: 10 - - name: Ethernet1/800 - ipv6: - - address: fd5d:12c9:2201:2::1/64 - tag: 6 + - name: Ethernet1/800 + ipv4: + - address: 192.168.1.100/24 + tag: 5 + - address: 10.1.1.1/24 + secondary: true + tag: 10 + - name: Ethernet1/800 + ipv6: + - address: fd5d:12c9:2201:2::1/64 + tag: 6 state: rendered -# Task Output (redacted) -# ----------------------- - +# Task Output +# ----------- +# # rendered: -# - "interface Ethernet1/800" -# - "ip address 192.168.1.100/24 tag 5" -# - "ip address 10.1.1.1/24 secondary tag 10" -# - "interface Ethernet1/800" -# - "ipv6 address fd5d:12c9:2201:2::1/64 tag 6" +# - interface Ethernet1/800 +# - ip address 192.168.1.100/24 tag 5 +# - ip address 10.1.1.1/24 secondary tag 10 +# - interface Ethernet1/800 +# - ipv6 address fd5d:12c9:2201:2::1/64 tag 6 # Using parsed # parsed.cfg -# ------------ +# ---------- +# # interface Ethernet1/800 # ip address 192.168.1.100/24 tag 5 # ip address 10.1.1.1/24 secondary tag 10 @@ -294,9 +541,9 @@ running_config: "{{ lookup('file', 'parsed.cfg') }}" state: parsed -# Task output (redacted) -# ----------------------- - +# Task output +# ----------- +# # parsed: # - name: Ethernet1/800 # ipv4: @@ -314,8 +561,9 @@ # Using gathered -# Existing device config state -# ------------------------------- +# Before state: +# ------------- +# # interface Ethernet1/1 # ip address 192.0.2.100/24 # interface Ethernet1/2 @@ -328,9 +576,9 @@ cisco.nxos.nxos_l3_interfaces: state: gathered -# Task output (redacted) -# ----------------------- - +# Task output +# ----------- +# # gathered: # - name: Ethernet1/1 # ipv4: @@ -367,6 +615,7 @@ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.l3_interfaces.l3_interfaces import ( L3_interfacesArgs, ) diff --git a/plugins/modules/nxos_lacp.py b/plugins/modules/nxos_lacp.py index 9cd14a124..257c1384e 100644 --- a/plugins/modules/nxos_lacp.py +++ b/plugins/modules/nxos_lacp.py @@ -28,6 +28,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -84,10 +85,12 @@ state: description: - The state of the configuration after module completion. + - States C(replaced) and C(overridden) have the same behaviour for this module. type: str choices: - merged - replaced + - overridden - deleted - gathered - rendered @@ -239,12 +242,11 @@ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.lacp.lacp import ( LacpArgs, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.lacp.lacp import ( - Lacp, -) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.lacp.lacp import Lacp def main(): diff --git a/plugins/modules/nxos_lacp_interfaces.py b/plugins/modules/nxos_lacp_interfaces.py index 32242c236..d51ea0a71 100644 --- a/plugins/modules/nxos_lacp_interfaces.py +++ b/plugins/modules/nxos_lacp_interfaces.py @@ -28,6 +28,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -142,9 +143,9 @@ - name: Merge provided configuration with device configuration. cisco.nxos.nxos_lacp_interfaces: config: - - name: Ethernet1/3 - port_priority: 5 - rate: fast + - name: Ethernet1/3 + port_priority: 5 + rate: fast state: merged # After state: @@ -168,9 +169,9 @@ - name: Replace device lacp interfaces configuration with the given configuration. cisco.nxos.nxos_lacp_interfaces: config: - - name: port-channel11 - links: - min: 4 + - name: port-channel11 + links: + min: 4 state: replaced # After state: @@ -196,9 +197,9 @@ on device with provided configuration. cisco.nxos.nxos_lacp_interfaces: config: - - name: port-channel11 - links: - min: 4 + - name: port-channel11 + links: + min: 4 state: overridden # After state: @@ -231,17 +232,17 @@ - name: Use rendered state to convert task input to device specific commands cisco.nxos.nxos_lacp_interfaces: config: - - name: Ethernet1/800 - rate: fast - - name: Ethernet1/801 - rate: fast - port_priority: 32 - - name: port-channel10 - links: - max: 15 - min: 2 - convergence: - graceful: true + - name: Ethernet1/800 + rate: fast + - name: Ethernet1/801 + rate: fast + port_priority: 32 + - name: port-channel10 + links: + max: 15 + min: 2 + convergence: + graceful: true state: rendered # Task Output (redacted) @@ -341,6 +342,7 @@ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.lacp_interfaces.lacp_interfaces import ( Lacp_interfacesArgs, ) diff --git a/plugins/modules/nxos_lag_interfaces.py b/plugins/modules/nxos_lag_interfaces.py index 25de937cd..8d0fabf7a 100644 --- a/plugins/modules/nxos_lag_interfaces.py +++ b/plugins/modules/nxos_lag_interfaces.py @@ -28,6 +28,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -112,9 +113,9 @@ - name: Merge provided configuration with device configuration. cisco.nxos.nxos_lag_interfaces: config: - - name: port-channel99 - members: - - member: Ethernet1/4 + - name: port-channel99 + members: + - member: Ethernet1/4 state: merged # After state: @@ -136,9 +137,9 @@ with provided configuration. cisco.nxos.nxos_lag_interfaces: config: - - name: port-channel10 - members: - - member: Ethernet1/4 + - name: port-channel10 + members: + - member: Ethernet1/4 state: replaced # After state: @@ -162,10 +163,10 @@ device with provided configuration. cisco.nxos.nxos_lag_interfaces: config: - - name: port-channel20 - members: - - member: Ethernet1/6 - force: true + - name: port-channel20 + members: + - member: Ethernet1/6 + force: true state: overridden # After state: @@ -188,7 +189,7 @@ itself). cisco.nxos.nxos_lag_interfaces: config: - - port-channel: port-channel99 + - port-channel: port-channel99 state: deleted - name: Delete LAG attributes of all the interfaces @@ -206,15 +207,15 @@ - name: Use rendered state to convert task input to device specific commands cisco.nxos.nxos_lag_interfaces: config: - - name: port-channel10 - members: - - member: Ethernet1/800 - mode: active - - member: Ethernet1/801 - - name: port-channel11 - members: - - member: Ethernet1/802 - mode: passive + - name: port-channel10 + members: + - member: Ethernet1/800 + mode: active + - member: Ethernet1/801 + - name: port-channel11 + members: + - member: Ethernet1/802 + mode: passive state: rendered # Task Output (redacted) @@ -328,6 +329,7 @@ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.lag_interfaces.lag_interfaces import ( Lag_interfacesArgs, ) diff --git a/plugins/modules/nxos_linkagg.py b/plugins/modules/nxos_linkagg.py deleted file mode 100644 index c452983c8..000000000 --- a/plugins/modules/nxos_linkagg.py +++ /dev/null @@ -1,559 +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: nxos_linkagg -extends_documentation_fragment: -- cisco.nxos.nxos -short_description: (deprecated, removed after 2022-06-01) Manage link - aggregation groups on Cisco NXOS devices. -description: -- This module provides declarative management of link aggregation groups on Cisco - NXOS devices. -version_added: 1.0.0 -deprecated: - alternative: nxos_lag_interfaces - why: Updated modules released with more functionality. - removed_at_date: '2022-06-01' -author: -- Trishna Guha (@trishnaguha) -notes: -- Tested against NXOSv 7.0(3)I5(1). -- Unsupported for Cisco MDS -- C(state=absent) removes the portchannel config and interface if it already exists. - If members to be removed are not explicitly passed, all existing members (if any), - are removed. -- Members must be a list. -- LACP needs to be enabled first if active/passive modes are used. -options: - group: - description: - - Channel-group number for the port-channel Link aggregation group. - type: str - mode: - description: - - Mode for the link aggregation group. - choices: - - 'active' - - 'on' - - 'passive' - default: 'on' - type: str - min_links: - description: - - Minimum number of ports required up before bringing up the link aggregation - group. - type: int - members: - description: - - List of interfaces that will be managed in the link aggregation group. - type: list - elements: str - force: - description: - - When true it forces link aggregation group members to match what is declared - in the members param. This can be used to remove members. - type: bool - default: no - aggregate: - description: List of link aggregation definitions. - type: list - elements: dict - suboptions: - group: - description: - - Channel-group number for the port-channel Link aggregation group. - type: str - required: True - mode: - description: - - Mode for the link aggregation group. - choices: - - 'active' - - 'on' - - 'passive' - type: str - min_links: - description: - - Minimum number of ports required up before bringing up the link aggregation - group. - type: int - members: - description: - - List of interfaces that will be managed in the link aggregation group. - type: list - elements: str - force: - description: - - When true it forces link aggregation group members to match what is declared - in the members param. This can be used to remove members. - type: bool - state: - description: - - State of the link aggregation group. - choices: - - present - - absent - type: str - state: - description: - - State of the link aggregation group. - default: present - choices: - - present - - absent - type: str - purge: - description: - - Purge links not defined in the I(aggregate) parameter. - type: bool - default: no -""" - -EXAMPLES = """ -- name: create link aggregation group - cisco.nxos.nxos_linkagg: - group: 99 - state: present - -- name: delete link aggregation group - cisco.nxos.nxos_linkagg: - group: 99 - state: absent - -- name: set link aggregation group to members - cisco.nxos.nxos_linkagg: - group: 10 - min_links: 3 - mode: active - members: - - Ethernet1/2 - - Ethernet1/4 - -- name: remove link aggregation group from Ethernet1/2 - cisco.nxos.nxos_linkagg: - group: 10 - min_links: 3 - mode: active - members: - - Ethernet1/4 - -- name: Create aggregate of linkagg definitions - cisco.nxos.nxos_linkagg: - aggregate: - - {group: 3} - - {group: 100, min_links: 3} - -- name: Remove aggregate of linkagg definitions - cisco.nxos.nxos_linkagg: - aggregate: - - {group: 3} - - {group: 100, min_links: 3} - 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 port-channel 30 - - lacp min-links 5 - - interface Ethernet2/1 - - channel-group 30 mode active - - no interface port-channel 30 -""" - -import re -from copy import deepcopy - -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_config, - load_config, - run_commands, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - normalize_interface, -) -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - remove_default_spec, -) - - -def search_obj_in_list(group, lst): - for o in lst: - if o["group"] == group: - return o - - -def get_diff(w, obj): - c = deepcopy(w) - o = deepcopy(obj) - - if o["group"] == c["group"] and o.get("members") == c.get("members"): - if "members" in o: - del o["members"] - if "members" in c: - del c["members"] - diff_dict = dict(set(c.items()) - set(o.items())) - return diff_dict - - -def map_obj_to_commands(updates, module): - commands = list() - want, have = updates - purge = module.params["purge"] - force = module.params["force"] - - for w in want: - group = w["group"] - mode = w["mode"] - min_links = w["min_links"] - members = w.get("members") or [] - state = w["state"] - del w["state"] - - obj_in_have = search_obj_in_list(group, have) - - if state == "absent": - if obj_in_have: - members_to_remove = list( - set(obj_in_have["members"]) - set(members) - ) - if members_to_remove: - for m in members_to_remove: - commands.append("interface {0}".format(m)) - commands.append( - "no channel-group {0}".format(obj_in_have["group"]) - ) - commands.append("exit") - commands.append("no interface port-channel {0}".format(group)) - - elif state == "present": - if not obj_in_have: - commands.append("interface port-channel {0}".format(group)) - if min_links != "None": - commands.append("lacp min-links {0}".format(min_links)) - commands.append("exit") - if members: - for m in members: - commands.append("interface {0}".format(m)) - if force: - commands.append( - "channel-group {0} force mode {1}".format( - group, mode - ) - ) - else: - commands.append( - "channel-group {0} mode {1}".format( - group, mode - ) - ) - - else: - if members: - if not obj_in_have["members"]: - for m in members: - commands.append( - "interface port-channel {0}".format(group) - ) - commands.append("exit") - commands.append("interface {0}".format(m)) - if force: - commands.append( - "channel-group {0} force mode {1}".format( - group, mode - ) - ) - else: - commands.append( - "channel-group {0} mode {1}".format( - group, mode - ) - ) - - elif set(members) != set(obj_in_have["members"]): - missing_members = list( - set(members) - set(obj_in_have["members"]) - ) - for m in missing_members: - commands.append( - "interface port-channel {0}".format(group) - ) - commands.append("exit") - commands.append("interface {0}".format(m)) - if force: - commands.append( - "channel-group {0} force mode {1}".format( - group, mode - ) - ) - else: - commands.append( - "channel-group {0} mode {1}".format( - group, mode - ) - ) - - superfluous_members = list( - set(obj_in_have["members"]) - set(members) - ) - for m in superfluous_members: - commands.append( - "interface port-channel {0}".format(group) - ) - commands.append("exit") - commands.append("interface {0}".format(m)) - commands.append( - "no channel-group {0}".format(group) - ) - - else: - diff = get_diff(w, obj_in_have) - if diff and "mode" in diff: - mode = diff["mode"] - for i in members: - commands.append("interface {0}".format(i)) - if force: - commands.append( - "channel-group {0} force mode {1}".format( - group, mode - ) - ) - else: - commands.append( - "channel-group {0} mode {1}".format( - group, mode - ) - ) - - if purge: - for h in have: - obj_in_want = search_obj_in_list(h["group"], want) - if not obj_in_want: - commands.append( - "no interface port-channel {0}".format(h["group"]) - ) - - return commands - - -def map_params_to_obj(module): - obj = [] - aggregate = module.params.get("aggregate") - if aggregate: - for item in aggregate: - for key in item: - if item.get(key) is None: - item[key] = module.params[key] - - d = item.copy() - d["group"] = str(d["group"]) - d["min_links"] = str(d["min_links"]) - if d["members"]: - d["members"] = [normalize_interface(i) for i in d["members"]] - - obj.append(d) - else: - members = None - if module.params["members"]: - members = [ - normalize_interface(i) for i in module.params["members"] - ] - - obj.append( - { - "group": str(module.params["group"]), - "mode": module.params["mode"], - "min_links": str(module.params["min_links"]), - "members": members, - "state": module.params["state"], - } - ) - - return obj - - -def parse_min_links(module, group): - min_links = None - - flags = ["| section interface.port-channel{0}".format(group)] - config = get_config(module, flags=flags) - match = re.search(r"lacp min-links (\S+)", config, re.M) - if match: - min_links = match.group(1) - - return min_links - - -def parse_mode(module, m): - mode = None - - flags = ["| section interface.{0}".format(m)] - config = get_config(module, flags=flags) - match = re.search( - r"channel-group [0-9]+ (force )?mode (\S+)", config, re.M - ) - if match: - mode = match.group(2) - - return mode - - -def get_members(channel): - members = [] - if "TABLE_member" in channel.keys(): - interfaces = channel["TABLE_member"]["ROW_member"] - else: - return list() - - if isinstance(interfaces, dict): - members.append(normalize_interface(interfaces.get("port"))) - elif isinstance(interfaces, list): - for i in interfaces: - members.append(normalize_interface(i.get("port"))) - - return members - - -def parse_members(output, group): - channels = output["TABLE_channel"]["ROW_channel"] - - if isinstance(channels, list): - for channel in channels: - if channel["group"] == group: - members = get_members(channel) - elif isinstance(channels, dict): - if channels["group"] == group: - members = get_members(channels) - else: - return list() - - return members - - -def parse_channel_options(module, output, channel): - obj = {} - - group = channel["group"] - obj["group"] = str(group) - obj["min_links"] = parse_min_links(module, group) - members = parse_members(output, group) - obj["members"] = members - for m in members: - obj["mode"] = parse_mode(module, m) - - return obj - - -def map_config_to_obj(module): - objs = list() - output = run_commands(module, ["show port-channel summary | json"])[0] - if not output: - return list() - - try: - channels = output["TABLE_channel"]["ROW_channel"] - except (TypeError, KeyError): - return objs - - if channels: - if isinstance(channels, list): - for channel in channels: - obj = parse_channel_options(module, output, channel) - objs.append(obj) - - elif isinstance(channels, dict): - obj = parse_channel_options(module, output, channels) - objs.append(obj) - - return objs - - -def main(): - """main entry point for module execution""" - element_spec = dict( - group=dict(type="str"), - mode=dict( - required=False, - choices=["on", "active", "passive"], - default="on", - type="str", - ), - min_links=dict(required=False, default=None, type="int"), - members=dict( - required=False, default=None, type="list", elements="str" - ), - force=dict(required=False, default=False, type="bool"), - state=dict( - required=False, choices=["absent", "present"], default="present" - ), - ) - - aggregate_spec = deepcopy(element_spec) - aggregate_spec["group"] = dict(required=True) - - # remove default in aggregate spec, to handle common arguments - remove_default_spec(aggregate_spec) - - argument_spec = dict( - aggregate=dict(type="list", elements="dict", options=aggregate_spec), - purge=dict(default=False, type="bool"), - ) - - argument_spec.update(element_spec) - argument_spec.update(nxos_argument_spec) - - required_one_of = [["group", "aggregate"]] - mutually_exclusive = [["group", "aggregate"]] - module = AnsibleModule( - argument_spec=argument_spec, - required_one_of=required_one_of, - mutually_exclusive=mutually_exclusive, - supports_check_mode=True, - ) - - warnings = list() - result = {"changed": False} - if warnings: - result["warnings"] = warnings - - want = map_params_to_obj(module) - have = map_config_to_obj(module) - - commands = map_obj_to_commands((want, have), module) - result["commands"] = commands - - if commands: - if not module.check_mode: - resp = load_config(module, commands, True) - if resp: - for item in resp: - if item: - if isinstance(item, dict): - err_str = item["clierror"] - else: - err_str = item - if "cannot add" in err_str.lower(): - module.fail_json(msg=err_str) - result["changed"] = True - - module.exit_json(**result) - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/nxos_lldp.py b/plugins/modules/nxos_lldp.py deleted file mode 100644 index e48609ca8..000000000 --- a/plugins/modules/nxos_lldp.py +++ /dev/null @@ -1,129 +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: nxos_lldp -author: Ganesh Nalawade (@ganeshrn) -short_description: (deprecated, removed after 2022-06-01) Manage LLDP - configuration on Cisco NXOS network devices. -description: -- This module provides declarative management of LLDP service on Cisco NXOS network - devices. -version_added: 1.0.0 -deprecated: - alternative: nxos_lldp_global - why: Updated modules released with more functionality - removed_at_date: '2022-06-01' -notes: -- Tested against NXOSv 7.0(3)I5(1). -- Unsupported for Cisco MDS -options: - state: - description: - - State of the LLDP configuration. If value is I(present) lldp will be enabled - else if it is I(absent) it will be disabled. - default: present - choices: - - present - - absent - - enabled - - disabled - type: str -extends_documentation_fragment: -- cisco.nxos.nxos - - -""" - -EXAMPLES = """ -- name: Enable LLDP service - cisco.nxos.nxos_lldp: - state: present - -- name: Disable LLDP service - cisco.nxos.nxos_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: - - feature lldp -""" -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_config, - load_config, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) - - -def has_lldp(module): - output = get_config(module, ["| section lldp"]) - is_lldp_enable = False - if output and "feature lldp" in output: - is_lldp_enable = True - - return is_lldp_enable - - -def main(): - """main entry point for module execution""" - argument_spec = dict( - state=dict( - default="present", - choices=["present", "absent", "enabled", "disabled"], - ) - ) - - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) - - warnings = list() - - result = {"changed": False} - - if warnings: - result["warnings"] = warnings - - HAS_LLDP = has_lldp(module) - - commands = [] - - if module.params["state"] == "absent" and HAS_LLDP: - commands.append("no feature lldp") - elif module.params["state"] == "present" and not HAS_LLDP: - commands.append("feature lldp") - - result["commands"] = commands - - if commands: - # On N35 A8 images, some features return a yes/no prompt - # on enablement or disablement. Bypass using terminal dont-ask - commands.insert(0, "terminal dont-ask") - if not module.check_mode: - load_config(module, commands) - - result["changed"] = True - - module.exit_json(**result) - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/nxos_lldp_global.py b/plugins/modules/nxos_lldp_global.py index a60c81881..56b7a04eb 100644 --- a/plugins/modules/nxos_lldp_global.py +++ b/plugins/modules/nxos_lldp_global.py @@ -26,6 +26,7 @@ """ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -133,11 +134,13 @@ type: bool state: description: - - The state of the configuration after module completion + - The state of the configuration after module completion. + - States C(replaced) and C(overridden) have the same behaviour for this module. type: str choices: - merged - replaced + - overridden - deleted - gathered - rendered @@ -228,8 +231,8 @@ port_id: 1 reinit: 5 tlv_select: - dcbxp: yes - power_management: yes + dcbxp: true + power_management: true state: rendered # Task Output (redacted) @@ -306,6 +309,7 @@ """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.lldp_global.lldp_global import ( Lldp_globalArgs, ) diff --git a/plugins/modules/nxos_lldp_interfaces.py b/plugins/modules/nxos_lldp_interfaces.py index 16f9f2b95..44ac5b09e 100644 --- a/plugins/modules/nxos_lldp_interfaces.py +++ b/plugins/modules/nxos_lldp_interfaces.py @@ -27,6 +27,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -110,12 +111,12 @@ - name: Merge provided configuration with device configuration cisco.nxos.nxos_lldp_interfaces: config: - - name: Ethernet1/4 - receive: false - transmit: true - tlv_set: - management_address: 192.168.122.64 - vlan: 12 + - name: Ethernet1/4 + receive: false + transmit: true + tlv_set: + management_address: 192.168.122.64 + vlan: 12 state: merged # After state: @@ -142,10 +143,10 @@ - name: Replace LLDP configuration on interfaces with given configuration cisco.nxos.nxos_lldp_interfaces: config: - - name: Ethernet1/4 - transmit: no - tlv_set: - vlan: 2 + - name: Ethernet1/4 + transmit: false + tlv_set: + vlan: 2 state: replaced @@ -175,10 +176,10 @@ - name: Override LLDP configuration on all interfaces with given configuration cisco.nxos.nxos_lldp_interfaces: config: - - name: Ethernet1/7 - receive: no - tlv_set: - vlan: 12 + - name: Ethernet1/7 + receive: false + tlv_set: + vlan: 12 state: overridden @@ -208,8 +209,6 @@ # After state: # ------------ # - - """ RETURN = """ before: @@ -234,6 +233,7 @@ """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.lldp_interfaces.lldp_interfaces import ( Lldp_interfacesArgs, ) diff --git a/plugins/modules/nxos_logging.py b/plugins/modules/nxos_logging.py index 3e8ce2f72..a6e6ccfff 100644 --- a/plugins/modules/nxos_logging.py +++ b/plugins/modules/nxos_logging.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import, division, print_function + __metaclass__ = type # Copyright: (c) 2017, Ansible by Red Hat, inc @@ -191,9 +192,9 @@ - name: Configure logging using aggregate cisco.nxos.nxos_logging: aggregate: - - {dest: console, dest_level: 2} - - {dest: logfile, dest_level: 2, name: testfile} - - {facility: daemon, facility_level: 0} + - {dest: console, dest_level: 2} + - {dest: logfile, dest_level: 2, name: testfile} + - {facility: daemon, facility_level: 0} state: present """ @@ -208,21 +209,19 @@ - logging level daemon 0 """ -import re import copy +import re + +from ansible.module_utils.basic import AnsibleModule from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( get_config, load_config, + normalize_interface, + read_module_context, run_commands, save_module_context, - read_module_context, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, - normalize_interface, ) -from ansible.module_utils.basic import AnsibleModule STATIC_CLI = { @@ -267,13 +266,10 @@ def map_obj_to_commands(module, updates): if ( not w["dest"] and not w["facility_link_status"] - and w["facility"] - not in DEFAULT_LOGGING_LEVEL[int(w["facility_level"])] + and w["facility"] not in DEFAULT_LOGGING_LEVEL[int(w["facility_level"])] ): commands.append( - "no logging level {0} {1}".format( - w["facility"], w["facility_level"] - ) + "no logging level {0} {1}".format(w["facility"], w["facility_level"]), ) if w["facility_link_status"] and w["facility"] in ("ethpm"): @@ -281,7 +277,7 @@ def map_obj_to_commands(module, updates): "no logging level {0} {1}".format( w["facility"], STATIC_CLI[w["facility_link_status"]], - ) + ), ) if w["name"] is not None: @@ -291,9 +287,7 @@ def map_obj_to_commands(module, updates): commands.append("no logging {0}".format(w["dest"])) if w["dest"] == "server": - commands.append( - "no logging server {0}".format(w["remote_server"]) - ) + commands.append("no logging server {0}".format(w["remote_server"])) if w["interface"]: commands.append("no logging source-interface") @@ -311,24 +305,20 @@ def map_obj_to_commands(module, updates): if w["facility"] is None: if w["dest"]: if w["dest"] not in ("logfile", "server"): - commands.append( - "logging {0} {1}".format( - w["dest"], w["dest_level"] - ) - ) + commands.append("logging {0} {1}".format(w["dest"], w["dest_level"])) elif w["dest"] == "logfile": if w["file_size"]: commands.append( "logging logfile {0} {1} size {2}".format( - w["name"], w["dest_level"], w["file_size"] - ) + w["name"], + w["dest_level"], + w["file_size"], + ), ) else: commands.append( - "logging logfile {0} {1}".format( - w["name"], w["dest_level"] - ) + "logging logfile {0} {1}".format(w["name"], w["dest_level"]), ) elif w["dest"] == "server": @@ -339,28 +329,26 @@ def map_obj_to_commands(module, updates): w["remote_server"], w["facility_level"], w["use_vrf"], - ) + ), ) else: commands.append( "logging server {0} {1}".format( - w["remote_server"], w["facility_level"] - ) + w["remote_server"], + w["facility_level"], + ), ) else: if w["use_vrf"]: commands.append( "logging server {0} use-vrf {1}".format( - w["remote_server"], w["use_vrf"] - ) + w["remote_server"], + w["use_vrf"], + ), ) else: - commands.append( - "logging server {0}".format( - w["remote_server"] - ) - ) + commands.append("logging server {0}".format(w["remote_server"])) if w["facility"]: if w["dest"] == "server": @@ -372,7 +360,7 @@ def map_obj_to_commands(module, updates): w["facility_level"], w["facility"], w["use_vrf"], - ) + ), ) else: commands.append( @@ -380,7 +368,7 @@ def map_obj_to_commands(module, updates): w["remote_server"], w["facility_level"], w["facility"], - ) + ), ) else: if w["use_vrf"]: @@ -389,13 +377,14 @@ def map_obj_to_commands(module, updates): w["remote_server"], w["facility"], w["use_vrf"], - ) + ), ) else: commands.append( "logging server {0} facility {1}".format( - w["remote_server"], w["facility"] - ) + w["remote_server"], + w["facility"], + ), ) else: if w["facility_link_status"]: @@ -403,23 +392,17 @@ def map_obj_to_commands(module, updates): "logging level {0} {1}".format( w["facility"], STATIC_CLI[w["facility_link_status"]], - ) + ), ) else: - if not match_facility_default( - module, w["facility"], w["facility_level"] - ): + if not match_facility_default(module, w["facility"], w["facility_level"]): commands.append( - "logging level {0} {1}".format( - w["facility"], w["facility_level"] - ) + "logging level {0} {1}".format(w["facility"], w["facility_level"]), ) if w["interface"]: commands.append( - "logging source-interface {0} {1}".format( - *split_interface(w["interface"]) - ) + "logging source-interface {0} {1}".format(*split_interface(w["interface"])), ) if w["event"] and w["event"] in STATIC_CLI: @@ -455,11 +438,7 @@ def match_facility_default(module, facility, want_level): facility_data = run_commands(module, cmd) for line in facility_data[0].split("\n"): mo = re.search(regexl, line) - if ( - mo - and int(mo.group(1)) == int(want_level) - and int(mo.group(2)) == int(want_level) - ): + if mo and int(mo.group(1)) == int(want_level) and int(mo.group(2)) == int(want_level): matches_default = True return matches_default @@ -475,9 +454,7 @@ def parse_facility_link_status(line, facility, status): facility_link_status = None if facility is not None: - match = re.search( - r"logging level {0} {1} (\S+)".format(facility, status), line, re.M - ) + match = re.search(r"logging level {0} {1} (\S+)".format(facility, status), line, re.M) if match: facility_link_status = status + "-" + match.group(1) @@ -487,9 +464,7 @@ def parse_facility_link_status(line, facility, status): def parse_event_status(line, event): status = None - match = re.search( - r"logging event {0} (\S+)".format(event + "-status"), line, re.M - ) + match = re.search(r"logging event {0} (\S+)".format(event + "-status"), line, re.M) if match: state = match.group(1) if state: @@ -515,9 +490,7 @@ def parse_event(line): def parse_message(line): message = None - match = re.search( - r"logging message interface type ethernet description", line, re.M - ) + match = re.search(r"logging message interface type ethernet description", line, re.M) if match: message = "add-interface-description" @@ -527,9 +500,7 @@ def parse_message(line): def parse_file_size(line, name, level): file_size = None - match = re.search( - r"logging logfile {0} {1} size (\S+)".format(name, level), line, re.M - ) + match = re.search(r"logging logfile {0} {1} size (\S+)".format(name, level), line, re.M) if match: file_size = match.group(1) if file_size == "8192" or file_size == "4194304": @@ -587,9 +558,7 @@ def parse_match(match): if dest and dest != "server": if dest == "logfile": - match = re.search( - r"logging logfile {0} (\S+)".format(name), line, re.M - ) + match = re.search(r"logging logfile {0} (\S+)".format(name), line, re.M) if match: dest_level = parse_match(match) @@ -614,9 +583,7 @@ def parse_facility_level(line, facility, dest): facility_level = match.group(1) elif facility is not None: - match = re.search( - r"logging level {0} (\S+)".format(facility), line, re.M - ) + match = re.search(r"logging level {0} (\S+)".format(facility), line, re.M) if match: facility_level = match.group(1) @@ -641,9 +608,7 @@ def parse_use_vrf(line, dest): use_vrf = None if dest and dest == "server": - match = re.search( - r"logging server (?:\S+) (?:\d+) use-vrf (\S+)", line, re.M - ) + match = re.search(r"logging server (?:\S+) (?:\d+) use-vrf (\S+)", line, re.M) if match: use_vrf = match.group(1) @@ -706,9 +671,7 @@ def map_config_to_obj(module): if level.isdigit(): facility_level = level else: - facility_link_status = parse_facility_link_status( - line, facility, level - ) + facility_link_status = parse_facility_link_status(line, facility, level) elif match.group(1) == "event" and state == "present": event = parse_event(line) @@ -737,7 +700,7 @@ def map_config_to_obj(module): "file_size": file_size, "message": parse_message(line), "timestamp": parse_timestamp(line), - } + }, ) cmd = [ @@ -764,10 +727,7 @@ def map_config_to_obj(module): if match.group(1) == "console" and match.group(2) == "critical": dest_level = "2" flag = True - elif ( - match.group(1) == "monitor" - and match.group(2) == "notifications" - ): + elif match.group(1) == "monitor" and match.group(2) == "notifications": dest_level = "5" flag = True if flag: @@ -786,7 +746,7 @@ def map_config_to_obj(module): "file_size": None, "message": None, "timestamp": None, - } + }, ) return obj @@ -866,7 +826,7 @@ def map_params_to_obj(module): "message": module.params["interface_message"], "file_size": file_size, "timestamp": module.params["timestamp"], - } + }, ) return obj @@ -916,7 +876,7 @@ def main(): "link-down-error", "link-up-notif", "link-up-error", - ] + ], ), event=dict( choices=[ @@ -924,7 +884,7 @@ def main(): "link-default", "trunk-enable", "trunk-default", - ] + ], ), interface_message=dict(choices=["add-interface-description"]), file_size=dict(type="int"), @@ -934,8 +894,6 @@ def main(): purge=dict(default=False, type="bool"), ) - argument_spec.update(nxos_argument_spec) - required_if = [ ("dest", "logfile", ["name"]), ("dest", "server", ["remote_server"]), @@ -968,9 +926,7 @@ def main(): save_module_context(module, merged_wants) if module.params.get("purge"): - pcommands = map_obj_to_commands( - module, (outliers(have, merged_wants), have) - ) + pcommands = map_obj_to_commands(module, (outliers(have, merged_wants), have)) if pcommands: if not module.check_mode: load_config(module, pcommands) diff --git a/plugins/modules/nxos_logging_global.py b/plugins/modules/nxos_logging_global.py index bef6fe78a..759dee67c 100644 --- a/plugins/modules/nxos_logging_global.py +++ b/plugins/modules/nxos_logging_global.py @@ -10,6 +10,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type DOCUMENTATION = """ @@ -19,9 +20,10 @@ - This module manages logging configuration on devices running Cisco NX-OS. version_added: 2.5.0 notes: -- Tested against NX-OS 9.3.6. +- Tested against NX-OS 9.3.6 on Cisco Nexus Switches. - Limited Support for Cisco MDS - This module works with connection C(network_cli) and C(httpapi). +- Tested against Cisco MDS NX-OS 9.2(2) with connection C(network_cli). author: Nilashish Chakraborty (@NilashishC) options: running_config: @@ -84,7 +86,9 @@ description: Set history table size. type: int ip: - description: IP configuration. + description: + - IP configuration. + - This option is unsupported on MDS switches. type: dict suboptions: access_list: @@ -136,7 +140,9 @@ type: str severity: *sev persistent_threshold: - description: Set persistent logging utilization alert threshold in percentage. + description: + - Set persistent logging utilization alert threshold in percentage. + - This option is unsupported on MDS switches. type: int size: description: Enter the logfile size in bytes. @@ -186,6 +192,7 @@ description: - Set RFC to which messages should compliant. - Syslogs will be compliant to RFC 5424. + - This option is unsupported on MDS switches. type: bool hosts: description: Enable forwarding to Remote Syslog Servers. @@ -216,10 +223,14 @@ - Trustpoint to use for client certificate authentication. type: str use_vrf: - description: Display per-VRF information. + description: + - Display per-VRF information. + - This option is unsupported on MDS switches. type: str source_interface: - description: Enable Source-Interface for Remote Syslog Server. + description: + - Enable Source-Interface for Remote Syslog Server. + - This option is unsupported on MDS switches. type: str timestamp: description: Set logging timestamp granularity. @@ -279,7 +290,7 @@ facility: local6 use_vrf: default origin_id: - hostname: True + hostname: true # Task output # ------------- @@ -565,7 +576,7 @@ facility: local6 use_vrf: default origin_id: - hostname: True + hostname: true # Task Output (redacted) # ----------------------- @@ -688,6 +699,7 @@ """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.logging_global.logging_global import ( Logging_globalArgs, ) diff --git a/plugins/modules/nxos_ntp.py b/plugins/modules/nxos_ntp.py index 61a366b22..046436d47 100644 --- a/plugins/modules/nxos_ntp.py +++ b/plugins/modules/nxos_ntp.py @@ -4,6 +4,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -118,9 +119,9 @@ import re from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( load_config, - nxos_argument_spec, run_commands, ) @@ -149,9 +150,7 @@ def get_ntp_source(module): source_type = None source = None command = "show run | inc ntp.source" - output = execute_show_command( - command, module, command_type="cli_show_ascii" - ) + output = execute_show_command(command, module, command_type="cli_show_ascii") if output: try: @@ -170,9 +169,7 @@ def get_ntp_source(module): def get_ntp_peer(module): command = "show run | inc ntp.(server|peer)" ntp_peer_list = [] - response = execute_show_command( - command, module, command_type="cli_show_ascii" - ) + response = execute_show_command(command, module, command_type="cli_show_ascii") if response: if isinstance(response, list): @@ -304,27 +301,17 @@ def config_ntp(delta, existing): if peer_type: if existing.get("peer_type") and existing.get("address"): ntp_cmds.append( - "no ntp {0} {1}".format( - existing.get("peer_type"), existing.get("address") - ) + "no ntp {0} {1}".format(existing.get("peer_type"), existing.get("address")), ) - ntp_cmds.append( - set_ntp_server_peer(peer_type, address, prefer, key_id, vrf_name) - ) + ntp_cmds.append(set_ntp_server_peer(peer_type, address, prefer, key_id, vrf_name)) if source: existing_source_type = existing.get("source_type") existing_source = existing.get("source") if existing_source_type and source_type != existing_source_type: - ntp_cmds.append( - "no ntp {0} {1}".format(existing_source_type, existing_source) - ) + ntp_cmds.append("no ntp {0} {1}".format(existing_source_type, existing_source)) if source == "default": if existing_source_type and existing_source: - ntp_cmds.append( - "no ntp {0} {1}".format( - existing_source_type, existing_source - ) - ) + ntp_cmds.append("no ntp {0} {1}".format(existing_source_type, existing_source)) else: ntp_cmds.append("ntp {0} {1}".format(source_type, source)) @@ -343,8 +330,6 @@ def main(): state=dict(choices=["absent", "present"], default="present"), ) - argument_spec.update(nxos_argument_spec) - module = AnsibleModule( argument_spec=argument_spec, mutually_exclusive=[["server", "peer"], ["source_addr", "source_int"]], @@ -418,9 +403,7 @@ def main(): elif state == "absent": if existing.get("peer_type") and existing.get("address"): - command = "no ntp {0} {1}".format( - existing["peer_type"], existing["address"] - ) + command = "no ntp {0} {1}".format(existing["peer_type"], existing["address"]) if command: commands.append([command]) @@ -432,9 +415,7 @@ def main(): if proposed_source_type: if proposed_source_type == existing_source_type: if proposed_source == existing_source: - command = "no ntp {0} {1}".format( - existing_source_type, existing_source - ) + command = "no ntp {0} {1}".format(existing_source_type, existing_source) if command: commands.append([command]) diff --git a/plugins/modules/nxos_ntp_auth.py b/plugins/modules/nxos_ntp_auth.py index 7ab6b657d..3e5643812 100644 --- a/plugins/modules/nxos_ntp_auth.py +++ b/plugins/modules/nxos_ntp_auth.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -102,14 +103,12 @@ import re +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule def execute_show_command(command, module): @@ -167,8 +166,7 @@ def get_ntp_auth_key(key_id, module): authentication_key = {} command = "show run | inc ntp.authentication-key.{0}".format(key_id) auth_regex = ( - r".*ntp\sauthentication-key\s(?P\d+)\s" - r"md5\s(?P\S+)\s(?P\S+).*" + r".*ntp\sauthentication-key\s(?P\d+)\smd5\s(?P\S+)\s(?P\S+).*" ) body = execute_show_command(command, module)[0] @@ -213,16 +211,12 @@ def auth_type_to_num(auth_type): return "0" -def set_ntp_auth_key( - key_id, md5string, auth_type, trusted_key, authentication -): +def set_ntp_auth_key(key_id, md5string, auth_type, trusted_key, authentication): ntp_auth_cmds = [] if key_id and md5string: auth_type_num = auth_type_to_num(auth_type) ntp_auth_cmds.append( - "ntp authentication-key {0} md5 {1} {2}".format( - key_id, md5string, auth_type_num - ) + "ntp authentication-key {0} md5 {1} {2}".format(key_id, md5string, auth_type_num), ) if trusted_key == "true": @@ -238,16 +232,12 @@ def set_ntp_auth_key( return ntp_auth_cmds -def remove_ntp_auth_key( - key_id, md5string, auth_type, trusted_key, authentication -): +def remove_ntp_auth_key(key_id, md5string, auth_type, trusted_key, authentication): auth_remove_cmds = [] if key_id: auth_type_num = auth_type_to_num(auth_type) auth_remove_cmds.append( - "no ntp authentication-key {0} md5 {1} {2}".format( - key_id, md5string, auth_type_num - ) + "no ntp authentication-key {0} md5 {1} {2}".format(key_id, md5string, auth_type_num), ) if authentication: @@ -265,11 +255,7 @@ def main(): state=dict(choices=["absent", "present"], default="present"), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() @@ -318,9 +304,7 @@ def main(): auth_toggle = True if not existing.get("key_id"): key_id = None - command = remove_ntp_auth_key( - key_id, md5string, auth_type, trusted_key, auth_toggle - ) + command = remove_ntp_auth_key(key_id, md5string, auth_type, trusted_key, auth_toggle) if command: commands.append(command) diff --git a/plugins/modules/nxos_ntp_global.py b/plugins/modules/nxos_ntp_global.py index 8833de98f..18cd851c9 100644 --- a/plugins/modules/nxos_ntp_global.py +++ b/plugins/modules/nxos_ntp_global.py @@ -10,6 +10,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type DOCUMENTATION = """ @@ -19,8 +20,9 @@ - This module manages ntp configuration on devices running Cisco NX-OS. version_added: 2.6.0 notes: -- Tested against NX-OS 9.3.6. +- Tested against NX-OS 9.3.6 on Cisco Nexus Switches. - This module works with connection C(network_cli) and C(httpapi). +- Tested against Cisco MDS NX-OS 9.2(2) with connection C(network_cli). author: Nilashish Chakraborty (@NilashishC) options: running_config: @@ -37,7 +39,9 @@ type: dict suboptions: access_group: - description: NTP access-group. + description: + - NTP access-group. + - This option is unsupported on MDS switches. type: dict suboptions: match_all: @@ -114,13 +118,16 @@ master: description: - Act as NTP master clock. + - This option is unsupported on MDS switches. type: dict suboptions: stratum: description: Stratum number. type: int passive: - description: NTP passive command. + description: + - NTP passive command. + - This option is unsupported on MDS switches. type: bool peers: description: NTP Peers. @@ -148,7 +155,9 @@ - Preferred Server. type: bool vrf: - description: Display per-VRF information. + description: + - Display per-VRF information. + - This option is unsupported on MDS switches. type: str aliases: ["use_vrf"] servers: @@ -177,11 +186,15 @@ - Preferred Server. type: bool vrf: - description: Display per-VRF information. + description: + - Display per-VRF information. + - This option is not applicable for MDS switches. type: str aliases: ["use_vrf"] source: - description: Source of NTP packets. + description: + - Source of NTP packets. + - This option is unsupported on MDS switches. type: str source_interface: description: Source interface sending NTP packets. @@ -228,7 +241,7 @@ - access_list: PeerAcl1 serve: - access_list: ServeAcl1 - authenticate: True + authenticate: true authentication_keys: - id: 1001 key: vagwwtKfkv @@ -236,7 +249,7 @@ - id: 1002 key: vagwwtKfkvgthz encryption: 7 - logging: True + logging: true master: stratum: 2 peers: @@ -247,7 +260,7 @@ vrf: default - peer: 192.0.2.2 key_id: 2 - prefer: True + prefer: true vrf: siteA servers: - server: 198.51.100.1 @@ -280,7 +293,7 @@ # - access_list: PeerAcl1 # serve: # - access_list: ServeAcl1 -# authenticate: True +# authenticate: true # authentication_keys: # - id: 1001 # key: vagwwtKfkv @@ -288,7 +301,7 @@ # - id: 1002 # key: vagwwtKfkvgthz # encryption: 7 -# logging: True +# logging: true # master: # stratum: 2 # peers: @@ -299,7 +312,7 @@ # vrf: default # - peer: 192.0.2.2 # key_id: 2 -# prefer: True +# prefer: true # vrf: siteA # servers: # - server: 198.51.100.1 @@ -349,7 +362,7 @@ - access_list: PeerAcl2 serve: - access_list: ServeAcl2 - logging: True + logging: true master: stratum: 2 peers: @@ -360,7 +373,7 @@ vrf: default - peer: 192.0.2.5 key_id: 2 - prefer: True + prefer: true vrf: siteA servers: - server: 198.51.100.1 @@ -376,7 +389,7 @@ # - access_list: PeerAcl1 # serve: # - access_list: ServeAcl1 -# authenticate: True +# authenticate: true # authentication_keys: # - id: 1001 # key: vagwwtKfkv @@ -384,7 +397,7 @@ # - id: 1002 # key: vagwwtKfkvgthz # encryption: 7 -# logging: True +# logging: true # master: # stratum: 2 # peers: @@ -395,7 +408,7 @@ # vrf: default # - peer: 192.0.2.2 # key_id: 2 -# prefer: True +# prefer: true # vrf: siteA # servers: # - server: 198.51.100.1 @@ -423,7 +436,7 @@ # - access_list: PeerAcl2 # serve: # - access_list: ServeAcl2 -# logging: True +# logging: true # master: # stratum: 2 # peers: @@ -434,7 +447,7 @@ # vrf: default # - peer: 192.0.2.5 # key_id: 2 -# prefer: True +# prefer: true # vrf: siteA # servers: # - server: 198.51.100.1 @@ -470,7 +483,7 @@ # - access_list: PeerAcl1 # serve: # - access_list: ServeAcl1 -# authenticate: True +# authenticate: true # authentication_keys: # - id: 1001 # key: vagwwtKfkv @@ -478,7 +491,7 @@ # - id: 1002 # key: vagwwtKfkvgthz # encryption: 7 -# logging: True +# logging: true # master: # stratum: 2 # peers: @@ -489,7 +502,7 @@ # vrf: default # - peer: 192.0.2.2 # key_id: 2 -# prefer: True +# prefer: true # vrf: siteA # servers: # - server: 198.51.100.1 @@ -529,7 +542,7 @@ - access_list: PeerAcl1 serve: - access_list: ServeAcl1 - authenticate: True + authenticate: true authentication_keys: - id: 1001 key: vagwwtKfkv @@ -537,7 +550,7 @@ - id: 1002 key: vagwwtKfkvgthz encryption: 7 - logging: True + logging: true master: stratum: 2 peers: @@ -548,7 +561,7 @@ vrf: default - peer: 192.0.2.2 key_id: 2 - prefer: True + prefer: true vrf: siteA servers: - server: 198.51.100.1 @@ -603,7 +616,7 @@ # - access_list: PeerAcl1 # serve: # - access_list: ServeAcl1 -# authenticate: True +# authenticate: true # authentication_keys: # - id: 1001 # key: vagwwtKfkv @@ -611,7 +624,7 @@ # - id: 1002 # key: vagwwtKfkvgthz # encryption: 7 -# logging: True +# logging: true # master: # stratum: 2 # peers: @@ -622,7 +635,7 @@ # vrf: default # - peer: 192.0.2.2 # key_id: 2 -# prefer: True +# prefer: true # vrf: siteA # servers: # - server: 198.51.100.1 @@ -687,6 +700,7 @@ """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.ntp_global.ntp_global import ( Ntp_globalArgs, ) diff --git a/plugins/modules/nxos_ntp_options.py b/plugins/modules/nxos_ntp_options.py index dd9729ab2..28fd1aac6 100644 --- a/plugins/modules/nxos_ntp_options.py +++ b/plugins/modules/nxos_ntp_options.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -82,14 +83,12 @@ """ import re +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule def get_current(module): @@ -119,11 +118,7 @@ def main(): state=dict(choices=["absent", "present"], default="present"), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() diff --git a/plugins/modules/nxos_nxapi.py b/plugins/modules/nxos_nxapi.py index 4dca946e9..400a7a5f5 100644 --- a/plugins/modules/nxos_nxapi.py +++ b/plugins/modules/nxos_nxapi.py @@ -17,6 +17,7 @@ # pylint: skip-file from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -138,8 +139,8 @@ cisco.nxos.nxos_nxapi: enable_http: false https_port: 9443 - https: yes - enable_sandbox: no + https: true + enable_sandbox: false - name: remove NXAPI configuration cisco.nxos.nxos_nxapi: @@ -157,20 +158,14 @@ """ import re -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import ( - Version, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - run_commands, - load_config, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( get_capabilities, + load_config, + run_commands, ) -from ansible.module_utils.basic import AnsibleModule +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.utils.utils import Version def check_args(module, warnings, capabilities): @@ -181,7 +176,7 @@ def check_args(module, warnings, capabilities): os_platform = capabilities["device_info"]["network_os_platform"] if "7K" not in os_platform and module.params["sandbox"]: module.fail_json( - msg="sandbox or enable_sandbox is supported on NX-OS 7K series of switches" + msg="sandbox or enable_sandbox is supported on NX-OS 7K series of switches", ) state = module.params["state"] @@ -190,13 +185,13 @@ def check_args(module, warnings, capabilities): module.params["state"] = "present" warnings.append( "state=started is deprecated and will be removed in a " - "a future release. Please use state=present instead" + "a future release. Please use state=present instead", ) elif state == "stopped": module.params["state"] = "absent" warnings.append( "state=stopped is deprecated and will be removed in a " - "a future release. Please use state=absent instead" + "a future release. Please use state=absent instead", ) for key in ["http_port", "https_port"]: @@ -255,15 +250,11 @@ def needs_update(x): commands["sandbox"] = "no %s" % commands["sandbox"] if os_platform and os_version: - if (os_platform == "N9K" or os_platform == "N3K") and Version( - os_version - ) >= "9.2": + if (os_platform == "N9K" or os_platform == "N3K") and Version(os_version) >= "9.2": if needs_update("ssl_strong_ciphers"): commands["ssl_strong_ciphers"] = "nxapi ssl ciphers weak" if want["ssl_strong_ciphers"] is True: - commands[ - "ssl_strong_ciphers" - ] = "no nxapi ssl ciphers weak" + commands["ssl_strong_ciphers"] = "no nxapi ssl ciphers weak" have_ssl_protocols = "" want_ssl_protocols = "" @@ -274,9 +265,7 @@ def needs_update(x): }.items(): if needs_update(key): if want.get(key) is True: - want_ssl_protocols = " ".join( - [want_ssl_protocols, value] - ) + want_ssl_protocols = " ".join([want_ssl_protocols, value]) elif have.get(key) is True: have_ssl_protocols = " ".join([have_ssl_protocols, value]) @@ -288,7 +277,7 @@ def needs_update(x): warnings.append( "os_version and/or os_platform keys from " "platform capabilities are not available. " - "Any NXAPI SSL optional arguments will be ignored" + "Any NXAPI SSL optional arguments will be ignored", ) send_commands.extend(commands.values()) @@ -323,9 +312,7 @@ def parse_https(data): def parse_sandbox(data): - sandbox = [ - item for item in data.split("\n") if re.search(r".*sandbox.*", item) - ] + sandbox = [item for item in data.split("\n") if re.search(r".*sandbox.*", item)] value = False if sandbox and sandbox[0] == "nxapi sandbox": value = True @@ -406,21 +393,13 @@ def main(): tlsv1_2=dict(type="bool", default=False), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() - warning_msg = ( - "Module nxos_nxapi currently defaults to configure 'http port 80'. " - ) + warning_msg = "Module nxos_nxapi currently defaults to configure 'http port 80'. " warning_msg += "Default behavior is changing to configure 'https port 443'" warning_msg += " when params 'http, http_port, https, https_port' are not set in the playbook" - module.deprecate( - msg=warning_msg, date="2022-06-01", collection_name="cisco.nxos" - ) + module.deprecate(msg=warning_msg, date="2022-06-01", collection_name="cisco.nxos") capabilities = get_capabilities(module) diff --git a/plugins/modules/nxos_ospf.py b/plugins/modules/nxos_ospf.py deleted file mode 100644 index 86e56bf5c..000000000 --- a/plugins/modules/nxos_ospf.py +++ /dev/null @@ -1,173 +0,0 @@ -#!/usr/bin/python -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - - -DOCUMENTATION = """ -module: nxos_ospf -extends_documentation_fragment: -- cisco.nxos.nxos -short_description: (deprecated, removed after 2022-06-01) Manages configuration - of an ospf instance. -description: -- Manages configuration of an ospf instance. -notes: -- Unsupported for Cisco MDS -version_added: 1.0.0 -author: Gabriele Gerbino (@GGabriele) -deprecated: - alternative: nxos_ospfv2 and nxos_ospfv3 - why: Updated modules released with more functionality. - removed_at_date: '2022-06-01' -options: - ospf: - description: - - Name of the ospf instance. - required: true - type: str - state: - description: - - Determines whether the config should be present or not on the device. - required: false - default: present - choices: - - present - - absent - type: str - -""" - -EXAMPLES = """ -- cisco.nxos.nxos_ospf: - ospf: 1 - state: present -""" - -RETURN = """ -commands: - description: commands sent to the device - returned: always - type: list - sample: ["router ospf 1"] -""" - -import re -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_config, - load_config, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( - CustomNetworkConfig, -) - - -PARAM_TO_COMMAND_KEYMAP = {"ospf": "router ospf"} - - -def get_value(config, module): - splitted_config = config.splitlines() - value_list = [] - REGEX = r"^router ospf\s(?P\S+).*" - for line in splitted_config: - value = "" - if "router ospf" in line: - try: - match_ospf = re.match(REGEX, line, re.DOTALL) - ospf_group = match_ospf.groupdict() - value = ospf_group["ospf"] - except AttributeError: - value = "" - if value: - value_list.append(value) - - return value_list - - -def get_existing(module): - existing = {} - config = str(get_config(module)) - - value = get_value(config, module) - if value: - existing["ospf"] = value - return existing - - -def state_present(module, proposed, candidate): - commands = ["router ospf {0}".format(proposed["ospf"])] - candidate.add(commands, parents=[]) - - -def state_absent(module, proposed, candidate): - commands = ["no router ospf {0}".format(proposed["ospf"])] - candidate.add(commands, parents=[]) - - -def main(): - argument_spec = dict( - ospf=dict(required=True, type="str"), - state=dict( - choices=["present", "absent"], default="present", required=False - ), - ) - - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) - - warnings = list() - result = dict(changed=False, warnings=warnings) - - state = module.params["state"] - ospf = str(module.params["ospf"]) - - existing = get_existing(module) - proposed = dict(ospf=ospf) - - if not existing: - existing_list = [] - else: - existing_list = existing["ospf"] - - candidate = CustomNetworkConfig(indent=3) - if state == "present" and ospf not in existing_list: - state_present(module, proposed, candidate) - if state == "absent" and ospf in existing_list: - state_absent(module, proposed, candidate) - - if candidate: - candidate = candidate.items_text() - load_config(module, candidate) - result["changed"] = True - result["commands"] = candidate - - else: - result["commands"] = [] - module.exit_json(**result) - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/nxos_ospf_interfaces.py b/plugins/modules/nxos_ospf_interfaces.py index 05953ef98..7ed26117a 100644 --- a/plugins/modules/nxos_ospf_interfaces.py +++ b/plugins/modules/nxos_ospf_interfaces.py @@ -10,6 +10,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type DOCUMENTATION = """ @@ -40,7 +41,7 @@ description: - Name/Identifier of the interface. type: str - required: True + required: true address_family: description: - OSPF settings on the interfaces in address-family context. @@ -52,7 +53,7 @@ - Address Family Identifier (AFI) for OSPF settings on the interfaces. type: str choices: ['ipv4', 'ipv6'] - required: True + required: true processes: description: - Interfaces configuration for an OSPF process. @@ -63,7 +64,7 @@ description: - OSPF process tag. type: str - required: True + required: true area: description: - Area associated with interface. @@ -73,7 +74,7 @@ description: - Area ID in IP address format. type: str - required: True + required: true secondaries: description: - Do not include secondary IPv4/IPv6 addresses. @@ -128,7 +129,7 @@ - Valid values are Cisco type 7 ENCRYPTED password, 3DES ENCRYPTED password and UNENCRYPTED (cleartext) password based on the value of encryption key. type: str - required: True + required: true message_digest_key: description: - Message digest authentication password (key) settings. @@ -138,7 +139,7 @@ description: - Key ID. type: int - required: True + required: true encryption: description: - 0 Specifies an UNENCRYPTED ospf password (key) will follow. @@ -151,7 +152,7 @@ - Valid values are Cisco type 7 ENCRYPTED password, 3DES ENCRYPTED password and UNENCRYPTED (cleartext) password based on the value of encryption key. type: str - required: True + required: true cost: description: - Cost associated with interface. @@ -235,164 +236,119 @@ config: - name: Ethernet1/1 address_family: - - afi: ipv4 - processes: - - process_id: "100" - area: - area_id: 1.1.1.1 - secondaries: False - multi_areas: - - 11.11.11.11 - - afi: ipv6 - processes: - - process_id: "200" - area: - area_id: 2.2.2.2 + - afi: ipv4 + processes: + - process_id: '100' + area: + area_id: 1.1.1.1 + secondaries: false multi_areas: - - 21.0.0.0 - - process_id: "300" + - 11.11.11.11 + - afi: ipv6 + processes: + - process_id: '200' + area: + area_id: 2.2.2.2 + multi_areas: + - 21.0.0.0 + - process_id: '300' + multi_areas: + - 50.50.50.50 multi_areas: - - 50.50.50.50 - multi_areas: - - 16.10.10.10 + - 16.10.10.10 - name: Ethernet1/2 address_family: - - afi: ipv4 - authentication: - enable: True - key_chain: test-1 - message_digest_key: - key_id: 10 - encryption: 3 - key: abc01d272be25d29 - cost: 100 - - afi: ipv6 - network: broadcast - shutdown: True + - afi: ipv4 + authentication: + enable: true + key_chain: test-1 + message_digest_key: + key_id: 10 + encryption: 3 + key: abc01d272be25d29 + cost: 100 + - afi: ipv6 + network: broadcast + shutdown: true - name: Ethernet1/3 address_family: - - afi: ipv4 - authentication_key: - encryption: 7 - key: 12090404011C03162E + - afi: ipv4 + authentication_key: + encryption: 7 + key: 12090404011C03162E state: merged -# Task output -# ------------- -# "before": [ -# { -# "name": "Ethernet1/1" -# }, -# { -# "name": "Ethernet1/2" -# }, -# { -# "name": "Ethernet1/3" -# }, -# ] +# Task output: +# ------------ +# before: +# - name: Ethernet1/1 +# - name: Ethernet1/2 +# - name: Ethernet1/3 # -# "commands": [ -# "interface Ethernet1/1", -# "ip router ospf multi-area 11.11.11.11", -# "ip router ospf 100 area 1.1.1.1 secondaries none", -# "ipv6 router ospfv3 multi-area 16.10.10.10", -# "ipv6 router ospfv3 200 area 2.2.2.2", -# "ipv6 router ospfv3 200 multi-area 21.0.0.0", -# "ipv6 router ospfv3 300 multi-area 50.50.50.50", -# "interface Ethernet1/2", -# "ip ospf authentication key-chain test-1", -# "ip ospf authentication", -# "ip ospf message-digest-key 10 md5 3 abc01d272be25d29", -# "ip ospf cost 100", -# "ospfv3 network broadcast", -# "ospfv3 shutdown", -# "interface Ethernet1/3", -# "ip ospf authentication-key 7 12090404011C03162E" -# ] +# commands: +# - interface Ethernet1/1 +# - ip router ospf multi-area 11.11.11.11 +# - ip router ospf 100 area 1.1.1.1 secondaries none +# - ipv6 router ospfv3 multi-area 16.10.10.10 +# - ipv6 router ospfv3 200 area 2.2.2.2 +# - ipv6 router ospfv3 200 multi-area 21.0.0.0 +# - ipv6 router ospfv3 300 multi-area 50.50.50.50 +# - interface Ethernet1/2 +# - ip ospf authentication key-chain test-1 +# - ip ospf authentication +# - ip ospf message-digest-key 10 md5 3 abc01d272be25d29 +# - ip ospf cost 100 +# - ospfv3 network broadcast +# - ospfv3 shutdown +# - interface Ethernet1/3 +# - ip ospf authentication-key 7 12090404011C03162E # -# "after": [ -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "multi_areas": [ -# "11.11.11.11" -# ], -# "processes": [ -# { -# "area": { -# "area_id": "1.1.1.1", -# "secondaries": false -# }, -# "process_id": "100" -# } -# ] -# }, -# { -# "afi": "ipv6", -# "multi_areas": [ -# "16.10.10.10" -# ], -# "processes": [ -# { -# "area": { -# "area_id": "2.2.2.2" -# }, -# "multi_areas": [ -# "21.0.0.0" -# ], -# "process_id": "200" -# }, -# { -# "multi_areas": [ -# "50.50.50.50" -# ], -# "process_id": "300" -# } -# ] -# } -# ], -# "name": "Ethernet1/1" -# }, -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "authentication": { -# "enable": true, -# "key_chain": "test-1" -# }, -# "cost": 100, -# "message_digest_key": { -# "encryption": 3, -# "key": "abc01d272be25d29", -# "key_id": 10 -# } -# }, -# { -# "afi": "ipv6", -# "network": "broadcast", -# "shutdown": true -# } -# ], -# "name": "Ethernet1/2" -# }, -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "authentication_key": { -# "encryption": 7, -# "key": "12090404011C03162E" -# } -# } -# ], -# "name": "Ethernet1/3" -# }, -# ] +# after: +# - address_family: +# - afi: ipv4 +# multi_areas: +# - 11.11.11.11 +# processes: +# - area: +# area_id: 1.1.1.1 +# secondaries: false +# process_id: '100' +# - afi: ipv6 +# multi_areas: +# - 16.10.10.10 +# processes: +# - area: +# area_id: 2.2.2.2 +# multi_areas: +# - 21.0.0.0 +# process_id: '200' +# - multi_areas: +# - 50.50.50.50 +# process_id: '300' +# name: Ethernet1/1 +# - address_family: +# - afi: ipv4 +# authentication: +# enable: true +# key_chain: test-1 +# cost: 100 +# message_digest_key: +# encryption: 3 +# key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER +# key_id: 10 +# - afi: ipv6 +# network: broadcast +# shutdown: true +# name: Ethernet1/2 +# - address_family: +# - afi: ipv4 +# authentication_key: +# encryption: 7 +# key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER +# name: Ethernet1/3 # After state: -# ------------- +# ------------ # NXOS# show running-config | section ^interface # interface Ethernet1/1 # no switchport @@ -418,7 +374,7 @@ # Using replaced # Before state: -# ------------ +# ------------- # NXOS# show running-config | section ^interface # interface Ethernet1/1 # no switchport @@ -443,164 +399,105 @@ - name: Replace OSPF configurations of listed interfaces with provided configurations cisco.nxos.nxos_ospf_interfaces: config: - - name: Ethernet1/1 - address_family: - - afi: ipv4 - processes: - - process_id: "100" - area: - area_id: 1.1.1.1 - secondaries: False - multi_areas: - - 11.11.11.12 - - name: Ethernet1/3 + - name: Ethernet1/1 + address_family: + - afi: ipv4 + processes: + - process_id: "100" + area: + area_id: 1.1.1.1 + secondaries: false + multi_areas: + - 11.11.11.12 + - name: Ethernet1/3 state: replaced -# Task output -# ------------- -# "before": [ -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "multi_areas": [ -# "11.11.11.11" -# ], -# "processes": [ -# { -# "area": { -# "area_id": "1.1.1.1", -# "secondaries": false -# }, -# "process_id": "100" -# } -# ] -# }, -# { -# "afi": "ipv6", -# "multi_areas": [ -# "16.10.10.10" -# ], -# "processes": [ -# { -# "area": { -# "area_id": "2.2.2.2" -# }, -# "multi_areas": [ -# "21.0.0.0" -# ], -# "process_id": "200" -# }, -# { -# "multi_areas": [ -# "50.50.50.50" -# ], -# "process_id": "300" -# } -# ] -# } -# ], -# "name": "Ethernet1/1" -# }, -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "authentication": { -# "enable": true, -# "key_chain": "test-1" -# }, -# "cost": 100, -# "message_digest_key": { -# "encryption": 3, -# "key": "abc01d272be25d29", -# "key_id": 10 -# } -# }, -# { -# "afi": "ipv6", -# "network": "broadcast", -# "shutdown": true -# } -# ], -# "name": "Ethernet1/2" -# }, -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "authentication_key": { -# "encryption": 7, -# "key": "12090404011C03162E" -# } -# } -# ], -# "name": "Ethernet1/3" -# }, -# ] +# Task output: +# ------------ +# before: +# - address_family: +# - afi: ipv4 +# multi_areas: +# - 11.11.11.11 +# processes: +# - area: +# area_id: 1.1.1.1 +# secondaries: false +# process_id: '100' +# - afi: ipv6 +# multi_areas: +# - 16.10.10.10 +# processes: +# - area: +# area_id: 2.2.2.2 +# multi_areas: +# - 21.0.0.0 +# process_id: '200' +# - multi_areas: +# - 50.50.50.50 +# process_id: '300' +# name: Ethernet1/1 +# - address_family: +# - afi: ipv4 +# authentication: +# enable: true +# key_chain: test-1 +# cost: 100 +# message_digest_key: +# encryption: 3 +# key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER +# key_id: 10 +# - afi: ipv6 +# network: broadcast +# shutdown: true +# name: Ethernet1/2 +# - address_family: +# - afi: ipv4 +# authentication_key: +# encryption: 7 +# key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER +# name: Ethernet1/3 # -# "commands": [ -# "interface Ethernet1/1", -# "ip router ospf multi-area 11.11.11.12", -# "no ip router ospf multi-area 11.11.11.11", -# "no ipv6 router ospfv3 multi-area 16.10.10.10", -# "no ipv6 router ospfv3 200 area 2.2.2.2", -# "no ipv6 router ospfv3 200 multi-area 21.0.0.0", -# "no ipv6 router ospfv3 300 multi-area 50.50.50.50", -# "interface Ethernet1/3", -# "no ip ospf authentication-key 7 12090404011C03162E" -# ] +# commands: +# - interface Ethernet1/1 +# - ip router ospf multi-area 11.11.11.12 +# - no ip router ospf multi-area 11.11.11.11 +# - no ipv6 router ospfv3 multi-area 16.10.10.10 +# - no ipv6 router ospfv3 200 area 2.2.2.2 +# - no ipv6 router ospfv3 200 multi-area 21.0.0.0 +# - no ipv6 router ospfv3 300 multi-area 50.50.50.50 +# - interface Ethernet1/3 +# - no ip ospf authentication-key 7 12090404011C03162E # -# "after": [ -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "multi_areas": [ -# "11.11.11.12" -# ], -# "processes": [ -# { -# "area": { -# "area_id": "1.1.1.1", -# "secondaries": false -# }, -# "process_id": "100" -# } -# ] -# } -# ], -# "name": "Ethernet1/1" -# }, -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "authentication": { -# "enable": true, -# "key_chain": "test-1" -# }, -# "cost": 100, -# "message_digest_key": { -# "encryption": 3, -# "key": "abc01d272be25d29", -# "key_id": 10 -# } -# }, -# { -# "afi": "ipv6", -# "network": "broadcast", -# "shutdown": true -# } -# ], -# "name": "Ethernet1/2" -# }, -# { -# "name": "Ethernet1/3" -# }, +# after: +# - address_family: +# - afi: ipv4 +# multi_areas: +# - 11.11.11.12 +# processes: +# - area: +# area_id: 1.1.1.1 +# secondaries: false +# process_id: '100' +# name: Ethernet1/1 +# - address_family: +# - afi: ipv4 +# authentication: +# enable: true +# key_chain: test-1 +# cost: 100 +# message_digest_key: +# encryption: 3 +# key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER +# key_id: 10 +# - afi: ipv6 +# network: broadcast +# shutdown: true +# name: Ethernet1/2 +# - name: Ethernet1/3 # # After state: -# ------------- +# ------------ # NXOS# show running-config | section ^interface # interface Ethernet1/1 # no switchport @@ -621,7 +518,7 @@ # Using overridden # Before state: -# ------------ +# ------------- # NXOS# show running-config | section ^interface # interface Ethernet1/1 # no switchport @@ -646,148 +543,95 @@ - name: Override all OSPF interfaces configuration with provided configuration cisco.nxos.nxos_ospf_interfaces: config: - - name: Ethernet1/1 - address_family: - - afi: ipv4 - processes: - - process_id: "100" - area: - area_id: 1.1.1.1 - secondaries: False - multi_areas: - - 11.11.11.12 + - name: Ethernet1/1 + address_family: + - afi: ipv4 + processes: + - process_id: "100" + area: + area_id: 1.1.1.1 + secondaries: false + multi_areas: + - 11.11.11.12 state: overridden -# Task output -# ------------- -# "before": [ -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "multi_areas": [ -# "11.11.11.11" -# ], -# "processes": [ -# { -# "area": { -# "area_id": "1.1.1.1", -# "secondaries": false -# }, -# "process_id": "100" -# } -# ] -# }, -# { -# "afi": "ipv6", -# "multi_areas": [ -# "16.10.10.10" -# ], -# "processes": [ -# { -# "area": { -# "area_id": "2.2.2.2" -# }, -# "multi_areas": [ -# "21.0.0.0" -# ], -# "process_id": "200" -# }, -# { -# "multi_areas": [ -# "50.50.50.50" -# ], -# "process_id": "300" -# } -# ] -# } -# ], -# "name": "Ethernet1/1" -# }, -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "authentication": { -# "enable": true, -# "key_chain": "test-1" -# }, -# "cost": 100, -# "message_digest_key": { -# "encryption": 3, -# "key": "abc01d272be25d29", -# "key_id": 10 -# } -# }, -# { -# "afi": "ipv6", -# "network": "broadcast", -# "shutdown": true -# } -# ], -# "name": "Ethernet1/2" -# }, -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "authentication_key": { -# "encryption": 7, -# "key": "12090404011C03162E" -# } -# } -# ], -# "name": "Ethernet1/3" -# }, -# ] +# Task output: +# ------------ +# before: +# - address_family: +# - afi: ipv4 +# multi_areas: +# - 11.11.11.11 +# processes: +# - area: +# area_id: 1.1.1.1 +# secondaries: false +# process_id: '100' +# - afi: ipv6 +# multi_areas: +# - 16.10.10.10 +# processes: +# - area: +# area_id: 2.2.2.2 +# multi_areas: +# - 21.0.0.0 +# process_id: '200' +# - multi_areas: +# - 50.50.50.50 +# process_id: '300' +# name: Ethernet1/1 +# - address_family: +# - afi: ipv4 +# authentication: +# enable: true +# key_chain: test-1 +# cost: 100 +# message_digest_key: +# encryption: 3 +# key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER +# key_id: 10 +# - afi: ipv6 +# network: broadcast +# shutdown: true +# name: Ethernet1/2 +# - address_family: +# - afi: ipv4 +# authentication_key: +# encryption: 7 +# key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER +# name: Ethernet1/3 # -# "commands": [ -# "interface Ethernet1/2", -# "no ip ospf authentication key-chain test-1", -# "no ip ospf authentication", -# "no ip ospf message-digest-key 10 md5 3 abc01d272be25d29", -# "no ip ospf cost 100", -# "no ospfv3 network broadcast", -# "no ospfv3 shutdown", -# "interface Ethernet1/3", -# "no ip ospf authentication-key 7 12090404011C03162E", -# "interface Ethernet1/1", -# "ip router ospf multi-area 11.11.11.12", -# "no ip router ospf multi-area 11.11.11.11", -# "no ipv6 router ospfv3 multi-area 16.10.10.10", -# "no ipv6 router ospfv3 200 area 2.2.2.2", -# "no ipv6 router ospfv3 200 multi-area 21.0.0.0", -# "no ipv6 router ospfv3 300 multi-area 50.50.50.50" -# ] +# commands: +# - interface Ethernet1/2 +# - no ip ospf authentication key-chain test-1 +# - no ip ospf authentication +# - no ip ospf message-digest-key 10 md5 3 abc01d272be25d29 +# - no ip ospf cost 100 +# - no ospfv3 network broadcast +# - no ospfv3 shutdown +# - interface Ethernet1/3 +# - no ip ospf authentication-key 7 12090404011C03162E +# - interface Ethernet1/1 +# - ip router ospf multi-area 11.11.11.12 +# - no ip router ospf multi-area 11.11.11.11 +# - no ipv6 router ospfv3 multi-area 16.10.10.10 +# - no ipv6 router ospfv3 200 area 2.2.2.2 +# - no ipv6 router ospfv3 200 multi-area 21.0.0.0 +# - no ipv6 router ospfv3 300 multi-area 50.50.50.50 # -# "after": [ -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "multi_areas": [ -# "11.11.11.12" -# ], -# "processes": [ -# { -# "area": { -# "area_id": "1.1.1.1", -# "secondaries": false -# }, -# "process_id": "100" -# } -# ] -# } -# ], -# "name": "Ethernet1/1" -# }, -# { -# "name": "Ethernet1/2" -# }, -# { -# "name": "Ethernet1/3" -# }, -# ] +# after: +# - address_family: +# - afi: ipv4 +# multi_areas: +# - 11.11.11.12 +# processes: +# - area: +# area_id: 1.1.1.1 +# secondaries: false +# process_id: '100' +# name: Ethernet1/1 +# - name: Ethernet1/2 +# - name: Ethernet1/3 # After state: # ------------- @@ -804,7 +648,7 @@ # Using deleted to delete OSPF config of a single interface # Before state: -# ------------ +# ------------- # NXOS# show running-config | section ^interface # interface Ethernet1/1 # no switchport @@ -832,139 +676,84 @@ - name: Ethernet1/1 state: deleted -# Task output -# ------------- -# "before": [ -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "multi_areas": [ -# "11.11.11.11" -# ], -# "processes": [ -# { -# "area": { -# "area_id": "1.1.1.1", -# "secondaries": false -# }, -# "process_id": "100" -# } -# ] -# }, -# { -# "afi": "ipv6", -# "multi_areas": [ -# "16.10.10.10" -# ], -# "processes": [ -# { -# "area": { -# "area_id": "2.2.2.2" -# }, -# "multi_areas": [ -# "21.0.0.0" -# ], -# "process_id": "200" -# }, -# { -# "multi_areas": [ -# "50.50.50.50" -# ], -# "process_id": "300" -# } -# ] -# } -# ], -# "name": "Ethernet1/1" -# }, -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "authentication": { -# "enable": true, -# "key_chain": "test-1" -# }, -# "cost": 100, -# "message_digest_key": { -# "encryption": 3, -# "key": "abc01d272be25d29", -# "key_id": 10 -# } -# }, -# { -# "afi": "ipv6", -# "network": "broadcast", -# "shutdown": true -# } -# ], -# "name": "Ethernet1/2" -# }, -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "authentication_key": { -# "encryption": 7, -# "key": "12090404011C03162E" -# } -# } -# ], -# "name": "Ethernet1/3" -# }, -# ] +# Task output: +# ------------ +# before: +# - address_family: +# - afi: ipv4 +# multi_areas: +# - 11.11.11.11 +# processes: +# - area: +# area_id: 1.1.1.1 +# secondaries: false +# process_id: '100' +# - afi: ipv6 +# multi_areas: +# - 16.10.10.10 +# processes: +# - area: +# area_id: 2.2.2.2 +# multi_areas: +# - 21.0.0.0 +# process_id: '200' +# - multi_areas: +# - 50.50.50.50 +# process_id: '300' +# name: Ethernet1/1 +# - address_family: +# - afi: ipv4 +# authentication: +# enable: true +# key_chain: test-1 +# cost: 100 +# message_digest_key: +# encryption: 3 +# key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER +# key_id: 10 +# - afi: ipv6 +# network: broadcast +# shutdown: true +# name: Ethernet1/2 +# - address_family: +# - afi: ipv4 +# authentication_key: +# encryption: 7 +# key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER +# name: Ethernet1/3 # -# "commands": [ -# "interface Ethernet1/1", -# "no ip router ospf multi-area 11.11.11.11", -# "no ip router ospf 100 area 1.1.1.1 secondaries none", -# "no ipv6 router ospfv3 multi-area 16.10.10.10", -# "no ipv6 router ospfv3 200 area 2.2.2.2", -# "no ipv6 router ospfv3 200 multi-area 21.0.0.0", -# "no ipv6 router ospfv3 300 multi-area 50.50.50.50" -# ] +# commands: +# - interface Ethernet1/1 +# - no ip router ospf multi-area 11.11.11.11 +# - no ip router ospf 100 area 1.1.1.1 secondaries none +# - no ipv6 router ospfv3 multi-area 16.10.10.10 +# - no ipv6 router ospfv3 200 area 2.2.2.2 +# - no ipv6 router ospfv3 200 multi-area 21.0.0.0 +# - no ipv6 router ospfv3 300 multi-area 50.50.50.50 # -# "before": [ -# { -# "name": "Ethernet1/1" -# }, -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "authentication": { -# "enable": true, -# "key_chain": "test-1" -# }, -# "cost": 100, -# "message_digest_key": { -# "encryption": 3, -# "key": "abc01d272be25d29", -# "key_id": 10 -# } -# }, -# { -# "afi": "ipv6", -# "network": "broadcast", -# "shutdown": true -# } -# ], -# "name": "Ethernet1/2" -# }, -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "authentication_key": { -# "encryption": 7, -# "key": "12090404011C03162E" -# } -# } -# ], -# "name": "Ethernet1/3" -# }, -# ] +# after: +# - name: Ethernet1/1 +# - address_family: +# - afi: ipv4 +# authentication: +# enable: true +# key_chain: test-1 +# cost: 100 +# message_digest_key: +# encryption: 3 +# key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER +# key_id: 10 +# - afi: ipv6 +# network: broadcast +# shutdown: true +# name: Ethernet1/2 +# - address_family: +# - afi: ipv4 +# authentication_key: +# encryption: 7 +# key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER +# name: Ethernet1/3 + # After state: # ------------ @@ -986,7 +775,7 @@ # Using deleted to delete OSPF config from all interfaces # Before state: -# ------------ +# ------------- # NXOS# show running-config | section ^interface # interface Ethernet1/1 # no switchport @@ -1012,119 +801,53 @@ cisco.nxos.nxos_ospf_interfaces: state: deleted -# Task output -# ------------- -# "before": [ -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "multi_areas": [ -# "11.11.11.11" -# ], -# "processes": [ -# { -# "area": { -# "area_id": "1.1.1.1", -# "secondaries": false -# }, -# "process_id": "100" -# } -# ] -# }, -# { -# "afi": "ipv6", -# "multi_areas": [ -# "16.10.10.10" -# ], -# "processes": [ -# { -# "area": { -# "area_id": "2.2.2.2" -# }, -# "multi_areas": [ -# "21.0.0.0" -# ], -# "process_id": "200" -# }, -# { -# "multi_areas": [ -# "50.50.50.50" -# ], -# "process_id": "300" -# } -# ] -# } -# ], -# "name": "Ethernet1/1" -# }, -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "authentication": { -# "enable": true, -# "key_chain": "test-1" -# }, -# "cost": 100, -# "message_digest_key": { -# "encryption": 3, -# "key": "abc01d272be25d29", -# "key_id": 10 -# } -# }, -# { -# "afi": "ipv6", -# "network": "broadcast", -# "shutdown": true -# } -# ], -# "name": "Ethernet1/2" -# }, -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "authentication_key": { -# "encryption": 7, -# "key": "12090404011C03162E" -# } -# } -# ], -# "name": "Ethernet1/3" -# }, -# ] +# Task output: +# ------------ +# before: +# - name: Ethernet1/1 +# - address_family: +# - afi: ipv4 +# authentication: +# enable: true +# key_chain: test-1 +# cost: 100 +# message_digest_key: +# encryption: 3 +# key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER +# key_id: 10 +# - afi: ipv6 +# network: broadcast +# shutdown: true +# name: Ethernet1/2 +# - address_family: +# - afi: ipv4 +# authentication_key: +# encryption: 7 +# key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER +# name: Ethernet1/3 # -# "commands": [ -# "interface Ethernet1/1", -# "no ip router ospf multi-area 11.11.11.11", -# "no ip router ospf 100 area 1.1.1.1 secondaries none", -# "no ipv6 router ospfv3 multi-area 16.10.10.10", -# "no ipv6 router ospfv3 200 area 2.2.2.2", -# "no ipv6 router ospfv3 200 multi-area 21.0.0.0", -# "no ipv6 router ospfv3 300 multi-area 50.50.50.50", -# "interface Ethernet1/2", -# "no ip ospf authentication key-chain test-1", -# "no ip ospf authentication", -# "no ip ospf message-digest-key 10 md5 3 abc01d272be25d29", -# "no ip ospf cost 100", -# "no ospfv3 network broadcast", -# "no ospfv3 shutdown", -# "interface Ethernet1/3", -# "no ip ospf authentication-key 7 12090404011C03162E" -# ] +# commands: +# - interface Ethernet1/1 +# - no ip router ospf multi-area 11.11.11.11 +# - no ip router ospf 100 area 1.1.1.1 secondaries none +# - no ipv6 router ospfv3 multi-area 16.10.10.10 +# - no ipv6 router ospfv3 200 area 2.2.2.2 +# - no ipv6 router ospfv3 200 multi-area 21.0.0.0 +# - no ipv6 router ospfv3 300 multi-area 50.50.50.50 +# - interface Ethernet1/2 +# - no ip ospf authentication key-chain test-1 +# - no ip ospf authentication +# - no ip ospf message-digest-key 10 md5 3 abc01d272be25d29 +# - no ip ospf cost 100 +# - no ospfv3 network broadcast +# - no ospfv3 shutdown +# - interface Ethernet1/3 +# - no ip ospf authentication-key 7 12090404011C03162E # -# "after": [ -# { -# "name": "Ethernet1/1" -# }, -# { -# "name": "Ethernet1/2" -# }, -# { -# "name": "Ethernet1/3" -# }, -# ] +# after: +# - name: Ethernet1/1 +# - name: Ethernet1/2 +# - name: Ethernet1/3 # After state: # ------------ @@ -1138,73 +861,75 @@ # Using rendered -- name: Render platform specific configuration lines with state rendered (without connecting to the device) +- name: >- + Render platform specific configuration lines with state rendered (without + connecting to the device) cisco.nxos.nxos_ospf_interfaces: config: - name: Ethernet1/1 address_family: - - afi: ipv4 - processes: - - process_id: "100" - area: - area_id: 1.1.1.1 - secondaries: False - multi_areas: - - 11.11.11.11 - - afi: ipv6 - processes: - - process_id: "200" - area: - area_id: 2.2.2.2 + - afi: ipv4 + processes: + - process_id: '100' + area: + area_id: 1.1.1.1 + secondaries: false multi_areas: - - 21.0.0.0 - - process_id: "300" + - 11.11.11.11 + - afi: ipv6 + processes: + - process_id: '200' + area: + area_id: 2.2.2.2 + multi_areas: + - 21.0.0.0 + - process_id: '300' + multi_areas: + - 50.50.50.50 multi_areas: - - 50.50.50.50 - multi_areas: - - 16.10.10.10 + - 16.10.10.10 - name: Ethernet1/2 address_family: - - afi: ipv4 - authentication: - enable: True - key_chain: test-1 - message_digest_key: - key_id: 10 - encryption: 3 - key: abc01d272be25d29 - cost: 100 - - afi: ipv6 - network: broadcast - shutdown: True + - afi: ipv4 + authentication: + enable: true + key_chain: test-1 + message_digest_key: + key_id: 10 + encryption: 3 + key: abc01d272be25d29 + cost: 100 + - afi: ipv6 + network: broadcast + shutdown: true - name: Ethernet1/3 address_family: - - afi: ipv4 - authentication_key: - encryption: 7 - key: 12090404011C03162E + - afi: ipv4 + authentication_key: + encryption: 7 + key: 12090404011C03162E state: rendered -# Task Output (redacted) -# ----------------------- -# "rendered": [ -# "interface Ethernet1/1", -# "ip router ospf multi-area 11.11.11.11", -# "ip router ospf 100 area 1.1.1.1 secondaries none", -# "ipv6 router ospfv3 multi-area 16.10.10.10", -# "ipv6 router ospfv3 200 area 2.2.2.2", -# "ipv6 router ospfv3 200 multi-area 21.0.0.0", -# "ipv6 router ospfv3 300 multi-area 50.50.50.50", -# "interface Ethernet1/2", -# "ip ospf authentication key-chain test-1", -# "ip ospf authentication", -# "ip ospf message-digest-key 10 md5 3 abc01d272be25d29", -# "ip ospf cost 100", -# "ospfv3 network broadcast", -# "ospfv3 shutdown", -# "interface Ethernet1/3", -# "ip ospf authentication-key 7 12090404011C03162E" -# ] + +# Task Output: +# ------------ +# rendered: +# - interface Ethernet1/1 +# - ip router ospf multi-area 11.11.11.11 +# - ip router ospf 100 area 1.1.1.1 secondaries none +# - ipv6 router ospfv3 multi-area 16.10.10.10 +# - ipv6 router ospfv3 200 area 2.2.2.2 +# - ipv6 router ospfv3 200 multi-area 21.0.0.0 +# - ipv6 router ospfv3 300 multi-area 50.50.50.50 +# - interface Ethernet1/2 +# - ip ospf authentication key-chain test-1 +# - ip ospf authentication +# - ip ospf message-digest-key 10 md5 3 abc01d272be25d29 +# - ip ospf cost 100 +# - ospfv3 network broadcast +# - ospfv3 shutdown +# - interface Ethernet1/3 +# - ip ospf authentication-key 7 12090404011C03162E # Using parsed @@ -1232,88 +957,51 @@ running_config: "{{ lookup('file', 'ospf_interfaces.cfg') }}" state: parsed -# Task output (redacted) -# ----------------------- -# "parsed": [ -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "multi_areas": [ -# "11.11.11.11" -# ], -# "processes": [ -# { -# "area": { -# "area_id": "1.1.1.1", -# "secondaries": false -# }, -# "process_id": "100" -# } -# ] -# }, -# { -# "afi": "ipv6", -# "multi_areas": [ -# "16.10.10.10" -# ], -# "processes": [ -# { -# "area": { -# "area_id": "2.2.2.2" -# }, -# "multi_areas": [ -# "21.0.0.0" -# ], -# "process_id": "200" -# }, -# { -# "multi_areas": [ -# "50.50.50.50" -# ], -# "process_id": "300" -# } -# ] -# } -# ], -# "name": "Ethernet1/1" -# }, -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "authentication": { -# "enable": true, -# "key_chain": "test-1" -# }, -# "cost": 100, -# "message_digest_key": { -# "encryption": 3, -# "key": "abc01d272be25d29", -# "key_id": 10 -# } -# }, -# { -# "afi": "ipv6", -# "network": "broadcast", -# "shutdown": true -# } -# ], -# "name": "Ethernet1/2" -# }, -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "authentication_key": { -# "encryption": 7, -# "key": "12090404011C03162E" -# } -# } -# ], -# "name": "Ethernet1/3" -# }, -# ] +# Task output: +# ------------ +# parsed: +# - address_family: +# - afi: ipv4 +# multi_areas: +# - 11.11.11.11 +# processes: +# - area: +# area_id: 1.1.1.1 +# secondaries: false +# process_id: '100' +# - afi: ipv6 +# multi_areas: +# - 16.10.10.10 +# processes: +# - area: +# area_id: 2.2.2.2 +# multi_areas: +# - 21.0.0.0 +# process_id: '200' +# - multi_areas: +# - 50.50.50.50 +# process_id: '300' +# name: Ethernet1/1 +# - address_family: +# - afi: ipv4 +# authentication: +# enable: true +# key_chain: test-1 +# cost: 100 +# message_digest_key: +# encryption: 3 +# key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER +# key_id: 10 +# - afi: ipv6 +# network: broadcast +# shutdown: true +# name: Ethernet1/2 +# - address_family: +# - afi: ipv4 +# authentication_key: +# encryption: 7 +# key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER +# name: Ethernet1/3 # Using gathered @@ -1335,55 +1023,34 @@ # interface Ethernet1/3 # no switchport -# Task output (redacted) -# ----------------------- -# "gathered": [ -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "multi_areas": [ -# "11.11.11.12" -# ], -# "processes": [ -# { -# "area": { -# "area_id": "1.1.1.1", -# "secondaries": false -# }, -# "process_id": "100" -# } -# ] -# } -# ], -# "name": "Ethernet1/1" -# }, -# { -# "address_family": [ -# { -# "afi": "ipv4", -# "authentication": { -# "enable": true, -# "key_chain": "test-1" -# }, -# "cost": 100, -# "message_digest_key": { -# "encryption": 3, -# "key": "abc01d272be25d29", -# "key_id": 10 -# } -# }, -# { -# "afi": "ipv6", -# "network": "broadcast", -# "shutdown": true -# } -# ], -# "name": "Ethernet1/2" -# }, -# { -# "name": "Ethernet1/3" -# }, +# Task output: +# ------------ +# gathered: +# - address_family: +# - afi: ipv4 +# multi_areas: +# - 11.11.11.12 +# processes: +# - area: +# area_id: 1.1.1.1 +# secondaries: false +# process_id: '100' +# name: Ethernet1/1 +# - address_family: +# - afi: ipv4 +# authentication: +# enable: true +# key_chain: test-1 +# cost: 100 +# message_digest_key: +# encryption: 3 +# key: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER +# key_id: 10 +# - afi: ipv6 +# network: broadcast +# shutdown: true +# name: Ethernet1/2 +# - name: Ethernet1/3 """ RETURN = """ before: @@ -1415,9 +1082,32 @@ - interface Ethernet1/2 - no ip ospf authentication key-chain test-1 - ip ospf authentication +rendered: + description: The provided configuration in the task rendered in device-native format (offline). + returned: when I(state) is C(rendered) + type: list + sample: + - interface Ethernet1/1 + - ip router ospf multi-area 11.11.11.11 + - ip router ospf 100 area 1.1.1.1 secondaries none +gathered: + description: Facts about the network resource gathered from the remote device as structured data. + returned: when I(state) is C(gathered) + type: list + sample: > + This output will always be in the same format as the + module argspec. +parsed: + description: The device native config provided in I(running_config) option parsed into structured data as per module argspec. + returned: when I(state) is C(parsed) + type: list + sample: > + This output will always be in the same format as the + module argspec. """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.ospf_interfaces.ospf_interfaces import ( Ospf_interfacesArgs, ) diff --git a/plugins/modules/nxos_ospf_vrf.py b/plugins/modules/nxos_ospf_vrf.py deleted file mode 100644 index 17deb8bba..000000000 --- a/plugins/modules/nxos_ospf_vrf.py +++ /dev/null @@ -1,496 +0,0 @@ -#!/usr/bin/python -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - - -DOCUMENTATION = """ -module: nxos_ospf_vrf -extends_documentation_fragment: -- cisco.nxos.nxos -short_description: (deprecated, removed after 2022-10-01)Manages a VRF for an OSPF router. -description: -- Manages a VRF for an OSPF router. -version_added: 1.0.0 -author: Gabriele Gerbino (@GGabriele) -deprecated: - alternative: nxos_ospfv2 and nxos_ospfv3 - why: Updated modules released with more functionality. - removed_at_date: '2022-10-01' -notes: -- Tested against NXOSv 7.3.(0)D1(1) on VIRL -- Unsupported for Cisco MDS -- Value I(default) restores params default value, if any. Otherwise it removes the - existing param configuration. -options: - vrf: - description: - - Name of the resource instance. Valid value is a string. The name 'default' is - a valid VRF representing the global OSPF. - default: default - type: str - ospf: - description: - - Name of the OSPF instance. - required: true - type: str - router_id: - description: - - Router Identifier (ID) of the OSPF router VRF instance. - type: str - default_metric: - description: - - Specify the default Metric value. Valid values are an integer or the keyword - 'default'. - type: str - log_adjacency: - description: - - Controls the level of log messages generated whenever a neighbor changes state. - Valid values are 'log', 'detail', and 'default'. - choices: - - log - - detail - - default - type: str - timer_throttle_lsa_start: - description: - - Specify the start interval for rate-limiting Link-State Advertisement (LSA) - generation. Valid values are an integer, in milliseconds, or the keyword 'default'. - type: str - timer_throttle_lsa_hold: - description: - - Specify the hold interval for rate-limiting Link-State Advertisement (LSA) generation. - Valid values are an integer, in milliseconds, or the keyword 'default'. - type: str - timer_throttle_lsa_max: - description: - - Specify the max interval for rate-limiting Link-State Advertisement (LSA) generation. - Valid values are an integer, in milliseconds, or the keyword 'default'. - type: str - timer_throttle_spf_start: - description: - - Specify initial Shortest Path First (SPF) schedule delay. Valid values are an - integer, in milliseconds, or the keyword 'default'. - type: str - timer_throttle_spf_hold: - description: - - Specify minimum hold time between Shortest Path First (SPF) calculations. Valid - values are an integer, in milliseconds, or the keyword 'default'. - type: str - timer_throttle_spf_max: - description: - - Specify the maximum wait time between Shortest Path First (SPF) calculations. - Valid values are an integer, in milliseconds, or the keyword 'default'. - type: str - auto_cost: - description: - - Specifies the reference bandwidth used to assign OSPF cost. Valid values are - an integer, in Mbps, or the keyword 'default'. - type: str - bfd: - description: - - Enables BFD on all OSPF interfaces. - - "Dependency: ''feature bfd''" - type: str - choices: - - enable - - disable - passive_interface: - description: - - Setting to C(yes) will suppress routing update on interface. - type: bool - state: - description: - - State of ospf vrf configuration. - default: present - choices: - - present - - absent - type: str -""" - -EXAMPLES = """ -- cisco.nxos.nxos_ospf_vrf: - ospf: 1 - timer_throttle_spf_start: 50 - timer_throttle_spf_hold: 1000 - timer_throttle_spf_max: 2000 - timer_throttle_lsa_start: 60 - timer_throttle_lsa_hold: 1100 - timer_throttle_lsa_max: 3000 - vrf: test - bfd: enable - state: present -""" - -RETURN = """ -commands: - description: commands sent to the device - returned: always - type: list - sample: - - router ospf 1 - - vrf test - - bfd - - timers throttle lsa 60 1100 3000 -""" - -import re -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_config, - load_config, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( - CustomNetworkConfig, -) - - -BOOL_PARAMS = ["passive_interface"] -PARAM_TO_COMMAND_KEYMAP = { - "vrf": "vrf", - "router_id": "router-id", - "default_metric": "default-metric", - "log_adjacency": "log-adjacency-changes", - "timer_throttle_lsa_start": "timers throttle lsa", - "timer_throttle_lsa_max": "timers throttle lsa", - "timer_throttle_lsa_hold": "timers throttle lsa", - "timer_throttle_spf_max": "timers throttle spf", - "timer_throttle_spf_start": "timers throttle spf", - "timer_throttle_spf_hold": "timers throttle spf", - "auto_cost": "auto-cost reference-bandwidth", - "bfd": "bfd", - "passive_interface": "passive-interface default", -} -PARAM_TO_DEFAULT_KEYMAP = { - "timer_throttle_lsa_start": "0", - "timer_throttle_lsa_max": "5000", - "timer_throttle_lsa_hold": "5000", - "timer_throttle_spf_start": "200", - "timer_throttle_spf_max": "5000", - "timer_throttle_spf_hold": "1000", - "auto_cost": "40000", - "bfd": "disable", - "default_metric": "", - "passive_interface": False, - "router_id": "", - "log_adjacency": "", -} - - -def get_existing(module, args): - existing = {} - netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) - parents = ["router ospf {0}".format(module.params["ospf"])] - - if module.params["vrf"] != "default": - parents.append("vrf {0}".format(module.params["vrf"])) - - config = netcfg.get_section(parents) - for arg in args: - if arg not in ["ospf", "vrf"]: - existing[arg] = PARAM_TO_DEFAULT_KEYMAP.get(arg) - - if config: - if module.params["vrf"] == "default": - splitted_config = config.splitlines() - vrf_index = False - for index in range(0, len(splitted_config) - 1): - if "vrf" in splitted_config[index].strip(): - vrf_index = index - break - if vrf_index: - config = "\n".join(splitted_config[0:vrf_index]) - - splitted_config = config.splitlines() - for line in splitted_config: - if "passive" in line: - existing["passive_interface"] = True - elif "router-id" in line: - existing["router_id"] = re.search( - r"router-id (\S+)", line - ).group(1) - elif "metric" in line: - existing["default_metric"] = re.search( - r"default-metric (\S+)", line - ).group(1) - elif "adjacency" in line: - log = re.search( - r"log-adjacency-changes(?: (\S+))?", line - ).group(1) - if log: - existing["log_adjacency"] = log - else: - existing["log_adjacency"] = "log" - elif "auto" in line: - cost = re.search( - r"auto-cost reference-bandwidth (\d+) (\S+)", line - ).group(1) - if "Gbps" in line: - cost = int(cost) * 1000 - existing["auto_cost"] = str(cost) - elif "bfd" in line: - existing["bfd"] = "enable" - elif "timers throttle lsa" in line: - tmp = re.search(r"timers throttle lsa (\S+) (\S+) (\S+)", line) - existing["timer_throttle_lsa_start"] = tmp.group(1) - existing["timer_throttle_lsa_hold"] = tmp.group(2) - existing["timer_throttle_lsa_max"] = tmp.group(3) - elif "timers throttle spf" in line: - tmp = re.search(r"timers throttle spf (\S+) (\S+) (\S+)", line) - existing["timer_throttle_spf_start"] = tmp.group(1) - existing["timer_throttle_spf_hold"] = tmp.group(2) - existing["timer_throttle_spf_max"] = tmp.group(3) - existing["vrf"] = module.params["vrf"] - existing["ospf"] = module.params["ospf"] - - return existing - - -def apply_key_map(key_map, table): - new_dict = {} - for key in table: - new_key = key_map.get(key) - if new_key: - new_dict[new_key] = table.get(key) - return new_dict - - -def get_timer_prd(key, proposed): - if proposed.get(key): - return proposed.get(key) - else: - return PARAM_TO_DEFAULT_KEYMAP.get(key) - - -def state_present(module, existing, proposed, candidate): - commands = list() - proposed_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, proposed) - existing_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, existing) - - for key, value in proposed_commands.items(): - if key == "vrf": - continue - if value is True: - commands.append(key) - - elif value is False: - if key == "passive-interface default": - if existing_commands.get(key): - commands.append("no {0}".format(key)) - else: - commands.append("no {0}".format(key)) - - elif value == "default" or value == "": - if key == "log-adjacency-changes": - commands.append("no {0}".format(key)) - elif existing_commands.get(key): - existing_value = existing_commands.get(key) - commands.append("no {0} {1}".format(key, existing_value)) - else: - if key == "timers throttle lsa": - command = "{0} {1} {2} {3}".format( - key, - get_timer_prd("timer_throttle_lsa_start", proposed), - get_timer_prd("timer_throttle_lsa_hold", proposed), - get_timer_prd("timer_throttle_lsa_max", proposed), - ) - elif key == "timers throttle spf": - command = "{0} {1} {2} {3}".format( - key, - get_timer_prd("timer_throttle_spf_start", proposed), - get_timer_prd("timer_throttle_spf_hold", proposed), - get_timer_prd("timer_throttle_spf_max", proposed), - ) - elif key == "log-adjacency-changes": - if value == "log": - command = key - elif value == "detail": - command = "{0} {1}".format(key, value) - elif key == "auto-cost reference-bandwidth": - if len(value) < 5: - command = "{0} {1} Mbps".format(key, value) - else: - value = str(int(value) // 1000) - command = "{0} {1} Gbps".format(key, value) - elif key == "bfd": - command = "no bfd" if value == "disable" else "bfd" - else: - command = "{0} {1}".format(key, value.lower()) - - if command not in commands: - commands.append(command) - - if commands: - parents = ["router ospf {0}".format(module.params["ospf"])] - if module.params["vrf"] != "default": - parents.append("vrf {0}".format(module.params["vrf"])) - candidate.add(commands, parents=parents) - - -def state_absent(module, existing, proposed, candidate): - commands = [] - parents = ["router ospf {0}".format(module.params["ospf"])] - if module.params["vrf"] == "default": - existing_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, existing) - for key, value in existing_commands.items(): - if value and key != "vrf": - command = None - if key == "passive-interface default": - command = "no {0}".format(key) - elif key == "timers throttle lsa": - if ( - existing["timer_throttle_lsa_start"] - != PARAM_TO_DEFAULT_KEYMAP.get( - "timer_throttle_lsa_start" - ) - or existing["timer_throttle_lsa_hold"] - != PARAM_TO_DEFAULT_KEYMAP.get( - "timer_throttle_lsa_hold" - ) - or existing["timer_throttle_lsa_max"] - != PARAM_TO_DEFAULT_KEYMAP.get( - "timer_throttle_lsa_max" - ) - ): - command = "no {0} {1} {2} {3}".format( - key, - existing["timer_throttle_lsa_start"], - existing["timer_throttle_lsa_hold"], - existing["timer_throttle_lsa_max"], - ) - elif key == "timers throttle spf": - if ( - existing["timer_throttle_spf_start"] - != PARAM_TO_DEFAULT_KEYMAP.get( - "timer_throttle_spf_start" - ) - or existing["timer_throttle_spf_hold"] - != PARAM_TO_DEFAULT_KEYMAP.get( - "timer_throttle_spf_hold" - ) - or existing["timer_throttle_spf_max"] - != PARAM_TO_DEFAULT_KEYMAP.get( - "timer_throttle_spf_max" - ) - ): - command = "no {0} {1} {2} {3}".format( - key, - existing["timer_throttle_spf_start"], - existing["timer_throttle_spf_hold"], - existing["timer_throttle_spf_max"], - ) - elif key == "log-adjacency-changes": - command = "no {0}".format(key) - elif key == "auto-cost reference-bandwidth": - if value != PARAM_TO_DEFAULT_KEYMAP.get("auto_cost"): - command = "no {0}".format(key) - else: - command = None - elif key == "bfd": - if value == "enable": - command = "no bfd" - else: - existing_value = existing_commands.get(key) - command = "no {0} {1}".format(key, existing_value) - - if command: - if command not in commands: - commands.append(command) - else: - if existing.get("vrf") and existing.get("vrf") == module.params["vrf"]: - commands = ["no vrf {0}".format(module.params["vrf"])] - - if commands: - candidate.add(commands, parents=parents) - - -def main(): - argument_spec = dict( - vrf=dict(required=False, type="str", default="default"), - ospf=dict(required=True, type="str"), - router_id=dict(required=False, type="str"), - default_metric=dict(required=False, type="str"), - log_adjacency=dict( - required=False, type="str", choices=["log", "detail", "default"] - ), - timer_throttle_lsa_start=dict(required=False, type="str"), - timer_throttle_lsa_hold=dict(required=False, type="str"), - timer_throttle_lsa_max=dict(required=False, type="str"), - timer_throttle_spf_start=dict(required=False, type="str"), - timer_throttle_spf_hold=dict(required=False, type="str"), - timer_throttle_spf_max=dict(required=False, type="str"), - auto_cost=dict(required=False, type="str"), - bfd=dict(required=False, type="str", choices=["enable", "disable"]), - passive_interface=dict(required=False, type="bool"), - state=dict( - choices=["present", "absent"], default="present", required=False - ), - ) - - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) - - warnings = list() - result = dict(changed=False, commands=[], warnings=warnings) - - state = module.params["state"] - args = PARAM_TO_COMMAND_KEYMAP.keys() - existing = get_existing(module, args) - proposed_args = dict( - (k, v) for k, v in module.params.items() if v is not None and k in args - ) - - proposed = {} - for key, value in proposed_args.items(): - if key != "interface": - if str(value).lower() == "true": - value = True - elif str(value).lower() == "false": - value = False - elif str(value).lower() == "default": - value = PARAM_TO_DEFAULT_KEYMAP.get(key) - if value is None: - value = "default" - if existing.get(key) != value: - proposed[key] = value - - candidate = CustomNetworkConfig(indent=3) - if state == "present": - state_present(module, existing, proposed, candidate) - if state == "absent" and existing: - state_absent(module, existing, proposed, candidate) - - if candidate: - candidate = candidate.items_text() - result["commands"] = candidate - if not module.check_mode: - load_config(module, candidate) - result["changed"] = True - module.exit_json(**result) - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/nxos_ospfv2.py b/plugins/modules/nxos_ospfv2.py index 3499abbf0..1d127b707 100644 --- a/plugins/modules/nxos_ospfv2.py +++ b/plugins/modules/nxos_ospfv2.py @@ -28,6 +28,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -1017,60 +1018,60 @@ cisco.nxos.nxos_ospfv2: config: processes: - - process_id: 100 - router_id: 203.0.113.20 - - process_id: 102 - router_id: 198.51.100.1 - areas: - - area_id: 0.0.0.100 - filter_list: - - route_map: rmap_1 - direction: in - - route_map: rmap_2 - direction: out - ranges: - - prefix: 198.51.100.64/27 - not_advertise: true - - prefix: 198.51.100.96/27 - cost: 120 - - area_id: 0.0.0.101 - authentication: - message_digest: true - redistribute: - - protocol: eigrp - id: 120 - route_map: rmap_1 - - protocol: direct - route_map: ospf102-direct-connect - vrfs: - - vrf: zone1 - router_id: 198.51.100.129 - redistribute: - - protocol: static - route_map: zone1-static-connect - summary_address: - - prefix: 198.51.100.128/27 - tag: 121 - - prefix: 198.51.100.160/27 + - process_id: 100 + router_id: 203.0.113.20 + - process_id: 102 + router_id: 198.51.100.1 areas: - - area_id: 0.0.0.102 - nssa: - default_information_originate: true - no_summary: true - - area_id: 0.0.0.103 - nssa: - no_summary: true - translate: - type7: - always: true - - vrf: zone2 - auto_cost: - reference_bandwidth: 45 - unit: Gbps + - area_id: 0.0.0.100 + filter_list: + - route_map: rmap_1 + direction: in + - route_map: rmap_2 + direction: out + ranges: + - prefix: 198.51.100.64/27 + not_advertise: true + - prefix: 198.51.100.96/27 + cost: 120 + - area_id: 0.0.0.101 + authentication: + message_digest: true + redistribute: + - protocol: eigrp + id: 120 + route_map: rmap_1 + - protocol: direct + route_map: ospf102-direct-connect + vrfs: + - vrf: zone1 + router_id: 198.51.100.129 + redistribute: + - protocol: static + route_map: zone1-static-connect + summary_address: + - prefix: 198.51.100.128/27 + tag: 121 + - prefix: 198.51.100.160/27 + areas: + - area_id: 0.0.0.102 + nssa: + default_information_originate: true + no_summary: true + - area_id: 0.0.0.103 + nssa: + no_summary: true + translate: + type7: + always: true + - vrf: zone2 + auto_cost: + reference_bandwidth: 45 + unit: Gbps state: merged -# Task output -# ------------- +# Task output: +# ------------ # before: {} # # commands: @@ -1198,45 +1199,48 @@ # vrf zone2 # auto-cost reference-bandwidth 45 Gbps -- name: Replace device configurations of listed OSPF processes with provided configurations +- name: >- + Replace device configurations of listed OSPF processes with provided + configurations cisco.nxos.nxos_ospfv2: config: processes: - - process_id: 102 - router_id: 198.51.100.1 - areas: - - area_id: 0.0.0.100 - filter_list: - - route_map: rmap_8 - direction: in - ranges: - - prefix: 198.51.100.64/27 - not_advertise: true - - area_id: 0.0.0.101 - stub: - no_summary: true - redistribute: - - protocol: eigrp - id: 130 - route_map: rmap_1 - - protocol: direct - route_map: ospf102-direct-connect - vrfs: - - vrf: zone1 - router_id: 198.51.100.129 - redistribute: - - protocol: bgp - id: 65563 - route_map: zone1-bgp-connect + - process_id: 102 + router_id: 198.51.100.1 areas: - - area_id: 0.0.0.102 - nssa: - default_information_originate: true - no_summary: true + - area_id: 0.0.0.100 + filter_list: + - route_map: rmap_8 + direction: in + ranges: + - prefix: 198.51.100.64/27 + not_advertise: true + - area_id: 0.0.0.101 + stub: + no_summary: true + redistribute: + - protocol: eigrp + id: 130 + route_map: rmap_1 + - protocol: direct + route_map: ospf102-direct-connect + vrfs: + - vrf: zone1 + router_id: 198.51.100.129 + redistribute: + - protocol: bgp + id: 65563 + route_map: zone1-bgp-connect + areas: + - area_id: 0.0.0.102 + nssa: + default_information_originate: true + no_summary: true state: replaced -# Task output -# ------------- + +# Task output: +# ------------ # before: # processes: # - process_id: "100" @@ -1388,15 +1392,15 @@ cisco.nxos.nxos_ospfv2: config: processes: - - process_id: 104 - router_id: 203.0.113.20 - - process_id: 102 - router_id: 198.51.100.1 - shutdown: true + - process_id: 104 + router_id: 203.0.113.20 + - process_id: 102 + router_id: 198.51.100.1 + shutdown: true state: overridden -# Task output -# ------------- +# Task output: +# ------------ # before: # processes: # - process_id: "100" @@ -1510,11 +1514,11 @@ cisco.nxos.nxos_ospfv2: config: processes: - - process_id: 102 + - process_id: 102 state: deleted -# Task output -# ------------- +# Task output: +# ------------ # before: # processes: # - process_id: "100" @@ -1609,8 +1613,8 @@ cisco.nxos.nxos_ospfv2: state: deleted -# Task output -# ------------- +# Task output: +# ------------ # before: # processes: # - process_id: "100" @@ -1673,64 +1677,67 @@ # Using rendered -- name: Render platform specific configuration lines (without connecting to the device) +- name: >- + Render platform specific configuration lines (without connecting to the + device) cisco.nxos.nxos_ospfv2: config: processes: - - process_id: 100 - router_id: 203.0.113.20 - - process_id: 102 - router_id: 198.51.100.1 - areas: - - area_id: 0.0.0.100 - filter_list: - - route_map: rmap_1 - direction: in - - route_map: rmap_2 - direction: out - ranges: - - prefix: 198.51.100.64/27 - not_advertise: true - - prefix: 198.51.100.96/27 - cost: 120 - - area_id: 0.0.0.101 - authentication: - message_digest: true - redistribute: - - protocol: eigrp - id: 120 - route_map: rmap_1 - - protocol: direct - route_map: ospf102-direct-connect - vrfs: - - vrf: zone1 - router_id: 198.51.100.129 - redistribute: - - protocol: static - route_map: zone1-static-connect - summary_address: - - prefix: 198.51.100.128/27 - tag: 121 - - prefix: 198.51.100.160/27 + - process_id: 100 + router_id: 203.0.113.20 + - process_id: 102 + router_id: 198.51.100.1 areas: - - area_id: 0.0.0.102 - nssa: - default_information_originate: true - no_summary: true - - area_id: 0.0.0.103 - nssa: - no_summary: true - translate: - type7: - always: true - - vrf: zone2 - auto_cost: - reference_bandwidth: 45 - unit: Gbps + - area_id: 0.0.0.100 + filter_list: + - route_map: rmap_1 + direction: in + - route_map: rmap_2 + direction: out + ranges: + - prefix: 198.51.100.64/27 + not_advertise: true + - prefix: 198.51.100.96/27 + cost: 120 + - area_id: 0.0.0.101 + authentication: + message_digest: true + redistribute: + - protocol: eigrp + id: 120 + route_map: rmap_1 + - protocol: direct + route_map: ospf102-direct-connect + vrfs: + - vrf: zone1 + router_id: 198.51.100.129 + redistribute: + - protocol: static + route_map: zone1-static-connect + summary_address: + - prefix: 198.51.100.128/27 + tag: 121 + - prefix: 198.51.100.160/27 + areas: + - area_id: 0.0.0.102 + nssa: + default_information_originate: true + no_summary: true + - area_id: 0.0.0.103 + nssa: + no_summary: true + translate: + type7: + always: true + - vrf: zone2 + auto_cost: + reference_bandwidth: 45 + unit: Gbps state: rendered -# Task Output (redacted) -# ----------------------- + +# Task output: +# ------------ # rendered: # - router ospf 100 # - router-id 203.0.113.20 @@ -1793,8 +1800,8 @@ running_config: "{{ lookup('file', 'ospfv2.cfg') }}" state: parsed -# Task output (redacted) -# ----------------------- +# Task output: +# ------------ # parsed: # processes: # - process_id: "100" @@ -1868,8 +1875,8 @@ cisco.nxos.nxos_ospfv2: state: gathered -# Task output (redacted) -# ----------------------- +# Task output: +# ------------ # gathered: # processes: # - process_id: "102" @@ -1943,10 +1950,33 @@ - "vrf zone2" - "auto-cost reference-bandwidth 45 Gbps" - "capability vrf-lite evpn" +rendered: + description: The provided configuration in the task rendered in device-native format (offline). + returned: when I(state) is C(rendered) + type: list + sample: + - "router ospf 102" + - "router-id 198.54.100.1" + - "router ospf 100" +gathered: + description: Facts about the network resource gathered from the remote device as structured data. + returned: when I(state) is C(gathered) + type: dict + sample: > + This output will always be in the same format as the + module argspec. +parsed: + description: The device native config provided in I(running_config) option parsed into structured data as per module argspec. + returned: when I(state) is C(parsed) + type: dict + sample: > + This output will always be in the same format as the + module argspec. """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.ospfv2.ospfv2 import ( Ospfv2Args, ) diff --git a/plugins/modules/nxos_ospfv3.py b/plugins/modules/nxos_ospfv3.py index 706479f17..226de291b 100644 --- a/plugins/modules/nxos_ospfv3.py +++ b/plugins/modules/nxos_ospfv3.py @@ -28,6 +28,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type DOCUMENTATION = """ @@ -86,7 +87,7 @@ description: - The Area ID in IP Address format. type: str - required: True + required: true default_cost: description: - Specify the default cost. @@ -101,13 +102,13 @@ description: - The Route-map name. type: str - required: True + required: true direction: description: - The direction to apply the route map. type: str choices: [in, out] - required: True + required: true ranges: description: - Configure an address range for the area. @@ -118,7 +119,7 @@ description: - IP in Prefix format (x.x.x.x/len) type: str - required: True + required: true cost: description: - Cost to use for the range. @@ -168,7 +169,7 @@ - The name of the protocol. type: str choices: [bgp, direct, eigrp, isis, lisp, ospfv3, rip, static] - required: True + required: true id: description: - The identifier for the protocol specified. @@ -177,7 +178,7 @@ description: - The route map policy to constrain redistribution. type: str - required: True + required: true summary_address: description: - Configure route summarization for redistribution. @@ -188,7 +189,7 @@ description: - IPv6 prefix format 'xxxx:xxxx/ml', 'xxxx:xxxx::/ml' or 'xxxx::xx/128' type: str - required: True + required: true not_advertise: description: - Suppress advertising the specified summary. @@ -207,7 +208,7 @@ description: - The Route Map name. type: str - required: True + required: true filter: description: - Block the OSPF routes from being sent to RIB. @@ -249,7 +250,7 @@ description: - The Area ID in IP Address format. type: str - required: True + required: true nssa: description: - NSSA settings for the area. @@ -319,12 +320,12 @@ description: - Reference bandwidth used to assign OSPF cost. type: int - required: True + required: true unit: description: - Specify in which unit the reference bandwidth is specified. type: str - required: True + required: true choices: [Gbps, Mbps] flush_routes: description: @@ -377,7 +378,7 @@ description: - Set the maximum number of non self-generated LSAs. type: int - required: True + required: true threshold: description: - Threshold value (%) at which to generate a warning message. @@ -476,7 +477,7 @@ description: - The OSPF process tag. type: str - required: True + required: true router_id: description: - Set OSPF process router-id. @@ -536,7 +537,7 @@ description: - The Area ID in IP Address format. type: str - required: True + required: true nssa: description: - NSSA settings for the area. @@ -606,12 +607,12 @@ description: - Reference bandwidth used to assign OSPF cost. type: int - required: True + required: true unit: description: - Specify in which unit the reference bandwidth is specified. type: str - required: True + required: true choices: [Gbps, Mbps] graceful_restart: description: @@ -656,7 +657,7 @@ description: - Set the maximum number of non self-generated LSAs. type: int - required: True + required: true threshold: description: - Threshold value (%) at which to generate a warning message. @@ -798,7 +799,7 @@ description: - Name/Identifier of the VRF. type: str - required: True + required: true state: description: - The state the configuration should be left in. @@ -825,53 +826,53 @@ cisco.nxos.nxos_ospfv3: config: processes: - - process_id: 100 - router_id: 203.0.113.20 - - process_id: 102 - router_id: 198.51.100.1 - address_family: - afi: ipv6 - safi: unicast - areas: - - area_id: 0.0.0.100 - filter_list: - - route_map: rmap_1 - direction: in - - route_map: rmap_2 - direction: out - ranges: - - prefix: 2001:db2::/32 - not_advertise: true - - prefix: 2001:db3::/32 - cost: 120 - redistribute: - - protocol: eigrp - id: 120 - route_map: rmap_1 - - protocol: direct - route_map: ospf102-direct-connect - vrfs: - - vrf: zone1 - router_id: 198.51.100.129 - areas: - - area_id: 0.0.0.102 - nssa: - default_information_originate: true - no_summary: true - - area_id: 0.0.0.103 - nssa: - no_summary: true - translate: - type7: - always: true - - vrf: zone2 - auto_cost: - reference_bandwidth: 45 - unit: Gbps + - process_id: 100 + router_id: 203.0.113.20 + - process_id: 102 + router_id: 198.51.100.1 + address_family: + afi: ipv6 + safi: unicast + areas: + - area_id: 0.0.0.100 + filter_list: + - route_map: rmap_1 + direction: in + - route_map: rmap_2 + direction: out + ranges: + - prefix: '2001:db2::/32' + not_advertise: true + - prefix: '2001:db3::/32' + cost: 120 + redistribute: + - protocol: eigrp + id: 120 + route_map: rmap_1 + - protocol: direct + route_map: ospf102-direct-connect + vrfs: + - vrf: zone1 + router_id: 198.51.100.129 + areas: + - area_id: 0.0.0.102 + nssa: + default_information_originate: true + no_summary: true + - area_id: 0.0.0.103 + nssa: + no_summary: true + translate: + type7: + always: true + - vrf: zone2 + auto_cost: + reference_bandwidth: 45 + unit: Gbps state: merged -# Task output -# ------------- +# Task output: +# ------------ # before: {} # # commands: @@ -966,7 +967,7 @@ # Using replaced # Before state: -# ------------ +# ------------- # nxos-9k-rdo# sh running-config | section "^router ospfv3" # router ospfv3 100 # router-id 203.0.113.20 @@ -991,37 +992,37 @@ cisco.nxos.nxos_ospfv3: config: processes: - - process_id: 102 - router_id: 198.51.100.1 - address_family: - afi: ipv6 - safi: unicast - areas: - - area_id: 0.0.0.100 - filter_list: - - route_map: rmap_8 - direction: in - ranges: - - not_advertise: true - prefix: 2001:db2::/32 - redistribute: - - protocol: eigrp - id: 130 - route_map: rmap_1 - - protocol: direct - route_map: ospf102-direct-connect - vrfs: - - vrf: zone1 - router_id: 198.51.100.129 - areas: - - area_id: 0.0.0.102 - nssa: - default_information_originate: True - no_summary: True + - process_id: 102 + router_id: 198.51.100.1 + address_family: + afi: ipv6 + safi: unicast + areas: + - area_id: 0.0.0.100 + filter_list: + - route_map: rmap_8 + direction: in + ranges: + - not_advertise: true + prefix: 2001:db2::/32 + redistribute: + - protocol: eigrp + id: 130 + route_map: rmap_1 + - protocol: direct + route_map: ospf102-direct-connect + vrfs: + - vrf: zone1 + router_id: 198.51.100.129 + areas: + - area_id: 0.0.0.102 + nssa: + default_information_originate: true + no_summary: true state: replaced -# Task output -# ------------- +# Task output: +# ------------ # before: # processes: # - process_id: "100" @@ -1132,7 +1133,7 @@ # Using overridden # Before state: -# ------------ +# ------------- # nxos-9k-rdo# sh running-config | section "^router ospfv3" # router ospfv3 100 # router-id 203.0.113.20 @@ -1157,15 +1158,15 @@ cisco.nxos.nxos_ospfv3: config: processes: - - process_id: 104 - router_id: 203.0.113.20 - - process_id: 102 - router_id: 198.51.100.1 - shutdown: true + - process_id: 104 + router_id: 203.0.113.20 + - process_id: 102 + router_id: 198.51.100.1 + shutdown: true state: overridden -# Task output -# ------------- +# Task output: +# ------------ # before: # processes: # - process_id: "100" @@ -1252,7 +1253,7 @@ # Using deleted to delete a single OSPF process # Before state: -# ------------ +# ------------- # nxos-9k-rdo# sh running-config | section "^router ospf .*" # router ospfv3 100 # router-id 203.0.113.20 @@ -1277,11 +1278,11 @@ cisco.nxos.nxos_ospfv3: config: processes: - - process_id: 102 + - process_id: 102 state: deleted -# Task output -# ------------- +# Task output: +# ------------ # before: # processes: # - process_id: "100" @@ -1329,7 +1330,7 @@ # vrf: zone2 # # commands: -# - no router ospfv3 102 +# - no router ospfv3 102 # # after: # processes: @@ -1345,7 +1346,7 @@ # Using deleted all OSPFv3 processes from the device # Before state: -# ------------ +# ------------- # nxos-9k-rdo# sh running-config | section "^router ospfv3" # router ospfv3 100 # router-id 203.0.113.20 @@ -1370,8 +1371,8 @@ cisco.nxos.nxos_ospfv3: state: deleted -# Task output -# ------------- +# Task output: +# ------------ # before: # processes: # - process_id: "100" @@ -1435,53 +1436,53 @@ cisco.nxos.nxos_ospfv3: config: processes: - - process_id: 100 - router_id: 203.0.113.20 - - process_id: 102 - router_id: 198.51.100.1 - address_family: - afi: ipv6 - safi: unicast - areas: - - area_id: 0.0.0.100 - filter_list: - - route_map: rmap_1 - direction: in - - route_map: rmap_2 - direction: out - ranges: - - prefix: 2001:db2::/32 - not_advertise: true - - prefix: 2001:db3::/32 - cost: 120 - redistribute: - - protocol: eigrp - id: 120 - route_map: rmap_1 - - protocol: direct - route_map: ospf102-direct-connect - vrfs: - - vrf: zone1 - router_id: 198.51.100.129 - areas: - - area_id: 0.0.0.102 - nssa: - default_information_originate: true - no_summary: true - - area_id: 0.0.0.103 - nssa: - no_summary: true - translate: - type7: - always: true - - vrf: zone2 - auto_cost: - reference_bandwidth: 45 - unit: Gbps + - process_id: 100 + router_id: 203.0.113.20 + - process_id: 102 + router_id: 198.51.100.1 + address_family: + afi: ipv6 + safi: unicast + areas: + - area_id: 0.0.0.100 + filter_list: + - route_map: rmap_1 + direction: in + - route_map: rmap_2 + direction: out + ranges: + - prefix: 2001:db2::/32 + not_advertise: true + - prefix: 2001:db3::/32 + cost: 120 + redistribute: + - protocol: eigrp + id: 120 + route_map: rmap_1 + - protocol: direct + route_map: ospf102-direct-connect + vrfs: + - vrf: zone1 + router_id: 198.51.100.129 + areas: + - area_id: 0.0.0.102 + nssa: + default_information_originate: true + no_summary: true + - area_id: 0.0.0.103 + nssa: + no_summary: true + translate: + type7: + always: true + - vrf: zone2 + auto_cost: + reference_bandwidth: 45 + unit: Gbps state: rendered -# Task Output (redacted) -# ----------------------- +# Task output: +# ------------ # rendered: # - router ospfv3 100 # - router-id 203.0.113.20 @@ -1527,8 +1528,8 @@ running_config: "{{ lookup('file', 'ospfv2.cfg') }}" state: parsed -# Task output (redacted) -# ----------------------- +# Task output: +# ------------ # parsed: # processes: # - process_id: "100" @@ -1570,7 +1571,7 @@ # router_id: 192.0.100.2 # - process_id: "102" # router_id: 198.54.100.1 -# shutdown: True +# shutdown: true # Using gathered @@ -1578,8 +1579,8 @@ cisco.nxos.nxos_ospfv3: state: gathered -# Task output (redacted) -# ----------------------- +# Task output: +# ------------ # gathered: # processes: # - process_id: "100" @@ -1662,9 +1663,32 @@ - "router-id 192.0.100.2" - "vrf zone2" - "auto-cost reference-bandwidth 45 Gbps" +rendered: + description: The provided configuration in the task rendered in device-native format (offline). + returned: when I(state) is C(rendered) + type: list + sample: + - "router ospfv3 102" + - "router-id 198.54.100.1" + - "router ospfv3 100" +gathered: + description: Facts about the network resource gathered from the remote device as structured data. + returned: when I(state) is C(gathered) + type: dict + sample: > + This output will always be in the same format as the + module argspec. +parsed: + description: The device native config provided in I(running_config) option parsed into structured data as per module argspec. + returned: when I(state) is C(parsed) + type: dict + sample: > + This output will always be in the same format as the + module argspec. """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.ospfv3.ospfv3 import ( Ospfv3Args, ) diff --git a/plugins/modules/nxos_overlay_global.py b/plugins/modules/nxos_overlay_global.py index d62a8ffed..70b25246a 100644 --- a/plugins/modules/nxos_overlay_global.py +++ b/plugins/modules/nxos_overlay_global.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -57,21 +58,19 @@ """ import re -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_config, - load_config, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) + from ansible.module_utils.basic import AnsibleModule from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( CustomNetworkConfig, ) -PARAM_TO_COMMAND_KEYMAP = { - "anycast_gateway_mac": "fabric forwarding anycast-gateway-mac" -} +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + get_config, + load_config, +) + + +PARAM_TO_COMMAND_KEYMAP = {"anycast_gateway_mac": "fabric forwarding anycast-gateway-mac"} def get_existing(module, args): @@ -80,9 +79,7 @@ def get_existing(module, args): for arg in args: command = PARAM_TO_COMMAND_KEYMAP[arg] - has_command = re.findall( - r"(?:{0}\s)(?P.*)$".format(command), config, re.M - ) + has_command = re.findall(r"(?:{0}\s)(?P.*)$".format(command), config, re.M) value = "" if has_command: value = has_command[0] @@ -157,9 +154,7 @@ def normalize_mac(proposed_mac, module): else: raise ValueError except ValueError: - module.fail_json( - msg="Invalid MAC address format", proposed_mac=proposed_mac - ) + module.fail_json(msg="Invalid MAC address format", proposed_mac=proposed_mac) joined_mac = "".join(splitted_mac) # fmt: off @@ -171,11 +166,7 @@ def normalize_mac(proposed_mac, module): def main(): argument_spec = dict(anycast_gateway_mac=dict(required=True, type="str")) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() result = {"changed": False, "commands": [], "warnings": warnings} @@ -183,9 +174,7 @@ def main(): args = PARAM_TO_COMMAND_KEYMAP.keys() existing = get_existing(module, args) - proposed = dict( - (k, v) for k, v in module.params.items() if v is not None and k in args - ) + proposed = dict((k, v) for k, v in module.params.items() if v is not None and k in args) candidate = CustomNetworkConfig(indent=3) get_commands(module, existing, proposed, candidate) diff --git a/plugins/modules/nxos_pim.py b/plugins/modules/nxos_pim.py index 65ead8cf9..d9fc6f469 100644 --- a/plugins/modules/nxos_pim.py +++ b/plugins/modules/nxos_pim.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -48,6 +49,7 @@ address. If you set multicast address, please ensure that it is not the same as the C(default), otherwise use the C(default) option. type: list + default: [] elements: str """ EXAMPLES = """ @@ -78,18 +80,16 @@ import re -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_config, - load_config, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) from ansible.module_utils.basic import AnsibleModule from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( CustomNetworkConfig, ) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + get_config, + load_config, +) + PARAM_TO_COMMAND_KEYMAP = { "bfd": "ip pim bfd", @@ -157,16 +157,10 @@ def get_commands(module, existing, proposed, candidate): def main(): argument_spec = dict( bfd=dict(required=False, type="str", choices=["enable", "disable"]), - ssm_range=dict( - required=False, type="list", default=[], elements="str" - ), + ssm_range=dict(required=False, type="list", default=[], elements="str"), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() result = {"changed": False, "commands": [], "warnings": warnings} @@ -181,7 +175,7 @@ def main(): if len(item.split(".")) != 4: module.fail_json( msg="Valid ssm_range values are multicast addresses " - "or the keyword 'none' or the keyword 'default'." + "or the keyword 'none' or the keyword 'default'.", ) existing = get_existing(module, args) diff --git a/plugins/modules/nxos_pim_interface.py b/plugins/modules/nxos_pim_interface.py index 3d3b31426..4d0f1052b 100644 --- a/plugins/modules/nxos_pim_interface.py +++ b/plugins/modules/nxos_pim_interface.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import, division, print_function + __metaclass__ = type # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) @@ -166,18 +167,15 @@ """ import re + from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( get_config, + get_interface_type, load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_interface_type, -) PARAM_TO_COMMAND_KEYMAP = { @@ -286,7 +284,8 @@ def get_pim_interface(module, interface): for each in all_lines: if "jp-policy" in each: policy_name = re.search( - r"ip pim jp-policy(?: prefix-list)? (\S+)(?: \S+)?", each + r"ip pim jp-policy(?: prefix-list)? (\S+)(?: \S+)?", + each, ).group(1) if "prefix-list" in each: ptype = "prefix" @@ -304,7 +303,8 @@ def get_pim_interface(module, interface): pim_interface["jp_bidir"] = True elif "neighbor-policy" in each: pim_interface["neighbor_policy"] = re.search( - r"ip pim neighbor-policy(?: prefix-list)? (\S+)", each + r"ip pim neighbor-policy(?: prefix-list)? (\S+)", + each, ).group(1) if "prefix-list" in each: pim_interface["neighbor_type"] = "prefix" @@ -315,23 +315,18 @@ def get_pim_interface(module, interface): elif "sparse-mode" in each: pim_interface["sparse"] = True elif "bfd-instance" in each: - m = re.search( - r"ip pim bfd-instance(?P disable)?", each - ) + m = re.search(r"ip pim bfd-instance(?P disable)?", each) if m: - pim_interface["bfd"] = ( - "disable" if m.group("disable") else "enable" - ) + pim_interface["bfd"] = "disable" if m.group("disable") else "enable" elif "border" in each: pim_interface["border"] = True elif "hello-interval" in each: pim_interface["hello_interval"] = re.search( - r"ip pim hello-interval (\d+)", body + r"ip pim hello-interval (\d+)", + body, ).group(1) elif "dr-priority" in each: - pim_interface["dr_prio"] = re.search( - r"ip pim dr-priority (\d+)", body - ).group(1) + pim_interface["dr_prio"] = re.search(r"ip pim dr-priority (\d+)", body).group(1) return pim_interface @@ -339,10 +334,7 @@ def get_pim_interface(module, interface): def fix_delta(delta, existing): for key in list(delta): if key in ["dr_prio", "hello_interval", "sparse", "border"]: - if ( - delta.get(key) == PARAM_TO_DEFAULT_KEYMAP.get(key) - and existing.get(key) is None - ): + if delta.get(key) == PARAM_TO_DEFAULT_KEYMAP.get(key) and existing.get(key) is None: delta.pop(key) return delta @@ -356,13 +348,9 @@ def config_pim_interface(delta, existing, jp_bidir, isauth): if jp_bidir: if delta.get("jp_policy_in") or delta.get("jp_policy_out"): if existing.get("jp_type_in") == "prefix": - command = "no ip pim jp-policy prefix-list {0}".format( - existing.get("jp_policy_in") - ) + command = "no ip pim jp-policy prefix-list {0}".format(existing.get("jp_policy_in")) else: - command = "no ip pim jp-policy {0}".format( - existing.get("jp_policy_in") - ) + command = "no ip pim jp-policy {0}".format(existing.get("jp_policy_in")) if command: commands.append(command) @@ -394,9 +382,7 @@ def config_pim_interface(delta, existing, jp_bidir, isauth): "neighbor_type", ]: if k in ["neighbor_policy", "neighbor_type"]: - temp = delta.get("neighbor_policy") or existing.get( - "neighbor_policy" - ) + temp = delta.get("neighbor_policy") or existing.get("neighbor_policy") if delta.get("neighbor_type") == "prefix": command = PARAM_TO_COMMAND_KEYMAP.get(k).format(temp) elif delta.get("neighbor_type") == "routemap": @@ -406,9 +392,7 @@ def config_pim_interface(delta, existing, jp_bidir, isauth): elif existing.get("neighbor_type") == "routemap": command = "ip pim neighbor-policy {0}".format(temp) elif k in ["jp_policy_in", "jp_type_in"]: - temp = delta.get("jp_policy_in") or existing.get( - "jp_policy_in" - ) + temp = delta.get("jp_policy_in") or existing.get("jp_policy_in") if delta.get("jp_type_in") == "prefix": command = PARAM_TO_COMMAND_KEYMAP.get(k).format(temp) elif delta.get("jp_type_in") == "routemap": @@ -418,9 +402,7 @@ def config_pim_interface(delta, existing, jp_bidir, isauth): elif existing.get("jp_type_in") == "routemap": command = "ip pim jp-policy {0} in".format(temp) elif k in ["jp_policy_out", "jp_type_out"]: - temp = delta.get("jp_policy_out") or existing.get( - "jp_policy_out" - ) + temp = delta.get("jp_policy_out") or existing.get("jp_policy_out") if delta.get("jp_type_out") == "prefix": command = PARAM_TO_COMMAND_KEYMAP.get(k).format(temp) elif delta.get("jp_type_out") == "routemap": @@ -441,7 +423,6 @@ def config_pim_interface(delta, existing, jp_bidir, isauth): def get_pim_interface_defaults(): - args = dict( dr_prio=PARAM_TO_DEFAULT_KEYMAP.get("dr_prio"), bfd=PARAM_TO_DEFAULT_KEYMAP.get("bfd"), @@ -451,9 +432,7 @@ def get_pim_interface_defaults(): hello_auth_key=PARAM_TO_DEFAULT_KEYMAP.get("hello_auth_key"), ) - default = dict( - (param, value) for (param, value) in args.items() if value is not None - ) + default = dict((param, value) for (param, value) in args.items() if value is not None) return default @@ -464,9 +443,7 @@ def default_pim_interface_policies(existing, jp_bidir): if jp_bidir: if existing.get("jp_policy_in") or existing.get("jp_policy_out"): if existing.get("jp_type_in") == "prefix": - command = "no ip pim jp-policy prefix-list {0}".format( - existing.get("jp_policy_in") - ) + command = "no ip pim jp-policy prefix-list {0}".format(existing.get("jp_policy_in")) if command: commands.append(command) @@ -476,26 +453,20 @@ def default_pim_interface_policies(existing, jp_bidir): if k == "jp_policy_in": if existing.get("jp_policy_in"): if existing.get("jp_type_in") == "prefix": - command = ( - "no ip pim jp-policy prefix-list {0} in".format( - existing.get("jp_policy_in") - ) + command = "no ip pim jp-policy prefix-list {0} in".format( + existing.get("jp_policy_in"), ) else: - command = "no ip pim jp-policy {0} in".format( - existing.get("jp_policy_in") - ) + command = "no ip pim jp-policy {0} in".format(existing.get("jp_policy_in")) elif k == "jp_policy_out": if existing.get("jp_policy_out"): if existing.get("jp_type_out") == "prefix": - command = ( - "no ip pim jp-policy prefix-list {0} out".format( - existing.get("jp_policy_out") - ) + command = "no ip pim jp-policy prefix-list {0} out".format( + existing.get("jp_policy_out"), ) else: command = "no ip pim jp-policy {0} out".format( - existing.get("jp_policy_out") + existing.get("jp_policy_out"), ) if command: commands.append(command) @@ -559,7 +530,6 @@ def main(): choices=["absent", "default", "present"], ), ) - argument_spec.update(nxos_argument_spec) required_by = {"hello_interval_ms": "hello_interval"} module = AnsibleModule( @@ -586,27 +556,19 @@ def main(): if jp_policy_in: if not jp_type_in: - module.fail_json( - msg="jp_type_in required when using jp_policy_in." - ) + module.fail_json(msg="jp_type_in required when using jp_policy_in.") if jp_policy_out: if not jp_type_out: - module.fail_json( - msg="jp_type_out required when using jp_policy_out." - ) + module.fail_json(msg="jp_type_out required when using jp_policy_out.") if neighbor_policy: if not neighbor_type: - module.fail_json( - msg="neighbor_type required when using neighbor_policy." - ) + module.fail_json(msg="neighbor_type required when using neighbor_policy.") get_existing = get_pim_interface(module, interface) existing, jp_bidir, isauth = local_existing(get_existing) args = PARAM_TO_COMMAND_KEYMAP.keys() - proposed = dict( - (k, v) for k, v in module.params.items() if v is not None and k in args - ) + proposed = dict((k, v) for k, v in module.params.items() if v is not None and k in args) normalize_proposed_values(proposed, module) delta = dict(set(proposed.items()).difference(existing.items())) diff --git a/plugins/modules/nxos_pim_rp_address.py b/plugins/modules/nxos_pim_rp_address.py index 9d48ac50e..fe9989ed9 100644 --- a/plugins/modules/nxos_pim_rp_address.py +++ b/plugins/modules/nxos_pim_rp_address.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -83,18 +84,16 @@ import re -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_config, - load_config, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) from ansible.module_utils.basic import AnsibleModule from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( CustomNetworkConfig, ) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + get_config, + load_config, +) + def get_existing(module, args, gl): existing = {} @@ -103,7 +102,6 @@ def get_existing(module, args, gl): pim_address_re = r"ip pim rp-address (?P.*)$" for line in re.findall(pim_address_re, config, re.M): - values = line.split() if values[0] != address: continue @@ -146,9 +144,7 @@ def state_present(module, existing, proposed, candidate): def build_command(param_dict, command): for param in ["group_list", "prefix_list", "route_map"]: if param_dict.get(param): - command += " {0} {1}".format( - param.replace("_", "-"), param_dict.get(param) - ) + command += " {0} {1}".format(param.replace("_", "-"), param_dict.get(param)) if param_dict.get("bidir"): command += " bidir" return [command] @@ -191,11 +187,8 @@ def main(): prefix_list=dict(required=False, type="str"), route_map=dict(required=False, type="str"), bidir=dict(required=False, type="bool"), - state=dict( - choices=["present", "absent"], default="present", required=False - ), + state=dict(choices=["present", "absent"], default="present", required=False), ) - argument_spec.update(nxos_argument_spec) module = AnsibleModule( argument_spec=argument_spec, @@ -214,9 +207,7 @@ def main(): args = ["rp_address", "group_list", "prefix_list", "route_map", "bidir"] - proposed_args = dict( - (k, v) for k, v in module.params.items() if v is not None and k in args - ) + proposed_args = dict((k, v) for k, v in module.params.items() if v is not None and k in args) if module.params["group_list"]: existing = get_existing(module, args, True) diff --git a/plugins/modules/nxos_ping.py b/plugins/modules/nxos_ping.py index 0abc9c433..31c8517a7 100644 --- a/plugins/modules/nxos_ping.py +++ b/plugins/modules/nxos_ping.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -129,14 +130,10 @@ type: str sample: "0.00%" """ -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - run_commands, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) from ansible.module_utils.basic import AnsibleModule +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import run_commands + def get_summary(results_list, reference_point): summary_string = results_list[reference_point + 1] @@ -205,9 +202,7 @@ def get_ping_results(command, module): splitted_ping = ping.split("\n") reference_point = get_statistics_summary_line(splitted_ping) summary, ping_pass = get_summary(splitted_ping, reference_point) - rtt = get_rtt( - splitted_ping, summary["packet_loss"], reference_point + 2 - ) + rtt = get_rtt(splitted_ping, summary["packet_loss"], reference_point + 2) return (summary, rtt, ping_pass) @@ -220,16 +215,10 @@ def main(): source=dict(required=False), size=dict(required=False, type="int"), df_bit=dict(required=False, default=False, type="bool"), - state=dict( - required=False, choices=["present", "absent"], default="present" - ), + state=dict(required=False, choices=["present", "absent"], default="present"), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) destination = module.params["dest"] state = module.params["state"] diff --git a/plugins/modules/nxos_prefix_lists.py b/plugins/modules/nxos_prefix_lists.py index 707cceb12..cbd2415ca 100644 --- a/plugins/modules/nxos_prefix_lists.py +++ b/plugins/modules/nxos_prefix_lists.py @@ -10,6 +10,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type DOCUMENTATION = """ @@ -805,6 +806,7 @@ """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.prefix_lists.prefix_lists import ( Prefix_listsArgs, ) diff --git a/plugins/modules/nxos_reboot.py b/plugins/modules/nxos_reboot.py index 6a0111777..51d0d70af 100644 --- a/plugins/modules/nxos_reboot.py +++ b/plugins/modules/nxos_reboot.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -57,14 +58,10 @@ sample: true """ -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - load_config, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) from ansible.module_utils.basic import AnsibleModule +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import load_config + def reboot(module): cmds = "terminal dont-ask ; reload" @@ -74,11 +71,8 @@ def reboot(module): def main(): argument_spec = dict(confirm=dict(default=False, type="bool")) - argument_spec.update(nxos_argument_spec) - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() results = dict(changed=False, warnings=warnings) diff --git a/plugins/modules/nxos_rollback.py b/plugins/modules/nxos_rollback.py index ae77292b4..4b26919d1 100644 --- a/plugins/modules/nxos_rollback.py +++ b/plugins/modules/nxos_rollback.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -74,12 +75,10 @@ """ -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, - run_commands, -) from ansible.module_utils.basic import AnsibleModule +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import run_commands + def checkpoint(filename, module): commands = [ @@ -94,17 +93,13 @@ def rollback(filename, module): { "command": "rollback running-config file %s" % filename, "output": "text", - } + }, ] run_commands(module, commands) def main(): - argument_spec = dict( - checkpoint_file=dict(required=False), rollback_to=dict(required=False) - ) - - argument_spec.update(nxos_argument_spec) + argument_spec = dict(checkpoint_file=dict(required=False), rollback_to=dict(required=False)) module = AnsibleModule( argument_spec=argument_spec, diff --git a/plugins/modules/nxos_route_maps.py b/plugins/modules/nxos_route_maps.py index 0cee81d7e..bf57dcb7a 100644 --- a/plugins/modules/nxos_route_maps.py +++ b/plugins/modules/nxos_route_maps.py @@ -10,6 +10,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type DOCUMENTATION = """ @@ -311,6 +312,23 @@ extcomm_list: description: Set BGP extcommunity list (for deletion). type: str + extcommunity: + description: Set BGP extcommunity attribute. + type: dict + suboptions: + rt: + description: Route-Target. + type: dict + suboptions: + additive: + description: Add to existing rt extcommunity. + type: bool + extcommunity_numbers: + description: + - Extcommunity number. + - "Supported formats are ASN2:NN, ASN4:NN, IPV4:NN." + type: list + elements: str forwarding_address: description: Set the forwarding address. type: bool @@ -331,10 +349,77 @@ precedence: description: Set precedence field. type: str + next_hop: + description: Set next-hop IP address (for policy-based routing) + type: dict + suboptions: + address: + description: Set space-separated list of next-hop IP addresses. Address ordering is important. Also don`t use unnecessary spaces. + type: str + drop_on_fail: + description: Drop packets instead of using default routing when the configured next hop becomes unreachable + type: bool + default: false + force_order: + description: Enable next-hop ordering as specified in the address parameter. + type: bool + default: false + load_share: + description: Enable traffic load balancing across a maximum of 32 next-hop addresses + type: bool + default: false + peer_address: + description: + - BGP prefix next hop is set to the local address of the peer. + - If no next hop is set in the route map, the next hop is set to the one stored in the path. + type: bool + redist_unchanged: + description: + - Set for next-hop address conservation for non-local generated routes. + - Used with redistribute command. Available to maintain BGP routing compliant with RFC 4271 on Nexus OS. + type: bool + unchanged: + description: Set for next-hop address conservation in eBGP outgoing updates + type: bool + verify_availability: + description: Set next-hop ip address tracking with IP SLA + type: list + elements: dict + suboptions: + address: + description: Set one next-hop address + type: str + required: true + track: + description: Set track number + type: int + required: true + drop_on_fail: + description: Drop packets instead of using default routing when the configured next hop becomes unreachable + type: bool + default: false + force_order: + description: Enable next-hop ordering as specified in the address parameter. + type: bool + default: false + load_share: + description: Enable traffic load balancing across a maximum of 32 next-hop addresses + type: bool + default: false ipv6: description: Configure IPv6 features. type: dict - suboptions: *id002 + suboptions: + address: + description: Specify IP address. + type: dict + suboptions: + prefix_list: + description: Name of prefix list (Max Size 63). + type: str + precedence: + description: Set precedence field. + type: str label_index: description: Set Segment Routing (SR) label index of route. type: int @@ -485,6 +570,47 @@ group_range: first: 239.0.0.1 last: 239.255.255.255 + + - route_map: rmap3 + entries: + - sequence: 10 + description: "*** first stanza ***" + action: permit + set: + ip: + next_hop: + verify_availability: + - address: 3.3.3.3 + track: 1 + - address: 4.4.4.4 + track: 3 + + - sequence: 20 + description: "*** second stanza ***" + action: permit + set: + ip: + next_hop: + address: 6.6.6.6 2.2.2.2 + load_share: true + drop_on_fail: true + + - sequence: 30 + description: "*** third stanza ***" + action: permit + set: + ip: + next_hop: + peer_address: true + + - sequence: 40 + description: "*** fourth stanza ***" + action: permit + set: + ip: + next_hop: + unchanged: true + redist_unchanged: true state: merged # Task output @@ -514,6 +640,20 @@ # - "match route-type level-1 level-2" # - "match tag 2" # - "description rmap2-40-deny" +# - "route-map rmap3 permit 10" +# - "description *** first stanza ***" +# - "set ip next-hop verify-availability 3.3.3.3 track 1" +# - "set ip next-hop verify-availability 4.4.4.4 track 3" +# - "route-map rmap3 permit 20" +# - "description *** second stanza ***" +# - "set ip next-hop 6.6.6.6 2.2.2.2 load-share drop-on-fail" +# - "route-map rmap3 permit 30" +# - "description *** third stanza ***" +# - "set ip next-hop peer-address" +# - "route-map rmap3 permit 40" +# - "description *** fourth stanza ***" +# - "set ip next-hop unchanged" +# - "set ip next-hop redist-unchanged" # # after: # - route_map: rmap1 @@ -591,6 +731,47 @@ # tags: # - 2 # sequence: 40 +# +# - route_map: rmap3 +# entries: +# - sequence: 10 +# description: "*** first stanza ***" +# action: permit +# set: +# ip: +# next_hop: +# verify_availability: +# - address: 3.3.3.3 +# track: 1 +# - address: 4.4.4.4 +# track: 3 +# +# - sequence: 20 +# description: "*** second stanza ***" +# action: permit +# set: +# ip: +# next_hop: +# address: 6.6.6.6 2.2.2.2 +# load_share: true +# drop_on_fail: true +# +# - sequence: 30 +# description: "*** third stanza ***" +# action: permit +# set: +# ip: +# next_hop: +# peer_address: true +# +# - sequence: 40 +# description: "*** fourth stanza ***" +# action: permit +# set: +# ip: +# next_hop: +# unchanged: true +# redist_unchanged: true # After state: # ------------ @@ -617,7 +798,21 @@ # match route-type level-1 level-2 # match tag 2 # description rmap2-40-deny - +# route-map rmap3 permit 10 +# description *** first stanza *** +# set ip next-hop verify-availability 3.3.3.3 track 1 +# set ip next-hop verify-availability 4.4.4.4 track 3 +# route-map rmap3 permit 20 +# description *** second stanza *** +# set ip next-hop 6.6.6.6 2.2.2.2 load-share drop-on-fail +# route-map rmap3 permit 30 +# description *** third stanza *** +# set ip next-hop peer-address +# route-map rmap3 permit 40 +# description *** fourth stanza *** +# set ip next-hop unchanged +# set ip next-hop redist-unchanged +# # Using replaced # (for the listed route-map(s), sequences that are in running-config but not in the task are negated) @@ -646,7 +841,21 @@ # match route-type level-1 level-2 # match tag 2 # description rmap2-40-deny - +# route-map rmap3 permit 10 +# description *** first stanza *** +# set ip next-hop verify-availability 3.3.3.3 track 1 +# set ip next-hop verify-availability 4.4.4.4 track 3 +# route-map rmap3 permit 20 +# description *** second stanza *** +# set ip next-hop 6.6.6.6 2.2.2.2 load-share drop-on-fail +# route-map rmap3 permit 30 +# description *** third stanza *** +# set ip next-hop peer-address +# route-map rmap3 permit 40 +# description *** fourth stanza *** +# set ip next-hop unchanged +# set ip next-hop redist-unchanged +# - name: Replace route-maps configurations of listed route-maps with provided configurations cisco.nxos.nxos_route_maps: config: @@ -666,7 +875,35 @@ - AllowPrefix1 set: community: - local_as: True + local_as: true + + - route_map: rmap3 + entries: + - sequence: 10 + description: "*** first stanza ***" + action: permit + set: + ip: + next_hop: + verify_availability: + - address: 3.3.3.3 + track: 1 + - sequence: 20 + description: "*** second stanza ***" + action: permit + set: + ip: + next_hop: + peer_address: true + - sequence: 30 + description: "*** third stanza ***" + action: permit + set: + ip: + next_hop: + address: 6.6.6.6 2.2.2.2 + load_share: true + drop_on_fail: true state: replaced # Task output @@ -748,6 +985,47 @@ # - 2 # sequence: 40 # +# - route_map: rmap3 +# entries: +# - sequence: 10 +# description: "*** first stanza ***" +# action: permit +# set: +# ip: +# next_hop: +# verify_availability: +# - address: 3.3.3.3 +# track: 1 +# - address: 4.4.4.4 +# track: 3 +# +# - sequence: 20 +# description: "*** second stanza ***" +# action: permit +# set: +# ip: +# next_hop: +# address: 6.6.6.6 2.2.2.2 +# load_share: true +# drop_on_fail: true +# +# - sequence: 30 +# description: "*** third stanza ***" +# action: permit +# set: +# ip: +# next_hop: +# peer_address: true +# +# - sequence: 40 +# description: "*** fourth stanza ***" +# action: permit +# set: +# ip: +# next_hop: +# unchanged: true +# redist_unchanged: true +# # commands: # - no route-map rmap1 permit 10 # - route-map rmap1 deny 20 @@ -757,6 +1035,15 @@ # - match ip address prefix-list AllowPrefix1 # - no set dampening 30 1500 10000 120 # - set community local-AS +# - route-map rmap3 permit 10 +# - no set ip next-hop verify-availability 4.4.4.4 track 3 +# - route-map rmap3 permit 20 +# - no set ip next-hop 6.6.6.6 2.2.2.2 load-share drop-on-fail +# - set ip next-hop peer-address +# - route-map rmap3 permit 30 +# - no set ip next-hop peer-address +# - set ip next-hop 6.6.6.6 2.2.2.2 load-share drop-on-fail +# - no route-map rmap3 permit 40 # # after: # - route_map: rmap1 @@ -775,7 +1062,7 @@ # - AllowPrefix1 # set: # community: -# local_as: True +# local_as: true # # - route_map: rmap2 # entries: @@ -818,6 +1105,33 @@ # - 2 # sequence: 40 # +# - route_map: rmap3 +# entries: +# - sequence: 10 +# description: "*** first stanza ***" +# action: permit +# set: +# ip: +# next_hop: +# verify_availability: +# - address: 3.3.3.3 +# track: 1 +# - sequence: 20 +# description: "*** second stanza ***" +# action: permit +# set: +# ip: +# next_hop: +# peer_address: true +# - sequence: 30 +# description: "*** third stanza ***" +# action: permit +# set: +# ip: +# next_hop: +# address: 6.6.6.6 2.2.2.2 +# load_share: true +# drop_on_fail: true # After state: # ------------ @@ -839,6 +1153,15 @@ # match route-type level-1 level-2 # match tag 2 # description rmap2-40-deny +# route-map rmap3 permit 10 +# description *** first stanza *** +# set ip next-hop verify-availability 3.3.3.3 track 1 +# route-map rmap3 permit 20 +# description *** second stanza *** +# set ip next-hop peer-address +# route-map rmap3 permit 30 +# description *** third stanza *** +# set ip next-hop 6.6.6.6 2.2.2.2 load-share drop-on-fail # Using overridden @@ -887,7 +1210,7 @@ - AllowPrefix1 set: community: - local_as: True + local_as: true state: overridden # Task output @@ -998,7 +1321,7 @@ # - AllowPrefix1 # set: # community: -# local_as: True +# local_as: true # # After state: # ------------ @@ -1611,6 +1934,7 @@ """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.route_maps.route_maps import ( Route_mapsArgs, ) diff --git a/plugins/modules/nxos_rpm.py b/plugins/modules/nxos_rpm.py index 1d890fad5..7d7ab4db4 100644 --- a/plugins/modules/nxos_rpm.py +++ b/plugins/modules/nxos_rpm.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -104,18 +105,16 @@ from copy import deepcopy -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - load_config, - run_commands, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) from ansible.module_utils.basic import AnsibleModule from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( remove_default_spec, ) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + load_config, + run_commands, +) + def execute_show_command(command, module): iteration = 0 @@ -203,8 +202,7 @@ def activate_reload(module, pkg, flag): if "socket is closed" in msg[0].lower(): return cmd if ( - "another install operation is in progress" - in msg[0].lower() + "another install operation is in progress" in msg[0].lower() or "failed" in msg[0].lower() ): time.sleep(2) @@ -263,11 +261,7 @@ def install_remove_rpm(module, full_pkg, file_system, state): active_body = execute_show_command(show_active, module) if pkg not in inactive_body and pkg not in active_body: - commands.append( - add_operation( - module, show_inactive, file_system, full_pkg, pkg - ) - ) + commands.append(add_operation(module, show_inactive, file_system, full_pkg, pkg)) patch_type_body = execute_show_command(show_pkg_info, module) if patch_type_body and "Patch Type : reload" in patch_type_body: @@ -286,13 +280,9 @@ def install_remove_rpm(module, full_pkg, file_system, state): patch_body = execute_show_command(show_patches, module) if pkg in patch_body: # This is smu/patch rpm - commands.append( - commit_operation(module, show_commit, pkg, False) - ) + commands.append(commit_operation(module, show_commit, pkg, False)) else: - err = 'Operation "install activate {0} forced" Failed'.format( - pkg - ) + err = 'Operation "install activate {0} forced" Failed'.format(pkg) module.fail_json(msg=err) else: @@ -309,15 +299,11 @@ def install_remove_rpm(module, full_pkg, file_system, state): commands.append(activate_reload(module, pkg, False)) return commands else: - commands.append( - deactivate_operation(module, show_active, pkg, True) - ) + commands.append(deactivate_operation(module, show_active, pkg, True)) commit_body = execute_show_command(show_commit, module) if pkg in commit_body: # This is smu/patch rpm - commands.append( - commit_operation(module, show_commit, pkg, True) - ) + commands.append(commit_operation(module, show_commit, pkg, True)) commands.extend(remove_operation(module, show_inactive, pkg)) elif pkg in commit_body: @@ -331,9 +317,7 @@ def install_remove_rpm(module, full_pkg, file_system, state): commands.append(activate_reload(module, pkg, False)) return commands else: - commands.append( - deactivate_operation(module, show_inactive, pkg, False) - ) + commands.append(deactivate_operation(module, show_inactive, pkg, False)) commands.extend(remove_operation(module, show_inactive, pkg)) else: @@ -357,13 +341,9 @@ def main(): # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) - argument_spec = dict( - aggregate=dict(type="list", elements="dict", options=aggregate_spec) - ) + argument_spec = dict(aggregate=dict(type="list", elements="dict", options=aggregate_spec)) argument_spec.update(element_spec) - argument_spec.update(nxos_argument_spec) - required_one_of = [["pkg", "aggregate"]] mutually_exclusive = [["pkg", "aggregate"]] @@ -393,23 +373,17 @@ def main(): "pkg": module.params["pkg"], "file_system": module.params["file_system"], "state": module.params["state"], - } + }, ) for obj in objects: if obj["state"] == "present": - remote_exists = remote_file_exists( - module, obj["pkg"], file_system=obj["file_system"] - ) + remote_exists = remote_file_exists(module, obj["pkg"], file_system=obj["file_system"]) if not remote_exists: - module.fail_json( - msg="The requested package doesn't exist on the device" - ) + module.fail_json(msg="The requested package doesn't exist on the device") - cmds = install_remove_rpm( - module, obj["pkg"], obj["file_system"], obj["state"] - ) + cmds = install_remove_rpm(module, obj["pkg"], obj["file_system"], obj["state"]) if cmds: results["changed"] = True diff --git a/plugins/modules/nxos_smu.py b/plugins/modules/nxos_smu.py deleted file mode 100644 index 5600e1c66..000000000 --- a/plugins/modules/nxos_smu.py +++ /dev/null @@ -1,164 +0,0 @@ -#!/usr/bin/python -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - - -DOCUMENTATION = """ -module: nxos_smu -extends_documentation_fragment: -- cisco.nxos.nxos -short_description: (deprecated, removed after 2022-10-01) Perform SMUs on Cisco NX-OS devices. -description: -- Perform software maintenance upgrades (SMUs) on Cisco NX-OS devices. -version_added: 1.0.0 -author: Gabriele Gerbino (@GGabriele) -deprecated: - alternative: nxos_rpm - why: Updated modules released with more functionality. - removed_at_date: '2022-10-01' -notes: -- Tested against NXOSv 7.3.(0)D1(1) on VIRL -- Unsupported for Cisco MDS -- The module can only activate and commit a package, not remove or deactivate it. -- Use C(transport=nxapi) to avoid connection timeout -options: - pkg: - description: - - Name of the remote package. - required: true - type: str - file_system: - description: - - The remote file system of the device. If omitted, devices that support a file_system - parameter will use their default values. - default: 'bootflash:' - type: str -""" - -EXAMPLES = """ -- cisco.nxos.nxos_smu: - pkg: nxos.CSCuz65185-n9k_EOR-1.0.0-7.0.3.I2.2d.lib32_n9000.rpm -""" - -RETURN = """ -commands: - description: commands sent to the device - returned: always - type: list - sample: ["install add bootflash:nxos.CSCuz65185-n9k_EOR-1.0.0-7.0.3.I2.2d.lib32_n9000.rpm", - "install activate bootflash:nxos.CSCuz65185-n9k_EOR-1.0.0-7.0.3.I2.2d.lib32_n9000.rpm force", - "install commit bootflash:nxos.CSCuz65185-n9k_EOR-1.0.0-7.0.3.I2.2d.lib32_n9000.rpm"] -""" - - -import time - -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - load_config, - run_commands, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule - - -def execute_show_command(command, module): - cmds = [{"command": command, "output": "text"}] - - return run_commands(module, cmds) - - -def remote_file_exists(module, dst, file_system="bootflash:"): - command = "dir {0}/{1}".format(file_system, dst) - body = execute_show_command(command, module) - if "No such file" in body[0]: - return False - return True - - -def apply_patch(module, commands): - for command in commands: - load_config(module, [command]) - time.sleep(5) - - -def get_commands(module, pkg, file_system): - commands = [] - splitted_pkg = pkg.split(".") - fixed_pkg = ".".join(splitted_pkg[0:-1]) - - command = "show install inactive" - inactive_body = execute_show_command(command, module) - - command = "show install active" - active_body = execute_show_command(command, module) - - if fixed_pkg not in inactive_body[0] and fixed_pkg not in active_body[0]: - commands.append("install add {0}{1}".format(file_system, pkg)) - - if fixed_pkg not in active_body[0]: - commands.append("install activate {0} force".format(pkg)) - command = "show install committed" - install_body = execute_show_command(command, module) - if fixed_pkg not in install_body[0]: - commands.append("install commit {0}".format(pkg)) - - return commands - - -def main(): - argument_spec = dict( - pkg=dict(required=True), - file_system=dict(required=False, default="bootflash:"), - ) - - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) - - warnings = list() - results = {"changed": False, "commands": [], "warnings": warnings} - - pkg = module.params["pkg"] - file_system = module.params["file_system"] - remote_exists = remote_file_exists(module, pkg, file_system=file_system) - - if not remote_exists: - module.fail_json( - msg="The requested package doesn't exist on the device" - ) - - commands = get_commands(module, pkg, file_system) - if commands: - results["changed"] = True - if not module.check_mode: - apply_patch(module, commands) - if "configure" in commands: - commands.pop(0) - results["commands"] = commands - - module.exit_json(**results) - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/nxos_snapshot.py b/plugins/modules/nxos_snapshot.py index 58cbbcd1e..7d59810a8 100644 --- a/plugins/modules/nxos_snapshot.py +++ b/plugins/modules/nxos_snapshot.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import, division, print_function + __metaclass__ = type # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) @@ -91,7 +92,7 @@ description: - Specify to locally store a new created snapshot, to be used when C(action=create). type: bool - default: no + default: false path: description: - Specify the path of the file where new created snapshot or snapshots comparison @@ -148,13 +149,11 @@ import re from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) def execute_show_command(command, module): @@ -199,8 +198,9 @@ def action_create(module, existing_snapshots): if exist is False: commands.append( "snapshot create {0} {1}".format( - module.params["snapshot_name"], module.params["description"] - ) + module.params["snapshot_name"], + module.params["description"], + ), ) return commands @@ -253,7 +253,7 @@ def action_add(module, existing_snapshots): module.params["row_id"], module.params["element_key1"], module.params["element_key2"], - ) + ), ) else: commands.append( @@ -262,7 +262,7 @@ def action_add(module, existing_snapshots): module.params["show_command"], module.params["row_id"], module.params["element_key1"], - ) + ), ) return commands @@ -270,7 +270,8 @@ def action_add(module, existing_snapshots): def action_compare(module, existing_snapshots): command = "show snapshot compare {0} {1}".format( - module.params["snapshot1"], module.params["snapshot2"] + module.params["snapshot1"], + module.params["snapshot2"], ) if module.params["compare_option"]: @@ -289,9 +290,7 @@ def action_delete(module, existing_snapshots): exist = True if exist: - commands.append( - "snapshot delete {0}".format(module.params["snapshot_name"]) - ) + commands.append("snapshot delete {0}".format(module.params["snapshot_name"])) return commands @@ -345,8 +344,6 @@ def main(): path=dict(type="str", default="./"), ) - argument_spec.update(nxos_argument_spec) - required_if = [ ( "action", @@ -372,11 +369,7 @@ def main(): comparison_results_file = module.params["comparison_results_file"] if not os.path.isdir(module.params["path"]): - module.fail_json( - msg="{0} is not a valid directory name.".format( - module.params["path"] - ) - ) + module.fail_json(msg="{0} is not a valid directory name.".format(module.params["path"])) existing_snapshots = invoke("get_existing", module) action_results = invoke("action_%s" % action, module, existing_snapshots) @@ -391,9 +384,7 @@ def main(): snapshot1 = module.params["snapshot1"] snapshot2 = module.params["snapshot2"] compare_option = module.params["compare_option"] - command = "show snapshot compare {0} {1}".format( - snapshot1, snapshot2 - ) + command = "show snapshot compare {0} {1}".format(snapshot1, snapshot2) if compare_option: command += " {0}".format(compare_option) content = execute_show_command(command, module)[0] @@ -410,14 +401,10 @@ def main(): and module.params["path"] and module.params["save_snapshot_locally"] ): - command = "show snapshot dump {0} | json".format( - module.params["snapshot_name"] - ) + command = "show snapshot dump {0} | json".format(module.params["snapshot_name"]) content = execute_show_command(command, module)[0] if content: - write_on_file( - str(content), module.params["snapshot_name"], module - ) + write_on_file(str(content), module.params["snapshot_name"], module) module.exit_json(**result) diff --git a/plugins/modules/nxos_snmp_community.py b/plugins/modules/nxos_snmp_community.py index 23571af14..4e94b1f00 100644 --- a/plugins/modules/nxos_snmp_community.py +++ b/plugins/modules/nxos_snmp_community.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -86,14 +87,13 @@ """ import re + +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule def execute_show_command(command, module): @@ -188,8 +188,6 @@ def main(): state=dict(choices=["absent", "present"], default="present"), ) - argument_spec.update(nxos_argument_spec) - module = AnsibleModule( argument_spec=argument_spec, required_one_of=[["access", "group"]], @@ -216,9 +214,7 @@ def main(): configured_groups = get_snmp_groups(module) if group not in configured_groups: - module.fail_json( - msg="Group not on switch. Please add before moving forward" - ) + module.fail_json(msg="Group not on switch. Please add before moving forward") existing = get_snmp_community(module, community) args = dict(group=group, acl=acl) diff --git a/plugins/modules/nxos_snmp_contact.py b/plugins/modules/nxos_snmp_contact.py index f4050374e..49dbc8a83 100644 --- a/plugins/modules/nxos_snmp_contact.py +++ b/plugins/modules/nxos_snmp_contact.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -73,14 +74,12 @@ import re +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule def execute_show_command(command, module): @@ -117,11 +116,7 @@ def main(): state=dict(choices=["absent", "present"], default="present"), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() results = {"changed": False, "commands": [], "warnings": warnings} diff --git a/plugins/modules/nxos_snmp_host.py b/plugins/modules/nxos_snmp_host.py index f7300db17..5899472e2 100644 --- a/plugins/modules/nxos_snmp_host.py +++ b/plugins/modules/nxos_snmp_host.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -123,14 +124,13 @@ import re + +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule def execute_show_command(command, module): @@ -202,11 +202,7 @@ def get_snmp_host(host, udp, module): vrf_filt = each.get("TABLE_vrf_filters") if vrf_filt: - vrf_filter = ( - vrf_filt["ROW_vrf_filters"]["vrf_filter"] - .split(":")[1] - .split(",") - ) + vrf_filter = vrf_filt["ROW_vrf_filters"]["vrf_filter"].split(":")[1].split(",") filters = [vrf.strip() for vrf in vrf_filter] host_resource["vrf_filter"] = filters @@ -223,18 +219,14 @@ def get_snmp_host(host, udp, module): resource_table = [resource_table] for each in resource_table: - key = ( - str(each["address"]) + "_" + str(each["port"]).strip() - ) + key = str(each["address"]) + "_" + str(each["port"]).strip() src = each.get("src_intf") host_resource = apply_key_map(host_map_5k, each) if src: host_resource["src_intf"] = src if re.search(r"interface:", src): - host_resource["src_intf"] = src.split(":")[ - 1 - ].strip() + host_resource["src_intf"] = src.split(":")[1].strip() vrf = each.get("use_vrf_name") if vrf: @@ -242,9 +234,7 @@ def get_snmp_host(host, udp, module): vrf_filt = each.get("TABLE_filter_vrf") if vrf_filt: - vrf_filter = vrf_filt["ROW_filter_vrf"][ - "filter_vrf_name" - ].split(",") + vrf_filter = vrf_filt["ROW_filter_vrf"]["filter_vrf_name"].split(",") filters = [vrf.strip() for vrf in vrf_filter] host_resource["vrf_filter"] = filters @@ -258,7 +248,7 @@ def get_snmp_host(host, udp, module): if find: fix_find = {} - for (key, value) in find.items(): + for key, value in find.items(): if isinstance(value, str): fix_find[key] = value.strip() else: @@ -274,21 +264,27 @@ def remove_snmp_host(host, udp, existing): existing["version"] = "3" command = "no snmp-server host {0} {snmp_type} version \ {version} {v3} {community} udp-port {1}".format( - host, udp, **existing + host, + udp, + **existing, ) elif existing["version"] == "v2c": existing["version"] = "2c" command = "no snmp-server host {0} {snmp_type} version \ {version} {community} udp-port {1}".format( - host, udp, **existing + host, + udp, + **existing, ) elif existing["version"] == "v1": existing["version"] = "1" command = "no snmp-server host {0} {snmp_type} version \ {version} {community} udp-port {1}".format( - host, udp, **existing + host, + udp, + **existing, ) if command: @@ -302,8 +298,10 @@ def remove_vrf(host, udp, proposed, existing): commands.append( "no snmp-server host {0} use-vrf \ {1} udp-port {2}".format( - host, proposed.get("vrf"), udp - ) + host, + proposed.get("vrf"), + udp, + ), ) return commands @@ -315,8 +313,10 @@ def remove_filter(host, udp, proposed, existing): commands.append( "no snmp-server host {0} filter-vrf \ {1} udp-port {2}".format( - host, proposed.get("vrf_filter"), udp - ) + host, + proposed.get("vrf_filter"), + udp, + ), ) return commands @@ -327,8 +327,10 @@ def remove_src(host, udp, proposed, existing): commands.append( "no snmp-server host {0} source-interface \ {1} udp-port {2}".format( - host, proposed.get("src_intf"), udp - ) + host, + proposed.get("src_intf"), + udp, + ), ) return commands @@ -405,11 +407,7 @@ def main(): state=dict(choices=["absent", "present"], default="present"), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() results = {"changed": False, "commands": [], "warnings": warnings} @@ -447,10 +445,7 @@ def main(): module.fail_json(msg="inform requires snmp v2c or v3") if (version == "v1" or version == "v2c") and v3: - module.fail_json( - msg='param: "v3" should not be used when ' - "using version v1 or v2c" - ) + module.fail_json(msg='param: "v3" should not be used when ' "using version v1 or v2c") if not any([vrf_filter, vrf, src_intf]): if not all([snmp_type, version, community, udp]): @@ -458,13 +453,13 @@ def main(): msg="when not configuring options like " "vrf_filter, vrf, and src_intf," "the following params are required: " - "type, version, community" + "type, version, community", ) if version == "v3" and v3 is None: module.fail_json( msg="when using version=v3, the param v3 " - "(options: auth, noauth, priv) is also required" + "(options: auth, noauth, priv) is also required", ) # existing returns the list of vrfs configured for a given host @@ -499,9 +494,7 @@ def main(): if proposed.get("vrf"): commands.append(remove_vrf(snmp_host, udp, proposed, existing)) if proposed.get("vrf_filter"): - commands.append( - remove_filter(snmp_host, udp, proposed, existing) - ) + commands.append(remove_filter(snmp_host, udp, proposed, existing)) elif state == "present": delta = dict(set(proposed.items()).difference(existing.items())) diff --git a/plugins/modules/nxos_snmp_location.py b/plugins/modules/nxos_snmp_location.py index 71c8f9770..d7526a9ee 100644 --- a/plugins/modules/nxos_snmp_location.py +++ b/plugins/modules/nxos_snmp_location.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -78,14 +79,12 @@ import re +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule def execute_show_command(command, module): @@ -122,11 +121,7 @@ def main(): state=dict(choices=["absent", "present"], default="present"), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() results = {"changed": False, "commands": [], "warnings": warnings} diff --git a/plugins/modules/nxos_snmp_server.py b/plugins/modules/nxos_snmp_server.py index 033777183..d31dbc72c 100644 --- a/plugins/modules/nxos_snmp_server.py +++ b/plugins/modules/nxos_snmp_server.py @@ -10,6 +10,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type DOCUMENTATION = """ @@ -19,8 +20,9 @@ - This module manages SNMP server configuration on devices running Cisco NX-OS. version_added: 2.8.0 notes: -- Tested against NX-OS 9.3.6. +- Tested against NX-OS 9.3.6 on Cisco Nexus Switches. - This module works with connection C(network_cli) and C(httpapi). +- Tested against Cisco MDS NX-OS 9.2(2) with connection C(network_cli). author: Nilashish Chakraborty (@NilashishC) options: running_config: @@ -62,10 +64,14 @@ description: Read-write access with this community string. type: bool use_ipv4acl: - description: Specify IPv4 ACL, the ACL name specified must be IPv4 ACL. + description: + - Specify IPv4 ACL, the ACL name specified must be IPv4 ACL. + - This option is unsupported on MDS switches. type: str use_ipv6acl: - description: Specify IPv6 ACL, the ACL name specified after must be IPv6 ACL. + description: + - Specify IPv6 ACL, the ACL name specified after must be IPv6 ACL. + - This option is unsupported on MDS switches. type: str contact: description: Modify sysContact. @@ -84,10 +90,14 @@ description: Topology associated with the SNMP context. type: str vrf: - description: VRF associated with the SNMP context. + description: + - VRF associated with the SNMP context. + - This option is unsupported on MDS switches. type: str counter: - description: Configure port counter configuration. + description: + - Configure port counter configuration. + - This option is unsupported on MDS switches. type: dict suboptions: cache: @@ -101,7 +111,9 @@ description: Timeout for which cached port stats exists(in secs). type: int drop: - description: Silently drop unknown v3 user packets. + description: + - Silently drop unknown v3 user packets. + - This option is unsupported on MDS switches. type: dict suboptions: unknown_engine_id: @@ -132,7 +144,9 @@ description: Enable SNMP BGP traps. type: bool bridge: - description: Bridge traps. + description: + - Bridge traps. + - This option is unsupported on MDS switches. type: dict suboptions: enable: @@ -149,7 +163,9 @@ type: dict suboptions: enable: - description: Enable callhome traps. + description: + - Enable callhome traps. + - This option is unsupported on MDS switches. type: bool event_notify: description: Callhome External Event Notification. @@ -162,7 +178,9 @@ type: dict suboptions: enable: - description: Enable cfs traps. + description: + - Enable cfs traps. + - This option is unsupported on MDS switches. type: bool merge_failure: description: Merge failure notification. @@ -175,7 +193,9 @@ type: dict suboptions: enable: - description: Enable config traps. + description: + - Enable config traps. + - This option is unsupported on MDS switches. type: bool ccmCLIRunningConfigChanged: description: Running config change trap. @@ -222,7 +242,9 @@ type: dict suboptions: enable: - description: Enable feature-control traps. + description: + - Enable feature-control traps. + - This option is unsupported on MDS switches. type: bool featureOpStatusChange: description: Feature operation status change notification. @@ -235,7 +257,9 @@ type: dict suboptions: enable: - description: Enable generic traps. + description: + - Enable generic traps. + - This option is unsupported on MDS switches. type: bool coldStart: description: Generic coldStart trap. @@ -248,7 +272,9 @@ type: dict suboptions: enable: - description: Enable license traps. + description: + - Enable license traps. + - This option is unsupported on MDS switches. type: bool notify_license_expiry: description: License Expiry Notification. @@ -267,10 +293,14 @@ type: dict suboptions: enable: - description: Enable link traps. + description: + - Enable link traps. + - This option is unsupported on MDS switches. type: bool cErrDisableInterfaceEventRev1: - description: Err-disable state notification. + description: + - Err-disable state notification. + - This option is unsupported on MDS switches. type: bool cieLinkDown: description: Cisco extended link state down notification. @@ -282,7 +312,9 @@ description: Cisco interface transceiver monitor status change notification. type: bool cmn_mac_move_notification: - description: Mac addr move trap. + description: + - Mac addr move trap. + - This option is unsupported on MDS switches. type: bool delayed_link_state_change: description: Delayed link state change. @@ -300,7 +332,9 @@ description: IETF Link state up notification. type: bool mmode: - description: MMode traps. + description: + - MMode traps. + - This option is unsupported on MDS switches. type: dict suboptions: enable: @@ -331,7 +365,9 @@ type: dict suboptions: enable: - description: Enable rf traps. + description: + - Enable rf traps. + - This option is unsupported on MDS switches. type: bool redundancy_framework: description: Redundancy_Framework (RF) Sup switchover MIB. @@ -341,7 +377,9 @@ type: dict suboptions: enable: - description: Enable rmon traps. + description: + - Enable rmon traps. + - This option is unsupported on MDS switches. type: bool fallingAlarm: description: Rmon falling alarm. @@ -360,7 +398,9 @@ type: dict suboptions: enable: - description: Enable snmp traps. + description: + - Enable snmp traps. + - This option is unsupported on MDS switches. type: bool authentication: description: SNMP authentication trap. @@ -370,16 +410,22 @@ type: dict suboptions: enable: - description: Enable storm-control traps. + description: + - Enable storm-control traps. + - This option is unsupported on MDS switches. type: bool cpscEventRev1: - description: Port-Storm-Control-Event. + description: + - Port-Storm-Control-Event. + - This option is unsupported on MDS switches. type: bool trap_rate: description: Number of traps per minute. type: bool stpx: - description: Stpx traps. + description: + - Stpx traps. + - This option is unsupported on MDS switches. type: dict suboptions: enable: @@ -399,7 +445,9 @@ type: dict suboptions: enable: - description: Enable syslog traps. + description: + - Enable syslog traps. + - This option is unsupported on MDS switches. type: bool message_generated: description: Message Generated Notification. @@ -409,7 +457,9 @@ type: dict suboptions: enable: - description: Enable sysmgr traps. + description: + - Enable sysmgr traps. + - This option is unsupported on MDS switches. type: bool cseFailSwCoreNotifyExtended: description: Software Core Notification. @@ -419,7 +469,9 @@ type: dict suboptions: enable: - description: Enable system traps. + description: + - Enable system traps. + - This option is unsupported on MDS switches. type: bool clock_change_notification: description: Clock-change-notification traps. @@ -429,7 +481,9 @@ type: dict suboptions: enable: - description: Enable upgrade traps. + description: + - Enable upgrade traps. + - This option is unsupported on MDS switches. type: bool upgradeJobStatusNotify: description: Upgrade Job Status Notification. @@ -438,7 +492,9 @@ description: Upgrade Global Status Notification. type: bool vtp: - description: VTP traps. + description: + - VTP traps. + - This option is unsupported on MDS switches. type: dict suboptions: enable: @@ -457,7 +513,9 @@ description: Enable vtpVlanDeleted notification. type: bool engine_id: - description: Configure a local SNMPv3 engineID. + description: + - Configure a local SNMPv3 engineID. + - This option is unsupported on MDS switches. type: dict suboptions: local: @@ -480,7 +538,9 @@ description: SNMP community string or SNMPv3 user name (Max Size 32). type: str filter_vrf: - description: Filters notifications to the notification host receiver based on the configured VRF. + description: + - Filters notifications to the notification host receiver based on the configured VRF. + - This option is unsupported on MDS switches. type: str informs: description: Send Inform messages to this host. @@ -492,7 +552,9 @@ description: Send Traps messages to this host. type: bool use_vrf: - description: Configures SNMP to use the selected VRF to communicate with the host receiver. + description: + - Configures SNMP to use the selected VRF to communicate with the host receiver. + - This option is unsupported on MDS switches. type: str version: description: SNMP version to use for notification messages. @@ -535,7 +597,9 @@ description: Enable/Disable snmp protocol operations. type: bool source_interface: - description: Source interface to be used for sending out SNMP notifications. + description: + - Source interface to be used for sending out SNMP notifications. + - This option is unsupported on MDS switches. type: dict suboptions: informs: @@ -552,7 +616,9 @@ type: dict suboptions: enable: - description: Enable tcp-session. + description: + - Enable tcp-session. + - This option is unsupported on MDS switches. type: bool auth: description: Enable one time authentication for snmp over tcp session. @@ -579,7 +645,7 @@ algorithm: description: Select algorithm for authentication. type: str - choices: ["md5", "sha"] + choices: ["md5", "sha", "sha-256"] password: description: - Authentication password for user (Max Size 127). @@ -593,6 +659,9 @@ localized_key: description: Specifies whether the passwords are in localized key format. type: bool + localizedv2_key: + description: Specifies whether the passwords are in localized V2 key format. + type: bool priv: description: Encryption parameters for the user. type: dict @@ -658,18 +727,18 @@ location: serverroom-1 traps: aaa: - server_state_change: True + server_state_change: true system: - clock_change_notification: True + clock_change_notification: true hosts: - host: 192.0.2.1 - traps: True + traps: true version: '1' community: public - host: 192.0.2.1 source_interface: Ethernet1/1 - host: 192.0.2.2 - informs: True + informs: true version: '3' auth: NMS users: @@ -679,16 +748,16 @@ authentication: algorithm: md5 password: '0x5632724fb8ac3699296af26281e1d0f1' - localized_key: True + localized_key: true - user: snmp_user_2 group: network-operator authentication: algorithm: md5 password: '0x5632724fb8ac3699296af26281e1d0f1' - localized_key: True + localized_key: true priv: privacy_password: '0x5632724fb8ac3699296af26281e1d0f1' - aes_128: True + aes_128: true use_acls: - user: snmp_user_1 ipv4: acl1 @@ -707,7 +776,7 @@ # authentication: # algorithm: md5 # password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" -# localized_key: True +# localized_key: true # priv: # privacy_password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" # @@ -739,9 +808,9 @@ # location: serverroom-1 # traps: # aaa: -# server_state_change: True +# server_state_change: true # system: -# clock_change_notification: True +# clock_change_notification: true # hosts: # - host: 192.0.2.1 # traps: true @@ -762,7 +831,7 @@ # authentication: # algorithm: md5 # password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" -# localized_key: True +# localized_key: true # priv: # privacy_password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" # @@ -771,7 +840,7 @@ # authentication: # algorithm: md5 # password: "0x5632724fb8ac3699296af26281e1d0f1" -# localized_key: True +# localized_key: true # # - authentication: # algorithm: md5 @@ -845,16 +914,16 @@ location: serverroom-2 traps: aaa: - server_state_change: True + server_state_change: true hosts: - host: 192.0.2.1 - traps: True + traps: true version: '1' community: public - host: 192.0.2.1 source_interface: Ethernet1/1 - host: 192.0.3.2 - informs: True + informs: true version: '3' auth: NMS users: @@ -864,7 +933,7 @@ authentication: algorithm: md5 password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" - localized_key: True + localized_key: true priv: privacy_password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" @@ -873,17 +942,17 @@ authentication: algorithm: md5 password: '0x5632724fb8ac3699296af26281e1d0f1' - localized_key: True + localized_key: true - user: snmp_user_2 group: network-operator authentication: algorithm: md5 password: '0x5632724fb8ac3699296af26281e1d0f1' - localized_key: True + localized_key: true priv: privacy_password: '0x5632724fb8ac3699296af26281e1d0f1' - aes_128: True + aes_128: true use_acls: - user: snmp_user_1 ipv4: acl1 @@ -904,9 +973,9 @@ # location: serverroom-1 # traps: # aaa: -# server_state_change: True +# server_state_change: true # system: -# clock_change_notification: True +# clock_change_notification: true # hosts: # - host: 192.0.2.1 # traps: true @@ -927,7 +996,7 @@ # authentication: # algorithm: md5 # password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" -# localized_key: True +# localized_key: true # priv: # privacy_password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" # @@ -936,7 +1005,7 @@ # authentication: # algorithm: md5 # password: "0x5632724fb8ac3699296af26281e1d0f1" -# localized_key: True +# localized_key: true # # - authentication: # algorithm: md5 @@ -978,16 +1047,16 @@ # location: serverroom-2 # traps: # aaa: -# server_state_change: True +# server_state_change: true # hosts: # - host: 192.0.2.1 -# traps: True +# traps: true # version: '1' # community: public # - host: 192.0.2.1 # source_interface: Ethernet1/1 # - host: 192.0.3.2 -# informs: True +# informs: true # version: '3' # auth: NMS # users: @@ -997,7 +1066,7 @@ # authentication: # algorithm: md5 # password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" -# localized_key: True +# localized_key: true # priv: # privacy_password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" # @@ -1006,17 +1075,17 @@ # authentication: # algorithm: md5 # password: '0x5632724fb8ac3699296af26281e1d0f1' -# localized_key: True +# localized_key: true # # - user: snmp_user_2 # group: network-operator # authentication: # algorithm: md5 # password: '0x5632724fb8ac3699296af26281e1d0f1' -# localized_key: True +# localized_key: true # priv: # privacy_password: '0x5632724fb8ac3699296af26281e1d0f1' -# aes_128: True +# aes_128: true # # use_acls: # - user: snmp_user_1 @@ -1082,9 +1151,9 @@ # location: serverroom-1 # traps: # aaa: -# server_state_change: True +# server_state_change: true # system: -# clock_change_notification: True +# clock_change_notification: true # hosts: # - host: 192.0.2.1 # traps: true @@ -1105,7 +1174,7 @@ # authentication: # algorithm: md5 # password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" -# localized_key: True +# localized_key: true # priv: # privacy_password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" # @@ -1114,7 +1183,7 @@ # authentication: # algorithm: md5 # password: "0x5632724fb8ac3699296af26281e1d0f1" -# localized_key: True +# localized_key: true # # - authentication: # algorithm: md5 @@ -1159,7 +1228,7 @@ # authentication: # algorithm: md5 # password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" -# localized_key: True +# localized_key: true # priv: # privacy_password: "0xcbde46b02c46e0bcd3ac5af6a8b13da9" @@ -1185,18 +1254,18 @@ location: serverroom-1 traps: aaa: - server_state_change: True + server_state_change: true system: - clock_change_notification: True + clock_change_notification: true hosts: - host: 192.0.2.1 - traps: True + traps: true version: '1' community: public - host: 192.0.2.1 source_interface: Ethernet1/1 - host: 192.0.2.2 - informs: True + informs: true version: '3' auth: NMS users: @@ -1206,16 +1275,16 @@ authentication: algorithm: md5 password: '0x5632724fb8ac3699296af26281e1d0f1' - localized_key: True + localized_key: true - user: snmp_user_2 group: network-operator authentication: algorithm: md5 password: '0x5632724fb8ac3699296af26281e1d0f1' - localized_key: True + localized_key: true priv: privacy_password: '0x5632724fb8ac3699296af26281e1d0f1' - aes_128: True + aes_128: true use_acls: - user: snmp_user_1 ipv4: acl1 @@ -1282,9 +1351,9 @@ # location: serverroom-1 # traps: # aaa: -# server_state_change: True +# server_state_change: true # system: -# clock_change_notification: True +# clock_change_notification: true # hosts: # - host: 192.0.2.1 # traps: true @@ -1305,7 +1374,7 @@ # authentication: # algorithm: md5 # password: "0x5632724fb8ac3699296af26281e1d0f1" -# localized_key: True +# localized_key: true # # - authentication: # algorithm: md5 @@ -1375,6 +1444,7 @@ """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.snmp_server.snmp_server import ( Snmp_serverArgs, ) diff --git a/plugins/modules/nxos_snmp_traps.py b/plugins/modules/nxos_snmp_traps.py index 0c9e263b5..fce1a8a20 100644 --- a/plugins/modules/nxos_snmp_traps.py +++ b/plugins/modules/nxos_snmp_traps.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -109,17 +110,13 @@ """ +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + get_capabilities, load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_capabilities, -) -from ansible.module_utils.basic import AnsibleModule def get_platform_id(module): @@ -180,9 +177,7 @@ def get_snmp_traps(group, module): ] if "all" in group and "N3K-C35" in get_platform_id(module): - module.warn( - "Platform does not support bfd traps; bfd ignored for 'group: all' request" - ) + module.warn("Platform does not support bfd traps; bfd ignored for 'group: all' request") feature_list.remove("bfd") for each in feature_list: @@ -230,17 +225,13 @@ def get_trap_commands(group, state, existing, module): if state == "disabled": for feature in existing: if existing[feature]: - trap_command = "no snmp-server enable traps {0}".format( - feature - ) + trap_command = "no snmp-server enable traps {0}".format(feature) commands.append(trap_command) elif state == "enabled": for feature in existing: if existing[feature] is False: - trap_command = "snmp-server enable traps {0}".format( - feature - ) + trap_command = "snmp-server enable traps {0}".format(feature) commands.append(trap_command) else: @@ -251,15 +242,11 @@ def get_trap_commands(group, state, existing, module): disabled = True if state == "disabled" and enabled: - commands.append( - ["no snmp-server enable traps {0}".format(group)] - ) + commands.append(["no snmp-server enable traps {0}".format(group)]) elif state == "enabled" and disabled: commands.append(["snmp-server enable traps {0}".format(group)]) else: - module.fail_json( - msg="{0} is not a currently " "enabled feature.".format(group) - ) + module.fail_json(msg="{0} is not a currently " "enabled feature.".format(group)) return commands @@ -304,11 +291,7 @@ def main(): ), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() results = {"changed": False, "commands": [], "warnings": warnings} diff --git a/plugins/modules/nxos_snmp_user.py b/plugins/modules/nxos_snmp_user.py index 88b34cf12..a3b0b5fa8 100644 --- a/plugins/modules/nxos_snmp_user.py +++ b/plugins/modules/nxos_snmp_user.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -100,14 +101,12 @@ import re +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule def execute_show_command(command, module, text=False): @@ -253,9 +252,7 @@ def get_non_structured_snmp_user(body_text): return resource resource["user"] = m.group("user") resource["auth"] = m.group("auth") - resource["encrypt"] = ( - "aes-128" if "aes" in str(m.group("priv")) else "none" - ) + resource["encrypt"] = "aes-128" if "aes" in str(m.group("priv")) else "none" resource["group"] = [m.group("group")] more_groups = re.findall(r"^\s+([\w\d-]+)\s*$", output, re.M) @@ -314,8 +311,6 @@ def main(): state=dict(choices=["absent", "present"], default="present"), ) - argument_spec.update(nxos_argument_spec) - module = AnsibleModule( argument_spec=argument_spec, required_together=[["authentication", "pwd"], ["encrypt", "privacy"]], @@ -336,8 +331,7 @@ def main(): if privacy and encrypt: if not pwd and authentication: module.fail_json( - msg="pwd and authentication must be provided " - "when using privacy and encrypt" + msg="pwd and authentication must be provided " "when using privacy and encrypt", ) if group and group not in get_snmp_groups(module): diff --git a/plugins/modules/nxos_static_route.py b/plugins/modules/nxos_static_route.py deleted file mode 100644 index 4db8c8a23..000000000 --- a/plugins/modules/nxos_static_route.py +++ /dev/null @@ -1,384 +0,0 @@ -#!/usr/bin/python -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - - -DOCUMENTATION = """ -module: nxos_static_route -extends_documentation_fragment: -- cisco.nxos.nxos -short_description: (deprecated, removed after 2022-06-01) Manages static - route configuration -description: -- Manages static route configuration -version_added: 1.0.0 -deprecated: - alternative: nxos_static_routes - why: Updated modules released with more functionality - removed_at_date: '2022-06-01' -author: Gabriele Gerbino (@GGabriele) -notes: -- Tested against NXOSv 7.3.(0)D1(1) on VIRL -- Unsupported for Cisco MDS -- If no vrf is supplied, vrf is set to default. -- If C(state=absent), the route will be removed, regardless of the non-required parameters. -options: - prefix: - description: - - Destination prefix of static route. - aliases: - - address - type: str - next_hop: - description: - - Next hop address or interface of static route. If interface, it must be the - fully-qualified interface name. - type: str - vrf: - description: - - VRF for static route. - default: default - type: str - tag: - description: - - Route tag value (numeric) or keyword 'default'. - type: str - route_name: - description: - - Name of the route or keyword 'default'. Used with the name parameter on the - CLI. - type: str - pref: - description: - - Preference or administrative difference of route (range 1-255) or keyword 'default'. - aliases: - - admin_distance - type: str - aggregate: - description: List of static route definitions - type: list - elements: dict - suboptions: - prefix: - description: - - Destination prefix of static route. - required: True - type: str - next_hop: - description: - - Next hop address or interface of static route. If interface, it must be the - fully-qualified interface name. - required: true - type: str - vrf: - description: - - VRF for static route. - type: str - tag: - description: - - Route tag value (numeric) or keyword 'default'. - type: str - route_name: - description: - - Name of the route or keyword 'default'. Used with the name parameter on the - CLI. - type: str - pref: - description: - - Preference or administrative difference of route (range 1-255) or keyword 'default'. - aliases: - - admin_distance - type: str - track: - description: - - Track value (range 1 - 512). Track must already be configured on the device - before adding the route. - type: int - state: - description: - - Manage the state of the resource. - choices: - - present - - absent - type: str - track: - description: - - Track value (range 1 - 512). Track must already be configured on the device - before adding the route. - type: int - state: - description: - - Manage the state of the resource. - choices: - - present - - absent - default: present - type: str -""" - -EXAMPLES = """ -- cisco.nxos.nxos_static_route: - prefix: 192.168.20.64/24 - next_hop: 192.0.2.3 - route_name: testing - pref: 100 -""" - -RETURN = """ -commands: - description: commands sent to the device - returned: always - type: list - sample: ["ip route 192.168.20.0/24 192.0.2.3 name testing 100"] -""" -import re -from copy import deepcopy - -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_config, - load_config, - run_commands, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( - CustomNetworkConfig, -) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - remove_default_spec, -) - - -def reconcile_candidate(module, candidate, prefix, want): - state, vrf = want["state"], want["vrf"] - if vrf == "default": - parents = [] - flags = " | include '^ip route'" - else: - parents = ["vrf context {0}".format(vrf)] - flags = " | section '{0}' | include '^ ip route'".format(parents[0]) - - # Find existing routes in this vrf/default - netcfg = CustomNetworkConfig( - indent=2, contents=get_config(module, flags=[flags]) - ) - routes = str(netcfg).split("\n") - # strip whitespace from route strings - routes = [i.strip() for i in routes] - - prefix_and_nh = "ip route {0} {1}".format(prefix, want["next_hop"]) - existing = [i for i in routes if i.startswith(prefix_and_nh)] - proposed = set_route_command(prefix, want, module) - - commands = [] - if state == "absent" and existing: - commands = ["no " + existing[0]] - elif state == "present" and proposed not in routes: - if existing: - commands = ["no " + existing[0]] - commands.append(proposed) - - if commands: - candidate.add(commands, parents=parents) - - -def get_configured_track(module, ctrack): - check_track = "{0}".format(ctrack) - track_exists = False - command = "show track" - try: - body = run_commands(module, {"command": command, "output": "text"}) - match = re.findall(r"Track\s+(\d+)", body[0]) - except IndexError: - return None - if check_track in match: - track_exists = True - return track_exists - - -def set_route_command(prefix, w, module): - route_cmd = "ip route {0} {1}".format(prefix, w["next_hop"]) - - if w["track"]: - if w["track"] in range(1, 512): - if get_configured_track(module, w["track"]): - route_cmd += " track {0}".format(w["track"]) - else: - module.fail_json( - msg="Track {0} not configured on device".format(w["track"]) - ) - else: - module.fail_json(msg="Invalid track number, valid range is 1-512.") - if w["route_name"] and w["route_name"] != "default": - route_cmd += " name {0}".format(w["route_name"]) - if w["tag"]: - if w["tag"] != "default" and w["tag"] != "0": - route_cmd += " tag {0}".format(w["tag"]) - if w["pref"] and w["pref"] != "default": - route_cmd += " {0}".format(w["pref"]) - - return route_cmd - - -def get_dotted_mask(mask): - bits = 0 - for i in range(32 - mask, 32): - bits |= 1 << i - mask = "%d.%d.%d.%d" % ( - (bits & 0xFF000000) >> 24, - (bits & 0xFF0000) >> 16, - (bits & 0xFF00) >> 8, - (bits & 0xFF), - ) - return mask - - -def get_network_start(address, netmask): - address = address.split(".") - netmask = netmask.split(".") - return [str(int(address[x]) & int(netmask[x])) for x in range(0, 4)] - - -def network_from_string(address, mask, module): - octects = address.split(".") - - if len(octects) > 4: - module.fail_json(msg="Incorrect address format.", address=address) - - for octect in octects: - try: - if int(octect) < 0 or int(octect) > 255: - module.fail_json( - msg="Address may contain invalid values.", address=address - ) - except ValueError: - module.fail_json( - msg="Address may contain non-integer values.", address=address - ) - - try: - if int(mask) < 0 or int(mask) > 32: - module.fail_json(msg="Incorrect mask value.", mask=mask) - except ValueError: - module.fail_json(msg="Mask may contain non-integer values.", mask=mask) - - netmask = get_dotted_mask(int(mask)) - return ".".join(get_network_start(address, netmask)) - - -def normalize_prefix(module, prefix): - splitted_prefix = prefix.split("/") - - address = splitted_prefix[0] - if len(splitted_prefix) > 2: - module.fail_json(msg="Incorrect address format.", address=address) - elif len(splitted_prefix) == 2: - mask = splitted_prefix[1] - network = network_from_string(address, mask, module) - - normalized_prefix = str(network) + "/" + str(mask) - else: - normalized_prefix = prefix + "/" + str(32) - - return normalized_prefix - - -def map_params_to_obj(module): - obj = [] - aggregate = module.params.get("aggregate") - if aggregate: - for item in aggregate: - for key in item: - if item.get(key) is None: - item[key] = module.params[key] - - d = item.copy() - obj.append(d) - else: - obj.append( - { - "prefix": module.params["prefix"], - "next_hop": module.params["next_hop"], - "vrf": module.params["vrf"], - "tag": module.params["tag"], - "route_name": module.params["route_name"], - "pref": module.params["pref"], - "state": module.params["state"], - "track": module.params["track"], - } - ) - - return obj - - -def main(): - element_spec = dict( - prefix=dict(type="str", aliases=["address"]), - next_hop=dict(type="str"), - vrf=dict(type="str", default="default"), - tag=dict(type="str"), - route_name=dict(type="str"), - pref=dict(type="str", aliases=["admin_distance"]), - state=dict(choices=["absent", "present"], default="present"), - track=dict(type="int"), - ) - - aggregate_spec = deepcopy(element_spec) - aggregate_spec["prefix"] = dict(required=True) - aggregate_spec["next_hop"] = dict(required=True) - - # remove default in aggregate spec, to handle common arguments - remove_default_spec(aggregate_spec) - - argument_spec = dict( - aggregate=dict(type="list", elements="dict", options=aggregate_spec) - ) - - argument_spec.update(element_spec) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) - - warnings = list() - result = {"changed": False, "commands": []} - if warnings: - result["warnings"] = warnings - - want = map_params_to_obj(module) - for w in want: - prefix = normalize_prefix(module, w["prefix"]) - candidate = CustomNetworkConfig(indent=3) - reconcile_candidate(module, candidate, prefix, w) - - if not module.check_mode and candidate: - candidate = candidate.items_text() - load_config(module, candidate) - result["commands"].extend(candidate) - result["changed"] = True - - module.exit_json(**result) - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/nxos_static_routes.py b/plugins/modules/nxos_static_routes.py index 0bcf1c0f0..679f5cdb4 100644 --- a/plugins/modules/nxos_static_routes.py +++ b/plugins/modules/nxos_static_routes.py @@ -1,34 +1,17 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# Copyright 2019 Red Hat +# Copyright 2023 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -############################################# -# WARNING # -############################################# -# -# This file is auto generated by the resource -# module builder playbook. -# -# Do not edit this file manually. -# -# Changes to this file will be over written -# by the resource module builder. -# -# Changes should be made in the model used to -# generate this file or in the resource module -# builder template. -# -############################################# """ The module file for nxos_static_routes """ from __future__ import absolute_import, division, print_function -__metaclass__ = type +__metaclass__ = type DOCUMENTATION = """ module: nxos_static_routes @@ -36,9 +19,11 @@ description: This module configures and manages the attributes of static routes on Cisco NX-OS platforms. version_added: 1.0.0 -author: Adharsh Srivats Rangarajan (@adharshsrivatsr) +author: + - Adharsh Srivats Rangarajan (@adharshsrivatsr) + - Sagar Paul (@KB-perByte) notes: -- Tested against NX-OS 7.3.(0)D1(1) on VIRL +- Tested against Nexus 9300v running NX-OS 9.3.6 on CML. - Unsupported for Cisco MDS - When a route is configured for a non-existent VRF, the VRF is created and the route is added to it. @@ -140,31 +125,57 @@ - rendered - parsed default: merged - """ + EXAMPLES = """ -# Using deleted: +# Using deleted - delete all # Before state: # ------------- # +# switch# show running-config | include '^ip(v6)* route' # ip route 192.0.2.32/28 192.0.2.12 name new_route # ip route 192.0.2.26/24 192.0.2.13 tag 12 +# switch# show running-config | section '^vrf context' - name: Delete all routes cisco.nxos.nxos_static_routes: state: deleted +# Task Output +# ----------- +# +# before: +# - address_families: +# - afi: ipv4 +# routes: +# - dest: 192.0.2.0/24 +# next_hops: +# - forward_router_address: 192.0.2.13 +# tag: 12 +# - dest: 192.0.2.32/28 +# next_hops: +# - forward_router_address: 192.0.2.12 +# route_name: new_route +# commands: +# - no ip route 192.0.2.0/24 192.0.2.13 tag 12 +# - no ip route 192.0.2.32/28 192.0.2.12 name new_route +# after: [] + # After state: # ------------ -# +# switch# show running-config | include '^ip(v6)* route' +# switch# show running-config | section '^vrf context' +# Using deleted - vrf based # Before state: # ------------ # +# switch# show running-config | include '^ip(v6)* route' # ip route 192.0.2.16/28 192.0.2.24 name new_route # ip route 192.0.2.80/28 192.0.2.26 tag 12 +# switch# show running-config | section '^vrf context' # vrf context trial_vrf # ip route 192.0.2.64/28 192.0.2.22 tag 4 # ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 @@ -173,21 +184,78 @@ - name: Delete routes based on VRF cisco.nxos.nxos_static_routes: config: - - vrf: trial_vrf + - vrf: trial_vrf state: deleted +# Task Output +# ----------- +# +# before: +# - address_families: +# - afi: ipv4 +# routes: +# - dest: 192.0.2.64/28 +# next_hops: +# - forward_router_address: 192.0.2.22 +# tag: 4 +# - admin_distance: 1 +# forward_router_address: 192.0.2.23 +# route_name: merged_route +# - afi: ipv6 +# routes: +# - dest: '2200:10::/36' +# next_hops: +# - admin_distance: 5 +# dest_vrf: dest +# forward_router_address: '2048:ae12::1' +# vrf: trial_vrf +# - address_families: +# - afi: ipv4 +# routes: +# - dest: 192.0.2.16/28 +# next_hops: +# - forward_router_address: 192.0.2.24 +# route_name: new_route +# - dest: 192.0.2.80/28 +# next_hops: +# - forward_router_address: 192.0.2.26 +# tag: 12 +# commands: +# - vrf context trial_vrf +# - no ip route 192.0.2.64/28 192.0.2.22 tag 4 +# - no ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 +# - no ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5 +# after: +# - address_families: +# - afi: ipv4 +# routes: +# - dest: 192.0.2.16/28 +# next_hops: +# - forward_router_address: 192.0.2.24 +# route_name: new_route +# - dest: 192.0.2.80/28 +# next_hops: +# - forward_router_address: 192.0.2.26 +# tag: 12 + # After state: # ----------- +# +# switch# show running-config | include '^ip(v6)* route' # ip route 192.0.2.16/28 192.0.2.24 name new_route # ip route 192.0.2.80/28 192.0.2.26 tag 12 +# switch# show running-config | section '^vrf context' # vrf context trial_vrf +# Using deleted - afi based # Before state: # ------------ # +# switch# show running-config | include '^ip(v6)* route' # ip route 192.0.2.16/28 192.0.2.24 name new_route # ip route 192.0.2.80/28 192.0.2.26 tag 12 +# switch# show running-config | section '^vrf context' # vrf context trial_vrf # ip route 192.0.2.64/28 192.0.2.22 tag 4 # ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 @@ -196,112 +264,255 @@ - name: Delete routes based on AFI in a VRF cisco.nxos.nxos_static_routes: config: - - vrf: trial_vrf - address_families: - - afi: ipv4 + - vrf: trial_vrf + address_families: + - afi: ipv4 state: deleted -# After state: +# Task Output # ----------- -# ip route 192.0.2.16/28 192.0.2.24 name new_route -# ip route 192.0.2.80/28 192.0.2.26 tag 12 -# vrf context trial_vrf -# ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5 - +# +# before: +# - address_families: +# - afi: ipv4 +# routes: +# - dest: 192.0.2.64/28 +# next_hops: +# - forward_router_address: 192.0.2.22 +# tag: 4 +# - admin_distance: 1 +# forward_router_address: 192.0.2.23 +# route_name: merged_route +# - afi: ipv6 +# routes: +# - dest: '2200:10::/36' +# next_hops: +# - admin_distance: 5 +# dest_vrf: dest +# forward_router_address: '2048:ae12::1' +# vrf: trial_vrf +# - address_families: +# - afi: ipv4 +# routes: +# - dest: 192.0.2.16/28 +# next_hops: +# - forward_router_address: 192.0.2.24 +# route_name: new_route +# - dest: 192.0.2.80/28 +# next_hops: +# - forward_router_address: 192.0.2.26 +# tag: 12 +# commands: +# - vrf context trial_vrf +# - no ip route 192.0.2.64/28 192.0.2.22 tag 4 +# - no ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 +# after: +# - address_families: +# - afi: ipv6 +# routes: +# - dest: '2200:10::/36' +# next_hops: +# - admin_distance: 5 +# dest_vrf: dest +# forward_router_address: '2048:ae12::1' +# vrf: trial_vrf +# - address_families: +# - afi: ipv4 +# routes: +# - dest: 192.0.2.16/28 +# next_hops: +# - forward_router_address: 192.0.2.24 +# route_name: new_route +# - dest: 192.0.2.80/28 +# next_hops: +# - forward_router_address: 192.0.2.26 +# tag: 12 -# Before state: +# After state: # ----------- +# +# switch# show running-config | include '^ip(v6)* route' # ip route 192.0.2.16/28 192.0.2.24 name new_route +# ip route 192.0.2.80/28 192.0.2.26 tag 12 +# switch# show running-config | section '^vrf context' # vrf context trial_vrf # ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5 - # Using merged # Before state: # ------------- -# +# switch# show running-config | include '^ip(v6)* route' +# switch# show running-config | section '^vrf context' - name: Merge new static route configuration cisco.nxos.nxos_static_routes: config: - - vrf: trial_vrf - address_families: - - afi: ipv4 - routes: - - dest: 192.0.2.64/24 - next_hops: - - forward_router_address: 192.0.2.22 - tag: 4 - admin_distance: 2 - - - address_families: - - afi: ipv4 - routes: - - dest: 192.0.2.16/24 - next_hops: - - forward_router_address: 192.0.2.24 - route_name: new_route - - afi: ipv6 - routes: - - dest: 2001:db8::/64 - next_hops: - - interface: eth1/3 - forward_router_address: 2001:db8::12 + - vrf: trial_vrf + address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.64/24 + next_hops: + - forward_router_address: 192.0.2.22 + tag: 4 + admin_distance: 2 + - address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.16/24 + next_hops: + - forward_router_address: 192.0.2.24 + route_name: new_route + - afi: ipv6 + routes: + - dest: '2001:db8::/64' + next_hops: + - interface: eth1/3 + forward_router_address: '2001:db8::12' state: merged +# Task Output +# ----------- +# +# before:[] +# commands: +# - vrf context trial_vrf +# - ip route 192.0.2.64/24 192.0.2.22 tag 4 2 +# - ip route 192.0.2.16/24 192.0.2.24 name new_route +# - ipv6 route 2001:db8::/64 Ethernet1/3 2001:db8::12 +# after: +# - vrf: trial_vrf +# address_families: +# - afi: ipv4 +# routes: +# - dest: 192.0.2.64/24 +# next_hops: +# - forward_router_address: 192.0.2.22 +# tag: 4 +# admin_distance: 2 +# - address_families: +# - afi: ipv4 +# routes: +# - dest: 192.0.2.16/24 +# next_hops: +# - forward_router_address: 192.0.2.24 +# route_name: new_route +# - afi: ipv6 +# routes: +# - dest: 2001:db8::/64 +# next_hops: +# - interface: eth1/3 +# forward_router_address: 2 + # After state: # ------------ # +# switch# show running-config | include '^ip(v6)* route' # ip route 192.0.2.16/24 192.0.2.24 name new_route # ipv6 route 2001:db8::/64 Ethernet1/3 2001:db8::12 +# switch# show running-config | section '^vrf context' # vrf context trial_vrf # ip route 192.0.2.0/24 192.0.2.22 tag 4 2 - -# Using overridden: +# Using overridden # Before state: # ------------- # +# switch# show running-config | include '^ip(v6)* route' # ip route 192.0.2.16/28 192.0.2.24 name new_route # ip route 192.0.2.80/28 192.0.2.26 tag 12 +# switch# show running-config | section '^vrf context' # vrf context trial_vrf # ip route 192.0.2.64/28 192.0.2.22 tag 4 # ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 -- name: Overriden existing static route configuration with new configuration +- name: Overridden existing static route configuration with new configuration cisco.nxos.nxos_static_routes: config: - - vrf: trial_vrf - address_families: - - afi: ipv4 - routes: - - dest: 192.0.2.16/28 - next_hops: - - forward_router_address: 192.0.2.23 - route_name: overridden_route1 - admin_distance: 3 - - - forward_router_address: 192.0.2.45 - route_name: overridden_route2 - dest_vrf: destinationVRF - interface: Ethernet1/2 + - vrf: trial_vrf + address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.16/28 + next_hops: + - forward_router_address: 192.0.2.23 + route_name: overridden_route1 + admin_distance: 3 + - forward_router_address: 192.0.2.45 + route_name: overridden_route2 + dest_vrf: destinationVRF + interface: Ethernet1/2 state: overridden +# Task Output +# ----------- +# +# before: +# - address_families: +# - afi: ipv4 +# routes: +# - dest: 192.0.2.64/28 +# next_hops: +# - forward_router_address: 192.0.2.22 +# tag: 4 +# - admin_distance: 1 +# forward_router_address: 192.0.2.23 +# route_name: merged_route +# vrf: trial_vrf +# - address_families: +# - afi: ipv4 +# routes: +# - dest: 192.0.2.16/28 +# next_hops: +# - forward_router_address: 192.0.2.24 +# route_name: new_route +# - dest: 192.0.2.80/28 +# next_hops: +# - forward_router_address: 192.0.2.26 +# tag: 12 +# commands: +# - no ip route 192.0.2.16/28 192.0.2.24 name new_route +# - no ip route 192.0.2.80/28 192.0.2.26 tag 12 +# - vrf context trial_vrf +# - no ip route 192.0.2.64/28 192.0.2.22 tag 4 +# - no ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 +# - ip route 192.0.2.16/28 192.0.2.23 name overridden_route1 3 +# - ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name overridden_route2 +# after: +# - address_families: +# - afi: ipv4 +# routes: +# - dest: 192.0.2.16/28 +# next_hops: +# - admin_distance: 3 +# forward_router_address: 192.0.2.23 +# route_name: overridden_route1 +# - dest_vrf: destinationVRF +# forward_router_address: 192.0.2.45 +# interface: Ethernet1/2 +# route_name: overridden_route2 +# vrf: trial_vrf + # After state: # ------------ # -# ip route 192.0.2.16/28 192.0.2.23 name replaced_route1 3 -# ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2 - +# switch# show running-config | include '^ip(v6)* route' +# switch# show running-config | section '^vrf context' +# vrf context trial_vrf +# ip route 192.0.2.16/28 192.0.2.23 name overridden_route1 3 +# ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name overridden_route2 -# Using replaced: +# Using replaced # Before state: # ------------ +# +# switch# show running-config | include '^ip(v6)* route' # ip route 192.0.2.16/28 192.0.2.24 name new_route # ip route 192.0.2.80/28 192.0.2.26 tag 12 +# switch# show running-config | section '^vrf context' # vrf context trial_vrf # ip route 192.0.2.64/28 192.0.2.22 tag 4 # ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 @@ -309,45 +520,111 @@ - name: Replaced the existing static configuration of a prefix with new configuration cisco.nxos.nxos_static_routes: config: - - address_families: - - afi: ipv4 - routes: - - dest: 192.0.2.16/28 - next_hops: - - forward_router_address: 192.0.2.23 - route_name: replaced_route1 - admin_distance: 3 - - - forward_router_address: 192.0.2.45 - route_name: replaced_route2 - dest_vrf: destinationVRF - interface: Ethernet1/2 + - address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.16/28 + next_hops: + - forward_router_address: 192.0.2.23 + route_name: replaced_route1 + admin_distance: 3 + - forward_router_address: 192.0.2.45 + route_name: replaced_route2 + dest_vrf: destinationVRF + interface: Ethernet1/2 state: replaced -# After state: +# Task Output # ----------- +# +# before: +# - address_families: +# - afi: ipv4 +# routes: +# - dest: 192.0.2.64/28 +# next_hops: +# - forward_router_address: 192.0.2.22 +# tag: 4 +# - admin_distance: 1 +# forward_router_address: 192.0.2.23 +# route_name: merged_route +# vrf: trial_vrf +# - address_families: +# - afi: ipv4 +# routes: +# - dest: 192.0.2.16/28 +# next_hops: +# - forward_router_address: 192.0.2.24 +# route_name: new_route +# - dest: 192.0.2.80/28 +# next_hops: +# - forward_router_address: 192.0.2.26 +# tag: 12 +# commands: +# - no ip route 192.0.2.16/28 192.0.2.24 name new_route +# - ip route 192.0.2.16/28 192.0.2.23 name replaced_route1 3 +# - ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2 +# after: +# - address_families: +# - afi: ipv4 +# routes: +# - dest: 192.0.2.64/28 +# next_hops: +# - forward_router_address: 192.0.2.22 +# tag: 4 +# - admin_distance: 1 +# forward_router_address: 192.0.2.23 +# route_name: merged_route +# vrf: trial_vrf +# - address_families: +# - afi: ipv4 +# routes: +# - dest: 192.0.2.16/28 +# next_hops: +# - admin_distance: 3 +# forward_router_address: 192.0.2.23 +# route_name: replaced_route1 +# - dest_vrf: destinationVRF +# forward_router_address: 192.0.2.45 +# interface: Ethernet1/2 +# route_name: replaced_route2 +# - dest: 192.0.2.80/28 +# next_hops: +# - forward_router_address: 192.0.2.26 +# tag: 12 + +# After state: +# ------------ +# +# switch# show running-config | include '^ip(v6)* route' # ip route 192.0.2.16/28 192.0.2.23 name replaced_route1 3 # ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2 # ip route 192.0.2.80/28 192.0.2.26 tag 12 +# switch# show running-config | section '^vrf context' # vrf context trial_vrf # ip route 192.0.2.64/28 192.0.2.22 tag 4 # ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 -# Using gathered: +# Using gathered # Before state: # ------------- +# +# switch# show running-config | include '^ip(v6)* route' # ipv6 route 2001:db8:12::/32 2001:db8::12 +# switch# show running-config | section '^vrf context' # vrf context Test # ip route 192.0.2.48/28 192.0.2.13 # ip route 192.0.2.48/28 192.0.2.14 5 -- name: Gather the exisitng condiguration +- name: Gather the existing configuration cisco.nxos.nxos_static_routes: state: gathered -# returns: +# Task Output +# ----------- +# # gathered: # - vrf: Test # address_families: @@ -368,44 +645,47 @@ # - forward_router_address: 2001:db8::12 -# Using rendered: +# Using rendered - name: Render required configuration to be pushed to the device cisco.nxos.nxos_static_routes: config: - - address_families: - - afi: ipv4 - routes: - - dest: 192.0.2.48/28 - next_hops: - - forward_router_address: 192.0.2.13 - - - afi: ipv6 - routes: - - dest: 2001:db8::/64 - next_hops: - - interface: eth1/3 - forward_router_address: 2001:db8::12 + - address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.48/28 + next_hops: + - forward_router_address: 192.0.2.13 + - afi: ipv6 + routes: + - dest: 2001:db8::/64 + next_hops: + - interface: eth1/3 + forward_router_address: 2001:db8::12 state: rendered -# returns +# Task Output +# ----------- +# # rendered: # vrf context default # ip route 192.0.2.48/28 192.0.2.13 # ipv6 route 2001:db8::/64 Ethernet1/3 2001:db8::12 - # Using parsed - name: Parse the config to structured data cisco.nxos.nxos_static_routes: + state: parsed running_config: | ipv6 route 2002:db8:12::/32 2002:db8:12::1 vrf context Test ip route 192.0.2.48/28 192.0.2.13 ip route 192.0.2.48/28 192.0.2.14 5 -# returns: +# Task Output +# ----------- +# # parsed: # - vrf: Test # address_families: @@ -414,43 +694,66 @@ # - dest: 192.0.2.48/28 # next_hops: # - forward_router_address: 192.0.2.13 -# # - forward_router_address: 192.0.2.14 # admin_distance: 5 -# # - address_families: # - afi: ipv6 # routes: # - dest: 2002:db8:12::/32 # next_hops: # - forward_router_address: 2002:db8:12::1 - - """ + RETURN = """ before: - description: The configuration prior to the model invocation. - returned: always + description: The configuration prior to the module execution. + returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) type: list sample: > - The configuration returned will always be in the same format - of the parameters above. + This output will always be in the same format as the + module argspec. after: - description: The resulting configuration model invocation. + description: The resulting configuration after module execution. returned: when changed type: list sample: > - The configuration returned will always be in the same format - of the parameters above. + This output will always be in the same format as the + module argspec. commands: description: The set of commands pushed to the remote device. - returned: always + returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) + type: list + sample: + - ip route 192.0.2.16/28 192.0.2.24 name new_route + - vrf context trial_vrf + - ip route 192.0.2.16/28 192.0.2.23 name overridden_route1 3 +rendered: + description: The provided configuration in the task rendered in device-native format (offline). + returned: when I(state) is C(rendered) + type: list + sample: + - ip route 192.0.2.16/28 192.0.2.24 name new_route + - vrf context trial_vrf + - ip route 192.0.2.16/28 192.0.2.23 name overridden_route1 3 +gathered: + description: Facts about the network resource gathered from the remote device as structured data. + returned: when I(state) is C(gathered) + type: list + sample: > + This output will always be in the same format as the + module argspec. +parsed: + description: The device native config provided in I(running_config) option parsed into structured data as per module argspec. + returned: when I(state) is C(parsed) type: list - sample: ['ip route 192.0.2.48/28 192.0.2.12 Ethernet1/2 name sample_route', - 'ipv6 route 2001:db8:3000::/36 2001:db8:200:2::2', 'vrf context test','ip route 192.0.2.48/28 192.0.2.121'] + sample: > + This output will always be in the same format as the + module argspec. """ + from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.static_routes.static_routes import ( Static_routesArgs, ) @@ -465,8 +768,18 @@ def main(): :returns: the result form module invocation """ + module = AnsibleModule( - argument_spec=Static_routesArgs.argument_spec, supports_check_mode=True + argument_spec=Static_routesArgs.argument_spec, + mutually_exclusive=[["config", "running_config"]], + required_if=[ + ["state", "merged", ["config"]], + ["state", "replaced", ["config"]], + ["state", "overridden", ["config"]], + ["state", "rendered", ["config"]], + ["state", "parsed", ["running_config"]], + ], + supports_check_mode=True, ) result = Static_routes(module).execute_module() diff --git a/plugins/modules/nxos_system.py b/plugins/modules/nxos_system.py index 4c5c77817..dafbf9f1f 100644 --- a/plugins/modules/nxos_system.py +++ b/plugins/modules/nxos_system.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -97,14 +98,14 @@ - name: configure name servers cisco.nxos.nxos_system: name_servers: - - 8.8.8.8 - - 8.8.4.4 + - 8.8.8.8 + - 8.8.4.4 - name: configure name servers with VRF support cisco.nxos.nxos_system: name_servers: - - {server: 8.8.8.8, vrf: mgmt} - - {server: 8.8.4.4, vrf: mgmt} + - {server: 8.8.8.8, vrf: mgmt} + - {server: 8.8.4.4, vrf: mgmt} """ RETURN = """ @@ -118,13 +119,6 @@ """ import re -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_config, - load_config, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( @@ -134,6 +128,12 @@ ComplexList, ) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + get_config, + load_config, +) + + _CONFIGURED_VRFS = None @@ -373,11 +373,7 @@ def main(): state=dict(default="present", choices=["present", "absent"]), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() diff --git a/plugins/modules/nxos_telemetry.py b/plugins/modules/nxos_telemetry.py index 7e1f65b7c..89a58e2d2 100644 --- a/plugins/modules/nxos_telemetry.py +++ b/plugins/modules/nxos_telemetry.py @@ -28,6 +28,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -82,10 +83,10 @@ elements: raw suboptions: id: - type: int + type: str description: - Destination group identifier. - - Value must be a int representing the destination group identifier. + - Value must be an integer or string representing the destination group identifier. destination: type: dict description: @@ -123,10 +124,10 @@ elements: raw suboptions: id: - type: int + type: str description: - Sensor group identifier. - - Value must be a int representing the sensor group identifier. + - Value must be a integer or a string representing the sensor group identifier. data_source: type: str description: @@ -167,12 +168,12 @@ elements: raw suboptions: id: - type: int + type: str description: - Subscription identifier. - - Value must be a int representing the subscription identifier. + - Value must be an integer or string representing the subscription identifier. destination_group: - type: int + type: str description: - Associated destination group. sensor_group: @@ -182,7 +183,7 @@ - Value must be a dict defining values for keys (id, sample_interval). suboptions: id: - type: int + type: str description: - Associated sensor group id. sample_interval: @@ -224,41 +225,41 @@ source_interface: Ethernet1/1 vrf: management destination_groups: - - id: 2 - destination: - ip: 192.168.0.2 - port: 50001 - protocol: gPRC - encoding: GPB - - id: 55 - destination: - ip: 192.168.0.55 - port: 60001 - protocol: gPRC - encoding: GPB + - id: 2 + destination: + ip: 192.168.0.2 + port: 50001 + protocol: gRPC + encoding: GPB + - id: 55 + destination: + ip: 192.168.0.55 + port: 60001 + protocol: gRPC + encoding: GPB sensor_groups: - - id: 1 - data_source: NX-API - path: - name: '"show lldp neighbors detail"' - depth: 0 - - id: 55 - data_source: DME - path: - name: sys/ch - depth: unbounded - filter_condition: ne(eqptFt.operSt,"ok") + - id: 1 + data_source: NX-API + path: + name: '"show lldp neighbors detail"' + depth: 0 + - id: 55 + data_source: DME + path: + name: sys/ch + depth: unbounded + filter_condition: ne(eqptFt.operSt,"ok") subscriptions: - - id: 5 - destination_group: 55 - sensor_group: - id: 1 - sample_interval: 1000 - - id: 6 - destination_group: 2 - sensor_group: - id: 55 - sample_interval: 2000 + - id: 5 + destination_group: 55 + sensor_group: + id: 1 + sample_interval: 1000 + - id: 6 + destination_group: 2 + sensor_group: + id: 55 + sample_interval: 2000 state: merged @@ -276,18 +277,16 @@ source_interface: Ethernet1/1 vrf: management destination_groups: - - id: 2 - destination: - ip: 192.168.0.2 - port: 50001 - protocol: gPRC - encoding: GPB + - id: 2 + destination: + ip: 192.168.0.2 + port: 50001 + protocol: gRPC + encoding: GPB subscriptions: - - id: 5 - destination_group: 55 + - id: 5 + destination_group: 55 state: replaced - - """ RETURN = """ before: @@ -313,6 +312,7 @@ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.telemetry.telemetry import ( TelemetryArgs, ) @@ -327,9 +327,7 @@ def main(): :returns: the result form module invocation """ - module = AnsibleModule( - argument_spec=TelemetryArgs.argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=TelemetryArgs.argument_spec, supports_check_mode=True) result = Telemetry(module).execute_module() module.exit_json(**result) diff --git a/plugins/modules/nxos_udld.py b/plugins/modules/nxos_udld.py index e47c7b6d1..83955e151 100644 --- a/plugins/modules/nxos_udld.py +++ b/plugins/modules/nxos_udld.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -108,14 +109,12 @@ sample: true """ +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule PARAM_TO_DEFAULT_KEYMAP = {"msg_time": "15"} @@ -148,17 +147,11 @@ def get_commands_config_udld_global(delta, reset, existing): commands = [] for param, value in delta.items(): if param == "aggressive": - command = ( - "udld aggressive" - if value == "enabled" - else "no udld aggressive" - ) + command = "udld aggressive" if value == "enabled" else "no udld aggressive" commands.append(command) elif param == "msg_time": if value == "default": - if existing.get("msg_time") != PARAM_TO_DEFAULT_KEYMAP.get( - "msg_time" - ): + if existing.get("msg_time") != PARAM_TO_DEFAULT_KEYMAP.get("msg_time"): commands.append("no udld message-time") else: commands.append("udld message-time " + value) @@ -203,11 +196,7 @@ def main(): state=dict(choices=["absent", "present"], default="present"), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() @@ -231,9 +220,7 @@ def main(): commands = [] if state == "present": if delta: - command = get_commands_config_udld_global( - dict(delta), reset, existing - ) + command = get_commands_config_udld_global(dict(delta), reset, existing) commands.append(command) elif state == "absent": diff --git a/plugins/modules/nxos_udld_interface.py b/plugins/modules/nxos_udld_interface.py index e9b37c2e4..b78ed5c7a 100644 --- a/plugins/modules/nxos_udld_interface.py +++ b/plugins/modules/nxos_udld_interface.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -118,14 +119,12 @@ """ +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule def flatten_list(command_lists): @@ -144,9 +143,7 @@ def get_udld_interface(module, interface): mode = None mode_str = None try: - body = run_commands(module, [{"command": command, "output": "text"}])[ - 0 - ] + body = run_commands(module, [{"command": command, "output": "text"}])[0] if "aggressive" in body: mode = "aggressive" mode_str = "aggressive" @@ -230,18 +227,12 @@ def get_commands_remove_udld_interface(delta, interface, module, existing): def main(): argument_spec = dict( - mode=dict( - choices=["enabled", "disabled", "aggressive"], required=True - ), + mode=dict(choices=["enabled", "disabled", "aggressive"], required=True), interface=dict(type="str", required=True), state=dict(choices=["absent", "present"], default="present"), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() @@ -260,9 +251,7 @@ def main(): cmds = [] if state == "present": if delta: - command = get_commands_config_udld_interface1( - delta, interface, module, existing - ) + command = get_commands_config_udld_interface1(delta, interface, module, existing) commands.append(command) cmds = flatten_list(commands) if module.check_mode: @@ -273,9 +262,7 @@ def main(): if delta["mode"] == "enabled" or delta["mode"] == "disabled": commands = [] - command = get_commands_config_udld_interface2( - delta, interface, module, existing - ) + command = get_commands_config_udld_interface2(delta, interface, module, existing) commands.append(command) cmds = flatten_list(commands) if module.check_mode: @@ -286,9 +273,7 @@ def main(): else: common = set(proposed.items()).intersection(existing.items()) if common: - command = get_commands_remove_udld_interface( - dict(common), interface, module, existing - ) + command = get_commands_remove_udld_interface(dict(common), interface, module, existing) cmds = flatten_list(commands) if module.check_mode: module.exit_json(changed=True, commands=cmds) diff --git a/plugins/modules/nxos_user.py b/plugins/modules/nxos_user.py index 5eab0b636..d3e847359 100644 --- a/plugins/modules/nxos_user.py +++ b/plugins/modules/nxos_user.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -54,8 +55,12 @@ configured_password: description: - The password to be configured on the network device. The password needs to be - provided in cleartext and it will be encrypted on the device. Please note that - this option is not same as C(provider password). + provided in cleartext and it will be encrypted on the device. + type: str + hashed_password: + description: + - The hashed password to be configured on the network device. The password needs to + already be encrypted. type: str update_password: description: @@ -99,8 +104,12 @@ configured_password: description: - The password to be configured on the network device. The password needs to be - provided in cleartext and it will be encrypted on the device. Please note that - this option is not same as C(provider password). + provided in cleartext and it will be encrypted on the device. + type: str + hashed_password: + description: + - The hashed password to be configured on the network device. The password needs to + already be encrypted. type: str update_password: description: @@ -133,7 +142,7 @@ absolute. It will remove any previously configured usernames on the device with the exception of the `admin` user which cannot be deleted per nxos constraints. type: bool - default: no + default: false state: description: - The C(state) argument configures the state of the username definition as it @@ -156,13 +165,13 @@ - name: remove all users except admin cisco.nxos.nxos_user: - purge: yes + purge: true - name: set multiple users role cisco.nxos.nxos_user: aggregate: - - name: netop - - name: netend + - name: netop + - name: netend role: network-operator state: present """ @@ -181,14 +190,6 @@ from copy import deepcopy from functools import partial -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - run_commands, - load_config, - get_config, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( @@ -196,6 +197,13 @@ to_list, ) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + get_config, + load_config, + run_commands, +) + + BUILTIN_ROLES = [ "network-admin", "network-operator", @@ -217,6 +225,7 @@ "priv-2", "priv-1", "priv-0", + "dev-ops", ] @@ -280,6 +289,10 @@ def configure_roles(): if update_password == "always" or not have: add("password %s" % want["configured_password"]) + if needs_update("hashed_password"): + if update_password == "always" or not have: + add("password 5 %s" % want["hashed_password"]) + if needs_update("sshkey"): add("sshkey %s" % want["sshkey"]) @@ -307,9 +320,7 @@ def parse_roles(data): def map_config_to_obj(module): - out = run_commands( - module, [{"command": "show user-account", "output": "json"}] - ) + out = run_commands(module, [{"command": "show user-account", "output": "json"}]) data = out[0] objects = list() @@ -319,10 +330,11 @@ def map_config_to_obj(module): { "name": item["usr_name"], "configured_password": parse_password(item), + "hashed_password": parse_password(item), "sshkey": item.get("sshkey_info"), "roles": parse_roles(item), "state": "present", - } + }, ) return objects @@ -368,10 +380,11 @@ def map_params_to_obj(module): item.update( { "configured_password": get_value("configured_password"), + "hashed_password": get_value("hashed_password"), "sshkey": get_value("sshkey"), "roles": get_value("roles"), "state": get_value("state"), - } + }, ) for key, value in iteritems(item): @@ -404,9 +417,8 @@ def main(): element_spec = dict( name=dict(), configured_password=dict(no_log=True), - update_password=dict( - default="always", choices=["on_create", "always"] - ), + hashed_password=dict(no_log=True), + update_password=dict(default="always", choices=["on_create", "always"]), roles=dict(type="list", aliases=["role"], elements="str"), sshkey=dict(no_log=False), state=dict(default="present", choices=["present", "absent"]), @@ -428,9 +440,8 @@ def main(): ) argument_spec.update(element_spec) - argument_spec.update(nxos_argument_spec) - mutually_exclusive = [("name", "aggregate")] + mutually_exclusive = [("name", "aggregate"), ("configured_password", "hashed_password")] module = AnsibleModule( argument_spec=argument_spec, @@ -460,6 +471,11 @@ def main(): if "no username admin" in commands: module.fail_json(msg="cannot delete the `admin` account") + # check if provided hashed password is infact a hash + if module.params["hashed_password"] is not None: + if not re.match(r"^\$5\$......\$.*$", module.params["hashed_password"]): + module.fail_json(msg="Provided hash is not valid") + if commands: if not module.check_mode: responses = load_config(module, commands) @@ -468,11 +484,7 @@ def main(): module.fail_json(msg=resp) else: result["warnings"].extend( - [ - x[9:] - for x in resp.splitlines() - if x.startswith("WARNING: ") - ] + [x[9:] for x in resp.splitlines() if x.startswith("WARNING: ")], ) result["changed"] = True diff --git a/plugins/modules/nxos_vlan.py b/plugins/modules/nxos_vlan.py deleted file mode 100644 index 055fb6b7e..000000000 --- a/plugins/modules/nxos_vlan.py +++ /dev/null @@ -1,848 +0,0 @@ -#!/usr/bin/python -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# - -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - - -DOCUMENTATION = """ -module: nxos_vlan -extends_documentation_fragment: -- cisco.nxos.nxos -short_description: (deprecated, removed after 2022-06-01) Manages VLAN - resources and attributes. -description: -- Manages VLAN configurations on NX-OS switches. -version_added: 1.0.0 -deprecated: - alternative: nxos_vlans - why: Updated modules released with more functionality - removed_at_date: '2022-06-01' -author: Jason Edelman (@jedelman8) -options: - vlan_id: - description: - - Single VLAN ID. - type: int - vlan_range: - description: - - Range of VLANs such as 2-10 or 2,5,10-15, etc. - type: str - name: - description: - - Name of VLAN or keyword 'default'. - type: str - interfaces: - description: - - List of interfaces that should be associated to the VLAN or keyword 'default'. - type: list - elements: str - associated_interfaces: - description: - - This is a intent option and checks the operational state of the for given vlan - C(name) for associated interfaces. If the value in the C(associated_interfaces) - does not match with the operational state of vlan interfaces on device it will - result in failure. - type: list - elements: str - vlan_state: - description: - - Manage the vlan operational state of the VLAN - default: active - choices: - - active - - suspend - type: str - admin_state: - description: - - Manage the VLAN administrative state of the VLAN equivalent to shut/no shut - in VLAN config mode. - default: up - choices: - - up - - down - type: str - mapped_vni: - description: - - The Virtual Network Identifier (VNI) ID that is mapped to the VLAN. Valid values - are integer and keyword 'default'. Range 4096-16773119. - type: str - aggregate: - description: List of VLANs definitions. - type: list - elements: dict - suboptions: - vlan_id: - description: - - Single VLAN ID. - required: True - type: int - vlan_range: - description: - - Range of VLANs such as 2-10 or 2,5,10-15, etc. - type: str - name: - description: - - Name of VLAN or keyword 'default'. - type: str - interfaces: - description: - - List of interfaces that should be associated to the VLAN or keyword 'default'. - type: list - elements: str - associated_interfaces: - description: - - This is a intent option and checks the operational state of the for given vlan - C(name) for associated interfaces. If the value in the C(associated_interfaces) - does not match with the operational state of vlan interfaces on device it will - result in failure. - type: list - elements: str - vlan_state: - description: - - Manage the vlan operational state of the VLAN - choices: - - active - - suspend - type: str - admin_state: - description: - - Manage the VLAN administrative state of the VLAN equivalent to shut/no shut - in VLAN config mode. - choices: - - up - - down - type: str - mapped_vni: - description: - - The Virtual Network Identifier (VNI) ID that is mapped to the VLAN. Valid values - are integer and keyword 'default'. Range 4096-16773119. - type: str - mode: - description: - - Set VLAN mode to classical ethernet or fabricpath. This is a valid option for - Nexus 5000 and 7000 series. - choices: - - ce - - fabricpath - type: str - delay: - description: - - Time in seconds to wait before checking for the operational state on remote - device. This wait is applicable for operational state arguments. - type: int - state: - description: - - Manage the state of the resource. - choices: - - present - - absent - type: str - state: - description: - - Manage the state of the resource. - default: present - choices: - - present - - absent - type: str - mode: - description: - - Set VLAN mode to classical ethernet or fabricpath. This is a valid option for - Nexus 5000 and 7000 series. - choices: - - ce - - fabricpath - default: ce - type: str - purge: - description: - - Purge VLANs not defined in the I(aggregate) parameter. This parameter can be - used without aggregate as well. - - Removal of Vlan 1 is not allowed and will be ignored by purge. - type: bool - default: no - delay: - description: - - Time in seconds to wait before checking for the operational state on remote - device. This wait is applicable for operational state arguments. - default: 10 - type: int - - -""" - -EXAMPLES = """ -- name: Ensure a range of VLANs are not present on the switch - cisco.nxos.nxos_vlan: - vlan_range: 2-10,20,50,55-60,100-150 - state: absent - -- name: Ensure VLAN 50 exists with the name WEB and is in the shutdown state - cisco.nxos.nxos_vlan: - vlan_id: 50 - admin_state: down - name: WEB - -- name: Ensure VLAN is NOT on the device - cisco.nxos.nxos_vlan: - vlan_id: 50 - state: absent - -- name: Add interfaces to VLAN and check intent (config + intent) - cisco.nxos.nxos_vlan: - vlan_id: 100 - interfaces: - - Ethernet2/1 - - Ethernet2/5 - associated_interfaces: - - Ethernet2/1 - - Ethernet2/5 - -- name: Check interfaces assigned to VLAN - cisco.nxos.nxos_vlan: - vlan_id: 100 - associated_interfaces: - - Ethernet2/1 - - Ethernet2/5 - -- name: Create aggregate of vlans - cisco.nxos.nxos_vlan: - aggregate: - - {vlan_id: 4000, mode: ce} - - {vlan_id: 4001, name: vlan-4001} - -- name: purge vlans - removes all other vlans except the ones mentioned in aggregate) - cisco.nxos.nxos_vlan: - aggregate: - - vlan_id: 1 - - vlan_id: 4001 - purge: yes - -""" - -RETURN = """ -commands: - description: Set of command strings to send to the remote device - returned: always - type: list - sample: ["vlan 20", "vlan 55", "vn-segment 5000"] -""" - -import re -import time - -from copy import deepcopy - -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_capabilities, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_config, - load_config, - run_commands, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - normalize_interface, - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( - CustomNetworkConfig, -) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - remove_default_spec, -) - - -def search_obj_in_list(vlan_id, lst): - for o in lst: - if o["vlan_id"] == vlan_id: - return o - - -def get_diff(w, obj): - c = deepcopy(w) - entries = ("interfaces", "associated_interfaces", "delay", "vlan_range") - for key in entries: - if key in c: - del c[key] - - o = deepcopy(obj) - del o["interfaces"] - if o["vlan_id"] == w["vlan_id"]: - diff_dict = dict(set(c.items()) - set(o.items())) - return diff_dict - - -def is_default_name(obj, vlan_id): - cname = obj["name"] - if "VLAN" in cname: - vid = int(cname[4:]) - if vid == int(vlan_id): - return True - - return False - - -def map_obj_to_commands(updates, module): - commands = list() - purge = module.params["purge"] - want, have = updates - info = get_capabilities(module).get("device_info") - os_platform = info.get("network_os_platform") - - for w in want: - vlan_id = w["vlan_id"] - name = w["name"] - interfaces = w.get("interfaces") or [] - mapped_vni = w["mapped_vni"] - mode = w["mode"] - vlan_state = w["vlan_state"] - admin_state = w["admin_state"] - state = w["state"] - del w["state"] - - obj_in_have = search_obj_in_list(vlan_id, have) or {} - if not re.match("N[567]", os_platform) or ( - not obj_in_have.get("mode") and mode == "ce" - ): - mode = w["mode"] = None - - if state == "absent": - if obj_in_have: - commands.append("no vlan {0}".format(vlan_id)) - - elif state == "present": - if not obj_in_have: - commands.append("vlan {0}".format(vlan_id)) - - if name and name != "default": - commands.append("name {0}".format(name)) - if mode: - commands.append("mode {0}".format(mode)) - if vlan_state: - commands.append("state {0}".format(vlan_state)) - if mapped_vni != "None" and mapped_vni != "default": - commands.append("vn-segment {0}".format(mapped_vni)) - if admin_state == "up": - commands.append("no shutdown") - if admin_state == "down": - commands.append("shutdown") - commands.append("exit") - - if interfaces and interfaces[0] != "default": - for i in interfaces: - commands.append("interface {0}".format(i)) - commands.append("switchport") - commands.append("switchport mode access") - commands.append( - "switchport access vlan {0}".format(vlan_id) - ) - - else: - diff = get_diff(w, obj_in_have) - if diff: - commands.append("vlan {0}".format(vlan_id)) - for key, value in diff.items(): - if key == "name": - if name != "default": - if name is not None: - commands.append("name {0}".format(value)) - else: - if not is_default_name(obj_in_have, vlan_id): - commands.append("no name") - if key == "vlan_state" and value: - commands.append("state {0}".format(value)) - if key == "mapped_vni": - if value == "default": - if obj_in_have["mapped_vni"] != "None": - commands.append("no vn-segment") - elif value != "None": - commands.append("vn-segment {0}".format(value)) - if key == "admin_state": - if value == "up": - commands.append("no shutdown") - elif value == "down": - commands.append("shutdown") - if key == "mode" and value: - commands.append("mode {0}".format(value)) - if len(commands) > 1: - commands.append("exit") - else: - del commands[:] - - if interfaces and interfaces[0] != "default": - if not obj_in_have["interfaces"]: - for i in interfaces: - commands.append("vlan {0}".format(vlan_id)) - commands.append("exit") - commands.append("interface {0}".format(i)) - commands.append("switchport") - commands.append("switchport mode access") - commands.append( - "switchport access vlan {0}".format(vlan_id) - ) - - elif set(interfaces) != set(obj_in_have["interfaces"]): - missing_interfaces = list( - set(interfaces) - set(obj_in_have["interfaces"]) - ) - for i in missing_interfaces: - commands.append("vlan {0}".format(vlan_id)) - commands.append("exit") - commands.append("interface {0}".format(i)) - commands.append("switchport") - commands.append("switchport mode access") - commands.append( - "switchport access vlan {0}".format(vlan_id) - ) - - superfluous_interfaces = list( - set(obj_in_have["interfaces"]) - set(interfaces) - ) - for i in superfluous_interfaces: - commands.append("vlan {0}".format(vlan_id)) - commands.append("exit") - commands.append("interface {0}".format(i)) - commands.append("switchport") - commands.append("switchport mode access") - commands.append( - "no switchport access vlan {0}".format(vlan_id) - ) - - elif interfaces and interfaces[0] == "default": - if obj_in_have["interfaces"]: - for i in obj_in_have["interfaces"]: - commands.append("vlan {0}".format(vlan_id)) - commands.append("exit") - commands.append("interface {0}".format(i)) - commands.append("switchport") - commands.append("switchport mode access") - commands.append( - "no switchport access vlan {0}".format(vlan_id) - ) - - if purge: - for h in have: - if h["vlan_id"] == "1": - module.warn( - "Deletion of vlan 1 is not allowed; purge will ignore vlan 1" - ) - continue - obj_in_want = search_obj_in_list(h["vlan_id"], want) - if not obj_in_want: - commands.append("no vlan {0}".format(h["vlan_id"])) - - return commands - - -def want_vlan_list(module): - result = [] - vlan_range = module.params["vlan_range"] - for part in vlan_range.split(","): - if part == "none": - break - if "-" in part: - start, end = part.split("-") - start, end = int(start), int(end) - result.extend([str(i) for i in range(start, end + 1)]) - else: - result.append(part) - return result - - -def have_vlan_list(have): - result = [] - if have: - for h in have: - result.append(str(h.get("vlan_id"))) - return result - - -def vlan_range_commands(module, have): - commands = list() - proposed_vlans_list = want_vlan_list(module) - existing_vlans_list = have_vlan_list(have) - - if module.params["state"] == "absent": - vlans = set(proposed_vlans_list).intersection(existing_vlans_list) - for vlan in vlans: - commands.append("no vlan {0}".format(vlan)) - - elif module.params["state"] == "present": - vlans = set(proposed_vlans_list).difference(existing_vlans_list) - for vlan in vlans: - commands.append("vlan {0}".format(vlan)) - - return commands - - -def normalize(interfaces): - normalized = None - if interfaces: - normalized = [normalize_interface(i) for i in interfaces] - return normalized - - -def map_params_to_obj(module): - obj = [] - if module.params["vlan_range"]: - return [] - - aggregate = module.params.get("aggregate") - if aggregate: - for item in aggregate: - for key in item: - if item.get(key) is None: - item[key] = module.params[key] - - d = item.copy() - d["vlan_id"] = str(d["vlan_id"]) - d["mapped_vni"] = str(d["mapped_vni"]) - d["interfaces"] = normalize(d["interfaces"]) - d["associated_interfaces"] = normalize(d["associated_interfaces"]) - - obj.append(d) - else: - interfaces = normalize(module.params["interfaces"]) - associated_interfaces = normalize( - module.params["associated_interfaces"] - ) - - obj.append( - { - "vlan_id": str(module.params["vlan_id"]), - "name": module.params["name"], - "interfaces": interfaces, - "vlan_state": module.params["vlan_state"], - "mapped_vni": str(module.params["mapped_vni"]), - "state": module.params["state"], - "admin_state": module.params["admin_state"], - "mode": module.params["mode"], - "associated_interfaces": associated_interfaces, - } - ) - - return obj - - -def parse_admin_state(vlan): - shutstate = vlan.get("vlanshowbr-shutstate") - if shutstate == "noshutdown": - return "up" - elif shutstate == "shutdown": - return "down" - - -def parse_mode(config): - mode = None - - if config: - match = re.search(r"mode (\S+)", config) - if match: - mode = match.group(1) - return mode - - -def parse_vni(config): - vni = None - - if config: - match = re.search(r"vn-segment (\S+)", config) - if match: - vni = match.group(1) - return str(vni) - - -def get_vlan_int(interfaces): - vlan_int = [] - for i in interfaces.split(","): - if "eth" in i.lower() and "-" in i: - int_range = i.split("-") - stop = int((int_range)[1]) - start = int(int_range[0].split("/")[1]) - eth = int_range[0].split("/")[0] - for r in range(start, stop + 1): - vlan_int.append(eth + "/" + str(r)) - else: - vlan_int.append(i) - return vlan_int - - -def parse_interfaces(module, vlan): - vlan_int = [] - interfaces = vlan.get("vlanshowplist-ifidx") - if interfaces: - if isinstance(interfaces, list): - interfaces_list = [i.strip() for i in interfaces] - interfaces_str = ",".join(interfaces_list) - vlan_int = get_vlan_int(interfaces_str) - else: - vlan_int = get_vlan_int(interfaces) - return vlan_int - - -def parse_vlan_config(netcfg, vlan_id): - parents = ["vlan {0}".format(vlan_id)] - config = netcfg.get_section(parents) - return config - - -def parse_vlan_options(module, netcfg, output, vlan): - obj = {} - vlan_id = vlan["vlanshowbr-vlanid-utf"] - config = parse_vlan_config(netcfg, vlan_id) - - obj["vlan_id"] = str(vlan_id) - obj["name"] = vlan.get("vlanshowbr-vlanname") - obj["vlan_state"] = vlan.get("vlanshowbr-vlanstate") - obj["admin_state"] = parse_admin_state(vlan) - obj["mode"] = parse_mode(config) - obj["mapped_vni"] = parse_vni(config) - obj["interfaces"] = parse_interfaces(module, vlan) - return obj - - -def parse_vlan_non_structured(module, netcfg, vlans): - objs = list() - - for vlan in vlans: - vlan_match = re.search(r"(\d+)", vlan, re.M) - if vlan_match: - obj = {} - vlan_id = vlan_match.group(1) - obj["vlan_id"] = str(vlan_id) - - name_match = re.search(r"{0}\s*(\S+)".format(vlan_id), vlan, re.M) - if name_match: - name = name_match.group(1) - obj["name"] = name - state_match = re.search( - r"{0}\s*{1}\s*(\S+)".format(vlan_id, re.escape(name)), - vlan, - re.M, - ) - if state_match: - vlan_state_match = state_match.group(1) - if vlan_state_match == "suspended": - vlan_state = "suspend" - admin_state = "up" - elif vlan_state_match == "sus/lshut": - vlan_state = "suspend" - admin_state = "down" - if vlan_state_match == "active": - vlan_state = "active" - admin_state = "up" - if vlan_state_match == "act/lshut": - vlan_state = "active" - admin_state = "down" - - obj["vlan_state"] = vlan_state - obj["admin_state"] = admin_state - - vlan = ",".join(vlan.splitlines()) - interfaces = list() - intfs_match = re.search( - r"{0}\s*{1}\s*{2}\s*(.*)".format( - vlan_id, re.escape(name), vlan_state_match - ), - vlan, - re.M, - ) - if intfs_match: - intfs = intfs_match.group(1) - intfs = intfs.split() - for i in intfs: - intf = normalize_interface(i.strip(",")) - interfaces.append(intf) - - if interfaces: - obj["interfaces"] = interfaces - else: - obj["interfaces"] = None - - config = parse_vlan_config(netcfg, vlan_id) - obj["mode"] = parse_mode(config) - obj["mapped_vni"] = parse_vni(config) - - objs.append(obj) - - return objs - - -def map_config_to_obj(module): - objs = list() - output = None - - command = ["show vlan brief | json"] - output = run_commands(module, command, check_rc="retry_json")[0] - if output: - netcfg = CustomNetworkConfig( - indent=2, contents=get_config(module, flags=["all"]) - ) - - if isinstance(output, dict): - vlans = None - try: - vlans = output["TABLE_vlanbriefxbrief"]["ROW_vlanbriefxbrief"] - except KeyError: - return objs - - if vlans: - if isinstance(vlans, list): - for vlan in vlans: - obj = parse_vlan_options(module, netcfg, output, vlan) - objs.append(obj) - elif isinstance(vlans, dict): - obj = parse_vlan_options(module, netcfg, output, vlans) - objs.append(obj) - else: - vlans = list() - splitted_line = re.split(r"\n(\d+)|\n{2}", output.strip()) - - for line in splitted_line: - if not line: - continue - if len(line) > 0: - line = line.strip() - if line[0].isdigit(): - match = re.search(r"^(\d+)$", line, re.M) - if match: - v = match.group(1) - pos1 = splitted_line.index(v) - pos2 = pos1 + 1 - # fmt: off - vlaninfo = "".join(splitted_line[pos1: pos2 + 1]) - # fmt: on - vlans.append(vlaninfo) - - if vlans: - objs = parse_vlan_non_structured(module, netcfg, vlans) - else: - return objs - - return objs - - -def check_declarative_intent_params(want, module, result): - - have = None - is_delay = False - - for w in want: - if w.get("associated_interfaces") is None: - continue - - if result["changed"] and not is_delay: - time.sleep(module.params["delay"]) - is_delay = True - - if have is None: - have = map_config_to_obj(module) - - for i in w["associated_interfaces"]: - obj_in_have = search_obj_in_list(w["vlan_id"], have) - if ( - obj_in_have - and "interfaces" in obj_in_have - and i not in obj_in_have["interfaces"] - ): - module.fail_json( - msg="Interface %s not configured on vlan %s" - % (i, w["vlan_id"]) - ) - - -def main(): - """main entry point for module execution""" - element_spec = dict( - vlan_id=dict(required=False, type="int"), - vlan_range=dict(required=False), - name=dict(required=False), - interfaces=dict(type="list", elements="str"), - associated_interfaces=dict(type="list", elements="str"), - vlan_state=dict( - choices=["active", "suspend"], required=False, default="active" - ), - mapped_vni=dict(required=False), - delay=dict(default=10, type="int"), - state=dict( - choices=["present", "absent"], default="present", required=False - ), - admin_state=dict(choices=["up", "down"], required=False, default="up"), - mode=dict(default="ce", choices=["ce", "fabricpath"]), - ) - - aggregate_spec = deepcopy(element_spec) - aggregate_spec["vlan_id"] = dict(required=True, type="int") - - # remove default in aggregate spec, to handle common arguments - remove_default_spec(aggregate_spec) - - argument_spec = dict( - aggregate=dict(type="list", elements="dict", options=aggregate_spec), - purge=dict(default=False, type="bool"), - ) - - argument_spec.update(element_spec) - argument_spec.update(nxos_argument_spec) - - required_one_of = [["vlan_id", "aggregate", "vlan_range"]] - mutually_exclusive = [ - ["vlan_id", "aggregate"], - ["vlan_range", "name"], - ["vlan_id", "vlan_range"], - ] - - module = AnsibleModule( - argument_spec=argument_spec, - required_one_of=required_one_of, - mutually_exclusive=mutually_exclusive, - supports_check_mode=True, - ) - - warnings = list() - result = {"changed": False} - if warnings: - result["warnings"] = warnings - - have = map_config_to_obj(module) - want = map_params_to_obj(module) - - if module.params["vlan_range"]: - commands = vlan_range_commands(module, have) - result["commands"] = commands - else: - commands = map_obj_to_commands((want, have), module) - result["commands"] = commands - - if commands: - if not module.check_mode: - load_config(module, commands) - result["changed"] = True - - if want: - check_declarative_intent_params(want, module, result) - - module.exit_json(**result) - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/nxos_vlans.py b/plugins/modules/nxos_vlans.py index 217a4ef10..4116f524b 100644 --- a/plugins/modules/nxos_vlans.py +++ b/plugins/modules/nxos_vlans.py @@ -28,6 +28,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -116,10 +117,10 @@ - name: Merge provided configuration with device configuration. cisco.nxos.nxos_vlans: config: - - vlan_id: 5 - name: test-vlan5 - - vlan_id: 10 - enabled: false + - vlan_id: 5 + name: test-vlan5 + - vlan_id: 10 + enabled: false state: merged # After state: @@ -146,11 +147,11 @@ - name: Replace device configuration of specified vlan with provided configuration. cisco.nxos.nxos_vlans: config: - - vlan_id: 5 - name: test-vlan - enabled: false - - vlan_id: 10 - enabled: false + - vlan_id: 5 + name: test-vlan + enabled: false + - vlan_id: 10 + enabled: false state: replaced # After state: @@ -181,10 +182,10 @@ - name: Override device configuration of all vlans with provided configuration. cisco.nxos.nxos_vlans: config: - - vlan_id: 5 - name: test-vlan - - vlan_id: 10 - state: active + - vlan_id: 5 + name: test-vlan + - vlan_id: 10 + state: active state: overridden # After state: @@ -209,8 +210,8 @@ - name: Delete vlans. cisco.nxos.nxos_vlans: config: - - vlan_id: 5 - - vlan_id: 10 + - vlan_id: 5 + - vlan_id: 10 state: deleted # After state: @@ -222,13 +223,13 @@ - name: Use rendered state to convert task input to device specific commands cisco.nxos.nxos_vlans: config: - - vlan_id: 5 - name: vlan5 - mapped_vni: 100 + - vlan_id: 5 + name: vlan5 + mapped_vni: 100 - - vlan_id: 6 - name: vlan6 - state: suspend + - vlan_id: 6 + name: vlan6 + state: suspend state: rendered # Task Output (redacted) @@ -413,6 +414,7 @@ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.vlans.vlans import ( VlansArgs, ) @@ -427,9 +429,7 @@ def main(): :returns: the result form module invocation """ - module = AnsibleModule( - argument_spec=VlansArgs.argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=VlansArgs.argument_spec, supports_check_mode=True) result = Vlans(module).execute_module() module.exit_json(**result) diff --git a/plugins/modules/nxos_vpc.py b/plugins/modules/nxos_vpc.py index 5f8b4fc90..f660efc10 100644 --- a/plugins/modules/nxos_vpc.py +++ b/plugins/modules/nxos_vpc.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -154,15 +155,14 @@ """ import re + +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( get_config, load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule CONFIG_ARGS = { @@ -198,7 +198,6 @@ def flatten_list(command_lists): def get_vrf_list(module): - try: body = run_commands(module, ["show vrf all | json"])[0] vrf_table = body["TABLE_vrf"]["ROW_vrf"] @@ -369,8 +368,6 @@ def main(): state=dict(choices=["absent", "present"], default="present"), ) - argument_spec.update(nxos_argument_spec) - mutually_exclusive = [("auto_recovery", "auto_recovery_reload_delay")] module = AnsibleModule( argument_spec=argument_spec, @@ -391,9 +388,7 @@ def main(): auto_recovery = module.params["auto_recovery"] auto_recovery_reload_delay = module.params["auto_recovery_reload_delay"] delay_restore = module.params["delay_restore"] - delay_restore_interface_vlan = module.params[ - "delay_restore_interface_vlan" - ] + delay_restore_interface_vlan = module.params["delay_restore_interface_vlan"] delay_restore_orphan_port = module.params["delay_restore_orphan_port"] state = module.params["state"] @@ -414,27 +409,22 @@ def main(): if not pkl_dest: if pkl_src: - module.fail_json( - msg="dest IP for peer-keepalive is required" - " when src IP is present" - ) + module.fail_json(msg="dest IP for peer-keepalive is required" " when src IP is present") elif pkl_vrf: if pkl_vrf != "management": module.fail_json( - msg="dest and src IP for peer-keepalive are required" - " when vrf is present" + msg="dest and src IP for peer-keepalive are required" " when vrf is present", ) else: module.fail_json( - msg="dest IP for peer-keepalive is required" - " when vrf is present" + msg="dest IP for peer-keepalive is required" " when vrf is present", ) if pkl_vrf: if pkl_vrf.lower() not in get_vrf_list(module): module.fail_json( msg="The VRF you are trying to use for the peer " "keepalive link is not on device yet. Add it" - " first, please." + " first, please.", ) proposed = dict((k, v) for k, v in args.items() if v is not None) existing = get_vpc(module) @@ -451,16 +441,13 @@ def main(): if delta: pkl_dependencies(module, delta, existing) - command = get_commands_to_config_vpc( - module, delta, domain, existing - ) + command = get_commands_to_config_vpc(module, delta, domain, existing) commands.append(command) elif state == "absent": if existing: if domain != existing["domain"]: module.fail_json( - msg="You are trying to remove a domain that " - "does not exist on the device" + msg="You are trying to remove a domain that " "does not exist on the device", ) else: commands.append("terminal dont-ask") diff --git a/plugins/modules/nxos_vpc_interface.py b/plugins/modules/nxos_vpc_interface.py index ab79e4ec0..5e3184578 100644 --- a/plugins/modules/nxos_vpc_interface.py +++ b/plugins/modules/nxos_vpc_interface.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -77,15 +78,13 @@ sample: ["interface port-channel100", "vpc 10"] """ +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( get_config, load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible.module_utils.basic import AnsibleModule def flatten_list(command_lists): @@ -198,9 +197,7 @@ def get_portchannel_vpc_config(module, portchannel): return config -def get_commands_to_config_vpc_interface( - portchannel, delta, config_value, existing -): +def get_commands_to_config_vpc_interface(portchannel, delta, config_value, existing): commands = [] if not delta.get("peer-link") and existing.get("peer-link"): @@ -222,9 +219,7 @@ def get_commands_to_config_vpc_interface( def state_present(portchannel, delta, config_value, existing): commands = [] - command = get_commands_to_config_vpc_interface( - portchannel, delta, config_value, existing - ) + command = get_commands_to_config_vpc_interface(portchannel, delta, config_value, existing) commands.append(command) return commands @@ -252,8 +247,6 @@ def main(): state=dict(choices=["absent", "present"], default="present"), ) - argument_spec.update(nxos_argument_spec) - module = AnsibleModule( argument_spec=argument_spec, mutually_exclusive=[["vpc", "peer_link"]], @@ -273,13 +266,11 @@ def main(): active_peer_link = None if portchannel not in get_portchannel_list(module): - if not portchannel.isdigit() or int( - portchannel - ) not in get_portchannel_list(module): + if not portchannel.isdigit() or int(portchannel) not in get_portchannel_list(module): module.fail_json( msg="The portchannel you are trying to make a" " VPC or PL is not created yet. " - "Create it first!" + "Create it first!", ) if vpc: mapping = get_existing_portchannel_to_vpc_mappings(module) @@ -307,7 +298,7 @@ def main(): module.fail_json( msg="That port channel is the current " "PEER LINK. Remove it if you want it" - " to be a VPC" + " to be a VPC", ) config_value = vpc @@ -317,8 +308,7 @@ def main(): if active_peer_link != portchannel: if peer_link: module.fail_json( - msg="A peer link already exists on" - " the device. Remove it first", + msg="A peer link already exists on" " the device. Remove it first", current_peer_link="Po{0}".format(active_peer_link), ) config_value = "peer-link" @@ -329,9 +319,7 @@ def main(): if state == "present": delta = dict(set(proposed.items()).difference(existing.items())) if delta: - commands = state_present( - portchannel, delta, config_value, existing - ) + commands = state_present(portchannel, delta, config_value, existing) elif state == "absent" and existing: commands = state_absent(portchannel, existing) diff --git a/plugins/modules/nxos_vrf.py b/plugins/modules/nxos_vrf.py index b928018f8..6017d3c88 100644 --- a/plugins/modules/nxos_vrf.py +++ b/plugins/modules/nxos_vrf.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -141,7 +142,7 @@ description: - Purge VRFs not defined in the I(aggregate) parameter. type: bool - default: no + default: false state: description: - Manages desired state of the resource. @@ -168,48 +169,48 @@ name: ntc description: testing state: present - - name: Aggregate definition of VRFs cisco.nxos.nxos_vrf: aggregate: - - {name: test1, description: Testing, admin_state: down} - - {name: test2, interfaces: Ethernet1/2} - + - name: test1 + description: Testing + admin_state: down + - name: test2 + interfaces: Ethernet1/2 - name: Aggregate definitions of VRFs with Purge cisco.nxos.nxos_vrf: aggregate: - - {name: ntc1, description: purge test1} - - {name: ntc2, description: purge test2} + - name: ntc1 + description: purge test1 + - name: ntc2 + description: purge test2 state: present - purge: yes - + purge: true - name: Delete VRFs exist on switch cisco.nxos.nxos_vrf: aggregate: - - {name: ntc1} - - {name: ntc2} + - name: ntc1 + - name: ntc2 state: absent - - name: Assign interfaces to VRF declaratively cisco.nxos.nxos_vrf: name: test1 interfaces: - - Ethernet2/3 - - Ethernet2/5 - + - Ethernet2/3 + - Ethernet2/5 - name: Check interfaces assigned to VRF cisco.nxos.nxos_vrf: name: test1 associated_interfaces: - - Ethernet2/3 - - Ethernet2/5 - -- name: Ensure VRF is tagged with interface Ethernet2/5 only (Removes from Ethernet2/3) + - Ethernet2/3 + - Ethernet2/5 +- name: >- + Ensure VRF is tagged with interface Ethernet2/5 only (Removes from + Ethernet2/3) cisco.nxos.nxos_vrf: name: test1 interfaces: - - Ethernet2/5 - + - Ethernet2/5 - name: Delete VRF cisco.nxos.nxos_vrf: name: ntc @@ -235,16 +236,14 @@ from copy import deepcopy from ansible.module_utils.basic import AnsibleModule -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - load_config, - run_commands, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + remove_default_spec, ) + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, get_interface_type, -) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - remove_default_spec, + load_config, + run_commands, ) @@ -340,12 +339,8 @@ def map_obj_to_commands(updates, module): else: # If vni is already configured on vrf, unconfigure it first. if vni: - if obj_in_have.get("vni") and vni != obj_in_have.get( - "vni" - ): - commands.append( - "no vni {0}".format(obj_in_have.get("vni")) - ) + if obj_in_have.get("vni") and vni != obj_in_have.get("vni"): + commands.append("no vni {0}".format(obj_in_have.get("vni"))) for item in args: candidate = w.get(item) @@ -356,9 +351,7 @@ def map_obj_to_commands(updates, module): elif candidate and candidate != obj_in_have.get(item): cmd = item + " " + str(candidate) commands.append(cmd) - if admin_state and admin_state != obj_in_have.get( - "admin_state" - ): + if admin_state and admin_state != obj_in_have.get("admin_state"): if admin_state == "up": commands.append("no shutdown") elif admin_state == "down": @@ -383,7 +376,7 @@ def map_obj_to_commands(updates, module): elif set(interfaces) != set(obj_in_have["interfaces"]): missing_interfaces = list( - set(interfaces) - set(obj_in_have["interfaces"]) + set(interfaces) - set(obj_in_have["interfaces"]), ) for i in missing_interfaces: commands.append("vrf context {0}".format(name)) @@ -397,7 +390,7 @@ def map_obj_to_commands(updates, module): commands.append("vrf member {0}".format(name)) superfluous_interfaces = list( - set(obj_in_have["interfaces"]) - set(interfaces) + set(obj_in_have["interfaces"]) - set(interfaces), ) for i in superfluous_interfaces: commands.append("vrf context {0}".format(name)) @@ -442,9 +435,7 @@ def validate_vrf(name, module): if name == "default": module.fail_json(msg="cannot use default as name of a VRF") elif len(name) > 32: - module.fail_json( - msg="VRF name exceeded max length of 32", name=name - ) + module.fail_json(msg="VRF name exceeded max length of 32", name=name) else: return name @@ -471,10 +462,8 @@ def map_params_to_obj(module): "admin_state": module.params["admin_state"], "state": module.params["state"], "interfaces": module.params["interfaces"], - "associated_interfaces": module.params[ - "associated_interfaces" - ], - } + "associated_interfaces": module.params["associated_interfaces"], + }, ) return obj @@ -534,7 +523,6 @@ def map_config_to_obj(want, element_spec, module): def check_declarative_intent_params(want, module, element_spec, result): - have = None is_delay = False @@ -556,8 +544,7 @@ def check_declarative_intent_params(want, module, element_spec, result): interfaces = obj_in_have.get("interfaces") if interfaces is not None and i not in interfaces: module.fail_json( - msg="Interface %s not configured on vrf %s" - % (i, w["name"]) + msg="Interface %s not configured on vrf %s" % (i, w["name"]), ) @@ -567,13 +554,9 @@ def vrf_error_check(module, commands, responses): if re.search(pattern, str(responses)): # Allow delay/retry for VRF changes time.sleep(15) - responses = load_config( - module, commands, opts={"catch_clierror": True} - ) + responses = load_config(module, commands, opts={"catch_clierror": True}) if re.search(pattern, str(responses)): - module.fail_json( - msg="VRF config (and retry) failure: %s " % responses - ) + module.fail_json(msg="VRF config (and retry) failure: %s " % responses) module.warn("VRF config delayed by VRF deletion - passed on retry") @@ -588,9 +571,7 @@ def main(): interfaces=dict(type="list", elements="str"), associated_interfaces=dict(type="list", elements="str"), delay=dict(type="int", default=10), - state=dict( - type="str", default="present", choices=["present", "absent"] - ), + state=dict(type="str", default="present", choices=["present", "absent"]), ) aggregate_spec = deepcopy(element_spec) @@ -604,7 +585,6 @@ def main(): ) argument_spec.update(element_spec) - argument_spec.update(nxos_argument_spec) required_one_of = [["name", "aggregate"]] mutually_exclusive = [["name", "aggregate"]] @@ -627,9 +607,7 @@ def main(): result["commands"] = commands if commands and not module.check_mode: - responses = load_config( - module, commands, opts={"catch_clierror": True} - ) + responses = load_config(module, commands, opts={"catch_clierror": True}) vrf_error_check(module, commands, responses) result["changed"] = True diff --git a/plugins/modules/nxos_vrf_af.py b/plugins/modules/nxos_vrf_af.py index 1f4fe9a1a..5bd043706 100644 --- a/plugins/modules/nxos_vrf_af.py +++ b/plugins/modules/nxos_vrf_af.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -102,55 +103,50 @@ afi: ipv4 route_target_both_auto_evpn: true state: present - - cisco.nxos.nxos_vrf_af: vrf: ntc afi: ipv4 route_targets: - - rt: 65000:1000 - direction: import - - rt: 65001:1000 - direction: import - + - rt: '65000:1000' + direction: import + - rt: '65001:1000' + direction: import - cisco.nxos.nxos_vrf_af: vrf: ntc afi: ipv4 route_targets: - - rt: 65000:1000 - direction: import - - rt: 65001:1000 - state: absent - + - rt: '65000:1000' + direction: import + - rt: '65001:1000' + state: absent - cisco.nxos.nxos_vrf_af: vrf: ntc afi: ipv4 route_targets: - - rt: 65000:1000 - direction: export - - rt: 65001:1000 - direction: export - + - rt: '65000:1000' + direction: export + - rt: '65001:1000' + direction: export - cisco.nxos.nxos_vrf_af: vrf: ntc afi: ipv4 route_targets: - - rt: 65000:1000 - direction: export - state: absent - + - rt: '65000:1000' + direction: export + state: absent - cisco.nxos.nxos_vrf_af: vrf: ntc afi: ipv4 route_targets: - - rt: 65000:1000 - direction: both - state: present - - rt: 65001:1000 - direction: import - state: present - - rt: 65002:1000 - direction: both - state: absent + - rt: '65000:1000' + direction: both + state: present + - rt: '65001:1000' + direction: import + state: present + - rt: '65002:1000' + direction: both + state: absent """ RETURN = """ @@ -160,20 +156,18 @@ type: list sample: ["vrf context ntc", "address-family ipv4 unicast"] """ -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_config, - load_config, - get_capabilities, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) +import re + from ansible.module_utils.basic import AnsibleModule from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( NetworkConfig, ) -import re +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + get_capabilities, + get_config, + load_config, +) def match_current_rt(rt, direction, current, rt_commands): @@ -198,19 +192,13 @@ def main(): elements="dict", options=dict( rt=dict(type="str", required=True), - direction=dict( - choices=["import", "export", "both"], default="both" - ), + direction=dict(choices=["import", "export", "both"], default="both"), state=dict(choices=["present", "absent"], default="present"), ), ), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() @@ -251,32 +239,35 @@ def main(): if module.params["route_targets"] is not None: for rt in module.params["route_targets"]: if rt.get("direction") == "both" or not rt.get("direction"): - platform = get_capabilities(module)["device_info"][ - "network_os_platform" - ] + platform = get_capabilities(module)["device_info"]["network_os_platform"] if platform.startswith("N9K") and rt.get("rt") == "auto": - rt_commands = match_current_rt( - rt, "both", current, rt_commands - ) + rt_commands = match_current_rt(rt, "both", current, rt_commands) else: rt_commands = match_current_rt( - rt, "import", current, rt_commands + rt, + "import", + current, + rt_commands, ) rt_commands = match_current_rt( - rt, "export", current, rt_commands + rt, + "export", + current, + rt_commands, ) else: rt_commands = match_current_rt( - rt, rt.get("direction"), current, rt_commands + rt, + rt.get("direction"), + current, + rt_commands, ) if rt_commands: commands.extend(rt_commands) if commands and current: - commands.insert( - 0, "address-family %s unicast" % module.params["afi"] - ) + commands.insert(0, "address-family %s unicast" % module.params["afi"]) if commands: commands.insert(0, "vrf context %s" % module.params["vrf"]) diff --git a/plugins/modules/nxos_vrf_interface.py b/plugins/modules/nxos_vrf_interface.py index 4273b9211..9e9a0cef2 100644 --- a/plugins/modules/nxos_vrf_interface.py +++ b/plugins/modules/nxos_vrf_interface.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -83,19 +84,15 @@ """ import re -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - load_config, - run_commands, -) +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( get_capabilities, - nxos_argument_spec, - normalize_interface, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( get_interface_type, + load_config, + normalize_interface, + run_commands, ) -from ansible.module_utils.basic import AnsibleModule def execute_show_command(command, module): @@ -184,16 +181,10 @@ def main(): argument_spec = dict( vrf=dict(required=True), interface=dict(type="str", required=True), - state=dict( - default="present", choices=["present", "absent"], required=False - ), + state=dict(default="present", choices=["present", "absent"], required=False), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() results = {"changed": False, "commands": [], "warnings": warnings} @@ -207,10 +198,7 @@ def main(): current_vrfs = get_vrf_list(module) if vrf not in current_vrfs: - warnings.append( - "The VRF is not present/active on the device. " - "Use nxos_vrf to fix this." - ) + warnings.append("The VRF is not present/active on the device. Use nxos_vrf to fix this.") intf_type = get_interface_type(interface) if intf_type != "ethernet" and network_api == "cliconf": @@ -218,7 +206,7 @@ def main(): module.fail_json( msg="interface does not exist on switch. Verify " "switch platform or create it first with " - "nxos_interface if it's a logical interface" + "nxos_interfaces if it's a logical interface", ) mode = get_interface_mode(interface, intf_type, module) @@ -226,7 +214,7 @@ def main(): module.fail_json( msg="Ensure interface is a Layer 3 port before " "configuring a VRF on an interface. You can " - "use nxos_interface" + "use nxos_interfaces", ) current_vrf = get_interface_info(interface, module) diff --git a/plugins/modules/nxos_vrrp.py b/plugins/modules/nxos_vrrp.py index f24020918..b5a026c4b 100644 --- a/plugins/modules/nxos_vrrp.py +++ b/plugins/modules/nxos_vrrp.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -123,18 +124,14 @@ "authentication text testing", "no shutdown"] """ -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - load_config, - run_commands, -) +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( get_capabilities, - nxos_argument_spec, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( get_interface_type, + load_config, + run_commands, ) -from ansible.module_utils.basic import AnsibleModule PARAM_TO_DEFAULT_KEYMAP = { @@ -180,7 +177,7 @@ def is_default(interface, module): return True else: return False - except (KeyError): + except KeyError: return "DNE" @@ -330,8 +327,7 @@ def validate_params(param, module): raise ValueError except ValueError: module.fail_json( - msg="Warning! 'priority' must be an integer " - "between 1 and 254", + msg="Warning! 'priority' must be an integer " "between 1 and 254", priority=value, ) @@ -351,15 +347,9 @@ def main(): default="shutdown", ), authentication=dict(required=False, type="str", no_log=True), - state=dict( - choices=["absent", "present"], required=False, default="present" - ), - ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True + state=dict(choices=["absent", "present"], required=False, default="present"), ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() results = {"changed": False, "commands": [], "warnings": warnings} @@ -396,8 +386,7 @@ def main(): mode, name = get_interface_mode(interface, intf_type, module) if mode == "layer2": module.fail_json( - msg="That interface is a layer2 port.\nMake it " - "a layer 3 port first.", + msg="That interface is a layer2 port.\nMake it " "a layer 3 port first.", interface=interface, ) diff --git a/plugins/modules/nxos_vsan.py b/plugins/modules/nxos_vsan.py deleted file mode 120000 index b472802a2..000000000 --- a/plugins/modules/nxos_vsan.py +++ /dev/null @@ -1 +0,0 @@ -storage/nxos_vsan.py \ No newline at end of file diff --git a/plugins/modules/nxos_vsan.py b/plugins/modules/nxos_vsan.py new file mode 100644 index 000000000..70f9b50ee --- /dev/null +++ b/plugins/modules/nxos_vsan.py @@ -0,0 +1,366 @@ +#!/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 + + +DOCUMENTATION = """ +module: nxos_vsan +short_description: Configuration of vsan for Cisco NXOS MDS Switches. +description: +- Configuration of vsan for Cisco MDS NXOS. +version_added: 1.0.0 +author: +- Suhas Bharadwaj (@srbharadwaj) (subharad@cisco.com) +notes: +- Tested against Cisco MDS NX-OS 8.4(1) +options: + vsan: + description: + - List of vsan details to be added or removed + type: list + elements: dict + suboptions: + id: + description: + - Vsan id + required: true + type: int + name: + description: + - Name of the vsan + type: str + suspend: + description: + - suspend the vsan if True + type: bool + remove: + description: + - Removes the vsan if True + type: bool + interface: + description: + - List of vsan's interfaces to be added + type: list + elements: str +""" + +EXAMPLES = """ +- name: Test that vsan module works + cisco.nxos.nxos_vsan: + vsan: + - id: 922 + interface: + - fc1/1 + - fc1/2 + - port-channel 1 + name: vsan-SAN-A + remove: false + suspend: false + - id: 923 + interface: + - fc1/11 + - fc1/21 + - port-channel 2 + name: vsan-SAN-B + remove: false + suspend: true + - id: 1923 + name: vsan-SAN-Old + remove: true +""" + +RETURN = """ +commands: + description: commands sent to the device + returned: always + type: list + sample: + - terminal dont-ask + - vsan database + - vsan 922 interface fc1/40 + - vsan 922 interface port-channel 155 + - no terminal dont-ask +""" + +import re + +from ansible.module_utils.basic import AnsibleModule + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + load_config, + run_commands, +) + + +__metaclass__ = type + + +class Vsan(object): + def __init__(self, vsanid): + self.vsanid = vsanid + self.vsanname = None + self.vsanstate = None + self.vsanoperstate = None + self.vsaninterfaces = [] + + +class GetVsanInfoFromSwitch(object): + """docstring for GetVsanInfoFromSwitch""" + + def __init__(self, module): + self.module = module + self.vsaninfo = {} + self.processShowVsan() + self.processShowVsanMembership() + + def execute_show_vsan_cmd(self): + output = execute_show_command("show vsan", self.module)[0] + return output + + def execute_show_vsan_mem_cmd(self): + output = execute_show_command("show vsan membership", self.module)[0] + return output + + def processShowVsan(self): + patv = r"^vsan\s+(\d+)\s+information" + patnamestate = "name:(.*)state:(.*)" + patoperstate = "operational state:(.*)" + + output = self.execute_show_vsan_cmd().split("\n") + for o in output: + z = re.match(patv, o.strip()) + if z: + v = z.group(1).strip() + self.vsaninfo[v] = Vsan(v) + + z1 = re.match(patnamestate, o.strip()) + if z1: + n = z1.group(1).strip() + s = z1.group(2).strip() + self.vsaninfo[v].vsanname = n + self.vsaninfo[v].vsanstate = s + + z2 = re.match(patoperstate, o.strip()) + if z2: + oper = z2.group(1).strip() + self.vsaninfo[v].vsanoperstate = oper + + # 4094/4079 vsan is always present + self.vsaninfo["4079"] = Vsan("4079") + self.vsaninfo["4094"] = Vsan("4094") + + def processShowVsanMembership(self): + patv = r"^vsan\s+(\d+).*" + output = self.execute_show_vsan_mem_cmd().split("\n") + memlist = [] + v = None + for o in output: + z = re.match(patv, o.strip()) + if z: + if v is not None: + self.vsaninfo[v].vsaninterfaces = memlist + memlist = [] + v = z.group(1) + if "interfaces" not in o: + llist = o.strip().split() + memlist = memlist + llist + self.vsaninfo[v].vsaninterfaces = memlist + + def getVsanInfoObjects(self): + return self.vsaninfo + + +def execute_show_command(command, module, command_type="cli_show"): + output = "text" + commands = [{"command": command, "output": output}] + return run_commands(module, commands) + + +def flatten_list(command_lists): + flat_command_list = [] + for command in command_lists: + if isinstance(command, list): + flat_command_list.extend(command) + else: + flat_command_list.append(command) + return flat_command_list + + +def main(): + vsan_element_spec = dict( + id=dict(required=True, type="int"), + name=dict(type="str"), + remove=dict(type="bool"), + suspend=dict(type="bool"), + interface=dict(type="list", elements="str"), + ) + + argument_spec = dict( + vsan=dict(type="list", elements="dict", options=vsan_element_spec), + ) + + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) + warnings = list() + messages = list() + commands_executed = list() + result = {"changed": False} + + obj = GetVsanInfoFromSwitch(module) + dictSwVsanObjs = obj.getVsanInfoObjects() + + commands = [] + vsan_list = module.params["vsan"] + + for eachvsan in vsan_list: + vsanid = str(eachvsan["id"]) + vsanname = eachvsan["name"] + vsanremove = eachvsan["remove"] + vsansuspend = eachvsan["suspend"] + vsaninterface_list = eachvsan["interface"] + + if int(vsanid) < 1 or int(vsanid) >= 4095: + module.fail_json( + msg=vsanid + " - This is an invalid vsan. Supported vsan range is 1-4094", + ) + + if vsanid in dictSwVsanObjs.keys(): + sw_vsanid = vsanid + sw_vsanname = dictSwVsanObjs[vsanid].vsanname + sw_vsanstate = dictSwVsanObjs[vsanid].vsanstate + sw_vsaninterfaces = dictSwVsanObjs[vsanid].vsaninterfaces + else: + sw_vsanid = None + sw_vsanname = None + sw_vsanstate = None + sw_vsaninterfaces = [] + + if vsanremove: + # Negative case: + if vsanid == "4079" or vsanid == "4094": + messages.append( + str(vsanid) + " is a reserved vsan, hence cannot be removed", + ) + continue + if vsanid == sw_vsanid: + commands.append("no vsan " + str(vsanid)) + messages.append("deleting the vsan " + str(vsanid)) + else: + messages.append( + "There is no vsan " + + str(vsanid) + + " present in the switch. Hence there is nothing to delete", + ) + continue + else: + # Negative case: + if vsanid == "4079" or vsanid == "4094": + messages.append( + str(vsanid) + " is a reserved vsan, and always present on the switch", + ) + else: + if vsanid == sw_vsanid: + messages.append( + "There is already a vsan " + + str(vsanid) + + " present in the switch. Hence there is nothing to configure", + ) + else: + commands.append("vsan " + str(vsanid)) + messages.append("creating vsan " + str(vsanid)) + + if vsanname is not None: + # Negative case: + if vsanid == "4079" or vsanid == "4094": + messages.append( + str(vsanid) + " is a reserved vsan, and cannot be renamed", + ) + else: + if vsanname == sw_vsanname: + messages.append( + "There is already a vsan " + + str(vsanid) + + " present in the switch, which has the name " + + vsanname + + " Hence there is nothing to configure", + ) + else: + commands.append("vsan " + str(vsanid) + " name " + vsanname) + messages.append( + "setting vsan name to " + vsanname + " for vsan " + str(vsanid), + ) + + if vsansuspend: + # Negative case: + if vsanid == "4079" or vsanid == "4094": + messages.append( + str(vsanid) + " is a reserved vsan, and cannot be suspended", + ) + else: + if sw_vsanstate == "suspended": + messages.append( + "There is already a vsan " + + str(vsanid) + + " present in the switch, which is in suspended state ", + ) + else: + commands.append("vsan " + str(vsanid) + " suspend") + messages.append("suspending the vsan " + str(vsanid)) + else: + if sw_vsanstate == "active": + messages.append( + "There is already a vsan " + + str(vsanid) + + " present in the switch, which is in active state ", + ) + else: + commands.append("no vsan " + str(vsanid) + " suspend") + messages.append("no suspending the vsan " + str(vsanid)) + + if vsaninterface_list is not None: + for each_interface_name in vsaninterface_list: + # For fcip,port-channel,vfc-port-channel need to remove the + # extra space to compare + temp = re.sub(" +", "", each_interface_name) + if temp in sw_vsaninterfaces: + messages.append( + each_interface_name + + " is already present in the vsan " + + str(vsanid) + + " interface list", + ) + else: + commands.append( + "vsan " + str(vsanid) + " interface " + each_interface_name, + ) + messages.append( + "adding interface " + each_interface_name + " to vsan " + str(vsanid), + ) + + if len(commands) != 0: + commands = ["terminal dont-ask"] + ["vsan database"] + commands + ["no terminal dont-ask"] + + cmds = flatten_list(commands) + commands_executed = cmds + + if commands_executed: + if module.check_mode: + module.exit_json( + changed=False, + commands=commands_executed, + msg="Check Mode: No cmds issued to the hosts", + ) + else: + result["changed"] = True + load_config(module, commands_executed) + + result["messages"] = messages + result["commands"] = commands_executed + result["warnings"] = warnings + module.exit_json(**result) + + +if __name__ == "__main__": + main() diff --git a/plugins/modules/nxos_vtp_domain.py b/plugins/modules/nxos_vtp_domain.py index 114fc2630..d1e3c39fd 100644 --- a/plugins/modules/nxos_vtp_domain.py +++ b/plugins/modules/nxos_vtp_domain.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -89,18 +90,15 @@ """ +import re + +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + get_capabilities, load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_capabilities, -) -from ansible.module_utils.basic import AnsibleModule -import re def execute_show_command(command, module, output="json"): @@ -172,11 +170,7 @@ def get_vtp_password(module): def main(): argument_spec = dict(domain=dict(type="str", required=True)) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() diff --git a/plugins/modules/nxos_vtp_password.py b/plugins/modules/nxos_vtp_password.py index 9d94d8d1e..c6e9cabdb 100644 --- a/plugins/modules/nxos_vtp_password.py +++ b/plugins/modules/nxos_vtp_password.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -102,18 +103,15 @@ sample: true """ +import re + +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + get_capabilities, load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_capabilities, -) -from ansible.module_utils.basic import AnsibleModule -import re def execute_show_command(command, module, output="json"): @@ -202,11 +200,7 @@ def main(): state=dict(choices=["absent", "present"], default="present"), ) - argument_spec.update(nxos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() @@ -240,14 +234,11 @@ def main(): "current vtp password. It cannot be " "removed when state=absent. If you are " "trying to change the vtp password, use " - "state=present." + "state=present.", ) else: if not existing.get("domain"): - module.fail_json( - msg="Cannot remove a vtp password " - "before vtp domain is set." - ) + module.fail_json(msg="Cannot remove a vtp password " "before vtp domain is set.") elif existing["vtp_password"] != ("\\"): commands.append(["no vtp password"]) @@ -255,9 +246,7 @@ def main(): elif state == "present": if delta: if not existing.get("domain"): - module.fail_json( - msg="Cannot set vtp password " "before vtp domain is set." - ) + module.fail_json(msg="Cannot set vtp password " "before vtp domain is set.") else: commands.append(["vtp password {0}".format(vtp_password)]) diff --git a/plugins/modules/nxos_vtp_version.py b/plugins/modules/nxos_vtp_version.py index 48d6ebc45..a98bff904 100644 --- a/plugins/modules/nxos_vtp_version.py +++ b/plugins/modules/nxos_vtp_version.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -45,15 +46,13 @@ choices: - '1' - '2' + - '3' type: str """ EXAMPLES = """ # ENSURE VTP VERSION IS 2 - cisco.nxos.nxos_vtp_version: version: 2 - host: '{{ inventory_hostname }}' - username: '{{ un }}' - password: '{{ pwd }}' """ RETURN = """ @@ -84,18 +83,15 @@ type: bool sample: true """ +import re + +from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + get_capabilities, load_config, run_commands, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_capabilities, -) -from ansible.module_utils.basic import AnsibleModule -import re def execute_show_command(command, module, output="json"): @@ -165,15 +161,9 @@ def get_vtp_password(module): def main(): - argument_spec = dict( - version=dict(type="str", choices=["1", "2"], required=True) - ) - - argument_spec.update(nxos_argument_spec) + argument_spec = dict(version=dict(type="str", choices=["1", "2", "3"], required=True)) - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() diff --git a/plugins/modules/nxos_vxlan_vtep.py b/plugins/modules/nxos_vxlan_vtep.py index fd9c996c5..f62b995c0 100644 --- a/plugins/modules/nxos_vxlan_vtep.py +++ b/plugins/modules/nxos_vxlan_vtep.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -33,7 +34,7 @@ notes: - Tested against NXOSv 7.3.(0)D1(1) on VIRL - Unsupported for Cisco MDS -- The module is used to manage NVE properties, not to create NVE interfaces. Use M(cisco.nxos.nxos_interface) +- The module is used to manage NVE properties, not to create NVE interfaces. Use M(cisco.nxos.nxos_interfaces) if you wish to do so. - C(state=absent) removes the interface. - Default, where supported, restores params default value. @@ -103,6 +104,12 @@ an existing gateway config. type: str version_added: 1.1.0 + advertise_virtual_rmac: + description: + - The advertise_virtual_rmac parameter lets BGP to use the VMAC with VIP as next-hop when + advertising type-2 routes. Should be used together with advertise_pip parameter from + cisco.nxos.nxos_bgp_address_family module. + type: bool """ EXAMPLES = """ - cisco.nxos.nxos_vxlan_vtep: @@ -128,26 +135,24 @@ import re +from ansible.module_utils.basic import AnsibleModule +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( + CustomNetworkConfig, +) + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( get_config, load_config, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( run_commands, ) -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( - CustomNetworkConfig, -) + BOOL_PARAMS = [ "shutdown", "host_reachability", "global_ingress_replication_bgp", "global_suppress_arp", + "advertise_virtual_rmac", ] PARAM_TO_COMMAND_KEYMAP = { "description": "description", @@ -161,6 +166,7 @@ "source_interface": "source-interface", "source_interface_hold_down_time": "source-interface hold-down-time", "multisite_border_gateway_interface": "multisite border-gateway interface", + "advertise_virtual_rmac": "advertise virtual-rmac", } PARAM_TO_DEFAULT_KEYMAP = { "description": False, @@ -171,9 +177,8 @@ def get_value(arg, config, module): if arg in BOOL_PARAMS: - REGEX = re.compile( - r"\s+{0}\s*$".format(PARAM_TO_COMMAND_KEYMAP[arg]), re.M - ) + REGEX = re.compile(r"\s+{0}\s*$".format(PARAM_TO_COMMAND_KEYMAP[arg]), re.M) + NO_REGEX = re.compile(r"\s+no\s{0}\s*$".format(PARAM_TO_COMMAND_KEYMAP[arg]), re.M) NO_SHUT_REGEX = re.compile(r"\s+no shutdown\s*$", re.M) value = False if arg == "shutdown": @@ -184,6 +189,14 @@ def get_value(arg, config, module): value = True except TypeError: value = False + elif arg == "advertise_virtual_rmac": + try: + if NO_REGEX.search(config): + value = False + elif REGEX.search(config): + value = True + except TypeError: + value = False else: try: if REGEX.search(config): @@ -195,9 +208,7 @@ def get_value(arg, config, module): r"(?:{0}\s)(?P.*)$".format(PARAM_TO_COMMAND_KEYMAP[arg]), re.M, ) - NO_DESC_REGEX = re.compile( - r"\s+{0}\s*$".format("no description"), re.M - ) + NO_DESC_REGEX = re.compile(r"\s+{0}\s*$".format("no description"), re.M) SOURCE_INTF_REGEX = re.compile( r"(?:{0}\s)(?P\S+)$".format(PARAM_TO_COMMAND_KEYMAP[arg]), re.M, @@ -212,11 +223,7 @@ def get_value(arg, config, module): for line in config.splitlines(): try: if PARAM_TO_COMMAND_KEYMAP[arg] in config: - value = ( - SOURCE_INTF_REGEX.search(config) - .group("value") - .strip() - ) + value = SOURCE_INTF_REGEX.search(config).group("value").strip() break except AttributeError: value = "" @@ -240,11 +247,7 @@ def get_value(arg, config, module): for line in config.splitlines(): try: if PARAM_TO_COMMAND_KEYMAP[arg] in config: - value = ( - SOURCE_INTF_REGEX.search(config) - .group("value") - .strip() - ) + value = SOURCE_INTF_REGEX.search(config).group("value").strip() break except AttributeError: value = "" @@ -256,13 +259,9 @@ def get_value(arg, config, module): def get_existing(module, args): existing = {} - netcfg = CustomNetworkConfig( - indent=2, contents=get_config(module, flags=["all"]) - ) + netcfg = CustomNetworkConfig(indent=2, contents=get_config(module, flags=["all"])) - interface_string = "interface {0}".format( - module.params["interface"].lower() - ) + interface_string = "interface {0}".format(module.params["interface"].lower()) parents = [interface_string] config = netcfg.get_section(parents) @@ -338,9 +337,7 @@ def gsa_tcam_check(module): This method checks the current TCAM allocation. Note that changing tcam_size requires a switch reboot to take effect. """ - cmds = [ - {"command": "show hardware access-list tcam region", "output": "json"} - ] + cmds = [{"command": "show hardware access-list tcam region", "output": "json"}] body = run_commands(module, cmds) if body: tcam_region = body[0]["TCAM_Region"]["TABLE_Sizes"]["ROW_Sizes"] @@ -348,9 +345,8 @@ def gsa_tcam_check(module): [ i for i in tcam_region - if i["type"].startswith("Ingress ARP-Ether ACL") - and i["tcam_size"] == "0" - ] + if i["type"].startswith("Ingress ARP-Ether ACL") and i["tcam_size"] == "0" + ], ): msg = ( "'show hardware access-list tcam region' indicates 'ARP-Ether' tcam size is 0 (no allocated resources). " @@ -396,9 +392,7 @@ def state_present(module, existing, proposed, candidate): candidate.add(commands, parents=parents) else: if not existing and module.params["interface"]: - commands = [ - "interface {0}".format(module.params["interface"].lower()) - ] + commands = ["interface {0}".format(module.params["interface"].lower())] candidate.add(commands, parents=[]) @@ -419,17 +413,12 @@ def main(): shutdown=dict(required=False, type="bool"), source_interface=dict(required=False, type="str"), source_interface_hold_down_time=dict(required=False, type="str"), - state=dict( - choices=["present", "absent"], default="present", required=False - ), + state=dict(choices=["present", "absent"], default="present", required=False), multisite_border_gateway_interface=dict(required=False, type="str"), + advertise_virtual_rmac=dict(required=False, type="bool"), ) - argument_spec.update(nxos_argument_spec) - - mutually_exclusive = [ - ("global_ingress_replication_bgp", "global_mcast_group_L2") - ] + mutually_exclusive = [("global_ingress_replication_bgp", "global_mcast_group_L2")] module = AnsibleModule( argument_spec=argument_spec, @@ -445,9 +434,7 @@ def main(): args = PARAM_TO_COMMAND_KEYMAP.keys() existing = get_existing(module, args) - proposed_args = dict( - (k, v) for k, v in module.params.items() if v is not None and k in args - ) + proposed_args = dict((k, v) for k, v in module.params.items() if v is not None and k in args) proposed = {} for key, value in proposed_args.items(): if key != "interface": @@ -469,8 +456,8 @@ def main(): if not existing: warnings.append( "The proposed NVE interface did not exist. " - "It's recommended to use nxos_interface to create " - "all logical interfaces." + "It's recommended to use nxos_interfaces to create " + "all logical interfaces.", ) state_present(module, existing, proposed, candidate) elif state == "absent" and existing: diff --git a/plugins/modules/nxos_vxlan_vtep_vni.py b/plugins/modules/nxos_vxlan_vtep_vni.py index 86bfc2d9b..d58bd6c95 100644 --- a/plugins/modules/nxos_vxlan_vtep_vni.py +++ b/plugins/modules/nxos_vxlan_vtep_vni.py @@ -17,6 +17,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -113,18 +114,18 @@ """ import re -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - get_config, - load_config, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - nxos_argument_spec, -) + from ansible.module_utils.basic import AnsibleModule from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( CustomNetworkConfig, ) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + get_config, + load_config, +) + + BOOL_PARAMS = ["assoc_vrf", "suppress_arp", "suppress_arp_disable"] PARAM_TO_DEFAULT_KEYMAP = { "multicast_group": "", @@ -146,9 +147,7 @@ def get_value(arg, config, module): command = PARAM_TO_COMMAND_KEYMAP[arg] - command_val_re = re.compile( - r"(?:{0}\s)(?P.*)$".format(command), re.M - ) + command_val_re = re.compile(r"(?:{0}\s)(?P.*)$".format(command), re.M) if arg in BOOL_PARAMS: command_re = re.compile(r"\s+{0}\s*$".format(command), re.M) @@ -196,13 +195,8 @@ def get_existing(module, args): parents = ["interface {0}".format(interface_exist)] temp_config = netcfg.get_section(parents) - if ( - "member vni {0} associate-vrf".format(module.params["vni"]) - in temp_config - ): - parents.append( - "member vni {0} associate-vrf".format(module.params["vni"]) - ) + if "member vni {0} associate-vrf".format(module.params["vni"]) in temp_config: + parents.append("member vni {0} associate-vrf".format(module.params["vni"])) config = netcfg.get_section(parents) elif "member vni {0}".format(module.params["vni"]) in temp_config: parents.append("member vni {0}".format(module.params["vni"])) @@ -250,19 +244,12 @@ def state_present(module, existing, proposed, candidate): vni_command = "member vni {0}".format(module.params["vni"]) if vni_command not in commands: commands.append("member vni {0}".format(module.params["vni"])) - if value != PARAM_TO_DEFAULT_KEYMAP.get( - "multicast_group", "default" - ): + if value != PARAM_TO_DEFAULT_KEYMAP.get("multicast_group", "default"): commands.append("{0} {1}".format(key, value)) - elif ( - key == "ingress-replication protocol" - and value != existing_commands.get(key) - ): + elif key == "ingress-replication protocol" and value != existing_commands.get(key): evalue = existing_commands.get(key) - dvalue = PARAM_TO_DEFAULT_KEYMAP.get( - "ingress_replication", "default" - ) + dvalue = PARAM_TO_DEFAULT_KEYMAP.get("ingress_replication", "default") if value != dvalue: if evalue and evalue != dvalue: commands.append("no {0} {1}".format(key, evalue)) @@ -286,10 +273,7 @@ def state_present(module, existing, proposed, candidate): else: if key.replace(" ", "_").replace("-", "_") in BOOL_PARAMS: commands.append("no {0}".format(key.lower())) - elif ( - key == "multisite ingress-replication" - and value != existing_commands.get(key) - ): + elif key == "multisite ingress-replication" and value != existing_commands.get(key): vni_command = "member vni {0}".format(module.params["vni"]) if vni_command not in commands: commands.append("member vni {0}".format(module.params["vni"])) @@ -310,9 +294,7 @@ def state_present(module, existing, proposed, candidate): vni_command = "member vni {0}".format(module.params["vni"]) ingress_replications_command = "ingress-replication protocol static" ingress_replicationb_command = "ingress-replication protocol bgp" - ingress_replicationns_command = ( - "no ingress-replication protocol static" - ) + ingress_replicationns_command = "no ingress-replication protocol static" ingress_replicationnb_command = "no ingress-replication protocol bgp" interface_command = "interface {0}".format(module.params["interface"]) @@ -351,9 +333,7 @@ def state_present(module, existing, proposed, candidate): def state_absent(module, existing, proposed, candidate): if existing["assoc_vrf"]: - commands = [ - "no member vni {0} associate-vrf".format(module.params["vni"]) - ] + commands = ["no member vni {0} associate-vrf".format(module.params["vni"])] else: commands = ["no member vni {0}".format(module.params["vni"])] parents = ["interface {0}".format(module.params["interface"])] @@ -369,12 +349,8 @@ def main(): peer_list=dict(required=False, type="list", elements="str"), suppress_arp=dict(required=False, type="bool"), suppress_arp_disable=dict(required=False, type="bool"), - ingress_replication=dict( - required=False, type="str", choices=["bgp", "static", "default"] - ), - state=dict( - choices=["present", "absent"], default="present", required=False - ), + ingress_replication=dict(required=False, type="str", choices=["bgp", "static", "default"]), + state=dict(choices=["present", "absent"], default="present", required=False), multisite_ingress_replication=dict( required=False, type="str", @@ -382,8 +358,6 @@ def main(): ), ) - argument_spec.update(nxos_argument_spec) - mutually_exclusive = [ ("suppress_arp", "suppress_arp_disable"), ("assoc_vrf", "multicast_group"), @@ -406,8 +380,7 @@ def main(): and module.params["ingress_replication"] != "static" ): module.fail_json( - msg="ingress_replication=static is required " - "when using peer_list param" + msg="ingress_replication=static is required " "when using peer_list param", ) else: peer_list = module.params["peer_list"] @@ -424,7 +397,7 @@ def main(): if module.params["ingress_replication"] == "static": module.fail_json( msg="ingress_replication=static is not allowed " - "when using multisite_ingress_replication" + "when using multisite_ingress_replication", ) state = module.params["state"] @@ -434,26 +407,22 @@ def main(): if state == "present": if not interface_exist: module.fail_json( - msg="The proposed NVE interface does not exist. Use nxos_interface to create it first." + msg="The proposed NVE interface does not exist. Use nxos_interface to create it first.", ) elif interface_exist != module.params["interface"]: - module.fail_json( - msg="Only 1 NVE interface is allowed on the switch." - ) + module.fail_json(msg="Only 1 NVE interface is allowed on the switch.") elif state == "absent": if interface_exist != module.params["interface"]: module.exit_json(**result) elif existing and existing["vni"] != module.params["vni"]: module.fail_json( msg="ERROR: VNI delete failed: Could not find vni node for {0}".format( - module.params["vni"] + module.params["vni"], ), existing_vni=existing["vni"], ) - proposed_args = dict( - (k, v) for k, v in module.params.items() if v is not None and k in args - ) + proposed_args = dict((k, v) for k, v in module.params.items() if v is not None and k in args) proposed = {} for key, value in proposed_args.items(): diff --git a/plugins/modules/nxos_zone_zoneset.py b/plugins/modules/nxos_zone_zoneset.py deleted file mode 120000 index c9c313856..000000000 --- a/plugins/modules/nxos_zone_zoneset.py +++ /dev/null @@ -1 +0,0 @@ -storage/nxos_zone_zoneset.py \ No newline at end of file diff --git a/plugins/modules/nxos_zone_zoneset.py b/plugins/modules/nxos_zone_zoneset.py new file mode 100644 index 000000000..5d519150f --- /dev/null +++ b/plugins/modules/nxos_zone_zoneset.py @@ -0,0 +1,922 @@ +#!/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 + + +DOCUMENTATION = """ +module: nxos_zone_zoneset +short_description: Configuration of zone/zoneset for Cisco NXOS MDS Switches. +description: + - Configuration of zone/zoneset for Cisco MDS NXOS. +version_added: 1.0.0 +author: + - Suhas Bharadwaj (@srbharadwaj) (subharad@cisco.com) +notes: + - Tested against Cisco MDS NX-OS 8.4(1) +options: + zone_zoneset_details: + description: + - List of zone/zoneset details to be added or removed + type: list + elements: dict + suboptions: + vsan: + description: + - vsan id + required: true + type: int + mode: + description: + - mode of the zone for the vsan + choices: + - enhanced + - basic + type: str + default_zone: + description: + - default zone behaviour for the vsan + choices: + - permit + - deny + type: str + smart_zoning: + description: + - Removes the vsan if True + type: bool + zone: + description: + - List of zone options for that vsan + type: list + elements: dict + suboptions: + name: + description: + - name of the zone + required: true + type: str + remove: + description: + - Deletes the zone if True + type: bool + default: false + members: + description: + - Members of the zone that needs to be removed or added + type: list + elements: dict + suboptions: + pwwn: + description: + - >- + pwwn member of the zone, use alias 'device_alias' as option + for device_alias member + aliases: + - device_alias + required: true + type: str + remove: + description: + - Removes member from the zone if True + type: bool + default: false + devtype: + description: + - >- + devtype of the zone member used along with Smart zoning + config + choices: + - initiator + - target + - both + type: str + zoneset: + description: + - List of zoneset options for the vsan + type: list + elements: dict + suboptions: + name: + description: + - name of the zoneset + required: true + type: str + remove: + description: + - Removes zoneset if True + type: bool + default: false + action: + description: + - activates/de-activates the zoneset + choices: + - activate + - deactivate + type: str + members: + description: + - Members of the zoneset that needs to be removed or added + type: list + elements: dict + suboptions: + name: + description: + - >- + name of the zone that needs to be added to the zoneset or + removed from the zoneset + required: true + type: str + remove: + description: + - Removes zone member from the zoneset + type: bool + default: false + +""" + +EXAMPLES = """ +- name: Test that zone/zoneset module works + cisco.nxos.nxos_zone_zoneset: + zone_zoneset_details: + - mode: enhanced + vsan: 22 + zone: + - members: + - pwwn: 31314874576271 + - device_alias: test123 + - pwwn: '61:61:62:62:12:12:12:12' + remove: true + name: zoneA + - members: + - pwwn: 28515514576271 + - pwwn: '62:62:62:62:21:21:21:21' + name: zoneB + - name: zoneC + remove: true + zoneset: + - action: activate + members: + - name: zoneA + - name: zoneB + - name: zoneC + remove: true + name: zsetname1 + - action: deactivate + name: zsetTestExtra + remove: true + - mode: basic + smart_zoning: true + vsan: 21 + zone: + - members: + - devtype: both + pwwn: 31314874576271 + - pwwn: '62:62:62:62:12:12:12:12' + - devtype: both + pwwn: '92:62:62:62:12:12:1a:1a' + remove: true + name: zone21A + - members: + - pwwn: 28515514576271 + - pwwn: '62:62:62:62:21:21:21:21' + name: zone21B + zoneset: + - action: activate + members: + - name: zone21A + - name: zone21B + name: zsetname212 +""" + +RETURN = """ +commands: + description: commands sent to the device + returned: always + type: list + sample: + - terminal dont-ask + - zone name zoneA vsan 923 + - member pwwn 11:11:11:11:11:11:11:11 + - no member device-alias test123 + - zone commit vsan 923 + - no terminal dont-ask +messages: + description: debug messages + returned: always + type: list + sample: + - "zone mode is already enhanced ,no change in zone mode configuration for vsan 922" + - "zone member '11:11:11:11:11:11:11:11' is already present in zone 'zoneA' in vsan 922 hence nothing to add" + - "zone member 'test123' is already present in zone 'zoneA' in vsan 922 hence nothing to add" + - "zone member '61:61:62:62:12:12:12:12' is not present in zone 'zoneA' in vsan 922 hence nothing to remove" + - "zone member '10:11:11:11:11:11:11:11' is already present in zone 'zoneB' in vsan 922 hence nothing to add" + - "zone member '62:62:62:62:21:21:21:21' is already present in zone 'zoneB' in vsan 922 hence nothing to add" + - "zone 'zoneC' is not present in vsan 922 , so nothing to remove" +""" + + +import re + +from ansible.module_utils.basic import AnsibleModule + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( + load_config, + run_commands, +) + + +__metaclass__ = type + + +class ShowZonesetActive(object): + """docstring for ShowZonesetActive""" + + def __init__(self, module, vsan): + self.vsan = vsan + self.module = module + self.activeZSName = None + self.parseCmdOutput() + + def execute_show_zoneset_active_cmd(self): + command = "show zoneset active vsan " + str(self.vsan) + " | grep zoneset" + output = execute_show_command(command, self.module)[0] + return output + + def parseCmdOutput(self): + patZoneset = r"zoneset name (\S+) vsan " + str(self.vsan) + output = self.execute_show_zoneset_active_cmd().split("\n") + if len(output) == 0: + return + else: + for line in output: + line = line.strip() + mzs = re.match(patZoneset, line.strip()) + if mzs: + self.activeZSName = mzs.group(1).strip() + return + + def isZonesetActive(self, zsname): + if zsname == self.activeZSName: + return True + return False + + +class ShowZoneset(object): + """docstring for ShowZoneset""" + + def __init__(self, module, vsan): + self.vsan = vsan + self.module = module + self.zsDetails = {} + self.parseCmdOutput() + + def execute_show_zoneset_cmd(self): + command = "show zoneset vsan " + str(self.vsan) + output = execute_show_command(command, self.module)[0] + return output + + def parseCmdOutput(self): + patZoneset = r"zoneset name (\S+) vsan " + str(self.vsan) + patZone = r"zone name (\S+) vsan " + str(self.vsan) + output = self.execute_show_zoneset_cmd().split("\n") + for line in output: + line = line.strip() + mzs = re.match(patZoneset, line.strip()) + mz = re.match(patZone, line.strip()) + if mzs: + zonesetname = mzs.group(1).strip() + self.zsDetails[zonesetname] = [] + continue + elif mz: + zonename = mz.group(1).strip() + v = self.zsDetails[zonesetname] + v.append(zonename) + self.zsDetails[zonesetname] = v + + def isZonesetPresent(self, zsname): + return zsname in self.zsDetails.keys() + + def isZonePresentInZoneset(self, zsname, zname): + if zsname in self.zsDetails.keys(): + return zname in self.zsDetails[zsname] + return False + + +class ShowZone(object): + """docstring for ShowZone""" + + def __init__(self, module, vsan): + self.vsan = vsan + self.module = module + self.zDetails = {} + self.parseCmdOutput() + + def execute_show_zone_vsan_cmd(self): + command = "show zone vsan " + str(self.vsan) + output = execute_show_command(command, self.module)[0] + return output + + def parseCmdOutput(self): + patZone = r"zone name (\S+) vsan " + str(self.vsan) + output = self.execute_show_zone_vsan_cmd().split("\n") + for line in output: + line = re.sub(r"[\[].*?[\]]", "", line) + line = " ".join(line.strip().split()) + if "init" in line: + line = line.replace("init", "initiator") + m = re.match(patZone, line) + if m: + zonename = m.group(1).strip() + self.zDetails[zonename] = [] + continue + else: + # For now we support only pwwn and device-alias under zone + # Ideally should use 'supported_choices'....but maybe next + # time. + if "pwwn" in line or "device-alias" in line: + v = self.zDetails[zonename] + v.append(line) + self.zDetails[zonename] = v + + def isZonePresent(self, zname): + return zname in self.zDetails.keys() + + def isZoneMemberPresent(self, zname, cmd): + if zname in self.zDetails.keys(): + zonememlist = self.zDetails[zname] + for eachline in zonememlist: + if cmd in eachline: + return True + return False + + def get_zDetails(self): + return self.zDetails + + +class ShowZoneStatus(object): + """docstring for ShowZoneStatus""" + + def __init__(self, module, vsan): + self.vsan = vsan + self.vsanAbsent = False + self.module = module + self.default_zone = "" + self.mode = "" + self.session = "" + self.sz = "" + self.locked = False + self.update() + + def execute_show_zone_status_cmd(self): + command = "show zone status vsan " + str(self.vsan) + output = execute_show_command(command, self.module)[0] + return output + + def update(self): + output = self.execute_show_zone_status_cmd().split("\n") + + patfordefzone = "VSAN: " + str(self.vsan) + r" default-zone:\s+(\S+).*" + patformode = r".*mode:\s+(\S+).*" + patforsession = r"^session:\s+(\S+).*" + patforsz = r".*smart-zoning:\s+(\S+).*" + for line in output: + if "is not configured" in line: + self.vsanAbsent = True + break + mdefz = re.match(patfordefzone, line.strip()) + mmode = re.match(patformode, line.strip()) + msession = re.match(patforsession, line.strip()) + msz = re.match(patforsz, line.strip()) + + if mdefz: + self.default_zone = mdefz.group(1) + if mmode: + self.mode = mmode.group(1) + if msession: + self.session = msession.group(1) + if self.session != "none": + self.locked = True + if msz: + self.sz = msz.group(1) + + def isLocked(self): + return self.locked + + def getDefaultZone(self): + return self.default_zone + + def getMode(self): + return self.mode + + def getSmartZoningStatus(self): + return self.sz + + def isVsanAbsent(self): + return self.vsanAbsent + + +def execute_show_command(command, module, command_type="cli_show"): + output = "text" + commands = [{"command": command, "output": output}] + return run_commands(module, commands) + + +def flatten_list(command_lists): + flat_command_list = [] + for command in command_lists: + if isinstance(command, list): + flat_command_list.extend(command) + else: + flat_command_list.append(command) + return flat_command_list + + +def getMemType(supported_choices, allmemkeys, default="pwwn"): + for eachchoice in supported_choices: + if eachchoice in allmemkeys: + return eachchoice + return default + + +def main(): + supported_choices = ["device_alias"] + zone_member_spec = dict( + pwwn=dict(required=True, type="str", aliases=["device_alias"]), + devtype=dict(type="str", choices=["initiator", "target", "both"]), + remove=dict(type="bool", default=False), + ) + + zone_spec = dict( + name=dict(required=True, type="str"), + members=dict(type="list", elements="dict", options=zone_member_spec), + remove=dict(type="bool", default=False), + ) + + zoneset_member_spec = dict( + name=dict(required=True, type="str"), + remove=dict(type="bool", default=False), + ) + + zoneset_spec = dict( + name=dict(type="str", required=True), + members=dict(type="list", elements="dict", options=zoneset_member_spec), + remove=dict(type="bool", default=False), + action=dict(type="str", choices=["activate", "deactivate"]), + ) + + zonedetails_spec = dict( + vsan=dict(required=True, type="int"), + mode=dict(type="str", choices=["enhanced", "basic"]), + default_zone=dict(type="str", choices=["permit", "deny"]), + smart_zoning=dict(type="bool"), + zone=dict(type="list", elements="dict", options=zone_spec), + zoneset=dict(type="list", elements="dict", options=zoneset_spec), + ) + + argument_spec = dict( + zone_zoneset_details=dict( + type="list", + elements="dict", + options=zonedetails_spec, + ), + ) + + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) + + warnings = list() + messages = list() + commands = list() + result = {"changed": False} + + commands_executed = [] + listOfZoneDetails = module.params["zone_zoneset_details"] + for eachZoneZonesetDetail in listOfZoneDetails: + vsan = eachZoneZonesetDetail["vsan"] + op_mode = eachZoneZonesetDetail["mode"] + op_default_zone = eachZoneZonesetDetail["default_zone"] + op_smart_zoning = eachZoneZonesetDetail["smart_zoning"] + op_zone = eachZoneZonesetDetail["zone"] + op_zoneset = eachZoneZonesetDetail["zoneset"] + + # Step1: execute show zone status and get + shZoneStatusObj = ShowZoneStatus(module, vsan) + sw_default_zone = shZoneStatusObj.getDefaultZone() + sw_mode = shZoneStatusObj.getMode() + sw_smart_zoning = shZoneStatusObj.getSmartZoningStatus() + + if sw_smart_zoning.lower() == "Enabled".lower(): + sw_smart_zoning_bool = True + else: + sw_smart_zoning_bool = False + + if shZoneStatusObj.isVsanAbsent(): + module.fail_json( + msg="Vsan " + str(vsan) + " is not present in the switch. Hence cannot procced.", + ) + + if shZoneStatusObj.isLocked(): + module.fail_json( + msg="zone has acquired lock on the switch for vsan " + + str(vsan) + + ". Hence cannot procced.", + ) + + # Process zone default zone options + if op_default_zone is not None: + if op_default_zone != sw_default_zone: + if op_default_zone == "permit": + commands_executed.append( + "zone default-zone permit vsan " + str(vsan), + ) + messages.append( + "default zone configuration changed from deny to permit for vsan " + + str(vsan), + ) + else: + commands_executed.append( + "no zone default-zone permit vsan " + str(vsan), + ) + messages.append( + "default zone configuration changed from permit to deny for vsan " + + str(vsan), + ) + else: + messages.append( + "default zone is already " + + op_default_zone + + " ,no change in default zone configuration for vsan " + + str(vsan), + ) + + # Process zone mode options + if op_mode is not None: + if op_mode != sw_mode: + if op_mode == "enhanced": + commands_executed.append("zone mode enhanced vsan " + str(vsan)) + messages.append( + "zone mode configuration changed from basic to enhanced for vsan " + + str(vsan), + ) + else: + commands_executed.append("no zone mode enhanced vsan " + str(vsan)) + messages.append( + "zone mode configuration changed from enhanced to basic for vsan " + + str(vsan), + ) + else: + messages.append( + "zone mode is already " + + op_mode + + " ,no change in zone mode configuration for vsan " + + str(vsan), + ) + + # Process zone smart-zone options + if op_smart_zoning is not None: + if op_smart_zoning != sw_smart_zoning_bool: + if op_smart_zoning: + commands_executed.append( + "zone smart-zoning enable vsan " + str(vsan), + ) + messages.append("smart-zoning enabled for vsan " + str(vsan)) + else: + commands_executed.append( + "no zone smart-zoning enable vsan " + str(vsan), + ) + messages.append("smart-zoning disabled for vsan " + str(vsan)) + else: + messages.append( + "smart-zoning is already set to " + + sw_smart_zoning + + " , no change in smart-zoning configuration for vsan " + + str(vsan), + ) + + # Process zone member options + # TODO: Obviously this needs to be cleaned up properly, as there are a lot of ifelse statements which is bad + # Will take it up later becoz of time constraints + if op_zone is not None: + shZoneObj = ShowZone(module, vsan) + for eachzone in op_zone: + zname = eachzone["name"] + zmembers = eachzone["members"] + removeflag = eachzone["remove"] + if removeflag: + if shZoneObj.isZonePresent(zname): + messages.append( + "zone '" + zname + "' is removed from vsan " + str(vsan), + ) + commands_executed.append( + "no zone name " + zname + " vsan " + str(vsan), + ) + else: + messages.append( + "zone '" + + zname + + "' is not present in vsan " + + str(vsan) + + " , so nothing to remove", + ) + else: + if zmembers is None: + if shZoneObj.isZonePresent(zname): + messages.append( + "zone '" + zname + "' is already present in vsan " + str(vsan), + ) + else: + commands_executed.append( + "zone name " + zname + " vsan " + str(vsan), + ) + messages.append( + "zone '" + zname + "' is created in vsan " + str(vsan), + ) + else: + cmdmemlist = [] + for eachmem in zmembers: + memtype = getMemType(supported_choices, eachmem.keys()) + cmd = memtype.replace("_", "-") + " " + eachmem[memtype] + if op_smart_zoning or sw_smart_zoning_bool: + if eachmem["devtype"] is not None: + cmd = cmd + " " + eachmem["devtype"] + if eachmem["remove"]: + if shZoneObj.isZonePresent(zname): + if shZoneObj.isZoneMemberPresent(zname, cmd): + cmd = "no member " + cmd + cmdmemlist.append(cmd) + if op_smart_zoning and eachmem["devtype"] is not None: + messages.append( + "removing zone member '" + + eachmem[memtype] + + " of device type '" + + eachmem["devtype"] + + "' from zone '" + + zname + + "' in vsan " + + str(vsan), + ) + else: + messages.append( + "removing zone member '" + + eachmem[memtype] + + "' from zone '" + + zname + + "' in vsan " + + str(vsan), + ) + else: + if op_smart_zoning and eachmem["devtype"] is not None: + messages.append( + "zone member '" + + eachmem[memtype] + + "' of device type '" + + eachmem["devtype"] + + "' is not present in zone '" + + zname + + "' in vsan " + + str(vsan) + + " hence nothing to remove", + ) + else: + messages.append( + "zone member '" + + eachmem[memtype] + + "' is not present in zone '" + + zname + + "' in vsan " + + str(vsan) + + " hence nothing to remove", + ) + else: + messages.append( + "zone '" + + zname + + "' is not present in vsan " + + str(vsan) + + " , hence cannot remove the members", + ) + + else: + if shZoneObj.isZoneMemberPresent(zname, cmd): + if op_smart_zoning and eachmem["devtype"] is not None: + messages.append( + "zone member '" + + eachmem[memtype] + + "' of device type '" + + eachmem["devtype"] + + "' is already present in zone '" + + zname + + "' in vsan " + + str(vsan) + + " hence nothing to add", + ) + else: + messages.append( + "zone member '" + + eachmem[memtype] + + "' is already present in zone '" + + zname + + "' in vsan " + + str(vsan) + + " hence nothing to add", + ) + else: + cmd = "member " + cmd + cmdmemlist.append(cmd) + if op_smart_zoning and eachmem["devtype"] is not None: + messages.append( + "adding zone member '" + + eachmem[memtype] + + "' of device type '" + + eachmem["devtype"] + + "' to zone '" + + zname + + "' in vsan " + + str(vsan), + ) + else: + messages.append( + "adding zone member '" + + eachmem[memtype] + + "' to zone '" + + zname + + "' in vsan " + + str(vsan), + ) + if len(cmdmemlist) != 0: + commands_executed.append( + "zone name " + zname + " vsan " + str(vsan), + ) + commands_executed = commands_executed + cmdmemlist + + # Process zoneset member options + if op_zoneset is not None: + dactcmd = [] + actcmd = [] + shZonesetObj = ShowZoneset(module, vsan) + shZonesetActiveObj = ShowZonesetActive(module, vsan) + for eachzoneset in op_zoneset: + zsetname = eachzoneset["name"] + zsetmembers = eachzoneset["members"] + removeflag = eachzoneset["remove"] + actionflag = eachzoneset["action"] + if removeflag: + if shZonesetObj.isZonesetPresent(zsetname): + messages.append( + "zoneset '" + zsetname + "' is removed from vsan " + str(vsan), + ) + commands_executed.append( + "no zoneset name " + zsetname + " vsan " + str(vsan), + ) + else: + messages.append( + "zoneset '" + + zsetname + + "' is not present in vsan " + + str(vsan) + + " ,hence there is nothing to remove", + ) + else: + if zsetmembers is not None: + cmdmemlist = [] + for eachzsmem in zsetmembers: + zsetmem_name = eachzsmem["name"] + zsetmem_removeflag = eachzsmem["remove"] + if zsetmem_removeflag: + if shZonesetObj.isZonePresentInZoneset( + zsetname, + zsetmem_name, + ): + cmd = "no member " + zsetmem_name + cmdmemlist.append(cmd) + messages.append( + "removing zoneset member '" + + zsetmem_name + + "' from zoneset '" + + zsetname + + "' in vsan " + + str(vsan), + ) + else: + messages.append( + "zoneset member '" + + zsetmem_name + + "' is not present in zoneset '" + + zsetname + + "' in vsan " + + str(vsan) + + " ,hence there is nothing to remove", + ) + else: + if shZonesetObj.isZonePresentInZoneset( + zsetname, + zsetmem_name, + ): + messages.append( + "zoneset member '" + + zsetmem_name + + "' is already present in zoneset '" + + zsetname + + "' in vsan " + + str(vsan) + + " ,hence there is nothing to add", + ) + else: + cmd = "member " + zsetmem_name + cmdmemlist.append(cmd) + messages.append( + "adding zoneset member '" + + zsetmem_name + + "' to zoneset '" + + zsetname + + "' in vsan " + + str(vsan), + ) + if len(cmdmemlist) != 0: + commands_executed.append( + "zoneset name " + zsetname + " vsan " + str(vsan), + ) + commands_executed = commands_executed + cmdmemlist + else: + if shZonesetObj.isZonesetPresent(zsetname): + messages.append( + "zoneset '" + + zsetname + + "' is already present in vsan " + + str(vsan), + ) + else: + commands_executed.append( + "zoneset name " + zsetname + " vsan " + str(vsan), + ) + messages.append( + "zoneset '" + zsetname + "' is created in vsan " + str(vsan), + ) + + # Process zoneset activate options + if actionflag == "deactivate": + if shZonesetActiveObj.isZonesetActive(zsetname): + messages.append( + "deactivating zoneset '" + zsetname + "' in vsan " + str(vsan), + ) + dactcmd.append( + "no zoneset activate name " + zsetname + " vsan " + str(vsan), + ) + else: + messages.append( + "zoneset '" + + zsetname + + "' in vsan " + + str(vsan) + + " is not activated, hence cannot deactivate", + ) + elif actionflag == "activate": + if commands_executed: + messages.append( + "activating zoneset '" + zsetname + "' in vsan " + str(vsan), + ) + actcmd.append( + "zoneset activate name " + zsetname + " vsan " + str(vsan), + ) + else: + messages.append( + "no changes to existing zoneset '" + + zsetname + + "' in vsan " + + str(vsan) + + " hence activate action is ignored", + ) + commands_executed = commands_executed + dactcmd + actcmd + + if commands_executed: + if op_mode == "enhanced": + commands_executed.append("zone commit vsan " + str(vsan)) + elif op_mode is None: + if sw_mode == "enhanced": + commands_executed.append("zone commit vsan " + str(vsan)) + + if commands_executed: + commands_executed = ["terminal dont-ask"] + commands_executed + ["no terminal dont-ask"] + + cmds = flatten_list(commands_executed) + if cmds: + if module.check_mode: + module.exit_json( + changed=False, + commands=cmds, + msg="Check Mode: No cmds issued to the hosts", + ) + else: + result["changed"] = True + commands = commands + cmds + load_config(module, cmds) + + result["messages"] = messages + result["commands"] = commands_executed + result["warnings"] = warnings + module.exit_json(**result) + + +if __name__ == "__main__": + main() diff --git a/plugins/modules/storage/nxos_devicealias.py b/plugins/modules/storage/nxos_devicealias.py deleted file mode 100644 index cbece233b..000000000 --- a/plugins/modules/storage/nxos_devicealias.py +++ /dev/null @@ -1,593 +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 - - -DOCUMENTATION = """ -module: nxos_devicealias -short_description: Configuration of device alias for Cisco NXOS MDS Switches. -description: -- Configuration of device alias for Cisco MDS NXOS. -version_added: 1.0.0 -author: -- Suhas Bharadwaj (@srbharadwaj) (subharad@cisco.com) -notes: -- Tested against Cisco MDS NX-OS 8.4(1) -options: - distribute: - description: - - Enable/Disable device-alias distribution - type: bool - mode: - description: - - Mode of devices-alias, basic or enhanced - choices: - - basic - - enhanced - type: str - da: - description: - - List of device-alias to be added or removed - type: list - elements: dict - suboptions: - name: - description: - - Name of the device-alias to be added or removed - required: true - type: str - pwwn: - description: - - pwwn to which the name needs to be associated with - type: str - remove: - description: - - Removes the device-alias if set to True - type: bool - default: false - rename: - description: - - List of device-alias to be renamed - type: list - elements: dict - suboptions: - old_name: - description: - - Old name of the device-alias that needs to be renamed - required: true - type: str - new_name: - description: - - New name of the device-alias - required: true - type: str -""" - -EXAMPLES = """ -- name: Test that device alias module works - cisco.nxos.nxos_devicealias: - da: - - name: test1_add - pwwn: 56:2:22:11:22:88:11:67 - - name: test2_add - pwwn: 65:22:22:11:22:22:11:d - - name: dev1 - remove: true - - name: dev2 - remove: true - distribute: true - mode: enhanced - rename: - - new_name: bcd - old_name: abc - - new_name: bcd1 - old_name: abc1 - - -""" - -RETURN = """ -commands: - description: commands sent to the device - returned: always - type: list - sample: - - terminal dont-ask - - device-alias database - - device-alias name somename pwwn 10:00:00:00:89:a1:01:03 - - device-alias name somename1 pwwn 10:00:00:00:89:a1:02:03 - - device-alias commit - - no terminal dont-ask -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - load_config, - run_commands, -) -import string - -__metaclass__ = type - -VALID_DA_CHARS = ("-", "_", "$", "^") - - -class showDeviceAliasStatus(object): - """docstring for showDeviceAliasStatus""" - - def __init__(self, module): - self.module = module - self.distribute = "" - self.mode = "" - self.locked = False - self.update() - - def execute_show_cmd(self, cmd): - output = execute_show_command(cmd, self.module)[0] - return output - - def update(self): - command = "show device-alias status" - output = self.execute_show_cmd(command).split("\n") - for o in output: - if "Fabric Distribution" in o: - self.distribute = o.split(":")[1].strip().lower() - if "Mode" in o: - self.mode = o.split("Mode:")[1].strip().lower() - if "Locked" in o: - self.locked = True - - def isLocked(self): - return self.locked - - def getDistribute(self): - return self.distribute - - def getMode(self): - return self.mode - - -class showDeviceAliasDatabase(object): - """docstring for showDeviceAliasDatabase""" - - def __init__(self, module): - self.module = module - self.da_dict = {} - self.update() - - def execute_show_cmd(self, cmd): - output = execute_show_command(cmd, self.module)[0] - return output - - def update(self): - command = "show device-alias database" - # output = execute_show_command(command, self.module)[0].split("\n") - output = self.execute_show_cmd(command) - self.da_list = output.split("\n") - for eachline in self.da_list: - if "device-alias" in eachline: - sv = eachline.strip().split() - self.da_dict[sv[2]] = sv[4] - - def isNameInDaDatabase(self, name): - return name in self.da_dict.keys() - - def isPwwnInDaDatabase(self, pwwn): - newpwwn = ":".join( - ["0" + str(ep) if len(ep) == 1 else ep for ep in pwwn.split(":")] - ) - return newpwwn in self.da_dict.values() - - def isNamePwwnPresentInDatabase(self, name, pwwn): - newpwwn = ":".join( - ["0" + str(ep) if len(ep) == 1 else ep for ep in pwwn.split(":")] - ) - if name in self.da_dict.keys(): - if newpwwn == self.da_dict[name]: - return True - return False - - def getPwwnByName(self, name): - if name in self.da_dict.keys(): - return self.da_dict[name] - else: - return None - - def getNameByPwwn(self, pwwn): - newpwwn = ":".join( - ["0" + str(ep) if len(ep) == 1 else ep for ep in pwwn.split(":")] - ) - for n, p in self.da_dict.items(): - if p == newpwwn: - return n - return None - - -def isPwwnValid(pwwn): - pwwnsplit = pwwn.split(":") - if len(pwwnsplit) != 8: - return False - for eachpwwnsplit in pwwnsplit: - if len(eachpwwnsplit) > 2 or len(eachpwwnsplit) < 1: - return False - if not all(c in string.hexdigits for c in eachpwwnsplit): - return False - return True - - -def isNameValid(name): - if not name[0].isalpha(): - # Illegal first character. Name must start with a letter - return False - if len(name) > 64: - return False - for character in name: - if not character.isalnum() and character not in VALID_DA_CHARS: - return False - return True - - -def execute_show_command(command, module, command_type="cli_show"): - output = "text" - commands = [{"command": command, "output": output}] - out = run_commands(module, commands) - return out - - -def flatten_list(command_lists): - flat_command_list = [] - for command in command_lists: - if isinstance(command, list): - flat_command_list.extend(command) - else: - flat_command_list.append(command) - return flat_command_list - - -def main(): - element_spec = dict( - name=dict(required=True, type="str"), - pwwn=dict(type="str"), - remove=dict(type="bool", default=False), - ) - - element_spec_rename = dict( - old_name=dict(required=True, type="str"), - new_name=dict(required=True, type="str"), - ) - - argument_spec = dict( - distribute=dict(type="bool"), - mode=dict(type="str", choices=["enhanced", "basic"]), - da=dict(type="list", elements="dict", options=element_spec), - rename=dict(type="list", elements="dict", options=element_spec_rename), - ) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) - - warnings = list() - messages = list() - commands_to_execute = list() - result = {"changed": False} - - distribute = module.params["distribute"] - mode = module.params["mode"] - da = module.params["da"] - rename = module.params["rename"] - - # Step 0.0: Validate syntax of name and pwwn - # Also validate syntax of rename arguments - if da is not None: - for eachdict in da: - name = eachdict["name"] - pwwn = eachdict["pwwn"] - remove = eachdict["remove"] - if pwwn is not None: - pwwn = pwwn.lower() - if not remove: - if pwwn is None: - module.fail_json( - msg="This device alias name " - + str(name) - + " which needs to be added, does not have pwwn specified. Please specify a valid pwwn" - ) - if not isNameValid(name): - module.fail_json( - msg="This pwwn name is invalid : " - + str(name) - + ". Note that name cannot be more than 64 alphanumeric chars, " - + "it must start with a letter, and can only contain these characters: " - + ", ".join( - ["'{0}'".format(c) for c in VALID_DA_CHARS] - ) - ) - if not isPwwnValid(pwwn): - module.fail_json( - msg="This pwwn is invalid : " - + str(pwwn) - + ". Please check that its a valid pwwn" - ) - if rename is not None: - for eachdict in rename: - oldname = eachdict["old_name"] - newname = eachdict["new_name"] - if not isNameValid(oldname): - module.fail_json( - msg="This pwwn name is invalid : " - + str(oldname) - + ". Note that name cannot be more than 64 alphanumeric chars, " - + "it must start with a letter, and can only contain these characters: " - + ", ".join(["'{0}'".format(c) for c in VALID_DA_CHARS]) - ) - if not isNameValid(newname): - module.fail_json( - msg="This pwwn name is invalid : " - + str(newname) - + ". Note that name cannot be more than 64 alphanumeric chars, " - + "it must start with a letter, and can only contain these characters: " - + ", ".join(["'{0}'".format(c) for c in VALID_DA_CHARS]) - ) - - # Step 0.1: Check DA status - shDAStausObj = showDeviceAliasStatus(module) - d = shDAStausObj.getDistribute() - m = shDAStausObj.getMode() - if shDAStausObj.isLocked(): - module.fail_json( - msg="device-alias has acquired lock on the switch. Hence cannot procced." - ) - - # Step 1: Process distribute - commands = [] - if distribute is not None: - if distribute: - # playbook has distribute as True(enabled) - if d == "disabled": - # but switch distribute is disabled(false), so set it to - # true(enabled) - commands.append("device-alias distribute") - messages.append( - "device-alias distribute changed from disabled to enabled" - ) - else: - messages.append( - "device-alias distribute remains unchanged. current distribution mode is enabled" - ) - else: - # playbook has distribute as False(disabled) - if d == "enabled": - # but switch distribute is enabled(true), so set it to - # false(disabled) - commands.append("no device-alias distribute") - messages.append( - "device-alias distribute changed from enabled to disabled" - ) - else: - messages.append( - "device-alias distribute remains unchanged. current distribution mode is disabled" - ) - - cmds = flatten_list(commands) - if cmds: - commands_to_execute = commands_to_execute + cmds - if module.check_mode: - # Check mode implemented at the da_add/da_remove stage - pass - else: - result["changed"] = True - load_config(module, cmds) - - # Step 2: Process mode - commands = [] - if mode is not None: - if mode == "basic": - # playbook has mode as basic - if m == "enhanced": - # but switch mode is enhanced, so set it to basic - commands.append("no device-alias mode enhanced") - messages.append( - "device-alias mode changed from enhanced to basic" - ) - else: - messages.append( - "device-alias mode remains unchanged. current mode is basic" - ) - - else: - # playbook has mode as enhanced - if m == "basic": - # but switch mode is basic, so set it to enhanced - commands.append("device-alias mode enhanced") - messages.append( - "device-alias mode changed from basic to enhanced" - ) - else: - messages.append( - "device-alias mode remains unchanged. current mode is enhanced" - ) - - if commands: - if distribute: - commands.append("device-alias commit") - commands = ( - ["terminal dont-ask"] + commands + ["no terminal dont-ask"] - ) - else: - if distribute is None and d == "enabled": - commands.append("device-alias commit") - commands = ( - ["terminal dont-ask"] + commands + ["no terminal dont-ask"] - ) - - cmds = flatten_list(commands) - - if cmds: - commands_to_execute = commands_to_execute + cmds - if module.check_mode: - # Check mode implemented at the end - pass - else: - result["changed"] = True - load_config(module, cmds) - - # Step 3: Process da - commands = [] - shDADatabaseObj = showDeviceAliasDatabase(module) - if da is not None: - da_remove_list = [] - da_add_list = [] - for eachdict in da: - name = eachdict["name"] - pwwn = eachdict["pwwn"] - remove = eachdict["remove"] - if pwwn is not None: - pwwn = pwwn.lower() - if remove: - if shDADatabaseObj.isNameInDaDatabase(name): - commands.append("no device-alias name " + name) - da_remove_list.append(name) - else: - messages.append( - name - + " - This device alias name is not in switch device-alias database, hence cannot be removed." - ) - else: - if shDADatabaseObj.isNamePwwnPresentInDatabase(name, pwwn): - messages.append( - name - + " : " - + pwwn - + " - This device alias name,pwwn is already in switch device-alias database, hence nothing to configure" - ) - else: - if shDADatabaseObj.isNameInDaDatabase(name): - module.fail_json( - msg=name - + " - This device alias name is already present in switch device-alias database but assigned to another pwwn (" - + shDADatabaseObj.getPwwnByName(name) - + ") hence cannot be added" - ) - - elif shDADatabaseObj.isPwwnInDaDatabase(pwwn): - module.fail_json( - msg=pwwn - + " - This device alias pwwn is already present in switch device-alias database but assigned to another name (" - + shDADatabaseObj.getNameByPwwn(pwwn) - + ") hence cannot be added" - ) - - else: - commands.append( - "device-alias name " + name + " pwwn " + pwwn - ) - da_add_list.append(name) - - if len(da_add_list) != 0 or len(da_remove_list) != 0: - commands = ["device-alias database"] + commands - if distribute: - commands.append("device-alias commit") - commands = ( - ["terminal dont-ask"] + commands + ["no terminal dont-ask"] - ) - else: - if distribute is None and d == "enabled": - commands.append("device-alias commit") - commands = ( - ["terminal dont-ask"] - + commands - + ["no terminal dont-ask"] - ) - - cmds = flatten_list(commands) - if cmds: - commands_to_execute = commands_to_execute + cmds - if module.check_mode: - # Check mode implemented at the end - pass - else: - result["changed"] = True - load_config(module, cmds) - if len(da_remove_list) != 0: - messages.append( - "the required device-alias were removed. " - + ",".join(da_remove_list) - ) - if len(da_add_list) != 0: - messages.append( - "the required device-alias were added. " - + ",".join(da_add_list) - ) - - # Step 5: Process rename - commands = [] - if rename is not None: - for eachdict in rename: - oldname = eachdict["old_name"] - newname = eachdict["new_name"] - if shDADatabaseObj.isNameInDaDatabase(newname): - module.fail_json( - changed=False, - commands=cmds, - msg=newname - + " - this name is already present in the device-alias database, hence we cannot rename " - + oldname - + " with this one", - ) - if shDADatabaseObj.isNameInDaDatabase(oldname): - commands.append( - "device-alias rename " + oldname + " " + newname - ) - else: - module.fail_json( - changed=False, - commands=cmds, - msg=oldname - + " - this name is not present in the device-alias database, hence we cannot rename.", - ) - - if len(commands) != 0: - commands = ["device-alias database"] + commands - if distribute: - commands.append("device-alias commit") - commands = ( - ["terminal dont-ask"] + commands + ["no terminal dont-ask"] - ) - else: - if distribute is None and d == "enabled": - commands.append("device-alias commit") - commands = ( - ["terminal dont-ask"] - + commands - + ["no terminal dont-ask"] - ) - cmds = flatten_list(commands) - if cmds: - commands_to_execute = commands_to_execute + cmds - if module.check_mode: - # Check mode implemented at the end - pass - else: - result["changed"] = True - load_config(module, cmds) - - # Step END: check for 'check' mode - if module.check_mode: - module.exit_json( - changed=False, - commands=commands_to_execute, - msg="Check Mode: No cmds issued to the hosts", - ) - - result["messages"] = messages - result["commands"] = commands_to_execute - result["warnings"] = warnings - module.exit_json(**result) - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/storage/nxos_vsan.py b/plugins/modules/storage/nxos_vsan.py deleted file mode 100644 index 2e7cc73d0..000000000 --- a/plugins/modules/storage/nxos_vsan.py +++ /dev/null @@ -1,385 +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 - - -DOCUMENTATION = """ -module: nxos_vsan -short_description: Configuration of vsan for Cisco NXOS MDS Switches. -description: -- Configuration of vsan for Cisco MDS NXOS. -version_added: 1.0.0 -author: -- Suhas Bharadwaj (@srbharadwaj) (subharad@cisco.com) -notes: -- Tested against Cisco MDS NX-OS 8.4(1) -options: - vsan: - description: - - List of vsan details to be added or removed - type: list - elements: dict - suboptions: - id: - description: - - Vsan id - required: true - type: int - name: - description: - - Name of the vsan - type: str - suspend: - description: - - suspend the vsan if True - type: bool - remove: - description: - - Removes the vsan if True - type: bool - interface: - description: - - List of vsan's interfaces to be added - type: list - elements: str -""" - -EXAMPLES = """ -- name: Test that vsan module works - cisco.nxos.nxos_vsan: - vsan: - - id: 922 - interface: - - fc1/1 - - fc1/2 - - port-channel 1 - name: vsan-SAN-A - remove: false - suspend: false - - id: 923 - interface: - - fc1/11 - - fc1/21 - - port-channel 2 - name: vsan-SAN-B - remove: false - suspend: true - - id: 1923 - name: vsan-SAN-Old - remove: true -""" - -RETURN = """ -commands: - description: commands sent to the device - returned: always - type: list - sample: - - terminal dont-ask - - vsan database - - vsan 922 interface fc1/40 - - vsan 922 interface port-channel 155 - - no terminal dont-ask -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - load_config, - run_commands, -) -import re - -__metaclass__ = type - - -class Vsan(object): - def __init__(self, vsanid): - self.vsanid = vsanid - self.vsanname = None - self.vsanstate = None - self.vsanoperstate = None - self.vsaninterfaces = [] - - -class GetVsanInfoFromSwitch(object): - """docstring for GetVsanInfoFromSwitch""" - - def __init__(self, module): - self.module = module - self.vsaninfo = {} - self.processShowVsan() - self.processShowVsanMembership() - - def execute_show_vsan_cmd(self): - output = execute_show_command("show vsan", self.module)[0] - return output - - def execute_show_vsan_mem_cmd(self): - output = execute_show_command("show vsan membership", self.module)[0] - return output - - def processShowVsan(self): - patv = r"^vsan\s+(\d+)\s+information" - patnamestate = "name:(.*)state:(.*)" - patoperstate = "operational state:(.*)" - - output = self.execute_show_vsan_cmd().split("\n") - for o in output: - z = re.match(patv, o.strip()) - if z: - v = z.group(1).strip() - self.vsaninfo[v] = Vsan(v) - - z1 = re.match(patnamestate, o.strip()) - if z1: - n = z1.group(1).strip() - s = z1.group(2).strip() - self.vsaninfo[v].vsanname = n - self.vsaninfo[v].vsanstate = s - - z2 = re.match(patoperstate, o.strip()) - if z2: - oper = z2.group(1).strip() - self.vsaninfo[v].vsanoperstate = oper - - # 4094/4079 vsan is always present - self.vsaninfo["4079"] = Vsan("4079") - self.vsaninfo["4094"] = Vsan("4094") - - def processShowVsanMembership(self): - patv = r"^vsan\s+(\d+).*" - output = self.execute_show_vsan_mem_cmd().split("\n") - memlist = [] - v = None - for o in output: - z = re.match(patv, o.strip()) - if z: - if v is not None: - self.vsaninfo[v].vsaninterfaces = memlist - memlist = [] - v = z.group(1) - if "interfaces" not in o: - llist = o.strip().split() - memlist = memlist + llist - self.vsaninfo[v].vsaninterfaces = memlist - - def getVsanInfoObjects(self): - return self.vsaninfo - - -def execute_show_command(command, module, command_type="cli_show"): - output = "text" - commands = [{"command": command, "output": output}] - return run_commands(module, commands) - - -def flatten_list(command_lists): - flat_command_list = [] - for command in command_lists: - if isinstance(command, list): - flat_command_list.extend(command) - else: - flat_command_list.append(command) - return flat_command_list - - -def main(): - vsan_element_spec = dict( - id=dict(required=True, type="int"), - name=dict(type="str"), - remove=dict(type="bool"), - suspend=dict(type="bool"), - interface=dict(type="list", elements="str"), - ) - - argument_spec = dict( - vsan=dict(type="list", elements="dict", options=vsan_element_spec) - ) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) - warnings = list() - messages = list() - commands_executed = list() - result = {"changed": False} - - obj = GetVsanInfoFromSwitch(module) - dictSwVsanObjs = obj.getVsanInfoObjects() - - commands = [] - vsan_list = module.params["vsan"] - - for eachvsan in vsan_list: - vsanid = str(eachvsan["id"]) - vsanname = eachvsan["name"] - vsanremove = eachvsan["remove"] - vsansuspend = eachvsan["suspend"] - vsaninterface_list = eachvsan["interface"] - - if int(vsanid) < 1 or int(vsanid) >= 4095: - module.fail_json( - msg=vsanid - + " - This is an invalid vsan. Supported vsan range is 1-4094" - ) - - if vsanid in dictSwVsanObjs.keys(): - sw_vsanid = vsanid - sw_vsanname = dictSwVsanObjs[vsanid].vsanname - sw_vsanstate = dictSwVsanObjs[vsanid].vsanstate - sw_vsaninterfaces = dictSwVsanObjs[vsanid].vsaninterfaces - else: - sw_vsanid = None - sw_vsanname = None - sw_vsanstate = None - sw_vsaninterfaces = [] - - if vsanremove: - # Negative case: - if vsanid == "4079" or vsanid == "4094": - messages.append( - str(vsanid) - + " is a reserved vsan, hence cannot be removed" - ) - continue - if vsanid == sw_vsanid: - commands.append("no vsan " + str(vsanid)) - messages.append("deleting the vsan " + str(vsanid)) - else: - messages.append( - "There is no vsan " - + str(vsanid) - + " present in the switch. Hence there is nothing to delete" - ) - continue - else: - # Negative case: - if vsanid == "4079" or vsanid == "4094": - messages.append( - str(vsanid) - + " is a reserved vsan, and always present on the switch" - ) - else: - if vsanid == sw_vsanid: - messages.append( - "There is already a vsan " - + str(vsanid) - + " present in the switch. Hence there is nothing to configure" - ) - else: - commands.append("vsan " + str(vsanid)) - messages.append("creating vsan " + str(vsanid)) - - if vsanname is not None: - # Negative case: - if vsanid == "4079" or vsanid == "4094": - messages.append( - str(vsanid) + " is a reserved vsan, and cannot be renamed" - ) - else: - if vsanname == sw_vsanname: - messages.append( - "There is already a vsan " - + str(vsanid) - + " present in the switch, which has the name " - + vsanname - + " Hence there is nothing to configure" - ) - else: - commands.append( - "vsan " + str(vsanid) + " name " + vsanname - ) - messages.append( - "setting vsan name to " - + vsanname - + " for vsan " - + str(vsanid) - ) - - if vsansuspend: - # Negative case: - if vsanid == "4079" or vsanid == "4094": - messages.append( - str(vsanid) - + " is a reserved vsan, and cannot be suspended" - ) - else: - if sw_vsanstate == "suspended": - messages.append( - "There is already a vsan " - + str(vsanid) - + " present in the switch, which is in suspended state " - ) - else: - commands.append("vsan " + str(vsanid) + " suspend") - messages.append("suspending the vsan " + str(vsanid)) - else: - if sw_vsanstate == "active": - messages.append( - "There is already a vsan " - + str(vsanid) - + " present in the switch, which is in active state " - ) - else: - commands.append("no vsan " + str(vsanid) + " suspend") - messages.append("no suspending the vsan " + str(vsanid)) - - if vsaninterface_list is not None: - for each_interface_name in vsaninterface_list: - # For fcip,port-channel,vfc-port-channel need to remove the - # extra space to compare - temp = re.sub(" +", "", each_interface_name) - if temp in sw_vsaninterfaces: - messages.append( - each_interface_name - + " is already present in the vsan " - + str(vsanid) - + " interface list" - ) - else: - commands.append( - "vsan " - + str(vsanid) - + " interface " - + each_interface_name - ) - messages.append( - "adding interface " - + each_interface_name - + " to vsan " - + str(vsanid) - ) - - if len(commands) != 0: - commands = ( - ["terminal dont-ask"] - + ["vsan database"] - + commands - + ["no terminal dont-ask"] - ) - - cmds = flatten_list(commands) - commands_executed = cmds - - if commands_executed: - if module.check_mode: - module.exit_json( - changed=False, - commands=commands_executed, - msg="Check Mode: No cmds issued to the hosts", - ) - else: - result["changed"] = True - load_config(module, commands_executed) - - result["messages"] = messages - result["commands"] = commands_executed - result["warnings"] = warnings - module.exit_json(**result) - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/storage/nxos_zone_zoneset.py b/plugins/modules/storage/nxos_zone_zoneset.py deleted file mode 100644 index 048e9658a..000000000 --- a/plugins/modules/storage/nxos_zone_zoneset.py +++ /dev/null @@ -1,991 +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 - - -DOCUMENTATION = """ -module: nxos_zone_zoneset -short_description: Configuration of zone/zoneset for Cisco NXOS MDS Switches. -description: -- Configuration of zone/zoneset for Cisco MDS NXOS. -version_added: 1.0.0 -author: -- Suhas Bharadwaj (@srbharadwaj) (subharad@cisco.com) -notes: -- Tested against Cisco MDS NX-OS 8.4(1) -options: - zone_zoneset_details: - description: - - List of zone/zoneset details to be added or removed - type: list - elements: dict - suboptions: - vsan: - description: - - vsan id - required: true - type: int - mode: - description: - - mode of the zone for the vsan - choices: - - enhanced - - basic - type: str - default_zone: - description: - - default zone behaviour for the vsan - choices: - - permit - - deny - type: str - smart_zoning: - description: - - Removes the vsan if True - type: bool - zone: - description: - - List of zone options for that vsan - type: list - elements: dict - suboptions: - name: - description: - - name of the zone - required: true - type: str - remove: - description: - - Deletes the zone if True - type: bool - default: false - members: - description: - - Members of the zone that needs to be removed or added - type: list - elements: dict - suboptions: - pwwn: - description: - - pwwn member of the zone, use alias 'device_alias' as option for - device_alias member - aliases: - - device_alias - required: true - type: str - remove: - description: - - Removes member from the zone if True - type: bool - default: false - devtype: - description: - - devtype of the zone member used along with Smart zoning config - choices: - - initiator - - target - - both - type: str - zoneset: - description: - - List of zoneset options for the vsan - type: list - elements: dict - suboptions: - name: - description: - - name of the zoneset - required: true - type: str - remove: - description: - - Removes zoneset if True - type: bool - default: false - action: - description: - - activates/de-activates the zoneset - choices: - - activate - - deactivate - type: str - members: - description: - - Members of the zoneset that needs to be removed or added - type: list - elements: dict - suboptions: - name: - description: - - name of the zone that needs to be added to the zoneset or removed - from the zoneset - required: true - type: str - remove: - description: - - Removes zone member from the zoneset - type: bool - default: false -""" - -EXAMPLES = """ -- name: Test that zone/zoneset module works - cisco.nxos.nxos_zone_zoneset: - zone_zoneset_details: - - mode: enhanced - vsan: 22 - zone: - - members: - - pwwn: 11:11:11:11:11:11:11:11 - - device_alias: test123 - - pwwn: 61:61:62:62:12:12:12:12 - remove: true - name: zoneA - - members: - - pwwn: 10:11:11:11:11:11:11:11 - - pwwn: 62:62:62:62:21:21:21:21 - name: zoneB - - name: zoneC - remove: true - zoneset: - - action: activate - members: - - name: zoneA - - name: zoneB - - name: zoneC - remove: true - name: zsetname1 - - action: deactivate - name: zsetTestExtra - remove: true - - mode: basic - smart_zoning: true - vsan: 21 - zone: - - members: - - devtype: both - pwwn: 11:11:11:11:11:11:11:11 - - pwwn: 62:62:62:62:12:12:12:12 - - devtype: both - pwwn: 92:62:62:62:12:12:1a:1a - remove: true - name: zone21A - - members: - - pwwn: 10:11:11:11:11:11:11:11 - - pwwn: 62:62:62:62:21:21:21:21 - name: zone21B - zoneset: - - action: activate - members: - - name: zone21A - - name: zone21B - name: zsetname212 - -""" - -RETURN = """ -commands: - description: commands sent to the device - returned: always - type: list - sample: - - terminal dont-ask - - zone name zoneA vsan 923 - - member pwwn 11:11:11:11:11:11:11:11 - - no member device-alias test123 - - zone commit vsan 923 - - no terminal dont-ask -messages: - description: debug messages - returned: always - type: list - sample: - - "zone mode is already enhanced ,no change in zone mode configuration for vsan 922" - - "zone member '11:11:11:11:11:11:11:11' is already present in zone 'zoneA' in vsan 922 hence nothing to add" - - "zone member 'test123' is already present in zone 'zoneA' in vsan 922 hence nothing to add" - - "zone member '61:61:62:62:12:12:12:12' is not present in zone 'zoneA' in vsan 922 hence nothing to remove" - - "zone member '10:11:11:11:11:11:11:11' is already present in zone 'zoneB' in vsan 922 hence nothing to add" - - "zone member '62:62:62:62:21:21:21:21' is already present in zone 'zoneB' in vsan 922 hence nothing to add" - - "zone 'zoneC' is not present in vsan 922 , so nothing to remove" -""" - - -import re -import json -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - load_config, - run_commands, -) - - -__metaclass__ = type - - -class ShowZonesetActive(object): - """docstring for ShowZonesetActive""" - - def __init__(self, module, vsan): - self.vsan = vsan - self.module = module - self.activeZSName = None - self.parseCmdOutput() - - def execute_show_zoneset_active_cmd(self): - command = ( - "show zoneset active vsan " + str(self.vsan) + " | grep zoneset" - ) - output = execute_show_command(command, self.module)[0] - return output - - def parseCmdOutput(self): - patZoneset = r"zoneset name (\S+) vsan " + str(self.vsan) - output = self.execute_show_zoneset_active_cmd().split("\n") - if len(output) == 0: - return - else: - for line in output: - line = line.strip() - mzs = re.match(patZoneset, line.strip()) - if mzs: - self.activeZSName = mzs.group(1).strip() - return - - def isZonesetActive(self, zsname): - if zsname == self.activeZSName: - return True - return False - - -class ShowZoneset(object): - """docstring for ShowZoneset""" - - def __init__(self, module, vsan): - self.vsan = vsan - self.module = module - self.zsDetails = {} - self.parseCmdOutput() - - def execute_show_zoneset_cmd(self): - command = "show zoneset vsan " + str(self.vsan) - output = execute_show_command(command, self.module)[0] - return output - - def parseCmdOutput(self): - patZoneset = r"zoneset name (\S+) vsan " + str(self.vsan) - patZone = r"zone name (\S+) vsan " + str(self.vsan) - output = self.execute_show_zoneset_cmd().split("\n") - for line in output: - line = line.strip() - mzs = re.match(patZoneset, line.strip()) - mz = re.match(patZone, line.strip()) - if mzs: - zonesetname = mzs.group(1).strip() - self.zsDetails[zonesetname] = [] - continue - elif mz: - zonename = mz.group(1).strip() - v = self.zsDetails[zonesetname] - v.append(zonename) - self.zsDetails[zonesetname] = v - - def isZonesetPresent(self, zsname): - return zsname in self.zsDetails.keys() - - def isZonePresentInZoneset(self, zsname, zname): - if zsname in self.zsDetails.keys(): - return zname in self.zsDetails[zsname] - return False - - -class ShowZone(object): - """docstring for ShowZone""" - - def __init__(self, module, vsan): - self.vsan = vsan - self.module = module - self.zDetails = {} - self.parseCmdOutput() - - def execute_show_zone_vsan_cmd(self): - command = "show zone vsan " + str(self.vsan) - output = execute_show_command(command, self.module)[0] - return output - - def parseCmdOutput(self): - patZone = r"zone name (\S+) vsan " + str(self.vsan) - output = self.execute_show_zone_vsan_cmd().split("\n") - for line in output: - line = re.sub(r"[\[].*?[\]]", "", line) - line = " ".join(line.strip().split()) - if "init" in line: - line = line.replace("init", "initiator") - m = re.match(patZone, line) - if m: - zonename = m.group(1).strip() - self.zDetails[zonename] = [] - continue - else: - # For now we support only pwwn and device-alias under zone - # Ideally should use 'supported_choices'....but maybe next - # time. - if "pwwn" in line or "device-alias" in line: - v = self.zDetails[zonename] - v.append(line) - self.zDetails[zonename] = v - - def isZonePresent(self, zname): - return zname in self.zDetails.keys() - - def isZoneMemberPresent(self, zname, cmd): - if zname in self.zDetails.keys(): - zonememlist = self.zDetails[zname] - for eachline in zonememlist: - if cmd in eachline: - return True - return False - - def get_zDetails(self): - return self.zDetails - - -class ShowZoneStatus(object): - """docstring for ShowZoneStatus""" - - def __init__(self, module, vsan): - self.vsan = vsan - self.vsanAbsent = False - self.module = module - self.default_zone = "" - self.mode = "" - self.session = "" - self.sz = "" - self.locked = False - self.update() - - def execute_show_zone_status_cmd(self): - command = "show zone status vsan " + str(self.vsan) - output = execute_show_command(command, self.module)[0] - return output - - def update(self): - - output = self.execute_show_zone_status_cmd().split("\n") - - patfordefzone = "VSAN: " + str(self.vsan) + r" default-zone:\s+(\S+).*" - patformode = r".*mode:\s+(\S+).*" - patforsession = r"^session:\s+(\S+).*" - patforsz = r".*smart-zoning:\s+(\S+).*" - for line in output: - if "is not configured" in line: - self.vsanAbsent = True - break - mdefz = re.match(patfordefzone, line.strip()) - mmode = re.match(patformode, line.strip()) - msession = re.match(patforsession, line.strip()) - msz = re.match(patforsz, line.strip()) - - if mdefz: - self.default_zone = mdefz.group(1) - if mmode: - self.mode = mmode.group(1) - if msession: - self.session = msession.group(1) - if self.session != "none": - self.locked = True - if msz: - self.sz = msz.group(1) - - def isLocked(self): - return self.locked - - def getDefaultZone(self): - return self.default_zone - - def getMode(self): - return self.mode - - def getSmartZoningStatus(self): - return self.sz - - def isVsanAbsent(self): - return self.vsanAbsent - - -def execute_show_command(command, module, command_type="cli_show"): - output = "text" - commands = [{"command": command, "output": output}] - return run_commands(module, commands) - - -def flatten_list(command_lists): - flat_command_list = [] - for command in command_lists: - if isinstance(command, list): - flat_command_list.extend(command) - else: - flat_command_list.append(command) - return flat_command_list - - -def getMemType(supported_choices, allmemkeys, default="pwwn"): - for eachchoice in supported_choices: - if eachchoice in allmemkeys: - return eachchoice - return default - - -def main(): - - supported_choices = ["device_alias"] - zone_member_spec = dict( - pwwn=dict(required=True, type="str", aliases=["device_alias"]), - devtype=dict(type="str", choices=["initiator", "target", "both"]), - remove=dict(type="bool", default=False), - ) - - zone_spec = dict( - name=dict(required=True, type="str"), - members=dict(type="list", elements="dict", options=zone_member_spec), - remove=dict(type="bool", default=False), - ) - - zoneset_member_spec = dict( - name=dict(required=True, type="str"), - remove=dict(type="bool", default=False), - ) - - zoneset_spec = dict( - name=dict(type="str", required=True), - members=dict( - type="list", elements="dict", options=zoneset_member_spec - ), - remove=dict(type="bool", default=False), - action=dict(type="str", choices=["activate", "deactivate"]), - ) - - zonedetails_spec = dict( - vsan=dict(required=True, type="int"), - mode=dict(type="str", choices=["enhanced", "basic"]), - default_zone=dict(type="str", choices=["permit", "deny"]), - smart_zoning=dict(type="bool"), - zone=dict(type="list", elements="dict", options=zone_spec), - zoneset=dict(type="list", elements="dict", options=zoneset_spec), - ) - - argument_spec = dict( - zone_zoneset_details=dict( - type="list", elements="dict", options=zonedetails_spec - ) - ) - - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) - - warnings = list() - messages = list() - commands = list() - result = {"changed": False} - - commands_executed = [] - listOfZoneDetails = module.params["zone_zoneset_details"] - for eachZoneZonesetDetail in listOfZoneDetails: - vsan = eachZoneZonesetDetail["vsan"] - op_mode = eachZoneZonesetDetail["mode"] - op_default_zone = eachZoneZonesetDetail["default_zone"] - op_smart_zoning = eachZoneZonesetDetail["smart_zoning"] - op_zone = eachZoneZonesetDetail["zone"] - op_zoneset = eachZoneZonesetDetail["zoneset"] - - # Step1: execute show zone status and get - shZoneStatusObj = ShowZoneStatus(module, vsan) - sw_default_zone = shZoneStatusObj.getDefaultZone() - sw_mode = shZoneStatusObj.getMode() - sw_smart_zoning = shZoneStatusObj.getSmartZoningStatus() - - if sw_smart_zoning.lower() == "Enabled".lower(): - sw_smart_zoning_bool = True - else: - sw_smart_zoning_bool = False - - if shZoneStatusObj.isVsanAbsent(): - module.fail_json( - msg="Vsan " - + str(vsan) - + " is not present in the switch. Hence cannot procced." - ) - - if shZoneStatusObj.isLocked(): - module.fail_json( - msg="zone has acquired lock on the switch for vsan " - + str(vsan) - + ". Hence cannot procced." - ) - - # Process zone default zone options - if op_default_zone is not None: - if op_default_zone != sw_default_zone: - if op_default_zone == "permit": - commands_executed.append( - "zone default-zone permit vsan " + str(vsan) - ) - messages.append( - "default zone configuration changed from deny to permit for vsan " - + str(vsan) - ) - else: - commands_executed.append( - "no zone default-zone permit vsan " + str(vsan) - ) - messages.append( - "default zone configuration changed from permit to deny for vsan " - + str(vsan) - ) - else: - messages.append( - "default zone is already " - + op_default_zone - + " ,no change in default zone configuration for vsan " - + str(vsan) - ) - - # Process zone mode options - if op_mode is not None: - if op_mode != sw_mode: - if op_mode == "enhanced": - commands_executed.append( - "zone mode enhanced vsan " + str(vsan) - ) - messages.append( - "zone mode configuration changed from basic to enhanced for vsan " - + str(vsan) - ) - else: - commands_executed.append( - "no zone mode enhanced vsan " + str(vsan) - ) - messages.append( - "zone mode configuration changed from enhanced to basic for vsan " - + str(vsan) - ) - else: - messages.append( - "zone mode is already " - + op_mode - + " ,no change in zone mode configuration for vsan " - + str(vsan) - ) - - # Process zone smart-zone options - if op_smart_zoning is not None: - if op_smart_zoning != sw_smart_zoning_bool: - if op_smart_zoning: - commands_executed.append( - "zone smart-zoning enable vsan " + str(vsan) - ) - messages.append( - "smart-zoning enabled for vsan " + str(vsan) - ) - else: - commands_executed.append( - "no zone smart-zoning enable vsan " + str(vsan) - ) - messages.append( - "smart-zoning disabled for vsan " + str(vsan) - ) - else: - messages.append( - "smart-zoning is already set to " - + sw_smart_zoning - + " , no change in smart-zoning configuration for vsan " - + str(vsan) - ) - - # Process zone member options - # TODO: Obviously this needs to be cleaned up properly, as there are a lot of ifelse statements which is bad - # Will take it up later becoz of time constraints - if op_zone is not None: - shZoneObj = ShowZone(module, vsan) - for eachzone in op_zone: - zname = eachzone["name"] - zmembers = eachzone["members"] - removeflag = eachzone["remove"] - if removeflag: - if shZoneObj.isZonePresent(zname): - messages.append( - "zone '" - + zname - + "' is removed from vsan " - + str(vsan) - ) - commands_executed.append( - "no zone name " + zname + " vsan " + str(vsan) - ) - else: - messages.append( - "zone '" - + zname - + "' is not present in vsan " - + str(vsan) - + " , so nothing to remove" - ) - else: - if zmembers is None: - if shZoneObj.isZonePresent(zname): - messages.append( - "zone '" - + zname - + "' is already present in vsan " - + str(vsan) - ) - else: - commands_executed.append( - "zone name " + zname + " vsan " + str(vsan) - ) - messages.append( - "zone '" - + zname - + "' is created in vsan " - + str(vsan) - ) - else: - cmdmemlist = [] - for eachmem in zmembers: - memtype = getMemType( - supported_choices, eachmem.keys() - ) - cmd = ( - memtype.replace("_", "-") - + " " - + eachmem[memtype] - ) - if op_smart_zoning or sw_smart_zoning_bool: - if eachmem["devtype"] is not None: - cmd = cmd + " " + eachmem["devtype"] - if eachmem["remove"]: - if shZoneObj.isZonePresent(zname): - if shZoneObj.isZoneMemberPresent( - zname, cmd - ): - cmd = "no member " + cmd - cmdmemlist.append(cmd) - if ( - op_smart_zoning - and eachmem["devtype"] is not None - ): - messages.append( - "removing zone member '" - + eachmem[memtype] - + " of device type '" - + eachmem["devtype"] - + "' from zone '" - + zname - + "' in vsan " - + str(vsan) - ) - else: - messages.append( - "removing zone member '" - + eachmem[memtype] - + "' from zone '" - + zname - + "' in vsan " - + str(vsan) - ) - else: - if ( - op_smart_zoning - and eachmem["devtype"] is not None - ): - messages.append( - "zone member '" - + eachmem[memtype] - + "' of device type '" - + eachmem["devtype"] - + "' is not present in zone '" - + zname - + "' in vsan " - + str(vsan) - + " hence nothing to remove" - ) - else: - messages.append( - "zone member '" - + eachmem[memtype] - + "' is not present in zone '" - + zname - + "' in vsan " - + str(vsan) - + " hence nothing to remove" - ) - else: - messages.append( - "zone '" - + zname - + "' is not present in vsan " - + str(vsan) - + " , hence cannot remove the members" - ) - - else: - if shZoneObj.isZoneMemberPresent(zname, cmd): - if ( - op_smart_zoning - and eachmem["devtype"] is not None - ): - messages.append( - "zone member '" - + eachmem[memtype] - + "' of device type '" - + eachmem["devtype"] - + "' is already present in zone '" - + zname - + "' in vsan " - + str(vsan) - + " hence nothing to add" - ) - else: - messages.append( - "zone member '" - + eachmem[memtype] - + "' is already present in zone '" - + zname - + "' in vsan " - + str(vsan) - + " hence nothing to add" - ) - else: - cmd = "member " + cmd - cmdmemlist.append(cmd) - if ( - op_smart_zoning - and eachmem["devtype"] is not None - ): - messages.append( - "adding zone member '" - + eachmem[memtype] - + "' of device type '" - + eachmem["devtype"] - + "' to zone '" - + zname - + "' in vsan " - + str(vsan) - ) - else: - messages.append( - "adding zone member '" - + eachmem[memtype] - + "' to zone '" - + zname - + "' in vsan " - + str(vsan) - ) - if len(cmdmemlist) != 0: - commands_executed.append( - "zone name " + zname + " vsan " + str(vsan) - ) - commands_executed = commands_executed + cmdmemlist - - # Process zoneset member options - if op_zoneset is not None: - dactcmd = [] - actcmd = [] - shZonesetObj = ShowZoneset(module, vsan) - shZonesetActiveObj = ShowZonesetActive(module, vsan) - for eachzoneset in op_zoneset: - zsetname = eachzoneset["name"] - zsetmembers = eachzoneset["members"] - removeflag = eachzoneset["remove"] - actionflag = eachzoneset["action"] - if removeflag: - if shZonesetObj.isZonesetPresent(zsetname): - messages.append( - "zoneset '" - + zsetname - + "' is removed from vsan " - + str(vsan) - ) - commands_executed.append( - "no zoneset name " - + zsetname - + " vsan " - + str(vsan) - ) - else: - messages.append( - "zoneset '" - + zsetname - + "' is not present in vsan " - + str(vsan) - + " ,hence there is nothing to remove" - ) - else: - if zsetmembers is not None: - cmdmemlist = [] - for eachzsmem in zsetmembers: - zsetmem_name = eachzsmem["name"] - zsetmem_removeflag = eachzsmem["remove"] - if zsetmem_removeflag: - if shZonesetObj.isZonePresentInZoneset( - zsetname, zsetmem_name - ): - cmd = "no member " + zsetmem_name - cmdmemlist.append(cmd) - messages.append( - "removing zoneset member '" - + zsetmem_name - + "' from zoneset '" - + zsetname - + "' in vsan " - + str(vsan) - ) - else: - messages.append( - "zoneset member '" - + zsetmem_name - + "' is not present in zoneset '" - + zsetname - + "' in vsan " - + str(vsan) - + " ,hence there is nothing to remove" - ) - else: - if shZonesetObj.isZonePresentInZoneset( - zsetname, zsetmem_name - ): - messages.append( - "zoneset member '" - + zsetmem_name - + "' is already present in zoneset '" - + zsetname - + "' in vsan " - + str(vsan) - + " ,hence there is nothing to add" - ) - else: - cmd = "member " + zsetmem_name - cmdmemlist.append(cmd) - messages.append( - "adding zoneset member '" - + zsetmem_name - + "' to zoneset '" - + zsetname - + "' in vsan " - + str(vsan) - ) - if len(cmdmemlist) != 0: - commands_executed.append( - "zoneset name " - + zsetname - + " vsan " - + str(vsan) - ) - commands_executed = commands_executed + cmdmemlist - else: - if shZonesetObj.isZonesetPresent(zsetname): - messages.append( - "zoneset '" - + zsetname - + "' is already present in vsan " - + str(vsan) - ) - else: - commands_executed.append( - "zoneset name " - + zsetname - + " vsan " - + str(vsan) - ) - messages.append( - "zoneset '" - + zsetname - + "' is created in vsan " - + str(vsan) - ) - - # Process zoneset activate options - if actionflag == "deactivate": - if shZonesetActiveObj.isZonesetActive(zsetname): - messages.append( - "deactivating zoneset '" - + zsetname - + "' in vsan " - + str(vsan) - ) - dactcmd.append( - "no zoneset activate name " - + zsetname - + " vsan " - + str(vsan) - ) - else: - messages.append( - "zoneset '" - + zsetname - + "' in vsan " - + str(vsan) - + " is not activated, hence cannot deactivate" - ) - elif actionflag == "activate": - if commands_executed: - messages.append( - "activating zoneset '" - + zsetname - + "' in vsan " - + str(vsan) - ) - actcmd.append( - "zoneset activate name " - + zsetname - + " vsan " - + str(vsan) - ) - else: - messages.append( - "no changes to existing zoneset '" - + zsetname - + "' in vsan " - + str(vsan) - + " hence activate action is ignored" - ) - commands_executed = commands_executed + dactcmd + actcmd - - if commands_executed: - if op_mode == "enhanced": - commands_executed.append("zone commit vsan " + str(vsan)) - elif op_mode is None: - if sw_mode == "enhanced": - commands_executed.append("zone commit vsan " + str(vsan)) - - if commands_executed: - commands_executed = ( - ["terminal dont-ask"] - + commands_executed - + ["no terminal dont-ask"] - ) - - cmds = flatten_list(commands_executed) - if cmds: - if module.check_mode: - module.exit_json( - changed=False, - commands=cmds, - msg="Check Mode: No cmds issued to the hosts", - ) - else: - result["changed"] = True - commands = commands + cmds - load_config(module, cmds) - - result["messages"] = messages - result["commands"] = commands_executed - result["warnings"] = warnings - module.exit_json(**result) - - -if __name__ == "__main__": - main() diff --git a/plugins/netconf/nxos.py b/plugins/netconf/nxos.py index 9df55f49d..fcbee7952 100644 --- a/plugins/netconf/nxos.py +++ b/plugins/netconf/nxos.py @@ -18,6 +18,7 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type DOCUMENTATION = """ @@ -38,9 +39,7 @@ """ from ansible.plugins.netconf import NetconfBase -from ansible_collections.ansible.netcommon.plugins.plugin_utils.netconf_base import ( - NetconfBase, -) +from ansible_collections.ansible.netcommon.plugins.plugin_utils.netconf_base import NetconfBase class Netconf(NetconfBase): diff --git a/plugins/terminal/nxos.py b/plugins/terminal/nxos.py index dfcb7608e..0df2956fb 100644 --- a/plugins/terminal/nxos.py +++ b/plugins/terminal/nxos.py @@ -18,23 +18,21 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type -import re import json +import re from ansible.errors import AnsibleConnectionFailure from ansible.module_utils._text import to_bytes, to_text -from ansible_collections.ansible.netcommon.plugins.plugin_utils.terminal_base import ( - TerminalBase, -) +from ansible_collections.ansible.netcommon.plugins.plugin_utils.terminal_base import TerminalBase class TerminalModule(TerminalBase): - terminal_stdout_re = [ re.compile( - rb"[\r\n](?!\s*<)?(\x1b\S+)*[a-zA-Z_0-9]{1}[a-zA-Z0-9-_.]*[>|#](?:\s*)(\x1b\S+)*$" + rb"[\r\n](?!\s*<)?(\x1b\S+)*[a-zA-Z_0-9]{1}[a-zA-Z0-9-_.]*[>|#](?:\s*)(\x1b\S+)*$", ), re.compile(rb"[\r\n]?[a-zA-Z0-9]{1}[a-zA-Z0-9-_.]*\(.+\)#(?:\s*)$"), ] @@ -58,21 +56,20 @@ class TerminalModule(TerminalBase): rb"[B|b]aud rate of console should be.* (\d*) to increase [a-z]* level", re.I, ), - re.compile( - rb"cannot apply non-existing acl policy to interface", re.I - ), + re.compile(rb"cannot apply non-existing acl policy to interface", re.I), re.compile(rb"Duplicate sequence number", re.I), re.compile( rb"Cannot apply ACL to an interface that is a port-channel member", re.I, ), re.compile(rb"No corresponding (.+) configured", re.I), + re.compile(rb"(.+)please specify sequence number", re.I), ] terminal_config_prompt = re.compile(r"^.*\((?!maint-mode).*\)#$") def on_become(self, passwd=None): - if self._get_prompt().strip().endswith(b"enable#"): + if self._get_prompt().strip().endswith(b"#"): return out = self._exec_cli_command("show privilege") @@ -90,27 +87,22 @@ def on_become(self, passwd=None): cmd = {"command": "enable"} if passwd: - cmd["prompt"] = to_text( - r"(?i)[\r\n]?Password: $", errors="surrogate_or_strict" - ) + cmd["prompt"] = to_text(r"(?i)[\r\n]?Password: $", errors="surrogate_or_strict") cmd["answer"] = passwd cmd["prompt_retry_check"] = True try: - self._exec_cli_command( - to_bytes(json.dumps(cmd), errors="surrogate_or_strict") - ) + self._exec_cli_command(to_bytes(json.dumps(cmd), errors="surrogate_or_strict")) prompt = self._get_prompt() if prompt is None or not prompt.strip().endswith(b"enable#"): raise AnsibleConnectionFailure( - "failed to elevate privilege to enable mode still at prompt [%s]" - % prompt + "failed to elevate privilege to enable mode still at prompt [%s]" % prompt, ) except AnsibleConnectionFailure as e: prompt = self._get_prompt() raise AnsibleConnectionFailure( "unable to elevate privilege to enable mode, at prompt [%s] with error: %s" - % (prompt, e.message) + % (prompt, e.message), ) def on_unbecome(self): diff --git a/pyproject.toml b/pyproject.toml index c547b3fd7..fa6d772ec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,9 +1,10 @@ [tool.black] -line-length = 79 +line-length = 100 [tool.pytest.ini_options] +addopts = ["-vvv", "-n", "2", "--log-level", "WARNING", "--color", "yes"] testpaths = ["tests"] filterwarnings = [ 'ignore:AnsibleCollectionFinder has already been configured', 'ignore:_AnsibleCollectionFinder.find_spec().*', -] +] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 00c176353..ee91c107c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -paramiko==2.8.1 +paramiko scp diff --git a/test-requirements.txt b/test-requirements.txt index 67655f3da..5a90586f2 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,7 +1,9 @@ -black==22.3.0 ; python_version > '3.5' +# For ansible-tox-linters +black==23.3.0 flake8 -mock ; python_version < '3.5' -pexpect -pytest-xdist yamllint -coverage==4.5.4 + +# Unit test runner +pytest-ansible +pytest-xdist +pytest-cov diff --git a/tests/config.yml b/tests/config.yml new file mode 100644 index 000000000..c26ea5966 --- /dev/null +++ b/tests/config.yml @@ -0,0 +1,3 @@ +--- +modules: + python_requires: ">=3.9" diff --git a/tests/integration/targets/nxos_aaa_server/tasks/cli.yaml b/tests/integration/targets/nxos_aaa_server/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_aaa_server/tasks/cli.yaml +++ b/tests/integration/targets/nxos_aaa_server/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_aaa_server/tasks/main.yaml b/tests/integration/targets/nxos_aaa_server/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_aaa_server/tasks/main.yaml +++ b/tests/integration/targets/nxos_aaa_server/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_aaa_server/tasks/nxapi.yaml b/tests/integration/targets/nxos_aaa_server/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_aaa_server/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_aaa_server/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_aaa_server/tests/common/tacacs.yaml b/tests/integration/targets/nxos_aaa_server/tests/common/tacacs.yaml index d3bac4030..7063cc61f 100644 --- a/tests/integration/targets/nxos_aaa_server/tests/common/tacacs.yaml +++ b/tests/integration/targets/nxos_aaa_server/tests/common/tacacs.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START connection={{ ansible_connection }} nxos_aaa_server tacacs.yaml sanity test -- name: Enable feature tacacs+ +- name: Enable 'feature tacacs+' cisco.nxos.nxos_feature: feature: tacacs+ state: enabled @@ -17,7 +17,7 @@ state: default - block: - - name: Configure tacacs server defaults + - name: Configure TACACS server defaults register: result cisco.nxos.nxos_aaa_server: &id001 server_type: tacacs @@ -31,7 +31,7 @@ that: - result.changed == false - - name: Configure tacacs server non defaults + - name: Configure TACACS server non defaults register: result cisco.nxos.nxos_aaa_server: &id002 server_type: tacacs @@ -50,13 +50,13 @@ - ansible.builtin.assert: *id003 - - name: Remove tacacs server configuration + - name: Remove TACACS server configuration register: result cisco.nxos.nxos_aaa_server: *id004 - ansible.builtin.assert: *id005 - - name: Configure tacacs server with global key + - name: Configure TACACS server with global key register: result cisco.nxos.nxos_aaa_server: &id006 server_type: tacacs @@ -72,7 +72,7 @@ - ansible.builtin.assert: *id003 - - name: Remove tacacs server configuration + - name: Remove TACACS server configuration register: result cisco.nxos.nxos_aaa_server: &id007 server_type: tacacs @@ -93,11 +93,11 @@ - ansible.builtin.debug: msg: connection={{ ansible_connection }} nxos_aaa_server failure detected always: - - name: Remove tacacs server configuration + - name: Remove TACACS server configuration register: result cisco.nxos.nxos_aaa_server: *id004 - - name: Disable feature tacacs+ + - name: Disable 'feature tacacs+' cisco.nxos.nxos_feature: feature: tacacs+ state: disabled diff --git a/tests/integration/targets/nxos_aaa_server_host/tasks/cli.yaml b/tests/integration/targets/nxos_aaa_server_host/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_aaa_server_host/tasks/cli.yaml +++ b/tests/integration/targets/nxos_aaa_server_host/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_aaa_server_host/tasks/main.yaml b/tests/integration/targets/nxos_aaa_server_host/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_aaa_server_host/tasks/main.yaml +++ b/tests/integration/targets/nxos_aaa_server_host/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_aaa_server_host/tasks/nxapi.yaml b/tests/integration/targets/nxos_aaa_server_host/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_aaa_server_host/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_aaa_server_host/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_aaa_server_host/tests/common/radius.yaml b/tests/integration/targets/nxos_aaa_server_host/tests/common/radius.yaml index 77645e39a..c52dd80d4 100644 --- a/tests/integration/targets/nxos_aaa_server_host/tests/common/radius.yaml +++ b/tests/integration/targets/nxos_aaa_server_host/tests/common/radius.yaml @@ -85,7 +85,7 @@ host_timeout: 25 auth_port: default acct_port: 2084 - encrypt_type: 00 + encrypt_type: 0 key: hello state: present diff --git a/tests/integration/targets/nxos_aaa_server_host/tests/common/tacacs.yaml b/tests/integration/targets/nxos_aaa_server_host/tests/common/tacacs.yaml index 04fdf684c..0258db28b 100644 --- a/tests/integration/targets/nxos_aaa_server_host/tests/common/tacacs.yaml +++ b/tests/integration/targets/nxos_aaa_server_host/tests/common/tacacs.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START connection={{ ansible_connection }} nxos_aaa_server_host tacacs.yaml sanity test -- name: Enable feature tacacs+ +- name: Enable 'feature tacacs+' cisco.nxos.nxos_feature: feature: tacacs+ state: enabled @@ -15,7 +15,7 @@ state: absent - block: - - name: Configure tacacs server defaults + - name: Configure TACACS server defaults register: result cisco.nxos.nxos_aaa_server_host: &id001 server_type: tacacs @@ -34,7 +34,7 @@ that: - result.changed == false - - name: Remove tacacs server configuration + - name: Remove TACACS server configuration register: result cisco.nxos.nxos_aaa_server_host: *id002 @@ -46,7 +46,7 @@ - ansible.builtin.assert: *id004 - - name: Configure tacacs server non defaults + - name: Configure TACACS server non defaults register: result cisco.nxos.nxos_aaa_server_host: &id005 server_type: tacacs @@ -63,7 +63,7 @@ - ansible.builtin.assert: *id004 - - name: Configure some defaults on tacacs server + - name: Configure some defaults on TACACS server register: result cisco.nxos.nxos_aaa_server_host: &id006 server_type: tacacs @@ -80,14 +80,14 @@ - ansible.builtin.assert: *id004 - - name: Configure tacacs server with clear text pwd + - name: Configure TACACS server with clear text pwd register: result cisco.nxos.nxos_aaa_server_host: &id007 server_type: tacacs address: 8.8.8.8 host_timeout: 25 tacacs_port: default - encrypt_type: 00 + encrypt_type: 0 key: hello state: present @@ -99,13 +99,13 @@ - ansible.builtin.assert: *id003 - - name: Remove tacacs server configuration + - name: Remove TACACS server configuration register: result cisco.nxos.nxos_aaa_server_host: *id002 - ansible.builtin.assert: *id003 - - name: Configure tacacs server with type 7 encryption + - name: Configure TACACS server with type 7 encryption register: result cisco.nxos.nxos_aaa_server_host: &id008 server_type: tacacs @@ -124,7 +124,7 @@ - ansible.builtin.assert: *id004 - - name: Configure tacacs server with new type 7 encryption key + - name: Configure TACACS server with new type 7 encryption key register: result cisco.nxos.nxos_aaa_server_host: &id009 server_type: tacacs @@ -146,7 +146,7 @@ - ansible.builtin.assert: *id004 - - name: Configure tacacs server with default key + - name: Configure TACACS server with default key register: result cisco.nxos.nxos_aaa_server_host: &id010 server_type: tacacs @@ -165,7 +165,7 @@ - ansible.builtin.assert: *id004 - - name: Configure tacacs server with all def + - name: Configure TACACS server with all def register: result cisco.nxos.nxos_aaa_server_host: &id011 server_type: tacacs @@ -186,11 +186,11 @@ - ansible.builtin.debug: msg: connection={{ ansible_connection }} nxos_aaa_server_host failure detected always: - - name: Remove tacacs server configuration + - name: Remove TACACS server configuration register: result cisco.nxos.nxos_aaa_server_host: *id002 - - name: Disable feature tacacs+ + - name: Disable 'feature tacacs+' cisco.nxos.nxos_feature: feature: tacacs+ state: disabled diff --git a/tests/integration/targets/nxos_acl/defaults/main.yaml b/tests/integration/targets/nxos_acl/defaults/main.yaml deleted file mode 100644 index 5f709c5aa..000000000 --- a/tests/integration/targets/nxos_acl/defaults/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -testcase: "*" diff --git a/tests/integration/targets/nxos_acl/meta/main.yml b/tests/integration/targets/nxos_acl/meta/main.yml deleted file mode 100644 index f504a6ab2..000000000 --- a/tests/integration/targets/nxos_acl/meta/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_nxos_tests diff --git a/tests/integration/targets/nxos_acl/tasks/main.yaml b/tests/integration/targets/nxos_acl/tasks/main.yaml deleted file mode 100644 index 62e44ffda..000000000 --- a/tests/integration/targets/nxos_acl/tasks/main.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Include the cli tasks - ansible.builtin.include_tasks: cli.yaml - tags: - - cli - -- name: Include the nx-api tasks - ansible.builtin.include_tasks: nxapi.yaml - tags: - - nxapi diff --git a/tests/integration/targets/nxos_acl/tasks/nxapi.yaml b/tests/integration/targets/nxos_acl/tasks/nxapi.yaml deleted file mode 100644 index cedab80f1..000000000 --- a/tests/integration/targets/nxos_acl/tasks/nxapi.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect nxapi test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/nxapi" - patterns: "{{ testcase }}.yaml" - connection: local - register: nxapi_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + nxapi_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.httpapi) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_acl/tests/common/sanity.yaml b/tests/integration/targets/nxos_acl/tests/common/sanity.yaml deleted file mode 100644 index c9ec083bf..000000000 --- a/tests/integration/targets/nxos_acl/tests/common/sanity.yaml +++ /dev/null @@ -1,234 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_acl sanity test - -- name: Set a fact for 'time_range' - ansible.builtin.set_fact: - time_range: ans-range - when: platform is not search('N35|N5K|N6K') - -- name: "Setup: cleanup possibly existing acl." - ignore_errors: true - cisco.nxos.nxos_acl: &id012 - name: TEST_ACL - seq: 10 - state: delete_acl - -- name: Configure ace10 - register: result - cisco.nxos.nxos_acl: &id001 - name: TEST_ACL - seq: 10 - action: permit - proto: tcp - src: 192.0.2.1/24 - src_port_op: range - src_port1: 1900 - src_port2: 1910 - ack: enable - dscp: af43 - dest: any - dest_port_op: neq - dest_port1: 1899 - urg: enable - psh: enable - established: enable - log: enable - fin: enable - rst: enable - syn: enable - time_range: "{{time_range|default(omit)}}" - state: present - -- ansible.builtin.assert: &id002 - that: - - result.changed == true - -- name: Check idempotence - register: result - cisco.nxos.nxos_acl: *id001 - -- ansible.builtin.assert: &id004 - that: - - result.changed == false - -- name: Change ace10 - register: result - cisco.nxos.nxos_acl: &id003 - name: TEST_ACL - seq: 10 - action: deny - proto: tcp - src: 192.0.2.1/24 - src_port_op: range - src_port1: 1900 - src_port2: 1910 - ack: enable - dscp: af43 - dest: any - dest_port_op: neq - dest_port1: 1899 - urg: enable - psh: enable - established: enable - log: enable - fin: enable - rst: enable - syn: enable - time_range: "{{time_range|default(omit)}}" - state: present - -- ansible.builtin.assert: *id002 - -- name: Check idempotence - register: result - cisco.nxos.nxos_acl: *id003 - -- ansible.builtin.assert: *id004 - -- name: Ace remark - register: result - cisco.nxos.nxos_acl: &id005 - name: TEST_ACL - seq: 20 - action: remark - remark: test_remark - state: present - -- ansible.builtin.assert: *id002 - -- name: Check idempotence - register: result - cisco.nxos.nxos_acl: *id005 - -- ansible.builtin.assert: *id004 - -- name: Change remark - register: result - cisco.nxos.nxos_acl: &id006 - name: TEST_ACL - seq: 20 - action: remark - remark: changed_remark - state: present - -- ansible.builtin.assert: *id002 - -- name: Check idempotence - register: result - cisco.nxos.nxos_acl: *id006 - -- ansible.builtin.assert: *id004 - -- name: Ace 30 - register: result - cisco.nxos.nxos_acl: &id007 - name: TEST_ACL - seq: 30 - action: deny - proto: 24 - src: any - dest: any - fragments: enable - precedence: network - state: present - -- ansible.builtin.assert: *id002 - -- name: Check idempotence - register: result - cisco.nxos.nxos_acl: *id007 - -- ansible.builtin.assert: *id004 - -- name: Change ace 30 options - register: result - cisco.nxos.nxos_acl: &id008 - name: TEST_ACL - seq: 30 - action: deny - proto: 24 - src: any - dest: any - precedence: network - state: present - -- ansible.builtin.assert: *id002 - -- name: Check idempotence - register: result - cisco.nxos.nxos_acl: *id008 - -- ansible.builtin.assert: *id004 - -- name: Ace 40 - register: result - cisco.nxos.nxos_acl: &id009 - name: TEST_ACL - seq: 40 - action: permit - proto: udp - src: any - src_port_op: neq - src_port1: 1200 - dest: any - precedence: network - state: present - -- ansible.builtin.assert: *id002 - -- name: Check idempotence - register: result - cisco.nxos.nxos_acl: *id009 - -- ansible.builtin.assert: *id004 - -- name: Change ace 40 - register: result - cisco.nxos.nxos_acl: &id010 - name: TEST_ACL - seq: 40 - action: permit - proto: udp - src: any - dest: any - precedence: network - state: present - -- ansible.builtin.assert: *id002 - -- name: Check idempotence - register: result - cisco.nxos.nxos_acl: *id010 - -- ansible.builtin.assert: *id004 - -- name: Remove ace 30 - register: result - cisco.nxos.nxos_acl: &id011 - name: TEST_ACL - seq: 30 - state: absent - -- ansible.builtin.assert: *id002 - -- name: Check idempotence - register: result - cisco.nxos.nxos_acl: *id011 - -- ansible.builtin.assert: *id004 - -- name: Remove acl - register: result - cisco.nxos.nxos_acl: *id012 - -- ansible.builtin.assert: *id002 - -- name: Check idempotence - register: result - cisco.nxos.nxos_acl: *id012 - -- ansible.builtin.assert: *id004 - -- ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_acl sanity test diff --git a/tests/integration/targets/nxos_acl_interface/defaults/main.yaml b/tests/integration/targets/nxos_acl_interface/defaults/main.yaml deleted file mode 100644 index 5f709c5aa..000000000 --- a/tests/integration/targets/nxos_acl_interface/defaults/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -testcase: "*" diff --git a/tests/integration/targets/nxos_acl_interface/meta/main.yml b/tests/integration/targets/nxos_acl_interface/meta/main.yml deleted file mode 100644 index f504a6ab2..000000000 --- a/tests/integration/targets/nxos_acl_interface/meta/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_nxos_tests diff --git a/tests/integration/targets/nxos_acl_interface/tasks/cli.yaml b/tests/integration/targets/nxos_acl_interface/tasks/cli.yaml deleted file mode 100644 index 90342e6b1..000000000 --- a/tests/integration/targets/nxos_acl_interface/tasks/cli.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect cli test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - connection: local - register: cli_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + cli_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.network_cli) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_acl_interface/tasks/main.yaml b/tests/integration/targets/nxos_acl_interface/tasks/main.yaml deleted file mode 100644 index 62e44ffda..000000000 --- a/tests/integration/targets/nxos_acl_interface/tasks/main.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Include the cli tasks - ansible.builtin.include_tasks: cli.yaml - tags: - - cli - -- name: Include the nx-api tasks - ansible.builtin.include_tasks: nxapi.yaml - tags: - - nxapi diff --git a/tests/integration/targets/nxos_acl_interface/tasks/nxapi.yaml b/tests/integration/targets/nxos_acl_interface/tasks/nxapi.yaml deleted file mode 100644 index cedab80f1..000000000 --- a/tests/integration/targets/nxos_acl_interface/tasks/nxapi.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect nxapi test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/nxapi" - patterns: "{{ testcase }}.yaml" - connection: local - register: nxapi_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + nxapi_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.httpapi) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_acl_interface/tests/common/sanity.yaml b/tests/integration/targets/nxos_acl_interface/tests/common/sanity.yaml deleted file mode 100644 index 11cc26177..000000000 --- a/tests/integration/targets/nxos_acl_interface/tests/common/sanity.yaml +++ /dev/null @@ -1,122 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_acl_interface sanity test - -- name: Set a fact for 'intname' - ansible.builtin.set_fact: - intname: "{{ nxos_int1 }}" - -- name: Interface selected for this test - ansible.builtin.debug: - msg: "{{ intname }}" - -- name: "Setup: put interface into a default state" - ignore_errors: true - cisco.nxos.nxos_config: &id007 - lines: - - default interface {{ intname }} - -- name: "Setup: put interface into no switch port mode" - ignore_errors: true - cisco.nxos.nxos_config: - commands: - - no switchport - parents: - - interface {{ intname }} - match: none - -- name: "Setup: cleanup possibly existing acl" - ignore_errors: true - cisco.nxos.nxos_acl: &id008 - name: ANSIBLE_ACL - seq: 10 - state: delete_acl - -- name: Configure supporting acl - cisco.nxos.nxos_acl: - name: ANSIBLE_ACL - seq: 10 - action: permit - proto: tcp - src: 192.0.2.1/24 - dest: any - -- block: - - name: Configure acl interface egress - register: result - cisco.nxos.nxos_acl_interface: &id001 - name: ANSIBLE_ACL - interface: "{{ intname }}" - direction: egress - state: present - - - ansible.builtin.assert: &id002 - that: - - result.changed == true - - - name: Check idempotence egress - register: result - cisco.nxos.nxos_acl_interface: *id001 - - - ansible.builtin.assert: &id004 - that: - - result.changed == false - - - name: Configure acl interface ingress - register: result - cisco.nxos.nxos_acl_interface: &id003 - name: ANSIBLE_ACL - interface: "{{ intname }}" - direction: ingress - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence ingress - register: result - cisco.nxos.nxos_acl_interface: *id003 - - - ansible.builtin.assert: *id004 - - - name: Cleanup acl interface egress - register: result - cisco.nxos.nxos_acl_interface: &id005 - name: ANSIBLE_ACL - interface: "{{ intname }}" - direction: egress - state: absent - - - ansible.builtin.assert: *id002 - - - name: Check idempotence egress cleanup - register: result - cisco.nxos.nxos_acl_interface: *id005 - - - ansible.builtin.assert: *id004 - - - name: Cleanup acl interface ingress - register: result - cisco.nxos.nxos_acl_interface: &id006 - name: ANSIBLE_ACL - interface: "{{ intname }}" - direction: ingress - state: absent - - - ansible.builtin.assert: *id002 - - - name: Check idempotence ingress cleanup - register: result - cisco.nxos.nxos_acl_interface: *id006 - - - ansible.builtin.assert: *id004 - rescue: - - name: Put test interface into default state. - ignore_errors: true - cisco.nxos.nxos_config: *id007 - always: - - name: Remove possible configured acl - ignore_errors: true - cisco.nxos.nxos_acl: *id008 - - - ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_acl_interface sanity test diff --git a/tests/integration/targets/nxos_acl_interfaces/tasks/cli.yaml b/tests/integration/targets/nxos_acl_interfaces/tasks/cli.yaml index b551048ee..3e5e72a07 100644 --- a/tests/integration/targets/nxos_acl_interfaces/tasks/cli.yaml +++ b/tests/integration/targets/nxos_acl_interfaces/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_acl_interfaces/tasks/main.yaml b/tests/integration/targets/nxos_acl_interfaces/tasks/main.yaml index 3b432ce65..4384d22ce 100644 --- a/tests/integration/targets/nxos_acl_interfaces/tasks/main.yaml +++ b/tests/integration/targets/nxos_acl_interfaces/tasks/main.yaml @@ -4,12 +4,12 @@ lines: "no system default switchport" connection: ansible.netcommon.network_cli -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_acl_interfaces/tasks/nxapi.yaml b/tests/integration/targets/nxos_acl_interfaces/tasks/nxapi.yaml index c787c9fb9..59a0777c5 100644 --- a/tests/integration/targets/nxos_acl_interfaces/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_acl_interfaces/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_acl_interfaces/tests/common/deleted.yml b/tests/integration/targets/nxos_acl_interfaces/tests/common/deleted.yml index b0e8739f8..2f5ff4da4 100644 --- a/tests/integration/targets/nxos_acl_interfaces/tests/common/deleted.yml +++ b/tests/integration/targets/nxos_acl_interfaces/tests/common/deleted.yml @@ -31,7 +31,7 @@ config: state: deleted - - name: Gather acl interfaces facts + - name: Gather ACL interfaces facts cisco.nxos.nxos_facts: &id001 gather_subset: - "!all" diff --git a/tests/integration/targets/nxos_acl_interfaces/tests/common/empty_config.yml b/tests/integration/targets/nxos_acl_interfaces/tests/common/empty_config.yml index 9e50577d3..35b54f476 100644 --- a/tests/integration/targets/nxos_acl_interfaces/tests/common/empty_config.yml +++ b/tests/integration/targets/nxos_acl_interfaces/tests/common/empty_config.yml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxos_acl_interfaces empty_config integration tests on connection={{ ansible_connection }} -- name: Merged with empty config should give appropriate error message +- name: Merged with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_acl_interfaces: @@ -13,7 +13,7 @@ that: - result.msg == 'value of config parameter must not be empty for state merged' -- name: Replaced with empty config should give appropriate error message +- name: Replaced with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_acl_interfaces: @@ -24,7 +24,7 @@ that: - result.msg == 'value of config parameter must not be empty for state replaced' -- name: Overridden with empty config should give appropriate error message +- name: Overridden with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_acl_interfaces: @@ -35,7 +35,7 @@ that: - result.msg == 'value of config parameter must not be empty for state overridden' -- name: Rendered with empty config should give appropriate error message +- name: Rendered with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_acl_interfaces: @@ -46,7 +46,7 @@ that: - result.msg == 'value of config parameter must not be empty for state rendered' -- name: Parsed with empty config should give appropriate error message +- name: Parsed with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_acl_interfaces: diff --git a/tests/integration/targets/nxos_acl_interfaces/tests/common/gathered.yml b/tests/integration/targets/nxos_acl_interfaces/tests/common/gathered.yml index d8b26d58b..f0130fe7d 100644 --- a/tests/integration/targets/nxos_acl_interfaces/tests/common/gathered.yml +++ b/tests/integration/targets/nxos_acl_interfaces/tests/common/gathered.yml @@ -5,7 +5,7 @@ - ansible.builtin.include_tasks: populate_config.yaml - block: - - name: Gather acl interfaces facts + - name: Gather ACL interfaces facts cisco.nxos.nxos_facts: gather_subset: - "!all" diff --git a/tests/integration/targets/nxos_acl_interfaces/tests/common/merged.yml b/tests/integration/targets/nxos_acl_interfaces/tests/common/merged.yml index 1f9a195eb..0874a0bdf 100644 --- a/tests/integration/targets/nxos_acl_interfaces/tests/common/merged.yml +++ b/tests/integration/targets/nxos_acl_interfaces/tests/common/merged.yml @@ -7,7 +7,7 @@ - ansible.builtin.include_tasks: populate_acl.yaml - block: - - name: Gather acl interfaces facts + - name: Gather ACL interfaces facts cisco.nxos.nxos_facts: gather_subset: - "!all" diff --git a/tests/integration/targets/nxos_acl_interfaces/tests/common/parsed.yml b/tests/integration/targets/nxos_acl_interfaces/tests/common/parsed.yml index 3046e18ef..0617a97b3 100644 --- a/tests/integration/targets/nxos_acl_interfaces/tests/common/parsed.yml +++ b/tests/integration/targets/nxos_acl_interfaces/tests/common/parsed.yml @@ -3,7 +3,7 @@ msg: Start nxos_acl_interfaces parsed integration tests connection={{ansible_connection}}" - block: - - name: Gather acl interfaces facts + - name: Gather ACL interfaces facts cisco.nxos.nxos_facts: gather_subset: - "!all" diff --git a/tests/integration/targets/nxos_acl_interfaces/tests/common/remove_config.yaml b/tests/integration/targets/nxos_acl_interfaces/tests/common/remove_config.yaml index 91ad65dec..3cad7ce53 100644 --- a/tests/integration/targets/nxos_acl_interfaces/tests/common/remove_config.yaml +++ b/tests/integration/targets/nxos_acl_interfaces/tests/common/remove_config.yaml @@ -1,5 +1,5 @@ --- -- name: Remove config - 1 +- name: Remove configuration - 1 cisco.nxos.nxos_config: lines: - "no ip access-list ACL1v4" @@ -11,7 +11,7 @@ - " no ipv6 traffic-filter ACL1v6 in" ignore_errors: true -- name: Remove config - 2 +- name: Remove configuration - 2 cisco.nxos.nxos_config: lines: - no ip access-group ACL1v4 out @@ -19,21 +19,21 @@ parents: interface Ethernet1/5 ignore_errors: true -- name: Remove config - 3 +- name: Remove configuration - 3 cisco.nxos.nxos_config: lines: - no ip access-group ACL1v4 out parents: interface Ethernet1/3 ignore_errors: true -- name: Remove config - 4 +- name: Remove configuration - 4 cisco.nxos.nxos_config: lines: - no ip access-group NewACLv4 out parents: interface Ethernet1/4 ignore_errors: true -- name: Remove config - 5 +- name: Remove configuration - 5 cisco.nxos.nxos_config: lines: - no switchport diff --git a/tests/integration/targets/nxos_acl_interfaces/tests/common/rtt.yml b/tests/integration/targets/nxos_acl_interfaces/tests/common/rtt.yml index b86613085..90f72fb39 100644 --- a/tests/integration/targets/nxos_acl_interfaces/tests/common/rtt.yml +++ b/tests/integration/targets/nxos_acl_interfaces/tests/common/rtt.yml @@ -89,7 +89,7 @@ config: "{{ ansible_facts['network_resources']['acl_interfaces'] }}" state: overridden - - name: Assert that config was reverted + - name: Assert that configuration was reverted ansible.builtin.assert: that: - result.changed==True diff --git a/tests/integration/targets/nxos_acls/tasks/cli.yaml b/tests/integration/targets/nxos_acls/tasks/cli.yaml index 95d6a016b..3e5e72a07 100644 --- a/tests/integration/targets/nxos_acls/tasks/cli.yaml +++ b/tests/integration/targets/nxos_acls/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yml" @@ -22,7 +22,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_acls/tasks/main.yaml b/tests/integration/targets/nxos_acls/tasks/main.yaml index c41f7b939..f900849c2 100644 --- a/tests/integration/targets/nxos_acls/tasks/main.yaml +++ b/tests/integration/targets/nxos_acls/tasks/main.yaml @@ -6,12 +6,12 @@ - "system default switchport shutdown" connection: ansible.netcommon.network_cli -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_acls/tasks/nxapi.yaml b/tests/integration/targets/nxos_acls/tasks/nxapi.yaml index fe9d48a7c..59a0777c5 100644 --- a/tests/integration/targets/nxos_acls/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_acls/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yml" @@ -22,7 +22,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_acls/tests/common/merged.yml b/tests/integration/targets/nxos_acls/tests/common/merged.yml index 2f8945eb4..874a2ad9d 100644 --- a/tests/integration/targets/nxos_acls/tests/common/merged.yml +++ b/tests/integration/targets/nxos_acls/tests/common/merged.yml @@ -80,7 +80,7 @@ that: - result.changed == false - - name: Update one parameter of an existing ace with state merged (should fail) + - name: Update one parameter of an existing ACE with state merged (should fail) register: result cisco.nxos.nxos_acls: config: diff --git a/tests/integration/targets/nxos_acls/tests/common/parsed.yml b/tests/integration/targets/nxos_acls/tests/common/parsed.yml index 306c4fbff..b408fecf0 100644 --- a/tests/integration/targets/nxos_acls/tests/common/parsed.yml +++ b/tests/integration/targets/nxos_acls/tests/common/parsed.yml @@ -15,10 +15,18 @@ - name: Parsed register: result cisco.nxos.nxos_acls: &id001 - running_config: - "ip access-list ACL1v4\n10 permit ip any any\n20 deny udp any any\nip access-list ACL2v4\n10 permit ahp 192.0.2.0 0.0.0.255 any\nipv6 access-list\ - \ ACL1v6\n10 permit sctp any any\n20 remark IPv6 ACL\nipv6 access-list ACL2v6\n10 deny ipv6 any 2001:db8:3000::36/128\n20 permit tcp 2001:db8:2000:2::2/128\ - \ 2001:db8:2000:ab::2/128\n" + running_config: >- + ip access-list ACL1v4 + 10 permit ip any any + 20 deny udp any any + ip access-list ACL2v4 + 10 permit ahp 192.0.2.0 0.0.0.255 any + ipv6 access-list ACL1v6 + 10 permit sctp any any + 20 remark IPv6 ACL + ipv6 access-list ACL2v6 + 10 deny ipv6 any 2001:db8:3000::36/128 + 20 permit tcp 2001:db8:2000:2::2/128 2001:db8:2000:ab::2/128 state: parsed - ansible.builtin.assert: diff --git a/tests/integration/targets/nxos_acls/tests/common/remove_config.yaml b/tests/integration/targets/nxos_acls/tests/common/remove_config.yaml index 24f7b9d02..17c6b5bc4 100644 --- a/tests/integration/targets/nxos_acls/tests/common/remove_config.yaml +++ b/tests/integration/targets/nxos_acls/tests/common/remove_config.yaml @@ -1,5 +1,5 @@ --- -- name: Remove config +- name: Remove configuration cisco.nxos.nxos_config: lines: - "no ip access-list ACL1v4" diff --git a/tests/integration/targets/nxos_banner/tasks/cli.yaml b/tests/integration/targets/nxos_banner/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_banner/tasks/cli.yaml +++ b/tests/integration/targets/nxos_banner/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_banner/tasks/main.yaml b/tests/integration/targets/nxos_banner/tasks/main.yaml index 352048df1..865cff2cb 100644 --- a/tests/integration/targets/nxos_banner/tasks/main.yaml +++ b/tests/integration/targets/nxos_banner/tasks/main.yaml @@ -4,12 +4,12 @@ banner_exec_image_ok: false banner_motd_image_ok: false -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_banner/tasks/nxapi.yaml b/tests/integration/targets/nxos_banner/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_banner/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_banner/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_banner/tests/common/sanity.yaml b/tests/integration/targets/nxos_banner/tests/common/sanity.yaml index 2ee7b9a52..93d0963b7 100644 --- a/tests/integration/targets/nxos_banner/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_banner/tests/common/sanity.yaml @@ -47,12 +47,12 @@ when: banner_exec_image_ok == True - block: - - name: Setup motd + - name: Setup MOTD cisco.nxos.nxos_banner: &id004 banner: motd state: absent - - name: Set motd + - name: Set MOTD register: result cisco.nxos.nxos_banner: &id003 banner: motd @@ -64,7 +64,7 @@ - result.changed == true - "'banner motd @\nJunk motd banner\nover multiple lines\n@' in result.commands" - - name: Set motd again (idempotent) + - name: Set MOTD again (idempotent) register: result cisco.nxos.nxos_banner: *id003 @@ -72,7 +72,7 @@ that: - result.changed == false - - name: Teardown motd + - name: Teardown MOTD cisco.nxos.nxos_banner: *id004 when: banner_motd_image_ok == True diff --git a/tests/integration/targets/nxos_bfd_global/tasks/cli.yaml b/tests/integration/targets/nxos_bfd_global/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_bfd_global/tasks/cli.yaml +++ b/tests/integration/targets/nxos_bfd_global/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_bfd_global/tasks/main.yaml b/tests/integration/targets/nxos_bfd_global/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_bfd_global/tasks/main.yaml +++ b/tests/integration/targets/nxos_bfd_global/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_bfd_global/tasks/nxapi.yaml b/tests/integration/targets/nxos_bfd_global/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_bfd_global/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_bfd_global/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_bfd_global/tests/common/sanity.yaml b/tests/integration/targets/nxos_bfd_global/tests/common/sanity.yaml index fa720b318..48322a822 100644 --- a/tests/integration/targets/nxos_bfd_global/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_bfd_global/tests/common/sanity.yaml @@ -87,7 +87,7 @@ lines: interface loopback1 match: none -- name: Feature bfd init +- name: "'feature bfd' init" delay: 3 retries: 1 register: result diff --git a/tests/integration/targets/nxos_bfd_interfaces/tasks/cli.yaml b/tests/integration/targets/nxos_bfd_interfaces/tasks/cli.yaml index ba1eff1cd..e3e64747b 100644 --- a/tests/integration/targets/nxos_bfd_interfaces/tasks/cli.yaml +++ b/tests/integration/targets/nxos_bfd_interfaces/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,11 +23,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_bfd_interfaces/tasks/main.yaml b/tests/integration/targets/nxos_bfd_interfaces/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_bfd_interfaces/tasks/main.yaml +++ b/tests/integration/targets/nxos_bfd_interfaces/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_bfd_interfaces/tasks/nxapi.yaml b/tests/integration/targets/nxos_bfd_interfaces/tasks/nxapi.yaml index 2e452bb6a..4ae68868c 100644 --- a/tests/integration/targets/nxos_bfd_interfaces/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_bfd_interfaces/tasks/nxapi.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_bfd_interfaces/tests/common/_populate_config.yaml b/tests/integration/targets/nxos_bfd_interfaces/tests/common/_populate_config.yaml index 697b31185..6c260fafb 100644 --- a/tests/integration/targets/nxos_bfd_interfaces/tests/common/_populate_config.yaml +++ b/tests/integration/targets/nxos_bfd_interfaces/tests/common/_populate_config.yaml @@ -1,5 +1,5 @@ --- -- name: Populate config - 1 +- name: Populate configuration - 1 cisco.nxos.nxos_config: lines: - "feature bfd" @@ -7,7 +7,7 @@ - " no switchport" - " no bfd" -- name: Populate config - 2 +- name: Populate configuration - 2 cisco.nxos.nxos_config: lines: - "interface {{ nxos_int2 }}" diff --git a/tests/integration/targets/nxos_bfd_interfaces/tests/common/_remove_config.yaml b/tests/integration/targets/nxos_bfd_interfaces/tests/common/_remove_config.yaml index 37c4a3d4d..b1fa61c19 100644 --- a/tests/integration/targets/nxos_bfd_interfaces/tests/common/_remove_config.yaml +++ b/tests/integration/targets/nxos_bfd_interfaces/tests/common/_remove_config.yaml @@ -1,5 +1,5 @@ --- -- name: Remove config +- name: Remove configuration cisco.nxos.nxos_config: lines: - "no feature bfd" diff --git a/tests/integration/targets/nxos_bfd_interfaces/tests/common/deleted.yaml b/tests/integration/targets/nxos_bfd_interfaces/tests/common/deleted.yaml index af98b6c9f..7c07064b9 100644 --- a/tests/integration/targets/nxos_bfd_interfaces/tests/common/deleted.yaml +++ b/tests/integration/targets/nxos_bfd_interfaces/tests/common/deleted.yaml @@ -26,7 +26,7 @@ - "interface {{ test_int1 }}" - " no switchport" - - name: Setup initial bfd state + - name: Setup initial BFD state cisco.nxos.nxos_bfd_interfaces: config: - name: "{{ test_int1 }}" diff --git a/tests/integration/targets/nxos_bfd_interfaces/tests/common/empty_config.yaml b/tests/integration/targets/nxos_bfd_interfaces/tests/common/empty_config.yaml index 3f1459db0..037de3892 100644 --- a/tests/integration/targets/nxos_bfd_interfaces/tests/common/empty_config.yaml +++ b/tests/integration/targets/nxos_bfd_interfaces/tests/common/empty_config.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxos_bfd_interfaces empty_config integration tests on connection={{ ansible_connection }} -- name: Merged with empty config should give appropriate error message +- name: Merged with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_bfd_interfaces: @@ -13,7 +13,7 @@ that: - result.msg == 'value of config parameter must not be empty for state merged' -- name: Replaced with empty config should give appropriate error message +- name: Replaced with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_bfd_interfaces: @@ -24,7 +24,7 @@ that: - result.msg == 'value of config parameter must not be empty for state replaced' -- name: Overridden with empty config should give appropriate error message +- name: Overridden with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_bfd_interfaces: @@ -35,7 +35,7 @@ that: - result.msg == 'value of config parameter must not be empty for state overridden' -- name: Rendered with empty config should give appropriate error message +- name: Rendered with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_bfd_interfaces: @@ -46,7 +46,7 @@ that: - result.msg == 'value of config parameter must not be empty for state rendered' -- name: Parsed with empty config should give appropriate error message +- name: Parsed with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_bfd_interfaces: diff --git a/tests/integration/targets/nxos_bfd_interfaces/tests/common/overridden.yaml b/tests/integration/targets/nxos_bfd_interfaces/tests/common/overridden.yaml index 1d939a725..8b3a66d4a 100644 --- a/tests/integration/targets/nxos_bfd_interfaces/tests/common/overridden.yaml +++ b/tests/integration/targets/nxos_bfd_interfaces/tests/common/overridden.yaml @@ -38,7 +38,7 @@ - "{{ test_int1 }}" - "{{ test_int2 }}" - - name: Setup initial bfd state + - name: Setup initial BFD state cisco.nxos.nxos_bfd_interfaces: config: - name: "{{ test_int1 }}" diff --git a/tests/integration/targets/nxos_bfd_interfaces/tests/common/parsed.yaml b/tests/integration/targets/nxos_bfd_interfaces/tests/common/parsed.yaml index 188bc1551..4cc9c6b38 100644 --- a/tests/integration/targets/nxos_bfd_interfaces/tests/common/parsed.yaml +++ b/tests/integration/targets/nxos_bfd_interfaces/tests/common/parsed.yaml @@ -4,7 +4,7 @@ - block: # Interfaces used in the task don't actually exist on the appliance - - name: Use parsed state to convert externally supplied config to structured format + - name: Use parsed state to convert externally supplied configuration to structured format register: result cisco.nxos.nxos_bfd_interfaces: running_config: | diff --git a/tests/integration/targets/nxos_bfd_interfaces/tests/common/replaced.yaml b/tests/integration/targets/nxos_bfd_interfaces/tests/common/replaced.yaml index ed97d9c8d..498ee7d9c 100644 --- a/tests/integration/targets/nxos_bfd_interfaces/tests/common/replaced.yaml +++ b/tests/integration/targets/nxos_bfd_interfaces/tests/common/replaced.yaml @@ -26,7 +26,7 @@ - "interface {{ test_int1 }}" - " no switchport" - - name: Setup initial bfd state + - name: Setup initial BFD state cisco.nxos.nxos_bfd_interfaces: config: - name: "{{ test_int1 }}" diff --git a/tests/integration/targets/nxos_bfd_interfaces/vars/main.yml b/tests/integration/targets/nxos_bfd_interfaces/vars/main.yml index 29552637f..eec612c56 100644 --- a/tests/integration/targets/nxos_bfd_interfaces/vars/main.yml +++ b/tests/integration/targets/nxos_bfd_interfaces/vars/main.yml @@ -1,3 +1,4 @@ +--- gathered: - name: "{{ nxos_int1 }}" bfd: disable diff --git a/tests/integration/targets/nxos_bgp/defaults/main.yaml b/tests/integration/targets/nxos_bgp/defaults/main.yaml deleted file mode 100644 index 525b7aab9..000000000 --- a/tests/integration/targets/nxos_bgp/defaults/main.yaml +++ /dev/null @@ -1,5 +0,0 @@ ---- -testcase: "*" -vrfs: - - default - - myvrf diff --git a/tests/integration/targets/nxos_bgp/meta/main.yml b/tests/integration/targets/nxos_bgp/meta/main.yml deleted file mode 100644 index f504a6ab2..000000000 --- a/tests/integration/targets/nxos_bgp/meta/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_nxos_tests diff --git a/tests/integration/targets/nxos_bgp/tasks/cli.yaml b/tests/integration/targets/nxos_bgp/tasks/cli.yaml deleted file mode 100644 index 90342e6b1..000000000 --- a/tests/integration/targets/nxos_bgp/tasks/cli.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect cli test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - connection: local - register: cli_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + cli_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.network_cli) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_bgp/tasks/main.yaml b/tests/integration/targets/nxos_bgp/tasks/main.yaml deleted file mode 100644 index 62e44ffda..000000000 --- a/tests/integration/targets/nxos_bgp/tasks/main.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Include the cli tasks - ansible.builtin.include_tasks: cli.yaml - tags: - - cli - -- name: Include the nx-api tasks - ansible.builtin.include_tasks: nxapi.yaml - tags: - - nxapi diff --git a/tests/integration/targets/nxos_bgp/tests/common/dis_policy.yaml b/tests/integration/targets/nxos_bgp/tests/common/dis_policy.yaml deleted file mode 100644 index 548e2d894..000000000 --- a/tests/integration/targets/nxos_bgp/tests/common/dis_policy.yaml +++ /dev/null @@ -1,85 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_bgp parameter test - -- ansible.builtin.debug: - msg: This bgp_disable_policy is not supported on {{ image_version }} - when: imagetag is search("A8|D1") - -- name: Set a fact for 'bgp_disable_policy' - ansible.builtin.set_fact: - bgp_disable_policy: false - -- name: Set a fact for 'bgp_disable_policy' - ansible.builtin.set_fact: - bgp_disable_policy: true - when: imagetag is not search("A8|D1") - -- name: Disable feature bgp - ignore_errors: true - cisco.nxos.nxos_feature: - feature: bgp - state: disabled - -- name: Enable feature bgp - ignore_errors: true - cisco.nxos.nxos_feature: - feature: bgp - state: enabled - -- block: - - name: Set disable policy - register: result - when: bgp_disable_policy - cisco.nxos.nxos_bgp: &id001 - asn: 65535 - disable_policy_batching: true - disable_policy_batching_ipv4_prefix_list: v4_p - disable_policy_batching_ipv6_prefix_list: v6_p - - - ansible.builtin.assert: &id002 - that: - - result.changed == true - when: bgp_disable_policy - - - name: Check idempotence - register: result - when: bgp_disable_policy - cisco.nxos.nxos_bgp: *id001 - - - ansible.builtin.assert: &id004 - that: - - result.changed == false - when: bgp_disable_policy - - - name: Reset disable policy - register: result - when: bgp_disable_policy - cisco.nxos.nxos_bgp: &id003 - asn: 65535 - disable_policy_batching: false - disable_policy_batching_ipv4_prefix_list: default - disable_policy_batching_ipv6_prefix_list: default - - - ansible.builtin.assert: *id002 - when: bgp_disable_policy - - - name: Check idempotence - register: result - when: bgp_disable_policy - cisco.nxos.nxos_bgp: *id003 - - - ansible.builtin.assert: *id004 - when: bgp_disable_policy - rescue: - - ansible.builtin.debug: - msg: Tests can fail on A8 or helsinki images - always: - - name: Disable feature bgp - ignore_errors: true - cisco.nxos.nxos_feature: - feature: bgp - state: disabled - - - ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_bgp parameter test diff --git a/tests/integration/targets/nxos_bgp/tests/common/hels.yaml b/tests/integration/targets/nxos_bgp/tests/common/hels.yaml deleted file mode 100644 index c052cf65c..000000000 --- a/tests/integration/targets/nxos_bgp/tests/common/hels.yaml +++ /dev/null @@ -1,101 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_bgp parameter test - -- ansible.builtin.debug: - msg: This test is not supported on {{ image_version }} - when: imagetag is search("D1") - -- name: Set a fact for 'test_helsinki' - ansible.builtin.set_fact: - test_helsinki: false - -- name: Set a fact for 'test_helsinki' - ansible.builtin.set_fact: - test_helsinki: true - when: imagetag is not search("D1") - -- name: Disable feature bgp - ignore_errors: true - when: test_helsinki - cisco.nxos.nxos_feature: - feature: bgp - state: disabled - -- name: Enable feature bgp - ignore_errors: true - when: test_helsinki - cisco.nxos.nxos_feature: - feature: bgp - state: enabled - -- block: - - name: Set helsinki - with_items: "{{ vrfs }}" - register: result - when: test_helsinki - cisco.nxos.nxos_bgp: &id001 - asn: 65535 - vrf: "{{ item }}" - graceful_restart_timers_restart: 130 - graceful_restart_timers_stalepath_time: 310 - neighbor_down_fib_accelerate: true - reconnect_interval: 55 - timer_bgp_hold: 110 - timer_bgp_keepalive: 45 - - - ansible.builtin.assert: &id002 - that: - - result.changed == true - when: test_helsinki - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - when: test_helsinki - cisco.nxos.nxos_bgp: *id001 - - - ansible.builtin.assert: &id004 - that: - - result.changed == false - when: test_helsinki - - - name: Reset helsinki - with_items: "{{ vrfs }}" - register: result - when: test_helsinki - cisco.nxos.nxos_bgp: &id003 - asn: 65535 - vrf: "{{ item }}" - graceful_restart: true - graceful_restart_timers_restart: default - graceful_restart_timers_stalepath_time: default - neighbor_down_fib_accelerate: false - reconnect_interval: default - timer_bgp_hold: default - timer_bgp_keepalive: default - - - ansible.builtin.assert: *id002 - when: test_helsinki - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - when: test_helsinki - cisco.nxos.nxos_bgp: *id003 - - - ansible.builtin.assert: *id004 - when: test_helsinki - rescue: - - ansible.builtin.debug: - msg: Tests can fail on helsinki images - always: - - name: Disable feature bgp - ignore_errors: true - when: test_helsinki - cisco.nxos.nxos_feature: - feature: bgp - state: disabled - - - ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_bgp parameter test diff --git a/tests/integration/targets/nxos_bgp/tests/common/isolate.yaml b/tests/integration/targets/nxos_bgp/tests/common/isolate.yaml deleted file mode 100644 index d46d4fd75..000000000 --- a/tests/integration/targets/nxos_bgp/tests/common/isolate.yaml +++ /dev/null @@ -1,81 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_bgp parameter test - -- ansible.builtin.debug: - msg: This bgp_isolate is not supported on {{ image_version }} - when: imagetag is search("A8") - -- name: Set a fact for 'bgp_isolate' - ansible.builtin.set_fact: - bgp_isolate: false - -- name: Set a fact for 'bgp_isolate' - ansible.builtin.set_fact: - bgp_isolate: true - when: imagetag is not search("A8") - -- name: Disable feature bgp - ignore_errors: true - cisco.nxos.nxos_feature: - feature: bgp - state: disabled - -- name: Enable feature bgp - ignore_errors: true - cisco.nxos.nxos_feature: - feature: bgp - state: enabled - -- block: - - name: Set isolate - register: result - when: bgp_isolate - cisco.nxos.nxos_bgp: &id001 - asn: 65535 - isolate: false - - - ansible.builtin.assert: &id002 - that: - - result.changed == true - when: bgp_isolate - - - name: Check idempotence - register: result - when: bgp_isolate - cisco.nxos.nxos_bgp: *id001 - - - ansible.builtin.assert: &id004 - that: - - result.changed == false - when: bgp_isolate - - - name: Reset isolate - register: result - when: bgp_isolate - cisco.nxos.nxos_bgp: &id003 - asn: 65535 - isolate: true - - - ansible.builtin.assert: *id002 - when: bgp_isolate - - - name: Check idempotence - register: result - when: bgp_isolate - cisco.nxos.nxos_bgp: *id003 - - - ansible.builtin.assert: *id004 - when: bgp_isolate - rescue: - - ansible.builtin.debug: - msg: Tests can fail on A8 images - always: - - name: Disable feature bgp - ignore_errors: true - cisco.nxos.nxos_feature: - feature: bgp - state: disabled - - - ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_bgp parameter test diff --git a/tests/integration/targets/nxos_bgp/tests/common/param.yaml b/tests/integration/targets/nxos_bgp/tests/common/param.yaml deleted file mode 100644 index ed2d3942a..000000000 --- a/tests/integration/targets/nxos_bgp/tests/common/param.yaml +++ /dev/null @@ -1,258 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_bgp parameter test - -- name: Disable feature bgp - ignore_errors: true - cisco.nxos.nxos_feature: - feature: bgp - state: disabled - -- name: Enable feature bgp - ignore_errors: true - cisco.nxos.nxos_feature: - feature: bgp - state: enabled - -- block: - - name: Set multi vrf params - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp: &id001 - asn: 65535 - vrf: "{{ item }}" - router_id: 192.0.2.1 - bestpath_always_compare_med: true - bestpath_aspath_multipath_relax: true - bestpath_compare_routerid: true - bestpath_cost_community_ignore: true - bestpath_med_confed: true - bestpath_med_missing_as_worst: true - bestpath_med_non_deterministic: true - graceful_restart_helper: true - log_neighbor_changes: true - maxas_limit: 50 - - - ansible.builtin.assert: &id002 - that: - - result.changed == true - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp: *id001 - - - ansible.builtin.assert: &id004 - that: - - result.changed == false - - - name: Reset multi vrf params - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp: &id003 - asn: 65535 - vrf: "{{ item }}" - bestpath_always_compare_med: false - bestpath_aspath_multipath_relax: false - bestpath_compare_routerid: false - bestpath_cost_community_ignore: false - bestpath_med_confed: false - bestpath_med_missing_as_worst: false - bestpath_med_non_deterministic: false - graceful_restart_helper: false - log_neighbor_changes: false - maxas_limit: default - router_id: default - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp: *id003 - - - ansible.builtin.assert: *id004 - - - name: Set clusterid - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp: &id005 - asn: 65535 - vrf: "{{ item }}" - cluster_id: 10.0.0.1 - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp: *id005 - - - ansible.builtin.assert: *id004 - - - name: Reset cluster_id - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp: &id006 - asn: 65535 - vrf: "{{ item }}" - cluster_id: default - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp: *id006 - - - ansible.builtin.assert: *id004 - - - name: Set confederation - register: result - cisco.nxos.nxos_bgp: &id007 - asn: 65535 - confederation_id: 99 - confederation_peers: - - 16 - - 22 - - 18 - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp: *id007 - - - ansible.builtin.assert: *id004 - - - name: Reset confederation - register: result - cisco.nxos.nxos_bgp: &id008 - asn: 65535 - confederation_id: default - confederation_peers: default - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp: *id008 - - - ansible.builtin.assert: *id004 - - - name: Set confederation_local_as - register: result - cisco.nxos.nxos_bgp: &id009 - asn: 65535 - vrf: myvrf - local_as: 33 - confederation_id: 99 - confederation_peers: - - 16 - - 22 - - 18 - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp: *id009 - - - ansible.builtin.assert: *id004 - - - name: Reset confederation local_as - register: result - cisco.nxos.nxos_bgp: &id010 - asn: 65535 - vrf: myvrf - local_as: default - confederation_id: default - confederation_peers: default - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp: *id010 - - - ansible.builtin.assert: *id004 - - - name: Set local_as - register: result - cisco.nxos.nxos_bgp: &id011 - asn: 65535 - vrf: myvrf - local_as: 33 - confederation_id: 99 - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp: *id011 - - - ansible.builtin.assert: *id004 - - - name: Reset local_as - register: result - cisco.nxos.nxos_bgp: &id012 - asn: 65535 - vrf: myvrf - confederation_id: default - local_as: default - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp: *id012 - - - ansible.builtin.assert: *id004 - - - name: Set default vrf params - register: result - cisco.nxos.nxos_bgp: &id013 - asn: 65535 - event_history_cli: size_medium - event_history_detail: size_large - event_history_events: size_medium - event_history_periodic: size_small - enforce_first_as: false - fast_external_fallover: false - flush_routes: true - shutdown: true - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp: *id013 - - - ansible.builtin.assert: *id004 - - - name: Reset default vrf params - register: result - cisco.nxos.nxos_bgp: &id014 - asn: 65535 - event_history_detail: default - enforce_first_as: true - fast_external_fallover: true - flush_routes: false - shutdown: false - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp: *id014 - - - ansible.builtin.assert: *id004 - always: - - name: Disable feature bgp - ignore_errors: true - cisco.nxos.nxos_feature: - feature: bgp - state: disabled - - - ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_bgp parameter test diff --git a/tests/integration/targets/nxos_bgp/tests/common/sanity.yaml b/tests/integration/targets/nxos_bgp/tests/common/sanity.yaml deleted file mode 100644 index a9cfadbf5..000000000 --- a/tests/integration/targets/nxos_bgp/tests/common/sanity.yaml +++ /dev/null @@ -1,138 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_bgp sanity test - -- name: Set a fact for 'neighbor_down_fib_accelerate' - ansible.builtin.set_fact: - neighbor_down_fib_accelerate: true - when: (not titanium) and ((imagetag != 'N1') and (imagetag != 'D1')) - -- name: Set a fact for 'reconnect_interval' - ansible.builtin.set_fact: - reconnect_interval: "55" - when: (not titanium) and ((imagetag != 'N1') and (imagetag != 'D1')) - -- name: Set a fact for 'isolate' - ansible.builtin.set_fact: - isolate: false - when: platform is not match("N35") - -- name: Enable feature bgp - ignore_errors: true - cisco.nxos.nxos_feature: - feature: bgp - state: enabled - -- name: Setup - ignore_errors: true - register: result - cisco.nxos.nxos_bgp: &id002 - asn: 65535 - state: absent - -- block: - - name: Configure bgp defaults - register: result - cisco.nxos.nxos_bgp: &id001 - asn: 65535 - router_id: 192.0.2.1 - state: present - - - ansible.builtin.assert: &id003 - that: - - result.changed == true - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp: *id001 - - - ansible.builtin.assert: &id004 - that: - - result.changed == false - - - name: Remove bgp - register: result - cisco.nxos.nxos_bgp: *id002 - - - ansible.builtin.assert: *id003 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp: *id002 - - - ansible.builtin.assert: *id004 - - - name: Configure bgp non defaults - register: result - cisco.nxos.nxos_bgp: &id005 - asn: 65535 - router_id: 192.0.2.1 - bestpath_always_compare_med: true - bestpath_aspath_multipath_relax: true - bestpath_compare_routerid: true - bestpath_cost_community_ignore: true - bestpath_med_confed: true - bestpath_med_missing_as_worst: true - bestpath_med_non_deterministic: true - cluster_id: 10.0.0.1 - confederation_id: 99 - disable_policy_batching: true - enforce_first_as: false - fast_external_fallover: false - flush_routes: true - graceful_restart_helper: true - graceful_restart_timers_restart: 130 - graceful_restart_timers_stalepath_time: 310 - isolate: "{{isolate|default(omit)}}" - log_neighbor_changes: true - maxas_limit: 50 - neighbor_down_fib_accelerate: "{{neighbor_down_fib_accelerate|default(omit)}}" - reconnect_interval: "{{reconnect_interval|default(omit)}}" - shutdown: true - timer_bestpath_limit: 255 - timer_bgp_hold: 110 - timer_bgp_keepalive: 45 - event_history_cli: size_medium - event_history_detail: size_large - event_history_events: size_medium - event_history_periodic: size_small - suppress_fib_pending: true - state: present - - - ansible.builtin.assert: *id003 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp: *id005 - - - ansible.builtin.assert: *id004 - - - name: Remove bgp - register: result - cisco.nxos.nxos_bgp: *id002 - - - ansible.builtin.assert: *id003 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp: *id002 - - - ansible.builtin.assert: *id004 - - - name: Disable feature bgp - cisco.nxos.nxos_feature: - feature: bgp - state: disabled - rescue: - - name: Cleanup bgp - ignore_errors: true - cisco.nxos.nxos_bgp: *id002 - - - name: Disable feature bgp - ignore_errors: true - cisco.nxos.nxos_feature: - feature: bgp - state: disabled - always: - - ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_bgp sanity test diff --git a/tests/integration/targets/nxos_bgp/tests/common/supp_fib.yaml b/tests/integration/targets/nxos_bgp/tests/common/supp_fib.yaml deleted file mode 100644 index 0238c8738..000000000 --- a/tests/integration/targets/nxos_bgp/tests/common/supp_fib.yaml +++ /dev/null @@ -1,120 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_bgp parameter test - -- name: Set a fact for 'bgp_best_path_limit' - ansible.builtin.set_fact: - bgp_best_path_limit: false - -- name: Set a fact for 'bgp_best_path_limit' - ansible.builtin.set_fact: - bgp_best_path_limit: true - when: imagetag is not search("I2") - -- name: Set a fact for 'bgp_suppress_fib_supported' - ansible.builtin.set_fact: - bgp_suppress_fib_supported: false - -- name: Set a fact for 'bgp_suppress_fib_supported' - ansible.builtin.set_fact: - bgp_suppress_fib_supported: true - when: imagetag is not search("A8|D1|I2|I4") - -- name: Disable feature bgp - ignore_errors: true - cisco.nxos.nxos_feature: - feature: bgp - state: disabled - -- name: Enable feature bgp - ignore_errors: true - cisco.nxos.nxos_feature: - feature: bgp - state: enabled - -- block: - - name: Set bestpath limit - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp: &id001 - asn: 65535 - vrf: "{{ item }}" - timer_bestpath_limit: 255 - - - ansible.builtin.assert: &id002 - that: - - result.changed == true - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp: *id001 - - - ansible.builtin.assert: &id004 - that: - - result.changed == false - - - name: Reset bestpath limit - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp: &id003 - asn: 65535 - vrf: "{{ item }}" - timer_bestpath_limit: default - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - when: bgp_best_path_limit - cisco.nxos.nxos_bgp: *id003 - - - ansible.builtin.assert: *id004 - when: bgp_best_path_limit - - - name: Set suppress fib - register: result - cisco.nxos.nxos_bgp: &id005 - asn: 65535 - suppress_fib_pending: false - - - ansible.builtin.assert: *id002 - when: bgp_suppress_fib_supported - - - name: Check idempotence - register: result - when: bgp_suppress_fib_supported - cisco.nxos.nxos_bgp: *id005 - - - ansible.builtin.assert: *id004 - when: bgp_suppress_fib_supported - - - name: Reset suppress fib - register: result - cisco.nxos.nxos_bgp: &id006 - asn: 65535 - suppress_fib_pending: true - - - ansible.builtin.assert: *id002 - when: bgp_suppress_fib_supported - - - name: Check idempotence - register: result - when: bgp_suppress_fib_supported - cisco.nxos.nxos_bgp: *id006 - - - ansible.builtin.assert: *id004 - when: bgp_suppress_fib_supported - rescue: - - ansible.builtin.debug: - msg: Tests can fail on I2/I4/A8/Fretta or helsinki images - always: - - name: Disable feature bgp - ignore_errors: true - cisco.nxos.nxos_feature: - feature: bgp - state: disabled - - - ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_bgp parameter test diff --git a/tests/integration/targets/nxos_bgp_address_family/meta/main.yml b/tests/integration/targets/nxos_bgp_address_family/meta/main.yml index e69de29bb..ed97d539c 100644 --- a/tests/integration/targets/nxos_bgp_address_family/meta/main.yml +++ b/tests/integration/targets/nxos_bgp_address_family/meta/main.yml @@ -0,0 +1 @@ +--- diff --git a/tests/integration/targets/nxos_bgp_address_family/tasks/cli.yaml b/tests/integration/targets/nxos_bgp_address_family/tasks/cli.yaml index 507d803cb..e3e64747b 100644 --- a/tests/integration/targets/nxos_bgp_address_family/tasks/cli.yaml +++ b/tests/integration/targets/nxos_bgp_address_family/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_bgp_address_family/tasks/main.yaml b/tests/integration/targets/nxos_bgp_address_family/tasks/main.yaml index 55f769a3b..026b6e477 100644 --- a/tests/integration/targets/nxos_bgp_address_family/tasks/main.yaml +++ b/tests/integration/targets/nxos_bgp_address_family/tasks/main.yaml @@ -1,23 +1,24 @@ --- -- name: Enable bgp feature +- name: Enable 'feature bgp' cisco.nxos.nxos_feature: feature: bgp vars: ansible_connection: ansible.netcommon.network_cli -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi always: - - name: Disable bgp feature + - name: Disable 'feature bgp' cisco.nxos.nxos_feature: feature: bgp state: disabled diff --git a/tests/integration/targets/nxos_bgp_address_family/tasks/nxapi.yaml b/tests/integration/targets/nxos_bgp_address_family/tasks/nxapi.yaml index 2e452bb6a..4ae68868c 100644 --- a/tests/integration/targets/nxos_bgp_address_family/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_bgp_address_family/tasks/nxapi.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_bgp_address_family/tests/common/_remove_config.yaml b/tests/integration/targets/nxos_bgp_address_family/tests/common/_remove_config.yaml index 9831b3d41..af7092576 100644 --- a/tests/integration/targets/nxos_bgp_address_family/tests/common/_remove_config.yaml +++ b/tests/integration/targets/nxos_bgp_address_family/tests/common/_remove_config.yaml @@ -1,5 +1,5 @@ --- -- name: Remove pre-existing bgp configurations +- name: Remove pre-existing BGP configurations cisco.nxos.nxos_config: lines: - no router bgp 65536 diff --git a/tests/integration/targets/nxos_bgp_address_family/tests/common/deleted.yaml b/tests/integration/targets/nxos_bgp_address_family/tests/common/deleted.yaml index 2b10e4f8a..5f068d665 100644 --- a/tests/integration/targets/nxos_bgp_address_family/tests/common/deleted.yaml +++ b/tests/integration/targets/nxos_bgp_address_family/tests/common/deleted.yaml @@ -18,7 +18,7 @@ ansible_connection: ansible.netcommon.network_cli - block: - - name: Delete bgp configs handled by this module + - name: Delete BGP configs handled by this module cisco.nxos.nxos_bgp_address_family: config: as_number: 65536 @@ -53,7 +53,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - - name: Delete all bgp configs handled by this module + - name: Delete all BGP configs handled by this module cisco.nxos.nxos_bgp_address_family: &id001 state: deleted register: result @@ -73,7 +73,7 @@ that: - deleted_all['after'] == result['after'] - - name: Delete all bgp configs handled by this module (idempotent) + - name: Delete all BGP configs handled by this module (idempotent) cisco.nxos.nxos_bgp_address_family: *id001 register: result diff --git a/tests/integration/targets/nxos_bgp_address_family/tests/common/empty_config.yaml b/tests/integration/targets/nxos_bgp_address_family/tests/common/empty_config.yaml index 46fd2c30a..5b9ff2f70 100644 --- a/tests/integration/targets/nxos_bgp_address_family/tests/common/empty_config.yaml +++ b/tests/integration/targets/nxos_bgp_address_family/tests/common/empty_config.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxos_bgp_address_family empty_config integration tests on connection={{ ansible_connection }} -- name: Merged with empty config should give appropriate error message +- name: Merged with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_bgp_address_family: @@ -13,7 +13,7 @@ that: - result.msg == 'value of config parameter must not be empty for state merged' -- name: Replaced with empty config should give appropriate error message +- name: Replaced with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_bgp_address_family: @@ -24,7 +24,7 @@ that: - result.msg == 'value of config parameter must not be empty for state replaced' -- name: Overridden with empty config should give appropriate error message +- name: Overridden with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_bgp_address_family: @@ -35,7 +35,7 @@ that: - result.msg == 'value of config parameter must not be empty for state overridden' -- name: Rendered with empty config should give appropriate error message +- name: Rendered with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_bgp_address_family: @@ -46,7 +46,7 @@ that: - result.msg == 'value of config parameter must not be empty for state rendered' -- name: Parsed with empty config should give appropriate error message +- name: Parsed with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_bgp_address_family: diff --git a/tests/integration/targets/nxos_bgp_address_family/tests/common/gathered.yaml b/tests/integration/targets/nxos_bgp_address_family/tests/common/gathered.yaml index ab493f7f2..bc7e63c64 100644 --- a/tests/integration/targets/nxos_bgp_address_family/tests/common/gathered.yaml +++ b/tests/integration/targets/nxos_bgp_address_family/tests/common/gathered.yaml @@ -7,7 +7,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - block: - - name: Gather bgp facts using gathered + - name: Gather BGP facts using gathered register: result cisco.nxos.nxos_bgp_address_family: state: gathered diff --git a/tests/integration/targets/nxos_bgp_address_family/tests/common/overridden.yaml b/tests/integration/targets/nxos_bgp_address_family/tests/common/overridden.yaml index 5ff613ab0..8aa99e45f 100644 --- a/tests/integration/targets/nxos_bgp_address_family/tests/common/overridden.yaml +++ b/tests/integration/targets/nxos_bgp_address_family/tests/common/overridden.yaml @@ -7,7 +7,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - block: - - name: Override all bgp af configuration with provided configuration + - name: Override all BGP AF configuration with provided configuration cisco.nxos.nxos_bgp_address_family: &overridden config: as_number: 65536 @@ -43,7 +43,7 @@ - "{{ overridden['after']['address_family'] | symmetric_difference(result['after']['address_family']) |length == 0 }}" - overridden['after']['as_number'] == result['after']['as_number'] - - name: Replace device configurations of listed ospf processes with provided configurarions (idempotent) + - name: Replace device configurations of listed OSPF processes with provided configurarions (idempotent) register: result cisco.nxos.nxos_bgp_address_family: *overridden diff --git a/tests/integration/targets/nxos_bgp_address_family/tests/common/parsed.yaml b/tests/integration/targets/nxos_bgp_address_family/tests/common/parsed.yaml index 670f0d8ab..6636605aa 100644 --- a/tests/integration/targets/nxos_bgp_address_family/tests/common/parsed.yaml +++ b/tests/integration/targets/nxos_bgp_address_family/tests/common/parsed.yaml @@ -2,13 +2,13 @@ - ansible.builtin.debug: msg: START nxos_bgp_address_family parsed integration tests on connection={{ ansible_connection }} -- name: Parse externally provided bgp config +- name: Parse externally provided BGP configuration register: result cisco.nxos.nxos_bgp_address_family: running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" state: parsed -- name: Assert that config was correctly parsed +- name: Assert that configuration was correctly parsed ansible.builtin.assert: that: - "{{ merged['after']['address_family'] | symmetric_difference(result['parsed']['address_family']) |length == 0 }}" diff --git a/tests/integration/targets/nxos_bgp_address_family/tests/common/rendered.yaml b/tests/integration/targets/nxos_bgp_address_family/tests/common/rendered.yaml index 47b6e583b..2f405b283 100644 --- a/tests/integration/targets/nxos_bgp_address_family/tests/common/rendered.yaml +++ b/tests/integration/targets/nxos_bgp_address_family/tests/common/rendered.yaml @@ -45,7 +45,7 @@ that: - "{{ merged['commands'] | symmetric_difference(result['rendered']) |length == 0 }}" -- name: Gather bgp facts +- name: Gather BGP facts cisco.nxos.nxos_bgp_address_family: state: gathered register: result diff --git a/tests/integration/targets/nxos_bgp_address_family/tests/common/replaced.yaml b/tests/integration/targets/nxos_bgp_address_family/tests/common/replaced.yaml index aa2e6967b..d6cb9d3dc 100644 --- a/tests/integration/targets/nxos_bgp_address_family/tests/common/replaced.yaml +++ b/tests/integration/targets/nxos_bgp_address_family/tests/common/replaced.yaml @@ -48,7 +48,7 @@ - "{{ replaced['after']['address_family'] | symmetric_difference(result['after']['address_family']) |length == 0 }}" - replaced['after']['as_number'] == result['after']['as_number'] - - name: Replace device configurations of listed ospf processes with provided configurarions (idempotent) + - name: Replace device configurations of listed OSPF processes with provided configurarions (idempotent) register: result cisco.nxos.nxos_bgp_address_family: *replaced diff --git a/tests/integration/targets/nxos_bgp_address_family/vars/main.yml b/tests/integration/targets/nxos_bgp_address_family/vars/main.yml index 21a533329..bc245dad7 100644 --- a/tests/integration/targets/nxos_bgp_address_family/vars/main.yml +++ b/tests/integration/targets/nxos_bgp_address_family/vars/main.yml @@ -32,11 +32,11 @@ merged: safi: unicast vrf: site-1 default_information: - originate: True + originate: true aggregate_address: - prefix: 203.0.113.0/24 - as_set: True - summary_only: True + as_set: true + summary_only: true - afi: ipv6 safi: multicast vrf: site-1 @@ -73,8 +73,8 @@ replaced: non_critical_delay: 180 aggregate_address: - prefix: 203.0.113.0/24 - as_set: True - summary_only: True + as_set: true + summary_only: true - afi: ipv4 safi: unicast @@ -116,8 +116,8 @@ overridden: route_map: rmap1 aggregate_address: - prefix: 203.0.113.0/24 - as_set: True - summary_only: True + as_set: true + summary_only: true - afi: ipv4 safi: unicast vrf: site-1 @@ -142,11 +142,11 @@ deleted: safi: unicast vrf: site-1 default_information: - originate: True + originate: true aggregate_address: - prefix: 203.0.113.0/24 - as_set: True - summary_only: True + as_set: true + summary_only: true - afi: ipv4 safi: multicast diff --git a/tests/integration/targets/nxos_bgp_af/defaults/main.yaml b/tests/integration/targets/nxos_bgp_af/defaults/main.yaml deleted file mode 100644 index 525b7aab9..000000000 --- a/tests/integration/targets/nxos_bgp_af/defaults/main.yaml +++ /dev/null @@ -1,5 +0,0 @@ ---- -testcase: "*" -vrfs: - - default - - myvrf diff --git a/tests/integration/targets/nxos_bgp_af/meta/main.yml b/tests/integration/targets/nxos_bgp_af/meta/main.yml deleted file mode 100644 index f504a6ab2..000000000 --- a/tests/integration/targets/nxos_bgp_af/meta/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_nxos_tests diff --git a/tests/integration/targets/nxos_bgp_af/tasks/cli.yaml b/tests/integration/targets/nxos_bgp_af/tasks/cli.yaml deleted file mode 100644 index 90342e6b1..000000000 --- a/tests/integration/targets/nxos_bgp_af/tasks/cli.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect cli test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - connection: local - register: cli_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + cli_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.network_cli) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_bgp_af/tasks/main.yaml b/tests/integration/targets/nxos_bgp_af/tasks/main.yaml deleted file mode 100644 index 62e44ffda..000000000 --- a/tests/integration/targets/nxos_bgp_af/tasks/main.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Include the cli tasks - ansible.builtin.include_tasks: cli.yaml - tags: - - cli - -- name: Include the nx-api tasks - ansible.builtin.include_tasks: nxapi.yaml - tags: - - nxapi diff --git a/tests/integration/targets/nxos_bgp_af/tasks/nxapi.yaml b/tests/integration/targets/nxos_bgp_af/tasks/nxapi.yaml deleted file mode 100644 index cedab80f1..000000000 --- a/tests/integration/targets/nxos_bgp_af/tasks/nxapi.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect nxapi test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/nxapi" - patterns: "{{ testcase }}.yaml" - connection: local - register: nxapi_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + nxapi_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.httpapi) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_bgp_af/tests/common/multisite.yaml b/tests/integration/targets/nxos_bgp_af/tests/common/multisite.yaml deleted file mode 100644 index e53b8675f..000000000 --- a/tests/integration/targets/nxos_bgp_af/tests/common/multisite.yaml +++ /dev/null @@ -1,132 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_bgp_af multisite sanity test - -- name: Enable feature bgp - multisite - ignore_errors: true - cisco.nxos.nxos_feature: - feature: bgp - state: enabled - -- name: Enable feature nv overlay - multisite - ignore_errors: true - cisco.nxos.nxos_feature: - feature: nv overlay - state: enabled - -- name: Setup - multisite - ignore_errors: true - cisco.nxos.nxos_bgp: - asn: 65535 - state: absent - -- name: Enable nv overlay evpn - multisite - when: platform is search('N9K') - ignore_errors: true - cisco.nxos.nxos_config: - lines: - - nv overlay evpn - -- name: Enable multisite border gateway - multisite - ignore_errors: true - register: multiout - cisco.nxos.nxos_config: - lines: - - evpn multisite border-gateway 10 - -- block: - - name: Configure bgp_af route target name - register: result - cisco.nxos.nxos_bgp_af: &id001 - asn: 65535 - afi: l2vpn - safi: evpn - state: present - retain_route_target: abc - - - ansible.builtin.assert: &id002 - that: - - result.changed == true - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp_af: *id001 - - - ansible.builtin.assert: &id004 - that: - - result.changed == false - - - name: Configure bgp_af route target default - register: result - cisco.nxos.nxos_bgp_af: &id003 - asn: 65535 - afi: l2vpn - safi: evpn - state: present - retain_route_target: default - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp_af: *id003 - - - ansible.builtin.assert: *id004 - - - name: Configure bgp_af 1 route target all - register: result - cisco.nxos.nxos_bgp_af: &id005 - asn: 65535 - afi: l2vpn - safi: evpn - state: present - retain_route_target: all - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp_af: *id005 - - - ansible.builtin.assert: *id004 - - - name: Remove bgp - route target - register: result - cisco.nxos.nxos_bgp_af: - asn: 65535 - afi: l2vpn - safi: evpn - retain_route_target: all - state: absent - - - ansible.builtin.assert: *id002 - - - name: Disable multisite border gateway - multisite - cisco.nxos.nxos_config: - lines: - - no evpn multisite border-gateway 10 - when: multiout is not search("Invalid command") - -- name: Disable feature bgp - multisite - ignore_errors: true - cisco.nxos.nxos_feature: - feature: bgp - state: disabled - -- name: Disable feature nv overlay - multisite - ignore_errors: true - cisco.nxos.nxos_feature: - feature: nv overlay - state: disabled - -- ansible.builtin.pause: - seconds: 5 - -- name: Remove nv overlay evpn - multisite - when: platform is search('N9K') - cisco.nxos.nxos_config: - lines: - - no nv overlay evpn - -- ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_bgp_af multisite sanity test diff --git a/tests/integration/targets/nxos_bgp_af/tests/common/sanity.yaml b/tests/integration/targets/nxos_bgp_af/tests/common/sanity.yaml deleted file mode 100644 index 0a9c13573..000000000 --- a/tests/integration/targets/nxos_bgp_af/tests/common/sanity.yaml +++ /dev/null @@ -1,342 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_bgp_af sanity test - -- name: Set a fact for 'advertise_l2vpn_evpn' - ansible.builtin.set_fact: - advertise_l2vpn_evpn: true - when: platform is search('N9K') - -- name: Enable feature bgp - ignore_errors: true - cisco.nxos.nxos_feature: - feature: bgp - state: enabled - -- name: Enable feature nv overlay - ignore_errors: true - cisco.nxos.nxos_feature: - feature: nv overlay - state: enabled - -- name: Setup - ignore_errors: true - cisco.nxos.nxos_bgp: &id012 - asn: 65535 - state: absent - -- block: - - name: Enable nv overlay evpn - when: platform is search('N9K') - cisco.nxos.nxos_config: - lines: - - nv overlay evpn - - - name: Configure bgp_af 1 - register: result - cisco.nxos.nxos_bgp_af: &id001 - asn: 65535 - vrf: testing - afi: ipv4 - safi: unicast - advertise_l2vpn_evpn: "{{advertise_l2vpn_evpn|default(omit)}}" - state: present - - - ansible.builtin.assert: &id002 - that: - - result.changed == true - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp_af: *id001 - - - ansible.builtin.assert: &id004 - that: - - result.changed == false - - - name: Remove bgp - register: result - cisco.nxos.nxos_bgp_af: - asn: 65535 - vrf: testing - afi: ipv4 - safi: unicast - state: absent - - - ansible.builtin.assert: *id002 - - - name: Configure bgp_af 2 - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_af: &id003 - asn: 65535 - vrf: "{{ item }}" - afi: ipv4 - safi: unicast - dampening_state: true - additional_paths_install: true - additional_paths_receive: true - additional_paths_selection: RouteMap - additional_paths_send: true - client_to_client: false - default_information_originate: true - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_af: *id003 - - - ansible.builtin.assert: *id004 - - - name: Configure bgp_af def2 - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_af: &id005 - asn: 65535 - vrf: "{{ item }}" - afi: ipv4 - safi: unicast - dampening_state: false - additional_paths_install: false - additional_paths_receive: false - additional_paths_selection: default - additional_paths_send: false - client_to_client: true - default_information_originate: false - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_af: *id005 - - - ansible.builtin.assert: *id004 - - - name: Remove bgp - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_af: &id008 - asn: 65535 - vrf: "{{ item }}" - afi: ipv4 - safi: unicast - state: absent - - - ansible.builtin.assert: *id002 - - - name: Configure bgp_af 3 - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_af: &id006 - asn: 65535 - vrf: "{{ item }}" - afi: ipv4 - safi: unicast - dampening_routemap: abcd - default_metric: 50 - distance_ebgp: 30 - distance_ibgp: 60 - distance_local: 90 - maximum_paths: 9 - maximum_paths_ibgp: 9 - next_hop_route_map: RouteMap - suppress_inactive: true - table_map: RouteMap - table_map_filter: true - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_af: *id006 - - - ansible.builtin.assert: *id004 - - - name: Configure bgp_af def3 - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_af: &id007 - asn: 65535 - vrf: "{{ item }}" - afi: ipv4 - safi: unicast - dampening_routemap: default - default_metric: default - distance_ebgp: default - distance_ibgp: default - distance_local: default - maximum_paths: default - maximum_paths_ibgp: default - next_hop_route_map: default - suppress_inactive: false - table_map: default - table_map_filter: false - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_af: *id007 - - - ansible.builtin.assert: *id004 - - - name: Remove bgp - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_af: *id008 - - - ansible.builtin.assert: *id002 - - - name: Configure bgp_af 4 - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_af: &id009 - asn: 65535 - vrf: "{{ item }}" - afi: ipv4 - safi: unicast - dampen_igp_metric: 200 - dampening_half_time: 1 - dampening_max_suppress_time: 4 - dampening_reuse_time: 2 - dampening_suppress_time: 3 - inject_map: - - - lax_inject_map - - lax_exist_map - - - nyc_inject_map - - nyc_exist_map - - copy-attributes - - - fsd_inject_map - - fsd_exist_map - networks: - - - 10.0.0.0/16 - - routemap_LA - - - 192.168.1.1/32 - - Chicago - - - 192.168.2.0/24 - - - 192.168.3.0/24 - - routemap_NYC - redistribute: - - - direct - - rm_direct - - - lisp - - rm_lisp - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_af: *id009 - - - ansible.builtin.assert: *id004 - - - name: Configure bgp_af 5 - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_af: &id010 - asn: 65535 - vrf: "{{ item }}" - afi: ipv4 - safi: unicast - dampen_igp_metric: 300 - dampening_half_time: 10 - dampening_max_suppress_time: 40 - dampening_reuse_time: 20 - dampening_suppress_time: 30 - inject_map: - - - fsd_inject_map - - fsd_exist_map - networks: - - - 192.168.2.0/24 - redistribute: - - - lisp - - rm_lisp - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_af: *id010 - - - ansible.builtin.assert: *id004 - - - name: Configure bgp_af def5 - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_af: &id011 - asn: 65535 - vrf: "{{ item }}" - afi: ipv4 - safi: unicast - dampen_igp_metric: default - dampening_half_time: default - dampening_max_suppress_time: default - dampening_reuse_time: default - dampening_suppress_time: default - inject_map: default - networks: default - redistribute: default - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_af: *id011 - - - ansible.builtin.assert: *id004 - - - name: Remove bgp - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_af: *id008 - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_af: *id008 - - - ansible.builtin.assert: *id004 - rescue: - - name: Cleanup bgp - ignore_errors: true - cisco.nxos.nxos_bgp: *id012 - always: - - name: Disable feature bgp - cisco.nxos.nxos_feature: - feature: bgp - state: disabled - - - name: Disable feature nv overlay - ignore_errors: true - cisco.nxos.nxos_feature: - feature: nv overlay - state: disabled - - - ansible.builtin.pause: - seconds: 5 - - - name: Remove nv overlay evpn - when: platform is search('N9K') - cisco.nxos.nxos_config: - lines: - - no nv overlay evpn - - - ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_bgp_af sanity test diff --git a/tests/integration/targets/nxos_bgp_global/meta/main.yml b/tests/integration/targets/nxos_bgp_global/meta/main.yml index e69de29bb..ed97d539c 100644 --- a/tests/integration/targets/nxos_bgp_global/meta/main.yml +++ b/tests/integration/targets/nxos_bgp_global/meta/main.yml @@ -0,0 +1 @@ +--- diff --git a/tests/integration/targets/nxos_bgp_global/tasks/cli.yaml b/tests/integration/targets/nxos_bgp_global/tasks/cli.yaml index 507d803cb..e3e64747b 100644 --- a/tests/integration/targets/nxos_bgp_global/tasks/cli.yaml +++ b/tests/integration/targets/nxos_bgp_global/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_bgp_global/tasks/main.yaml b/tests/integration/targets/nxos_bgp_global/tasks/main.yaml index 9d9af9c38..7e1c3b635 100644 --- a/tests/integration/targets/nxos_bgp_global/tasks/main.yaml +++ b/tests/integration/targets/nxos_bgp_global/tasks/main.yaml @@ -1,5 +1,5 @@ --- -- name: Enable bgp feature +- name: Enable 'feature bgp' cisco.nxos.nxos_feature: feature: bgp vars: @@ -9,19 +9,20 @@ cisco.nxos.nxos_config: lines: feature fabric forwarding -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi always: - - name: Disable bgp feature + - name: Disable 'feature bgp' cisco.nxos.nxos_feature: feature: bgp state: disabled diff --git a/tests/integration/targets/nxos_bgp_global/tasks/nxapi.yaml b/tests/integration/targets/nxos_bgp_global/tasks/nxapi.yaml index 2e452bb6a..4ae68868c 100644 --- a/tests/integration/targets/nxos_bgp_global/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_bgp_global/tasks/nxapi.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_bgp_global/tests/common/_remove_config.yaml b/tests/integration/targets/nxos_bgp_global/tests/common/_remove_config.yaml index 9831b3d41..af7092576 100644 --- a/tests/integration/targets/nxos_bgp_global/tests/common/_remove_config.yaml +++ b/tests/integration/targets/nxos_bgp_global/tests/common/_remove_config.yaml @@ -1,5 +1,5 @@ --- -- name: Remove pre-existing bgp configurations +- name: Remove pre-existing BGP configurations cisco.nxos.nxos_config: lines: - no router bgp 65536 diff --git a/tests/integration/targets/nxos_bgp_global/tests/common/deleted.yaml b/tests/integration/targets/nxos_bgp_global/tests/common/deleted.yaml index fc98c5968..9f9f4dd87 100644 --- a/tests/integration/targets/nxos_bgp_global/tests/common/deleted.yaml +++ b/tests/integration/targets/nxos_bgp_global/tests/common/deleted.yaml @@ -7,7 +7,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - block: - - name: Delete bgp configs handled by this module + - name: Delete BGP configs handled by this module cisco.nxos.nxos_bgp_global: &id001 state: deleted register: result @@ -30,7 +30,7 @@ that: - deleted['after'] == result['after'] - - name: Delete bgp configs handled by this module (idempotent) + - name: Delete BGP configs handled by this module (idempotent) register: result cisco.nxos.nxos_bgp_global: *id001 diff --git a/tests/integration/targets/nxos_bgp_global/tests/common/deleted_af.yaml b/tests/integration/targets/nxos_bgp_global/tests/common/deleted_af.yaml index 750cc5365..32ee63728 100644 --- a/tests/integration/targets/nxos_bgp_global/tests/common/deleted_af.yaml +++ b/tests/integration/targets/nxos_bgp_global/tests/common/deleted_af.yaml @@ -2,13 +2,13 @@ - ansible.builtin.debug: msg: Start nxos_bgp_global deleted_af integration tests connection={{ ansible_connection}} -- name: Remove pre-existing bgp configurations +- name: Remove pre-existing BGP configurations cisco.nxos.nxos_config: &remove lines: - no router bgp 65536 ignore_errors: true -- name: "Setup - 1 (add neighbor with af config)" +- name: "Setup - 1 (add neighbor with AF config)" cisco.nxos.nxos_config: lines: - "router bgp 65536" @@ -26,7 +26,7 @@ - " remote-as 65537" - block: - - name: Remove a neighbor having af configurations (should fail) + - name: Remove a neighbor having AF configurations (should fail) cisco.nxos.nxos_bgp_global: &deleted state: deleted register: result @@ -38,11 +38,11 @@ - result.failed == True - "'Neighbor 203.0.113.2 has address-family configurations. Please use the nxos_bgp_neighbor_af module to remove those first.' in result.msg" - - name: Remove pre-existing bgp configurations + - name: Remove pre-existing BGP configurations cisco.nxos.nxos_config: *remove ignore_errors: true - - name: "Setup - 2 (add neighbor with af config under a vrf)" + - name: "Setup - 2 (add neighbor with AF configuration under a vrf)" cisco.nxos.nxos_config: lines: - "router bgp 65536" @@ -61,7 +61,7 @@ - " low-memory exempt" - " neighbor-down fib-accelerate" - - name: Remove a neighbor under a vrf having af configurations (should fail) + - name: Remove a neighbor under a VRF having AF configurations (should fail) cisco.nxos.nxos_bgp_global: *deleted register: result ignore_errors: true @@ -72,11 +72,11 @@ - result.failed == True - "'VRF site-1 has address-family configurations. Please use the nxos_bgp_af module to remove those first.' in result.msg" - - name: Remove pre-existing bgp configurations + - name: Remove pre-existing BGP configurations cisco.nxos.nxos_config: *remove ignore_errors: true - - name: "Setup - 3 (add a vrf with af config)" + - name: "Setup - 3 (add a VRF with AF config)" cisco.nxos.nxos_config: lines: - "router bgp 65536" @@ -97,7 +97,7 @@ - "vrf site-2" - " neighbor-down fib-accelerate" - - name: Remove a neighbor under a vrf having af configurations (should fail) + - name: Remove a neighbor under a VRF having AF configurations (should fail) cisco.nxos.nxos_bgp_global: *deleted register: result ignore_errors: true @@ -109,5 +109,5 @@ - "'VRF site-1 has address-family configurations. Please use the nxos_bgp_af module to remove those first.' in result.msg" always: - - name: Remove pre-existing bgp configurations + - name: Remove pre-existing BGP configurations cisco.nxos.nxos_config: *remove diff --git a/tests/integration/targets/nxos_bgp_global/tests/common/empty_config.yaml b/tests/integration/targets/nxos_bgp_global/tests/common/empty_config.yaml index 0305bd0cd..05b95e484 100644 --- a/tests/integration/targets/nxos_bgp_global/tests/common/empty_config.yaml +++ b/tests/integration/targets/nxos_bgp_global/tests/common/empty_config.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxos_bgp_global empty_config integration tests on connection={{ ansible_connection }} -- name: Merged with empty config should give appropriate error message +- name: Merged with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_bgp_global: @@ -13,7 +13,7 @@ that: - result.msg == 'value of config parameter must not be empty for state merged' -- name: Replaced with empty config should give appropriate error message +- name: Replaced with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_bgp_global: @@ -24,7 +24,7 @@ that: - result.msg == 'value of config parameter must not be empty for state replaced' -- name: Rendered with empty config should give appropriate error message +- name: Rendered with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_bgp_global: @@ -35,7 +35,7 @@ that: - result.msg == 'value of config parameter must not be empty for state rendered' -- name: Parsed with empty config should give appropriate error message +- name: Parsed with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_bgp_global: diff --git a/tests/integration/targets/nxos_bgp_global/tests/common/gathered.yaml b/tests/integration/targets/nxos_bgp_global/tests/common/gathered.yaml index 073df3341..7b4d28a51 100644 --- a/tests/integration/targets/nxos_bgp_global/tests/common/gathered.yaml +++ b/tests/integration/targets/nxos_bgp_global/tests/common/gathered.yaml @@ -7,7 +7,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - block: - - name: Gather bgp facts using gathered + - name: Gather BGP facts using gathered register: result cisco.nxos.nxos_bgp_global: state: gathered diff --git a/tests/integration/targets/nxos_bgp_global/tests/common/parsed.yaml b/tests/integration/targets/nxos_bgp_global/tests/common/parsed.yaml index f27bf52ab..73da9ca88 100644 --- a/tests/integration/targets/nxos_bgp_global/tests/common/parsed.yaml +++ b/tests/integration/targets/nxos_bgp_global/tests/common/parsed.yaml @@ -2,13 +2,13 @@ - ansible.builtin.debug: msg: START nxos_bgp_global parsed integration tests on connection={{ ansible_connection }} -- name: Parse externally provided bgp config +- name: Parse externally provided BGP configuration register: result cisco.nxos.nxos_bgp_global: running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" state: parsed -- name: Assert that config was correctly parsed +- name: Assert that configuration was correctly parsed ansible.builtin.assert: that: - merged['after'] == result['parsed'] diff --git a/tests/integration/targets/nxos_bgp_global/tests/common/purged.yaml b/tests/integration/targets/nxos_bgp_global/tests/common/purged.yaml index eaffe33ce..c0288a5bc 100644 --- a/tests/integration/targets/nxos_bgp_global/tests/common/purged.yaml +++ b/tests/integration/targets/nxos_bgp_global/tests/common/purged.yaml @@ -7,7 +7,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - block: - - name: Delete all bgp config from the device + - name: Delete all BGP configuration from the device cisco.nxos.nxos_bgp_global: &id001 state: purged register: result @@ -28,7 +28,7 @@ that: - result['after'] == {} - - name: Delete all bgp config from the device (idempotent) + - name: Delete all BGP configuration from the device (idempotent) register: result cisco.nxos.nxos_bgp_global: *id001 diff --git a/tests/integration/targets/nxos_bgp_global/tests/common/rendered.yaml b/tests/integration/targets/nxos_bgp_global/tests/common/rendered.yaml index dc50866d4..af3505fbe 100644 --- a/tests/integration/targets/nxos_bgp_global/tests/common/rendered.yaml +++ b/tests/integration/targets/nxos_bgp_global/tests/common/rendered.yaml @@ -60,7 +60,7 @@ that: - merged['commands'] == result['rendered'] -- name: Gather bgp facts +- name: Gather BGP facts cisco.nxos.nxos_bgp_global: state: gathered register: result diff --git a/tests/integration/targets/nxos_bgp_global/tests/common/replaced.yaml b/tests/integration/targets/nxos_bgp_global/tests/common/replaced.yaml index 3dbc13f6e..62ea0ca50 100644 --- a/tests/integration/targets/nxos_bgp_global/tests/common/replaced.yaml +++ b/tests/integration/targets/nxos_bgp_global/tests/common/replaced.yaml @@ -7,7 +7,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - block: - - name: Replace bgp configuration with provided configuration + - name: Replace BGP configuration with provided configuration cisco.nxos.nxos_bgp_global: &id001 config: as_number: 65536 @@ -58,7 +58,7 @@ that: - merged['after'] == result['before'] - - name: Replace device configurations of listed ospf processes with provided configurarions (idempotent) + - name: Replace device configurations of listed OSPF processes with provided configurarions (idempotent) register: result cisco.nxos.nxos_bgp_global: *id001 diff --git a/tests/integration/targets/nxos_bgp_global/tests/common/replaced_af.yaml b/tests/integration/targets/nxos_bgp_global/tests/common/replaced_af.yaml index ff4c0c27e..c6e280686 100644 --- a/tests/integration/targets/nxos_bgp_global/tests/common/replaced_af.yaml +++ b/tests/integration/targets/nxos_bgp_global/tests/common/replaced_af.yaml @@ -2,13 +2,13 @@ - ansible.builtin.debug: msg: Start nxos_bgp_global replaced_af integration tests connection={{ ansible_connection}} -- name: Remove pre-existing bgp configurations +- name: Remove pre-existing BGP configurations cisco.nxos.nxos_config: &remove lines: - no router bgp 65536 ignore_errors: true -- name: "Setup - 1 (add neighbor with af config)" +- name: "Setup - 1 (add neighbor with AF config)" cisco.nxos.nxos_config: lines: - "router bgp 65536" @@ -26,7 +26,7 @@ - " remote-as 65537" - block: - - name: Remove a neighbor having af configurations (should fail) + - name: Remove a neighbor having AF configurations (should fail) cisco.nxos.nxos_bgp_global: config: as_number: 65536 @@ -46,11 +46,11 @@ - result.failed == True - "'Neighbor 203.0.113.2 has address-family configurations. Please use the nxos_bgp_neighbor_af module to remove those first.' in result.msg" - - name: Remove pre-existing bgp configurations + - name: Remove pre-existing BGP configurations cisco.nxos.nxos_config: *remove ignore_errors: true - - name: "Setup - 2 (add neighbor with af config under a vrf)" + - name: "Setup - 2 (add neighbor with AF configuration under a vrf)" cisco.nxos.nxos_config: lines: - "router bgp 65536" @@ -69,7 +69,7 @@ - " low-memory exempt" - " neighbor-down fib-accelerate" - - name: Remove a neighbor under a vrf having af configurations (should fail) + - name: Remove a neighbor under a VRF having AF configurations (should fail) cisco.nxos.nxos_bgp_global: config: as_number: 65536 @@ -93,11 +93,11 @@ - result.failed == True - "'Neighbor 203.0.113.2 has address-family configurations. Please use the nxos_bgp_neighbor_af module to remove those first.' in result.msg" - - name: Remove pre-existing bgp configurations + - name: Remove pre-existing BGP configurations cisco.nxos.nxos_config: *remove ignore_errors: true - - name: "Setup - 3 (add a vrf with af config)" + - name: "Setup - 3 (add a VRF with AF config)" cisco.nxos.nxos_config: lines: - "router bgp 65536" @@ -117,7 +117,7 @@ - "vrf site-2" - " neighbor-down fib-accelerate" - - name: Remove a vrf having af configurations (should fail) + - name: Remove a VRF having AF configurations (should fail) cisco.nxos.nxos_bgp_global: config: as_number: 65536 @@ -142,5 +142,5 @@ - "'VRF site-1 has address-family configurations. Please use the nxos_bgp_af module to remove those first.' in result.msg" always: - - name: Remove pre-existing bgp configurations + - name: Remove pre-existing BGP configurations cisco.nxos.nxos_config: *remove diff --git a/tests/integration/targets/nxos_bgp_global/tests/common/sanity.yaml b/tests/integration/targets/nxos_bgp_global/tests/common/sanity.yaml index 64c76ea95..8ed423f3d 100644 --- a/tests/integration/targets/nxos_bgp_global/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_bgp_global/tests/common/sanity.yaml @@ -7,7 +7,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - block: - - name: Replace bgp configuration with different asn (should fail) + - name: Replace BGP configuration with different asn (should fail) cisco.nxos.nxos_bgp_global: config: as_number: "65538" @@ -24,7 +24,7 @@ - result.failed == True - "'BGP is already configured with ASN 65536. Please remove it with state purged before configuring new ASN' in result.msg" - - name: Merge bgp configuration with different asn (should fail) + - name: Merge BGP configuration with different asn (should fail) cisco.nxos.nxos_bgp_global: config: as_number: "65538" diff --git a/tests/integration/targets/nxos_bgp_neighbor/defaults/main.yaml b/tests/integration/targets/nxos_bgp_neighbor/defaults/main.yaml deleted file mode 100644 index 525b7aab9..000000000 --- a/tests/integration/targets/nxos_bgp_neighbor/defaults/main.yaml +++ /dev/null @@ -1,5 +0,0 @@ ---- -testcase: "*" -vrfs: - - default - - myvrf diff --git a/tests/integration/targets/nxos_bgp_neighbor/meta/main.yml b/tests/integration/targets/nxos_bgp_neighbor/meta/main.yml deleted file mode 100644 index f504a6ab2..000000000 --- a/tests/integration/targets/nxos_bgp_neighbor/meta/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_nxos_tests diff --git a/tests/integration/targets/nxos_bgp_neighbor/tasks/cli.yaml b/tests/integration/targets/nxos_bgp_neighbor/tasks/cli.yaml deleted file mode 100644 index 90342e6b1..000000000 --- a/tests/integration/targets/nxos_bgp_neighbor/tasks/cli.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect cli test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - connection: local - register: cli_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + cli_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.network_cli) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_bgp_neighbor/tasks/main.yaml b/tests/integration/targets/nxos_bgp_neighbor/tasks/main.yaml deleted file mode 100644 index 62e44ffda..000000000 --- a/tests/integration/targets/nxos_bgp_neighbor/tasks/main.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Include the cli tasks - ansible.builtin.include_tasks: cli.yaml - tags: - - cli - -- name: Include the nx-api tasks - ansible.builtin.include_tasks: nxapi.yaml - tags: - - nxapi diff --git a/tests/integration/targets/nxos_bgp_neighbor/tasks/nxapi.yaml b/tests/integration/targets/nxos_bgp_neighbor/tasks/nxapi.yaml deleted file mode 100644 index cedab80f1..000000000 --- a/tests/integration/targets/nxos_bgp_neighbor/tasks/nxapi.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect nxapi test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/nxapi" - patterns: "{{ testcase }}.yaml" - connection: local - register: nxapi_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + nxapi_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.httpapi) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_bgp_neighbor/tests/common/multisite.yaml b/tests/integration/targets/nxos_bgp_neighbor/tests/common/multisite.yaml deleted file mode 100644 index d3a8b68b6..000000000 --- a/tests/integration/targets/nxos_bgp_neighbor/tests/common/multisite.yaml +++ /dev/null @@ -1,123 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_bgp_neighbor multisite sanity test - -- name: Set a fact for 'intname' - ansible.builtin.set_fact: - intname: "{{ nxos_int1 }}" - -- name: "Setup: disable features - multisite" - loop: - - bgp - - bfd - - nv overlay - ignore_errors: true - cisco.nxos.nxos_feature: - feature: "{{ item }}" - state: disabled - -- name: "Setup: enable features - multisite" - loop: - - bgp - - bfd - - nv overlay - ignore_errors: true - cisco.nxos.nxos_feature: - feature: "{{ item }}" - state: enabled - -- name: Enable nv overlay evpn - multisite - when: platform is search('N9K') - ignore_errors: true - cisco.nxos.nxos_config: - lines: - - nv overlay evpn - -- name: Enable multisite border gateway - multisite - ignore_errors: true - register: multiout - cisco.nxos.nxos_config: - lines: - - evpn multisite border-gateway 10 - -- block: - - name: Configure bgp neighbor1 - multisite - register: result - cisco.nxos.nxos_bgp_neighbor: &id001 - asn: 65535 - neighbor: 192.0.2.3/32 - remote_as: 33.22 - description: just a description - shutdown: true - state: present - peer_type: fabric_border_leaf - - - ansible.builtin.assert: &id002 - that: - - result.changed == true - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp_neighbor: *id001 - - - ansible.builtin.assert: &id004 - that: - - result.changed == false - - - name: Configure bgp neighbor2 - multisite - register: result - cisco.nxos.nxos_bgp_neighbor: &id003 - asn: 65535 - neighbor: 192.0.2.3/32 - peer_type: disable - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp_neighbor: *id003 - - - ansible.builtin.assert: *id004 - - - name: Configure bgp neighbor3 - multisite - register: result - cisco.nxos.nxos_bgp_neighbor: &id005 - asn: 65535 - neighbor: 192.0.2.3/32 - peer_type: fabric_external - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp_neighbor: *id005 - - - ansible.builtin.assert: *id004 - - - name: Disable multisite border gateway - multisite - cisco.nxos.nxos_config: - lines: - - no evpn multisite border-gateway 10 - when: multiout is not search("Invalid command") - -- name: "Teardown: disable features" - loop: - - bgp - - bfd - - nv overlay - ignore_errors: true - cisco.nxos.nxos_feature: - feature: "{{ item }}" - state: disabled - -- ansible.builtin.pause: - seconds: 5 - -- name: Remove nv overlay evpn - multisite - when: platform is search('N9K') - cisco.nxos.nxos_config: - lines: - - no nv overlay evpn - -- ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_bgp_neighbor multisite sanity test diff --git a/tests/integration/targets/nxos_bgp_neighbor/tests/common/sanity.yaml b/tests/integration/targets/nxos_bgp_neighbor/tests/common/sanity.yaml deleted file mode 100644 index a342920e4..000000000 --- a/tests/integration/targets/nxos_bgp_neighbor/tests/common/sanity.yaml +++ /dev/null @@ -1,357 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_bgp_neighbor sanity test - -- name: Set a fact for 'intname' - ansible.builtin.set_fact: - intname: "{{ nxos_int1 }}" - -- name: Set a fact for 'log_neighbor_changese' - ansible.builtin.set_fact: - log_neighbor_changese: enable - when: (imagetag and imagetag is not search("D1|N1")) - -- name: Set a fact for 'log_neighbor_changesd' - ansible.builtin.set_fact: - log_neighbor_changesd: disable - when: (imagetag and imagetag is not search("D1|N1")) - -- ansible.builtin.debug: - var: titanium - -- name: Set a fact for 'remove_private_asa' - ansible.builtin.set_fact: - remove_private_asa: all - when: not titanium - -- name: Set a fact for 'remove_private_asr' - ansible.builtin.set_fact: - remove_private_asr: replace-as - when: not titanium - -- name: "Setup: disable features" - loop: - - bgp - - bfd - ignore_errors: true - cisco.nxos.nxos_feature: - feature: "{{ item }}" - state: disabled - -- name: "Setup: enable features" - loop: - - bgp - - bfd - cisco.nxos.nxos_feature: - feature: "{{ item }}" - state: enabled - -- block: - - name: Configure bgp neighbor1 - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: &id001 - asn: 65535 - neighbor: 192.0.2.3/32 - vrf: "{{ item }}" - connected_check: true - capability_negotiation: true - dynamic_capability: true - ebgp_multihop: 2 - low_memory_exempt: true - maximum_peers: 10 - suppress_4_byte_as: true - timers_keepalive: 90 - timers_holdtime: 270 - log_neighbor_changes: "{{log_neighbor_changese|default(omit)}}" - local_as: 22.33 - remote_as: 33.22 - description: just a description - update_source: "{{ intname.capitalize() }}" - shutdown: true - state: present - - - ansible.builtin.assert: &id002 - that: - - result.changed == true - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: *id001 - - - ansible.builtin.assert: &id004 - that: - - result.changed == false - - - name: Configure bgp neighbor2 - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: &id003 - asn: 65535 - neighbor: 192.0.2.3/32 - vrf: "{{ item }}" - connected_check: false - capability_negotiation: false - dynamic_capability: false - ebgp_multihop: default - low_memory_exempt: false - maximum_peers: default - suppress_4_byte_as: false - timers_keepalive: default - timers_holdtime: default - log_neighbor_changes: "{{log_neighbor_changesd|default(omit)}}" - local_as: default - remote_as: default - description: default - update_source: default - shutdown: false - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: *id003 - - - ansible.builtin.assert: *id004 - - - name: Remove bgp - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: &id005 - asn: 65535 - neighbor: 192.0.2.3/32 - vrf: "{{ item }}" - state: absent - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: *id005 - - - ansible.builtin.assert: *id004 - - - name: Configure bgp neighbor3 - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: &id006 - asn: 65535 - neighbor: 192.0.2.3/32 - vrf: "{{ item }}" - description: tested by ansible - remove_private_as: "{{remove_private_asa|default(omit)}}" - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: *id006 - - - ansible.builtin.assert: *id004 - - - name: Configure bgp neighbor4 - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: &id007 - asn: 65535 - neighbor: 192.0.2.3/32 - vrf: "{{ item }}" - description: tested by ansible - remove_private_as: "{{remove_private_asr|default(omit)}}" - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: *id007 - - - ansible.builtin.assert: *id004 - - - name: Remove bgp - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: *id005 - - - ansible.builtin.assert: *id002 - - - name: Configure bgp neighbor 3des password - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: &id008 - asn: 65535 - neighbor: 192.0.2.3/32 - vrf: "{{ item }}" - remote_as: 30 - pwd: 386c0565965f89de - pwd_type: 3des - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: *id008 - - - ansible.builtin.assert: *id004 - - - name: Remove bgp - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: *id005 - - - ansible.builtin.assert: *id002 - - - name: Configure bgp neighbor type 7 password - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: &id009 - asn: 65535 - neighbor: 192.0.2.3/32 - vrf: "{{ item }}" - remote_as: 30 - pwd: 386c0565965f89de - pwd_type: cisco_type_7 - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: *id009 - - - ansible.builtin.assert: *id004 - - - name: Remove bgp neighbor password - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: &id010 - asn: 65535 - neighbor: 192.0.2.3/32 - vrf: "{{ item }}" - remote_as: 30 - pwd: default - pwd_type: default - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: *id010 - - - ansible.builtin.assert: *id004 - - - name: Remove bgp - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: *id005 - - - ansible.builtin.assert: *id002 - - - name: Configure bgp neighbor transport type passive - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: &id011 - asn: 65535 - neighbor: 192.0.2.3 - vrf: "{{ item }}" - remote_as: 30 - transport_passive_only: true - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: *id011 - - - ansible.builtin.assert: *id004 - - - name: Configure bgp neighbor transport type default - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: &id012 - asn: 65535 - neighbor: 192.0.2.3 - vrf: "{{ item }}" - remote_as: 30 - transport_passive_only: false - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: *id012 - - - ansible.builtin.assert: *id004 - - - name: Remove bgp - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: &id013 - asn: 65535 - neighbor: 192.0.2.3 - vrf: "{{ item }}" - state: absent - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_bgp_neighbor: *id013 - - - ansible.builtin.assert: *id004 - - - name: Configure bfd enable - register: result - cisco.nxos.nxos_bgp_neighbor: &id014 - asn: 65535 - neighbor: 192.168.1.1 - bfd: enable - state: present - - - ansible.builtin.assert: *id002 - - - name: Check bfd enable idempotence - register: result - cisco.nxos.nxos_bgp_neighbor: *id014 - - - ansible.builtin.assert: *id004 - - - name: Configure bfd disable idempotence - register: result - cisco.nxos.nxos_bgp_neighbor: &id015 - asn: 65535 - neighbor: 192.168.1.1 - bfd: disable - state: present - - - ansible.builtin.assert: *id002 - - - name: Check bfd disable idempotence - register: result - cisco.nxos.nxos_bgp_neighbor: *id015 - - - ansible.builtin.assert: *id004 - always: - - name: "Teardown: disable features" - loop: - - bgp - - bfd - ignore_errors: true - cisco.nxos.nxos_feature: - feature: "{{ item }}" - state: disabled - -- ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_bgp_neighbor sanity test diff --git a/tests/integration/targets/nxos_bgp_neighbor_address_family/meta/main.yml b/tests/integration/targets/nxos_bgp_neighbor_address_family/meta/main.yml index e69de29bb..ed97d539c 100644 --- a/tests/integration/targets/nxos_bgp_neighbor_address_family/meta/main.yml +++ b/tests/integration/targets/nxos_bgp_neighbor_address_family/meta/main.yml @@ -0,0 +1 @@ +--- diff --git a/tests/integration/targets/nxos_bgp_neighbor_address_family/tasks/cli.yaml b/tests/integration/targets/nxos_bgp_neighbor_address_family/tasks/cli.yaml index 507d803cb..e3e64747b 100644 --- a/tests/integration/targets/nxos_bgp_neighbor_address_family/tasks/cli.yaml +++ b/tests/integration/targets/nxos_bgp_neighbor_address_family/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_bgp_neighbor_address_family/tasks/main.yaml b/tests/integration/targets/nxos_bgp_neighbor_address_family/tasks/main.yaml index 55f769a3b..13eaed64c 100644 --- a/tests/integration/targets/nxos_bgp_neighbor_address_family/tasks/main.yaml +++ b/tests/integration/targets/nxos_bgp_neighbor_address_family/tasks/main.yaml @@ -1,23 +1,24 @@ --- -- name: Enable bgp feature +- name: Enable BGP feature cisco.nxos.nxos_feature: feature: bgp vars: ansible_connection: ansible.netcommon.network_cli -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi always: - - name: Disable bgp feature + - name: Disable BGP feature cisco.nxos.nxos_feature: feature: bgp state: disabled diff --git a/tests/integration/targets/nxos_bgp_neighbor_address_family/tasks/nxapi.yaml b/tests/integration/targets/nxos_bgp_neighbor_address_family/tasks/nxapi.yaml index 2e452bb6a..4ae68868c 100644 --- a/tests/integration/targets/nxos_bgp_neighbor_address_family/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_bgp_neighbor_address_family/tasks/nxapi.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/_populate_config.yaml b/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/_populate_config.yaml index 77e88dec7..15c070713 100644 --- a/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/_populate_config.yaml +++ b/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/_populate_config.yaml @@ -1,5 +1,5 @@ --- -- name: Populate config +- name: Populate configuration cisco.nxos.nxos_bgp_neighbor_address_family: config: as_number: 65536 diff --git a/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/_remove_config.yaml b/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/_remove_config.yaml index 9831b3d41..af7092576 100644 --- a/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/_remove_config.yaml +++ b/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/_remove_config.yaml @@ -1,5 +1,5 @@ --- -- name: Remove pre-existing bgp configurations +- name: Remove pre-existing BGP configurations cisco.nxos.nxos_config: lines: - no router bgp 65536 diff --git a/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/deleted.yaml b/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/deleted.yaml index 03c826ae7..7428ad835 100644 --- a/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/deleted.yaml +++ b/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/deleted.yaml @@ -7,7 +7,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - block: - - name: Delete bgp configs handled by this module + - name: Delete BGP configs handled by this module cisco.nxos.nxos_bgp_neighbor_address_family: config: as_number: 65536 @@ -49,7 +49,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - - name: Delete all bgp neighbor af configs handled by this module + - name: Delete all BGP neighbor AF configs handled by this module cisco.nxos.nxos_bgp_neighbor_address_family: &deleted_all state: deleted register: result @@ -64,7 +64,7 @@ that: - deleted_all['after'] == result['after'] - - name: Delete all bgp neighbor af configs (idempotent) + - name: Delete all BGP neighbor AF configs (idempotent) cisco.nxos.nxos_bgp_neighbor_address_family: *deleted_all register: result diff --git a/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/empty_config.yaml b/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/empty_config.yaml index efb9bbcf0..5128d38cd 100644 --- a/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/empty_config.yaml +++ b/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/empty_config.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxos_bgp_neighbor_address_family empty_config integration tests on connection={{ ansible_connection }} -- name: Merged with empty config should give appropriate error message +- name: Merged with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_bgp_neighbor_address_family: @@ -13,7 +13,7 @@ that: - result.msg == 'value of config parameter must not be empty for state merged' -- name: Replaced with empty config should give appropriate error message +- name: Replaced with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_bgp_neighbor_address_family: @@ -24,7 +24,7 @@ that: - result.msg == 'value of config parameter must not be empty for state replaced' -- name: Overridden with empty config should give appropriate error message +- name: Overridden with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_bgp_neighbor_address_family: @@ -35,7 +35,7 @@ that: - result.msg == 'value of config parameter must not be empty for state overridden' -- name: Rendered with empty config should give appropriate error message +- name: Rendered with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_bgp_neighbor_address_family: @@ -46,7 +46,7 @@ that: - result.msg == 'value of config parameter must not be empty for state rendered' -- name: Parsed with empty config should give appropriate error message +- name: Parsed with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_bgp_neighbor_address_family: diff --git a/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/gathered.yaml b/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/gathered.yaml index 330e340e7..05bce177a 100644 --- a/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/gathered.yaml +++ b/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/gathered.yaml @@ -7,7 +7,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - block: - - name: Gather bgp facts using gathered + - name: Gather BGP facts using gathered register: result cisco.nxos.nxos_bgp_neighbor_address_family: state: gathered diff --git a/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/overridden.yaml b/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/overridden.yaml index cd6ece9a0..c83481b22 100644 --- a/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/overridden.yaml +++ b/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/overridden.yaml @@ -7,7 +7,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - block: - - name: Override all bgp af configuration with provided configuration + - name: Override all BGP AF configuration with provided configuration cisco.nxos.nxos_bgp_neighbor_address_family: &overridden config: as_number: 65536 @@ -48,7 +48,7 @@ - "{{ overridden['after']['vrfs'] | symmetric_difference(result['after']['vrfs']) |length == 0 }}" - overridden['after']['as_number'] == result['after']['as_number'] - - name: Override all bgp af configuration with provided configuration (idempotent) + - name: Override all BGP AF configuration with provided configuration (idempotent) register: result cisco.nxos.nxos_bgp_neighbor_address_family: *overridden diff --git a/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/parsed.yaml b/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/parsed.yaml index a98b646bf..299c0e099 100644 --- a/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/parsed.yaml +++ b/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/parsed.yaml @@ -2,13 +2,13 @@ - ansible.builtin.debug: msg: START nxos_bgp_neighbor_address_family parsed integration tests on connection={{ ansible_connection }} -- name: Parse externally provided bgp config +- name: Parse externally provided BGP configuration register: result cisco.nxos.nxos_bgp_neighbor_address_family: running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" state: parsed -- name: Assert that config was correctly parsed +- name: Assert that configuration was correctly parsed ansible.builtin.assert: that: - "{{ merged['after']['neighbors'] | symmetric_difference(result['parsed']['neighbors']) |length == 0 }}" diff --git a/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/rendered.yaml b/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/rendered.yaml index af6681a65..5b2c47de7 100644 --- a/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/rendered.yaml +++ b/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/rendered.yaml @@ -53,7 +53,7 @@ that: - "{{ merged['commands'] | symmetric_difference(result['rendered']) |length == 0 }}" -- name: Gather bgp facts +- name: Gather BGP facts cisco.nxos.nxos_bgp_neighbor_address_family: state: gathered register: result diff --git a/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/replaced.yaml b/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/replaced.yaml index cf61ef724..1b90933b1 100644 --- a/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/replaced.yaml +++ b/tests/integration/targets/nxos_bgp_neighbor_address_family/tests/common/replaced.yaml @@ -63,7 +63,7 @@ - "{{ replaced['after']['vrfs'] | symmetric_difference(result['after']['vrfs']) |length == 0 }}" - replaced['after']['as_number'] == result['after']['as_number'] - - name: Replace device configurations of listed ospf processes with provided configurarions (idempotent) + - name: Replace device configurations of listed OSPF processes with provided configurarions (idempotent) register: result cisco.nxos.nxos_bgp_neighbor_address_family: *replaced diff --git a/tests/integration/targets/nxos_bgp_neighbor_address_family/vars/main.yml b/tests/integration/targets/nxos_bgp_neighbor_address_family/vars/main.yml index 13ce69a47..894dcbd07 100644 --- a/tests/integration/targets/nxos_bgp_neighbor_address_family/vars/main.yml +++ b/tests/integration/targets/nxos_bgp_neighbor_address_family/vars/main.yml @@ -59,7 +59,7 @@ merged: - afi: ipv4 safi: multicast send_community: - standard: True + standard: true - afi: ipv6 safi: unicast @@ -106,7 +106,7 @@ replaced: - afi: ipv4 safi: multicast send_community: - standard: True + standard: true - afi: ipv6 safi: unicast @@ -140,9 +140,9 @@ overridden: address_family: - afi: ipv4 safi: unicast - suppress_inactive: True + suppress_inactive: true next_hop_self: - set: True + set: true deleted: commands: @@ -181,7 +181,7 @@ deleted: - afi: ipv4 safi: multicast send_community: - standard: True + standard: true deleted_all: commands: diff --git a/tests/integration/targets/nxos_bgp_neighbor_af/defaults/main.yaml b/tests/integration/targets/nxos_bgp_neighbor_af/defaults/main.yaml deleted file mode 100644 index 5f709c5aa..000000000 --- a/tests/integration/targets/nxos_bgp_neighbor_af/defaults/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -testcase: "*" diff --git a/tests/integration/targets/nxos_bgp_neighbor_af/meta/main.yml b/tests/integration/targets/nxos_bgp_neighbor_af/meta/main.yml deleted file mode 100644 index f504a6ab2..000000000 --- a/tests/integration/targets/nxos_bgp_neighbor_af/meta/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_nxos_tests diff --git a/tests/integration/targets/nxos_bgp_neighbor_af/tasks/cli.yaml b/tests/integration/targets/nxos_bgp_neighbor_af/tasks/cli.yaml deleted file mode 100644 index 90342e6b1..000000000 --- a/tests/integration/targets/nxos_bgp_neighbor_af/tasks/cli.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect cli test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - connection: local - register: cli_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + cli_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.network_cli) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_bgp_neighbor_af/tasks/main.yaml b/tests/integration/targets/nxos_bgp_neighbor_af/tasks/main.yaml deleted file mode 100644 index 62e44ffda..000000000 --- a/tests/integration/targets/nxos_bgp_neighbor_af/tasks/main.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Include the cli tasks - ansible.builtin.include_tasks: cli.yaml - tags: - - cli - -- name: Include the nx-api tasks - ansible.builtin.include_tasks: nxapi.yaml - tags: - - nxapi diff --git a/tests/integration/targets/nxos_bgp_neighbor_af/tasks/nxapi.yaml b/tests/integration/targets/nxos_bgp_neighbor_af/tasks/nxapi.yaml deleted file mode 100644 index cedab80f1..000000000 --- a/tests/integration/targets/nxos_bgp_neighbor_af/tasks/nxapi.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect nxapi test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/nxapi" - patterns: "{{ testcase }}.yaml" - connection: local - register: nxapi_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + nxapi_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.httpapi) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_bgp_neighbor_af/tests/common/multisite.yaml b/tests/integration/targets/nxos_bgp_neighbor_af/tests/common/multisite.yaml deleted file mode 100644 index 35b67ecac..000000000 --- a/tests/integration/targets/nxos_bgp_neighbor_af/tests/common/multisite.yaml +++ /dev/null @@ -1,117 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_bgp_neighbor_af multisite sanity test - -- name: Set a fact for 'soft_reconfiguration_ina' - ansible.builtin.set_fact: - soft_reconfiguration_ina: always - when: imagetag is not search("D1|N1") - -- name: Disable feature bgp - multisite - ignore_errors: true - cisco.nxos.nxos_feature: - feature: bgp - state: disabled - -- name: Enable feature bgp - multisite - ignore_errors: true - cisco.nxos.nxos_feature: - feature: bgp - state: enabled - -- name: Enable feature nv overlay - multisite - ignore_errors: true - cisco.nxos.nxos_feature: - feature: nv overlay - state: enabled - -- name: Enable nv overlay evpn - multisite - when: platform is search('N9K') - cisco.nxos.nxos_config: - lines: - - nv overlay evpn - -- name: Enable multisite border gateway - multisite - ignore_errors: true - register: multiout - cisco.nxos.nxos_config: - lines: - - evpn multisite border-gateway 10 - -- block: - - name: Configure ebgp - multisite - cisco.nxos.nxos_bgp_neighbor: - asn: 65535 - neighbor: 192.0.2.3 - remote_as: 2 - - - name: Configure bgp neighbor - multisite - register: result - cisco.nxos.nxos_bgp_neighbor_af: &id001 - asn: 65535 - neighbor: 192.0.2.3 - afi: l2vpn - safi: evpn - send_community: standard - rewrite_evpn_rt_asn: true - state: present - - - ansible.builtin.assert: &id002 - that: - - result.changed == true - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp_neighbor_af: *id001 - - - ansible.builtin.assert: &id004 - that: - - result.changed == false - - - name: Configure bgp neighbor 1 - multisite - register: result - cisco.nxos.nxos_bgp_neighbor_af: &id003 - asn: 65535 - neighbor: 192.0.2.3 - afi: l2vpn - safi: evpn - send_community: standard - rewrite_evpn_rt_asn: false - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp_neighbor_af: *id003 - - - ansible.builtin.assert: *id004 - - - name: Disable multisite border gateway - multisite - cisco.nxos.nxos_config: - lines: - - no evpn multisite border-gateway 10 - when: multiout is not search("Invalid command") - -- name: Disable feature bgp - multisite - cisco.nxos.nxos_feature: - feature: bgp - state: disabled - -- name: Disable feature nv overlay - multisite - ignore_errors: true - cisco.nxos.nxos_feature: - feature: nv overlay - state: disabled - -- ansible.builtin.pause: - seconds: 5 - -- name: Remove nv overlay evpn - multisite - when: platform is search('N9K') - cisco.nxos.nxos_config: - lines: - - no nv overlay evpn - -- ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_bgp_neighbor_af multisite sanity test diff --git a/tests/integration/targets/nxos_bgp_neighbor_af/tests/common/sanity.yaml b/tests/integration/targets/nxos_bgp_neighbor_af/tests/common/sanity.yaml deleted file mode 100644 index 64f018b77..000000000 --- a/tests/integration/targets/nxos_bgp_neighbor_af/tests/common/sanity.yaml +++ /dev/null @@ -1,295 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_bgp_neighbor_af sanity test - -- name: Set a fact for 'soft_reconfiguration_ina' - ansible.builtin.set_fact: - soft_reconfiguration_ina: always - when: imagetag is not search("D1|N1") - -- name: Disable feature bgp - ignore_errors: true - cisco.nxos.nxos_feature: &id013 - feature: bgp - state: disabled - -- name: Enable feature bgp - ignore_errors: true - cisco.nxos.nxos_feature: - feature: bgp - state: enabled - -- block: - - name: Configure bgp neighbor address-family - register: result - cisco.nxos.nxos_bgp_neighbor_af: &id001 - asn: 65535 - neighbor: 192.0.2.3 - afi: ipv4 - safi: unicast - additional_paths_receive: enable - additional_paths_send: enable - advertise_map_exist: - - ansible_rm - - my_exist_map - allowas_in: true - default_originate: true - disable_peer_as_check: true - filter_list_in: my_filter_list_in - filter_list_out: my_filter_list_out - max_prefix_limit: 100 - max_prefix_threshold: 50 - max_prefix_warning: "true" - next_hop_self: true - next_hop_third_party: false - prefix_list_in: pfx_in - prefix_list_out: pfx_out - send_community: both - soft_reconfiguration_in: enable - suppress_inactive: true - unsuppress_map: unsup_map - weight: "30" - state: present - - - ansible.builtin.assert: &id002 - that: - - result.changed == true - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp_neighbor_af: *id001 - - - ansible.builtin.assert: &id004 - that: - - result.changed == false - - - name: Configure bgp neighbor address-family def1 - register: result - cisco.nxos.nxos_bgp_neighbor_af: &id003 - asn: 65535 - neighbor: 192.0.2.3 - afi: ipv4 - safi: unicast - additional_paths_receive: inherit - additional_paths_send: inherit - advertise_map_exist: default - allowas_in: false - default_originate: false - disable_peer_as_check: false - filter_list_in: default - filter_list_out: default - max_prefix_limit: default - max_prefix_threshold: default - max_prefix_warning: false - next_hop_self: false - next_hop_third_party: false - prefix_list_in: default - prefix_list_out: default - send_community: none - soft_reconfiguration_in: inherit - suppress_inactive: false - unsuppress_map: default - weight: default - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp_neighbor_af: *id003 - - - ansible.builtin.assert: *id004 - - - name: "Setup: remove bgp config" - register: result - cisco.nxos.nxos_bgp_neighbor_af: &id005 - asn: 65535 - neighbor: 192.0.2.3 - afi: ipv4 - safi: unicast - state: absent - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp_neighbor_af: *id005 - - - ansible.builtin.assert: *id004 - - - name: Configure bgp neighbor address-family - register: result - cisco.nxos.nxos_bgp_neighbor_af: &id006 - asn: 65535 - neighbor: 192.0.2.3 - afi: ipv4 - safi: unicast - allowas_in_max: "5" - advertise_map_non_exist: - - ansible_rm - - my_non_exist_map - default_originate_route_map: my_route_map - max_prefix_limit: 100 - max_prefix_interval: 30 - max_prefix_threshold: 50 - route_map_in: rm_in - route_map_out: rm_out - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp_neighbor_af: *id006 - - - ansible.builtin.assert: *id004 - - - name: Configure bgp neighbor address-family def2 - register: result - cisco.nxos.nxos_bgp_neighbor_af: &id007 - asn: 65535 - neighbor: 192.0.2.3 - afi: ipv4 - safi: unicast - allowas_in_max: default - advertise_map_non_exist: default - default_originate_route_map: default - max_prefix_limit: default - max_prefix_interval: default - max_prefix_threshold: default - route_map_in: default - route_map_out: default - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp_neighbor_af: *id007 - - - ansible.builtin.assert: *id004 - - - name: "Setup: remove bgp config" - register: result - cisco.nxos.nxos_bgp_neighbor_af: *id005 - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp_neighbor_af: *id005 - - - ansible.builtin.assert: *id004 - - - name: Configure ebgp - cisco.nxos.nxos_bgp_neighbor: - asn: 65535 - vrf: blue - neighbor: 192.0.2.3 - remote_as: 2 - - - name: Configure bgp neighbor 3 - register: result - cisco.nxos.nxos_bgp_neighbor_af: &id008 - asn: 65535 - vrf: blue - neighbor: 192.0.2.3 - afi: ipv4 - safi: unicast - additional_paths_receive: disable - additional_paths_send: disable - as_override: "true" - send_community: standard - soft_reconfiguration_in: "{{soft_reconfiguration_ina|default(omit)}}" - soo: "3:3" - next_hop_third_party: true - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp_neighbor_af: *id008 - - - ansible.builtin.assert: *id004 - - - name: Configure bgp neighbor def3 - register: result - cisco.nxos.nxos_bgp_neighbor_af: &id009 - asn: 65535 - vrf: blue - neighbor: 192.0.2.3 - afi: ipv4 - safi: unicast - additional_paths_receive: inherit - additional_paths_send: inherit - as_override: false - send_community: default - soo: default - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp_neighbor_af: *id009 - - - ansible.builtin.assert: *id004 - - - name: "Setup: remove bgp config" - register: result - cisco.nxos.nxos_bgp: &id012 - asn: 65535 - state: absent - - - ansible.builtin.assert: *id002 - - - name: Configure bgp neighbor af route_reflector_client - cisco.nxos.nxos_bgp_neighbor: - asn: 65535 - neighbor: 192.0.2.2 - remote_as: 65535 - - - name: Configure bgp neighbor 4 - register: result - cisco.nxos.nxos_bgp_neighbor_af: &id010 - asn: 65535 - neighbor: 192.0.2.2 - afi: ipv4 - safi: unicast - route_reflector_client: "true" - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp_neighbor_af: *id010 - - - ansible.builtin.assert: *id004 - - - name: Configure bgp neighbor def4 - register: result - cisco.nxos.nxos_bgp_neighbor_af: &id011 - asn: 65535 - neighbor: 192.0.2.2 - afi: ipv4 - safi: unicast - route_reflector_client: false - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_bgp_neighbor_af: *id011 - - - ansible.builtin.assert: *id004 - always: - - name: Cleanup bgp - ignore_errors: true - cisco.nxos.nxos_bgp: *id012 - - - name: Disable feature bgp - cisco.nxos.nxos_feature: *id013 - - - ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_bgp_neighbor_af sanity test diff --git a/tests/integration/targets/nxos_bgp_templates/defaults/main.yaml b/tests/integration/targets/nxos_bgp_templates/defaults/main.yaml new file mode 100644 index 000000000..871ea460c --- /dev/null +++ b/tests/integration/targets/nxos_bgp_templates/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: "[^_].*" diff --git a/tests/integration/targets/nxos_bgp_templates/meta/main.yml b/tests/integration/targets/nxos_bgp_templates/meta/main.yml new file mode 100644 index 000000000..ed97d539c --- /dev/null +++ b/tests/integration/targets/nxos_bgp_templates/meta/main.yml @@ -0,0 +1 @@ +--- diff --git a/tests/integration/targets/nxos_acl/tasks/cli.yaml b/tests/integration/targets/nxos_bgp_templates/tasks/cli.yaml similarity index 86% rename from tests/integration/targets/nxos_acl/tasks/cli.yaml rename to tests/integration/targets/nxos_bgp_templates/tasks/cli.yaml index 90342e6b1..e3e64747b 100644 --- a/tests/integration/targets/nxos_acl/tasks/cli.yaml +++ b/tests/integration/targets/nxos_bgp_templates/tasks/cli.yaml @@ -3,10 +3,11 @@ ansible.builtin.find: paths: "{{ role_path }}/tests/common" patterns: "{{ testcase }}.yaml" + use_regex: true connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +23,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_bgp_templates/tasks/main.yaml b/tests/integration/targets/nxos_bgp_templates/tasks/main.yaml new file mode 100644 index 000000000..026b6e477 --- /dev/null +++ b/tests/integration/targets/nxos_bgp_templates/tasks/main.yaml @@ -0,0 +1,26 @@ +--- +- name: Enable 'feature bgp' + cisco.nxos.nxos_feature: + feature: bgp + vars: + ansible_connection: ansible.netcommon.network_cli + +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks + ansible.builtin.include_tasks: cli.yaml + tags: + - cli + + - name: Include the NX-API tasks + ansible.builtin.include_tasks: nxapi.yaml + tags: + - nxapi + + always: + - name: Disable 'feature bgp' + cisco.nxos.nxos_feature: + feature: bgp + state: disabled + vars: + ansible_connection: ansible.netcommon.network_cli diff --git a/tests/integration/targets/nxos_bgp/tasks/nxapi.yaml b/tests/integration/targets/nxos_bgp_templates/tasks/nxapi.yaml similarity index 86% rename from tests/integration/targets/nxos_bgp/tasks/nxapi.yaml rename to tests/integration/targets/nxos_bgp_templates/tasks/nxapi.yaml index cedab80f1..4ae68868c 100644 --- a/tests/integration/targets/nxos_bgp/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_bgp_templates/tasks/nxapi.yaml @@ -3,10 +3,11 @@ ansible.builtin.find: paths: "{{ role_path }}/tests/common" patterns: "{{ testcase }}.yaml" + use_regex: true connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +23,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_bgp_templates/tests/common/_populate_config.yaml b/tests/integration/targets/nxos_bgp_templates/tests/common/_populate_config.yaml new file mode 100644 index 000000000..2fe977e28 --- /dev/null +++ b/tests/integration/targets/nxos_bgp_templates/tests/common/_populate_config.yaml @@ -0,0 +1,25 @@ +--- +- name: "Setup - 1" + cisco.nxos.nxos_config: + lines: + - router bgp 65536 + - template peer neighbor_tmplt_2 + - description Test_BGP_PEER_TEMPLATE_2 + - inherit peer-session psession1 + - timers 45 100 + - address-family ipv4 multicast + - advertise-map rmap1 exist-map emap1 + - as-override + - filter-list flist1 in + - filter-list flist2 out + - template peer neighbor_tmplt_1 + - bmp-activate-server 2 + - capability suppress 4-byte-as + - description Test_BGP_PEER_TEMPLATE_1 + - local-as 65536 + - remote-as 65001 + - address-family ipv4 unicast + - advertise-map rmap1 non-exist-map nemap1 + - advertisement-interval 60 + - disable-peer-as-check + match: none diff --git a/tests/integration/targets/nxos_bgp_templates/tests/common/_remove_config.yaml b/tests/integration/targets/nxos_bgp_templates/tests/common/_remove_config.yaml new file mode 100644 index 000000000..af7092576 --- /dev/null +++ b/tests/integration/targets/nxos_bgp_templates/tests/common/_remove_config.yaml @@ -0,0 +1,8 @@ +--- +- name: Remove pre-existing BGP configurations + cisco.nxos.nxos_config: + lines: + - no router bgp 65536 + ignore_errors: true + vars: + ansible_connection: ansible.netcommon.network_cli diff --git a/tests/integration/targets/nxos_bgp_templates/tests/common/deleted.yaml b/tests/integration/targets/nxos_bgp_templates/tests/common/deleted.yaml new file mode 100644 index 000000000..ab2efb521 --- /dev/null +++ b/tests/integration/targets/nxos_bgp_templates/tests/common/deleted.yaml @@ -0,0 +1,44 @@ +--- +- ansible.builtin.debug: + msg: Start nxos_bgp_templates deleted integration tests connection={{ ansible_connection}} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Delete BGP configs handled by this module + cisco.nxos.nxos_bgp_templates: &id001 + state: deleted + register: result + + - name: Assert that before dicts are correctly generated + ansible.builtin.assert: + that: + - merged['after'] == result['before'] + + - ansible.builtin.debug: + msg: "{{ result['commands'] | symmetric_difference(deleted['commands']) }}" + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ result['commands'] | symmetric_difference(deleted['commands']) |length == 0 }}" + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - deleted['after'] == result['after'] + + - name: Delete BGP configs handled by this module (idempotent) + register: result + cisco.nxos.nxos_bgp_templates: *id001 + + - name: Assert that task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/nxos_bgp_templates/tests/common/empty_config.yaml b/tests/integration/targets/nxos_bgp_templates/tests/common/empty_config.yaml new file mode 100644 index 000000000..f57679e8b --- /dev/null +++ b/tests/integration/targets/nxos_bgp_templates/tests/common/empty_config.yaml @@ -0,0 +1,61 @@ +--- +- ansible.builtin.debug: + msg: START nxos_bgp_templates empty_config integration tests on connection={{ ansible_connection }} + +- name: Merged with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.nxos.nxos_bgp_templates: + config: + state: merged + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state merged' + +- name: Replaced with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.nxos.nxos_bgp_templates: + config: + state: replaced + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Overridden with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.nxos.nxos_bgp_templates: + config: + state: overridden + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state overridden' + +- name: Rendered with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.nxos.nxos_bgp_templates: + config: + state: rendered + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' + +- name: Parsed with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.nxos.nxos_bgp_templates: + running_config: + state: parsed + +- ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state parsed' + +- ansible.builtin.debug: + msg: END nxos_bgp_templates empty_config integration tests diff --git a/tests/integration/targets/nxos_bgp_templates/tests/common/fixtures/parsed.cfg b/tests/integration/targets/nxos_bgp_templates/tests/common/fixtures/parsed.cfg new file mode 100644 index 000000000..615f7fa21 --- /dev/null +++ b/tests/integration/targets/nxos_bgp_templates/tests/common/fixtures/parsed.cfg @@ -0,0 +1,20 @@ +router bgp 65536 + template peer neighbor_tmplt_1 + bmp-activate-server 2 + capability suppress 4-byte-as + description Test_BGP_PEER_TEMPLATE_1 + local-as 65536 + remote-as 65001 + address-family ipv4 unicast + advertise-map rmap1 non-exist-map nemap1 + advertisement-interval 60 + disable-peer-as-check + template peer neighbor_tmplt_2 + description Test_BGP_PEER_TEMPLATE_2 + inherit peer-session psession1 + timers 45 100 + address-family ipv4 multicast + advertise-map rmap1 exist-map emap1 + as-override + filter-list flist1 in + filter-list flist2 out diff --git a/tests/integration/targets/nxos_bgp_templates/tests/common/gathered.yaml b/tests/integration/targets/nxos_bgp_templates/tests/common/gathered.yaml new file mode 100644 index 000000000..1cdf9a2f2 --- /dev/null +++ b/tests/integration/targets/nxos_bgp_templates/tests/common/gathered.yaml @@ -0,0 +1,20 @@ +--- +- ansible.builtin.debug: + msg: "START nxos_bgp_templates gathered integration tests" + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Gather BGP templates facts using gathered + register: result + cisco.nxos.nxos_bgp_templates: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: merged['after'] == result['gathered'] + + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/nxos_bgp_templates/tests/common/merged.yaml b/tests/integration/targets/nxos_bgp_templates/tests/common/merged.yaml new file mode 100644 index 000000000..acacacd02 --- /dev/null +++ b/tests/integration/targets/nxos_bgp_templates/tests/common/merged.yaml @@ -0,0 +1,72 @@ +--- +- ansible.builtin.debug: + msg: Start nxos_bgp_templates merged integration tests connection={{ ansible_connection}} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- block: + - name: Merge the provided configuration with the existing running configuration + cisco.nxos.nxos_bgp_templates: &id001 + config: + as_number: 65536 + neighbor: + - name: neighbor_tmplt_1 + address_family: + - afi: ipv4 + safi: unicast + advertise_map: + route_map: rmap1 + non_exist_map: nemap1 + advertisement_interval: 60 + disable_peer_as_check: true + bmp_activate_server: 2 + capability: + suppress_4_byte_as: true + description: Test_BGP_PEER_TEMPLATE_1 + local_as: 65536 + remote_as: 65001 + + - name: neighbor_tmplt_2 + description: Test_BGP_PEER_TEMPLATE_2 + address_family: + - afi: ipv4 + safi: multicast + advertise_map: + route_map: rmap1 + exist_map: emap1 + as_override: true + filter_list: + inbound: flist1 + outbound: flist2 + inherit: + peer_session: psession1 + timers: + holdtime: 100 + keepalive: 45 + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ result['before'] == {} }}" + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length == 0 }}" + + - name: Assert that after dicts were correctly generated + ansible.builtin.assert: + that: + - merged['after'] == result['after'] + + - name: Merge the provided configuration with the existing running configuration (idempotent) + cisco.nxos.nxos_bgp_templates: *id001 + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + - result.commands|length == 0 + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/nxos_bgp_templates/tests/common/overridden.yaml b/tests/integration/targets/nxos_bgp_templates/tests/common/overridden.yaml new file mode 100644 index 000000000..c66b10284 --- /dev/null +++ b/tests/integration/targets/nxos_bgp_templates/tests/common/overridden.yaml @@ -0,0 +1,61 @@ +--- +- ansible.builtin.debug: + msg: Start nxos_bgp_templates replaced integration tests connection={{ ansible_connection}} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Override BGP templates configuration with provided configuration + cisco.nxos.nxos_bgp_templates: &id001 + config: + as_number: 65536 + neighbor: + - name: neighbor_tmplt_1 + address_family: + - afi: ipv4 + safi: unicast + advertise_map: + route_map: rmap1 + non_exist_map: nemap1 + advertisement_interval: 60 + disable_peer_as_check: true + inherit: + peer_session: psession1 + description: Test_BGP_PEER_TEMPLATE_1 + local_as: 65537 + state: overridden + register: result + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ overridden['commands'] | symmetric_difference(result['commands']) |length == 0 }}" + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - overridden['after'] == result['after'] + + - name: Assert that before dicts are correctly generated + ansible.builtin.assert: + that: + - merged['after'] == result['before'] + + - name: Override device configurations of listed OSPF processes with provided configurarions (idempotent) + register: result + cisco.nxos.nxos_bgp_templates: *id001 + + - name: Assert that task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dict is correctly generated + ansible.builtin.assert: + that: + - overridden['after'] == result['before'] + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/nxos_bgp_templates/tests/common/parsed.yaml b/tests/integration/targets/nxos_bgp_templates/tests/common/parsed.yaml new file mode 100644 index 000000000..0a04fa376 --- /dev/null +++ b/tests/integration/targets/nxos_bgp_templates/tests/common/parsed.yaml @@ -0,0 +1,14 @@ +--- +- ansible.builtin.debug: + msg: START nxos_bgp_templates parsed integration tests on connection={{ ansible_connection }} + +- name: Parse externally provided BGP templates configuration + register: result + cisco.nxos.nxos_bgp_templates: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that configuration was correctly parsed + ansible.builtin.assert: + that: + - merged['after'] == result['parsed'] diff --git a/tests/integration/targets/nxos_bgp_templates/tests/common/rendered.yaml b/tests/integration/targets/nxos_bgp_templates/tests/common/rendered.yaml new file mode 100644 index 000000000..411e8761f --- /dev/null +++ b/tests/integration/targets/nxos_bgp_templates/tests/common/rendered.yaml @@ -0,0 +1,59 @@ +--- +- ansible.builtin.debug: + msg: START nxos_bgp_templates rendered integration tests on connection={{ ansible_connection }} + +- name: Render platform specific configuration lines with state rendered (without connecting to the device) + cisco.nxos.nxos_bgp_templates: + config: + as_number: 65536 + neighbor: + - name: neighbor_tmplt_1 + address_family: + - afi: ipv4 + safi: unicast + advertise_map: + route_map: rmap1 + non_exist_map: nemap1 + advertisement_interval: 60 + disable_peer_as_check: true + bmp_activate_server: 2 + capability: + suppress_4_byte_as: true + description: Test_BGP_PEER_TEMPLATE_1 + local_as: 65536 + remote_as: 65001 + + - name: neighbor_tmplt_2 + description: Test_BGP_PEER_TEMPLATE_2 + address_family: + - afi: ipv4 + safi: multicast + advertise_map: + route_map: rmap1 + exist_map: emap1 + as_override: true + filter_list: + inbound: flist1 + outbound: flist2 + inherit: + peer_session: psession1 + timers: + holdtime: 100 + keepalive: 45 + state: rendered + register: result + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['rendered']) |length == 0 }}" + +- name: Gather BGP templates facts + cisco.nxos.nxos_bgp_templates: + state: gathered + register: result + +- name: Ensure that no configuration changes were made + ansible.builtin.assert: + that: + - result.gathered == {} diff --git a/tests/integration/targets/nxos_bgp_templates/tests/common/replaced.yaml b/tests/integration/targets/nxos_bgp_templates/tests/common/replaced.yaml new file mode 100644 index 000000000..73bd4b73f --- /dev/null +++ b/tests/integration/targets/nxos_bgp_templates/tests/common/replaced.yaml @@ -0,0 +1,61 @@ +--- +- ansible.builtin.debug: + msg: Start nxos_bgp_templates replaced integration tests connection={{ ansible_connection}} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Replace BGP templates configuration with provided configuration + cisco.nxos.nxos_bgp_templates: &id001 + config: + as_number: 65536 + neighbor: + - name: neighbor_tmplt_1 + address_family: + - afi: ipv4 + safi: unicast + advertise_map: + route_map: rmap1 + non_exist_map: nemap1 + advertisement_interval: 60 + disable_peer_as_check: true + inherit: + peer_session: psession1 + description: Test_BGP_PEER_TEMPLATE_1 + local_as: 65537 + state: replaced + register: result + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ replaced['commands'] | symmetric_difference(result['commands']) |length == 0 }}" + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - replaced['after'] == result['after'] + + - name: Assert that before dicts are correctly generated + ansible.builtin.assert: + that: + - merged['after'] == result['before'] + + - name: Replace device configurations of listed OSPF processes with provided configurarions (idempotent) + register: result + cisco.nxos.nxos_bgp_templates: *id001 + + - name: Assert that task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dict is correctly generated + ansible.builtin.assert: + that: + - replaced['after'] == result['before'] + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/nxos_bgp_templates/vars/main.yml b/tests/integration/targets/nxos_bgp_templates/vars/main.yml new file mode 100644 index 000000000..77acf1516 --- /dev/null +++ b/tests/integration/targets/nxos_bgp_templates/vars/main.yml @@ -0,0 +1,142 @@ +--- +merged: + commands: + - router bgp 65536 + - template peer neighbor_tmplt_2 + - description Test_BGP_PEER_TEMPLATE_2 + - inherit peer-session psession1 + - timers 45 100 + - address-family ipv4 multicast + - advertise-map rmap1 exist-map emap1 + - as-override + - filter-list flist1 in + - filter-list flist2 out + - template peer neighbor_tmplt_1 + - bmp-activate-server 2 + - capability suppress 4-byte-as + - description Test_BGP_PEER_TEMPLATE_1 + - local-as 65536 + - remote-as 65001 + - address-family ipv4 unicast + - advertise-map rmap1 non-exist-map nemap1 + - advertisement-interval 60 + - disable-peer-as-check + + after: + as_number: "65536" + neighbor: + - name: neighbor_tmplt_1 + address_family: + - afi: ipv4 + safi: unicast + advertise_map: + non_exist_map: nemap1 + route_map: rmap1 + advertisement_interval: 60 + disable_peer_as_check: true + bmp_activate_server: 2 + capability: + suppress_4_byte_as: true + description: Test_BGP_PEER_TEMPLATE_1 + local_as: "65536" + remote_as: "65001" + + - name: neighbor_tmplt_2 + description: Test_BGP_PEER_TEMPLATE_2 + address_family: + - afi: ipv4 + safi: multicast + advertise_map: + exist_map: emap1 + route_map: rmap1 + as_override: true + filter_list: + inbound: flist1 + outbound: flist2 + inherit: + peer_session: psession1 + timers: + holdtime: 100 + keepalive: 45 + +replaced: + commands: + - router bgp 65536 + - template peer neighbor_tmplt_1 + - no bmp-activate-server 2 + - no capability suppress 4-byte-as + - inherit peer-session psession1 + - local-as 65537 + - no remote-as 65001 + + after: + as_number: "65536" + neighbor: + - name: neighbor_tmplt_1 + address_family: + - afi: ipv4 + safi: unicast + advertise_map: + non_exist_map: nemap1 + route_map: rmap1 + advertisement_interval: 60 + disable_peer_as_check: true + description: Test_BGP_PEER_TEMPLATE_1 + inherit: + peer_session: psession1 + local_as: "65537" + + - name: neighbor_tmplt_2 + description: Test_BGP_PEER_TEMPLATE_2 + address_family: + - afi: ipv4 + safi: multicast + advertise_map: + exist_map: emap1 + route_map: rmap1 + as_override: true + filter_list: + inbound: flist1 + outbound: flist2 + inherit: + peer_session: psession1 + timers: + holdtime: 100 + keepalive: 45 + +overridden: + commands: + - router bgp 65536 + - template peer neighbor_tmplt_1 + - no bmp-activate-server 2 + - no capability suppress 4-byte-as + - inherit peer-session psession1 + - local-as 65537 + - no remote-as 65001 + - no template peer neighbor_tmplt_2 + + after: + as_number: "65536" + neighbor: + - name: neighbor_tmplt_1 + address_family: + - afi: ipv4 + safi: unicast + advertise_map: + non_exist_map: nemap1 + route_map: rmap1 + advertisement_interval: 60 + disable_peer_as_check: true + description: Test_BGP_PEER_TEMPLATE_1 + inherit: + peer_session: psession1 + local_as: "65537" + +deleted: + commands: + - router bgp 65536 + - no template peer neighbor_tmplt_1 + - no template peer neighbor_tmplt_2 + + after: + as_number: "65536" diff --git a/tests/integration/targets/nxos_command/tasks/cli.yaml b/tests/integration/targets/nxos_command/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_command/tasks/cli.yaml +++ b/tests/integration/targets/nxos_command/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_command/tasks/main.yaml b/tests/integration/targets/nxos_command/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_command/tasks/main.yaml +++ b/tests/integration/targets/nxos_command/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_command/tasks/nxapi.yaml b/tests/integration/targets/nxos_command/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_command/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_command/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_command/tests/cli/sanity.yaml b/tests/integration/targets/nxos_command/tests/cli/sanity.yaml index 97a38df02..bb8a3db43 100644 --- a/tests/integration/targets/nxos_command/tests/cli/sanity.yaml +++ b/tests/integration/targets/nxos_command/tests/cli/sanity.yaml @@ -2,13 +2,13 @@ - ansible.builtin.debug: msg: START cli/sanity.yaml on connection={{ ansible_connection }} -- name: Disable feature bgp +- name: Disable 'feature bgp' cisco.nxos.nxos_feature: feature: bgp state: disabled - block: - - name: Run show running-config bgp - should fail + - name: Run show running-config BGP - should fail ignore_errors: true register: result cisco.nxos.nxos_command: @@ -19,23 +19,24 @@ that: - result.failed == true - - name: Enable feature bgp + - name: Enable 'feature bgp' cisco.nxos.nxos_feature: feature: bgp state: enabled - - name: Configure bgp defaults + - name: Configure BGP defaults register: result - cisco.nxos.nxos_bgp: - asn: 65535 - router_id: 192.0.2.1 - state: present + cisco.nxos.nxos_bgp_global: + config: + as_number: 65535 + router_id: 192.0.2.1 + state: merged - ansible.builtin.assert: that: - result.changed == true - - name: Run show running-config bgp - should pass + - name: Run show running-config BGP - should pass register: result cisco.nxos.nxos_command: commands: @@ -58,7 +59,7 @@ - ansible.builtin.debug: msg: nxos_command sanity test failure detected always: - - name: Disable feature bgp + - name: Disable 'feature bgp' cisco.nxos.nxos_feature: feature: bgp state: disabled diff --git a/tests/integration/targets/nxos_command/tests/common/greaterthan.yaml b/tests/integration/targets/nxos_command/tests/common/greaterthan.yaml index 958b33121..dcdee7b47 100644 --- a/tests/integration/targets/nxos_command/tests/common/greaterthan.yaml +++ b/tests/integration/targets/nxos_command/tests/common/greaterthan.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START common/greaterthan.yaml on connection={{ ansible_connection }} -- name: Test gt operator +- name: Test 'gt' operator register: result cisco.nxos.nxos_command: commands: diff --git a/tests/integration/targets/nxos_command/tests/common/greaterthanorequal.yaml b/tests/integration/targets/nxos_command/tests/common/greaterthanorequal.yaml index efb68d6c4..6446e6b80 100644 --- a/tests/integration/targets/nxos_command/tests/common/greaterthanorequal.yaml +++ b/tests/integration/targets/nxos_command/tests/common/greaterthanorequal.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START common/greaterthanorequal.yaml on connection={{ ansible_connection }} -- name: Test ge operator +- name: Test 'ge' operator register: result cisco.nxos.nxos_command: commands: diff --git a/tests/integration/targets/nxos_command/tests/common/lessthan.yaml b/tests/integration/targets/nxos_command/tests/common/lessthan.yaml index f5ec2951c..dd01ecc7f 100644 --- a/tests/integration/targets/nxos_command/tests/common/lessthan.yaml +++ b/tests/integration/targets/nxos_command/tests/common/lessthan.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START common/lessthan.yaml on connection={{ ansible_connection }} -- name: Test lt operator +- name: Test 'lt' operator register: result cisco.nxos.nxos_command: commands: diff --git a/tests/integration/targets/nxos_command/tests/common/lessthanorequal.yaml b/tests/integration/targets/nxos_command/tests/common/lessthanorequal.yaml index 34f544eb3..04748f522 100644 --- a/tests/integration/targets/nxos_command/tests/common/lessthanorequal.yaml +++ b/tests/integration/targets/nxos_command/tests/common/lessthanorequal.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START common/lessthanorequal.yaml on connection={{ ansible_connection }} -- name: Test le operator +- name: Test 'le' operator register: result cisco.nxos.nxos_command: commands: diff --git a/tests/integration/targets/nxos_command/tests/common/notequal.yaml b/tests/integration/targets/nxos_command/tests/common/notequal.yaml index 90a97b876..c2fe39577 100644 --- a/tests/integration/targets/nxos_command/tests/common/notequal.yaml +++ b/tests/integration/targets/nxos_command/tests/common/notequal.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START common/notequal.yaml on connection={{ ansible_connection }} -- name: Test neq operator +- name: Test 'neq' operator register: result cisco.nxos.nxos_command: commands: diff --git a/tests/integration/targets/nxos_command/tests/nxapi/sanity.yaml b/tests/integration/targets/nxos_command/tests/nxapi/sanity.yaml index a7cfae72e..e9f2f162c 100644 --- a/tests/integration/targets/nxos_command/tests/nxapi/sanity.yaml +++ b/tests/integration/targets/nxos_command/tests/nxapi/sanity.yaml @@ -2,13 +2,13 @@ - ansible.builtin.debug: msg: START nxapi/sanity.yaml on connection={{ ansible_connection }} -- name: Disable feature bgp +- name: Disable 'feature bgp' cisco.nxos.nxos_feature: feature: bgp state: disabled - block: - - name: Run show running-config bgp - should fail + - name: Run show running-config BGP - should fail ignore_errors: true register: result cisco.nxos.nxos_command: @@ -19,12 +19,12 @@ that: - result.failed == true - - name: Enable feature bgp + - name: Enable 'feature bgp' cisco.nxos.nxos_feature: feature: bgp state: enabled - - name: Configure bgp defaults + - name: Configure BGP defaults register: result cisco.nxos.nxos_bgp: asn: 65535 @@ -35,7 +35,7 @@ that: - result.changed == true - - name: Run show running-config bgp - should pass + - name: Run show running-config BGP - should pass register: result cisco.nxos.nxos_command: commands: @@ -58,7 +58,7 @@ - ansible.builtin.debug: msg: nxos_command sanity test failure detected always: - - name: Disable feature bgp + - name: Disable 'feature bgp' cisco.nxos.nxos_feature: feature: bgp state: disabled diff --git a/tests/integration/targets/nxos_config/tasks/cli.yaml b/tests/integration/targets/nxos_config/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_config/tasks/cli.yaml +++ b/tests/integration/targets/nxos_config/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_config/tasks/cli_config.yaml b/tests/integration/targets/nxos_config/tasks/cli_config.yaml index 4c960185d..79b7f90ab 100644 --- a/tests/integration/targets/nxos_config/tasks/cli_config.yaml +++ b/tests/integration/targets/nxos_config/tasks/cli_config.yaml @@ -10,7 +10,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test case (connection=ansible.netcommon.network_cli) +- name: Run test case with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_config/tasks/main.yaml b/tests/integration/targets/nxos_config/tasks/main.yaml index 1b303bb42..641205bf8 100644 --- a/tests/integration/targets/nxos_config/tasks/main.yaml +++ b/tests/integration/targets/nxos_config/tasks/main.yaml @@ -1,20 +1,23 @@ --- -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi - - ansible.builtin.include: cli_config.yaml + - name: Run cli_config tests + ansible.builtin.include_tasks: cli_config.yaml tags: - cli_config - - ansible.builtin.include: redirection.yaml + - name: Run redirection tests + ansible.builtin.include_tasks: redirection.yaml when: ansible_version.full is version('2.10.0', '>=') always: - name: Change hostname back to {{ inventory_hostname_short }} diff --git a/tests/integration/targets/nxos_config/tasks/nxapi.yaml b/tests/integration/targets/nxos_config/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_config/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_config/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_config/tasks/redirection.yaml b/tests/integration/targets/nxos_config/tasks/redirection.yaml index 46b7cfea1..dde1662ea 100644 --- a/tests/integration/targets/nxos_config/tasks/redirection.yaml +++ b/tests/integration/targets/nxos_config/tasks/redirection.yaml @@ -1,5 +1,5 @@ --- -- name: Collect all redirection cli test cases +- name: Collect all redirection CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/redirection/cli" patterns: "{{ testcase }}.yaml" @@ -10,7 +10,7 @@ ansible.builtin.set_fact: test_items: "{{ shortname_test_cases.files | map(attribute='path') | list }}" -- name: Run test case (connection=ansible.netcommon.network_cli) +- name: Run test case with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_config/templates/basic/acl_config.j2 b/tests/integration/targets/nxos_config/templates/basic/acl_config.j2 new file mode 100644 index 000000000..ec03c24a2 --- /dev/null +++ b/tests/integration/targets/nxos_config/templates/basic/acl_config.j2 @@ -0,0 +1,5 @@ +ip access-list test + 10 permit ip 192.0.2.1/32 any log + 20 permit ip 192.0.2.2/32 any log + 30 permit ip 192.0.2.3/32 any log + 40 permit ip 192.0.2.4/32 any log diff --git a/tests/integration/targets/nxos_config/tests/cli/diff.yaml b/tests/integration/targets/nxos_config/tests/cli/diff.yaml index d20b92378..e8999c849 100644 --- a/tests/integration/targets/nxos_config/tests/cli/diff.yaml +++ b/tests/integration/targets/nxos_config/tests/cli/diff.yaml @@ -6,7 +6,7 @@ cisco.nxos.nxos_config: lines: hostname switch -- name: Nxos_config diff against retrieved config +- name: Nxos_config diff against retrieved configuration diff: true register: result cisco.nxos.nxos_config: diff --git a/tests/integration/targets/nxos_config/tests/cli/multilevel.yaml b/tests/integration/targets/nxos_config/tests/cli/multilevel.yaml index 9c8565f8f..277f10d5a 100644 --- a/tests/integration/targets/nxos_config/tests/cli/multilevel.yaml +++ b/tests/integration/targets/nxos_config/tests/cli/multilevel.yaml @@ -2,17 +2,17 @@ - ansible.builtin.debug: msg: START cli/mulitlevel.yaml -- name: Get config +- name: Get configuration register: config cisco.nxos.nxos_command: commands: show running-config -- name: Enable feature bgp +- name: Enable 'feature bgp' when: "'feature bgp' not in config.stdout[0]" cisco.nxos.nxos_config: lines: feature bgp -- name: Remove bgp +- name: Remove BGP when: "'router bgp 1' in config.stdout[0]" cisco.nxos.nxos_config: lines: no router bgp 1 diff --git a/tests/integration/targets/nxos_config/tests/cli/replace_block.yaml b/tests/integration/targets/nxos_config/tests/cli/replace_block.yaml new file mode 100644 index 000000000..deb79b940 --- /dev/null +++ b/tests/integration/targets/nxos_config/tests/cli/replace_block.yaml @@ -0,0 +1,35 @@ +--- +- ansible.builtin.debug: msg="START cli/replace_block.yaml on connection={{ ansible_connection }}" + +- name: "setup" + cisco.nxos.nxos_config: + lines: + - "no ip access-list test" + ignore_errors: true + +- name: "Populate nxos acls configuration with replace block and lines options" + register: result1 + cisco.nxos.nxos_config: + lines: "{{ lookup('template', 'basic/acl_config.j2') }}" + replace: block + +- ansible.builtin.assert: + that: + - result1.changed == true + +- name: "setup" + cisco.nxos.nxos_config: + lines: + - "no ip access-list test" + ignore_errors: true + +- name: "Populate acl configuration with replace block and src options" + register: result2 + cisco.nxos.nxos_config: + src: basic/acl_config.j2 + replace: block + +- ansible.builtin.assert: + that: + - result2.changed == true + - result1.commands == result2.commands diff --git a/tests/integration/targets/nxos_config/tests/cli_config/cli_backup.yaml b/tests/integration/targets/nxos_config/tests/cli_config/cli_backup.yaml index 376f12faf..8f21457e7 100644 --- a/tests/integration/targets/nxos_config/tests/cli_config/cli_backup.yaml +++ b/tests/integration/targets/nxos_config/tests/cli_config/cli_backup.yaml @@ -32,7 +32,7 @@ state: absent with_items: "{{backup_files.files|default([])}}" -- name: Take config backup +- name: Take configuration backup become: "{{ can_become }}" register: result ansible.netcommon.cli_config: diff --git a/tests/integration/targets/nxos_config/tests/cli_config/cli_basic.yaml b/tests/integration/targets/nxos_config/tests/cli_config/cli_basic.yaml index d0572f4e2..a2492af26 100644 --- a/tests/integration/targets/nxos_config/tests/cli_config/cli_basic.yaml +++ b/tests/integration/targets/nxos_config/tests/cli_config/cli_basic.yaml @@ -7,7 +7,7 @@ config: "interface loopback1\nno description\nno shutdown\n" diff_match: none -- name: Configure device with config +- name: Configure device with configuration register: result ansible.netcommon.cli_config: &id001 config: "{{ lookup('template', 'basic/config.j2') }}" @@ -24,10 +24,10 @@ that: - result.changed == false -- name: Remove config +- name: Remove configuration ansible.netcommon.cli_config: *id002 -- name: Configure device with config +- name: Configure device with configuration register: result ansible.netcommon.cli_config: config: "{{ lookup('template', 'basic/config.j2') }}" diff --git a/tests/integration/targets/nxos_config/tests/common/backup.yaml b/tests/integration/targets/nxos_config/tests/common/backup.yaml index 770252383..e1aecb6b5 100644 --- a/tests/integration/targets/nxos_config/tests/common/backup.yaml +++ b/tests/integration/targets/nxos_config/tests/common/backup.yaml @@ -28,7 +28,7 @@ state: absent with_items: "{{backup_files.files|default([])}}" -- name: Configure device with config +- name: Configure device with configuration register: result cisco.nxos.nxos_config: commands: diff --git a/tests/integration/targets/nxos_config/tests/common/save.yaml b/tests/integration/targets/nxos_config/tests/common/save.yaml index 59a26ce08..9300247ae 100644 --- a/tests/integration/targets/nxos_config/tests/common/save.yaml +++ b/tests/integration/targets/nxos_config/tests/common/save.yaml @@ -15,7 +15,7 @@ - interface {{ intname }} match: none -- name: Save config +- name: Save configuration register: result cisco.nxos.nxos_config: save_when: always diff --git a/tests/integration/targets/nxos_config/tests/common/src_basic.yaml b/tests/integration/targets/nxos_config/tests/common/src_basic.yaml index b549fbaf9..176b679c5 100644 --- a/tests/integration/targets/nxos_config/tests/common/src_basic.yaml +++ b/tests/integration/targets/nxos_config/tests/common/src_basic.yaml @@ -15,7 +15,7 @@ - interface {{ intname }} match: none -- name: Configure device with config +- name: Configure device with configuration register: result cisco.nxos.nxos_config: src: basic/config.j2 @@ -26,7 +26,7 @@ - result.changed == true - result.updates is defined -- name: Check device with config +- name: Check device with configuration register: result cisco.nxos.nxos_config: src: basic/config.j2 diff --git a/tests/integration/targets/nxos_config/tests/common/src_match_none.yaml b/tests/integration/targets/nxos_config/tests/common/src_match_none.yaml index f25afa64f..a9b94ac50 100644 --- a/tests/integration/targets/nxos_config/tests/common/src_match_none.yaml +++ b/tests/integration/targets/nxos_config/tests/common/src_match_none.yaml @@ -15,7 +15,7 @@ - interface {{ intname }} match: none -- name: Configure device with config +- name: Configure device with configuration register: result cisco.nxos.nxos_config: commands: @@ -31,7 +31,7 @@ - result.changed == true - result.updates is defined -- name: Check device with config +- name: Check device with configuration register: result cisco.nxos.nxos_config: commands: diff --git a/tests/integration/targets/nxos_devicealias/tasks/cli.yaml b/tests/integration/targets/nxos_devicealias/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_devicealias/tasks/cli.yaml +++ b/tests/integration/targets/nxos_devicealias/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_devicealias/tasks/main.yaml b/tests/integration/targets/nxos_devicealias/tasks/main.yaml index eb055621b..477fbd41f 100644 --- a/tests/integration/targets/nxos_devicealias/tasks/main.yaml +++ b/tests/integration/targets/nxos_devicealias/tasks/main.yaml @@ -1,5 +1,5 @@ --- -- name: Check platform type and skip if not mds +- name: Check platform type and skip if not MDS register: result cisco.nxos.nxos_command: commands: show version | grep MDS @@ -8,12 +8,12 @@ ansible.builtin.set_fact: skip_test: false -- name: Set skip_test flag to true if not mds +- name: Set skip_test flag to true if not MDS ansible.builtin.set_fact: skip_test: true when: result.stdout[0] is not search('MDS') -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: cli when: not skip_test diff --git a/tests/integration/targets/nxos_devicealias/tests/common/sanity.yaml b/tests/integration/targets/nxos_devicealias/tests/common/sanity.yaml index fb61300ad..61d8a02df 100644 --- a/tests/integration/targets/nxos_devicealias/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_devicealias/tests/common/sanity.yaml @@ -29,8 +29,15 @@ - ansible.builtin.assert: that: - - result.commands == ["terminal dont-ask", "device-alias database", "device-alias name ansible_test1_add pwwn 57:bb:cc:dd:ee:ff:11:67", "device-alias name - ansible_test2_add pwwn 65:22:21:20:19:18:1a:0d", "device-alias commit", "no terminal dont-ask"] + - result.commands == desired + vars: + desired: + - "terminal dont-ask" + - "device-alias database" + - "device-alias name ansible_test1_add pwwn 57:bb:cc:dd:ee:ff:11:67" + - "device-alias name ansible_test2_add pwwn 65:22:21:20:19:18:1a:0d" + - "device-alias commit" + - "no terminal dont-ask" - name: Idempotence check register: result @@ -44,7 +51,7 @@ that: - result.commands == [] always: - - name: Remove device alias config + - name: Remove device alias configuration cisco.nxos.nxos_devicealias: *id002 - ansible.builtin.debug: diff --git a/tests/integration/targets/nxos_evpn_global/tasks/cli.yaml b/tests/integration/targets/nxos_evpn_global/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_evpn_global/tasks/cli.yaml +++ b/tests/integration/targets/nxos_evpn_global/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_evpn_global/tasks/main.yaml b/tests/integration/targets/nxos_evpn_global/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_evpn_global/tasks/main.yaml +++ b/tests/integration/targets/nxos_evpn_global/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_evpn_global/tasks/nxapi.yaml b/tests/integration/targets/nxos_evpn_global/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_evpn_global/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_evpn_global/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_evpn_global/tests/common/sanity.yaml b/tests/integration/targets/nxos_evpn_global/tests/common/sanity.yaml index 804bd6371..92feff4de 100644 --- a/tests/integration/targets/nxos_evpn_global/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_evpn_global/tests/common/sanity.yaml @@ -8,20 +8,20 @@ lines: no nv overlay evpn match: none -- name: Disable feature nv overlay +- name: Disable 'feature nv overlay' ignore_errors: true cisco.nxos.nxos_feature: &id006 feature: nv overlay state: disabled - block: - - name: Enable feature nv overlay + - name: Enable 'feature nv overlay' ignore_errors: true cisco.nxos.nxos_feature: feature: nv overlay state: enabled - - name: Enable nv overlay evpn + - name: Enable NV overlay EVPN register: result cisco.nxos.nxos_evpn_global: &id001 nv_overlay_evpn: true @@ -30,7 +30,7 @@ that: - result.changed == true - - name: Check idempotence - enable nv overlay evpn + - name: Check idempotence - enable NV overlay EVPN register: result cisco.nxos.nxos_evpn_global: *id001 @@ -38,14 +38,14 @@ that: - result.changed == false - - name: Disable nv overlay evpn + - name: Disable NV overlay EVPN register: result cisco.nxos.nxos_evpn_global: &id003 nv_overlay_evpn: false - ansible.builtin.assert: *id002 - - name: Check dempotence - disable nv overlay evpn + - name: Check dempotence - disable NV overlay EVPN register: result cisco.nxos.nxos_evpn_global: *id003 @@ -55,11 +55,11 @@ - ansible.builtin.debug: msg: connection={{ ansible_connection }} nxos_evpn_global sanity test - FALURE ENCOUNTERED always: - - name: Cleanup - disable nv overlay evpn + - name: Cleanup - disable NV overlay EVPN ignore_errors: true cisco.nxos.nxos_config: *id005 - - name: Cleanup - disable feature nv overlay + - name: Cleanup - disable 'feature nv overlay' ignore_errors: true cisco.nxos.nxos_feature: *id006 diff --git a/tests/integration/targets/nxos_evpn_vni/tasks/cli.yaml b/tests/integration/targets/nxos_evpn_vni/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_evpn_vni/tasks/cli.yaml +++ b/tests/integration/targets/nxos_evpn_vni/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_evpn_vni/tasks/main.yaml b/tests/integration/targets/nxos_evpn_vni/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_evpn_vni/tasks/main.yaml +++ b/tests/integration/targets/nxos_evpn_vni/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_evpn_vni/tasks/nxapi.yaml b/tests/integration/targets/nxos_evpn_vni/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_evpn_vni/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_evpn_vni/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_evpn_vni/tests/common/sanity.yaml b/tests/integration/targets/nxos_evpn_vni/tests/common/sanity.yaml index 206a437c7..344fe3749 100644 --- a/tests/integration/targets/nxos_evpn_vni/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_evpn_vni/tests/common/sanity.yaml @@ -14,12 +14,12 @@ match: none - block: - - name: Enable feature bgp + - name: Enable 'feature bgp' cisco.nxos.nxos_feature: feature: bgp state: enabled - - name: Enable nv overlay evpn + - name: Enable NV overlay EVPN cisco.nxos.nxos_config: lines: nv overlay evpn match: none @@ -102,7 +102,7 @@ ignore_errors: true cisco.nxos.nxos_config: *id007 - - name: Disable feature bgp + - name: Disable 'feature bgp' ignore_errors: true cisco.nxos.nxos_feature: feature: bgp diff --git a/tests/integration/targets/nxos_facts/tasks/cli.yaml b/tests/integration/targets/nxos_facts/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_facts/tasks/cli.yaml +++ b/tests/integration/targets/nxos_facts/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_facts/tasks/main.yaml b/tests/integration/targets/nxos_facts/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_facts/tasks/main.yaml +++ b/tests/integration/targets/nxos_facts/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_facts/tasks/nxapi.yaml b/tests/integration/targets/nxos_facts/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_facts/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_facts/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_facts/tests/common/all_facts.yaml b/tests/integration/targets/nxos_facts/tests/common/all_facts.yaml index 0dd9d8ead..7aece91d1 100644 --- a/tests/integration/targets/nxos_facts/tests/common/all_facts.yaml +++ b/tests/integration/targets/nxos_facts/tests/common/all_facts.yaml @@ -18,6 +18,7 @@ - result.ansible_facts.ansible_net_filesystems is defined - result.ansible_facts.ansible_net_interfaces is defined - result.ansible_facts.ansible_net_config is defined + - result.ansible_facts.ansible_net_cpu_utilization is defined - result.ansible_facts.ansible_net_model is defined - result.ansible_facts.ansible_net_memfree_mb > 1 - result.ansible_facts.ansible_net_memtotal_mb > 1 @@ -26,14 +27,12 @@ register: result cisco.nxos.nxos_facts: available_network_resources: true - gather_network_resources: all - name: Assert that correct available_network_resources returned ansible.builtin.assert: that: - result.changed == false - - "{{ result['ansible_facts']['available_network_resources'] | symmetric_difference(result['ansible_facts']['ansible_net_gather_network_resources']) |length\ - \ == 0 }}" + - "{{ result['ansible_facts']['available_network_resources'] | symmetric_difference(available_network_resources) | length == 0 }}" - ansible.builtin.debug: msg: END connection={{ ansible_connection }}/all_facts.yaml diff --git a/tests/integration/targets/nxos_facts/tests/common/sanity.yaml b/tests/integration/targets/nxos_facts/tests/common/sanity.yaml index 338a4d5ff..1861fa4a7 100644 --- a/tests/integration/targets/nxos_facts/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_facts/tests/common/sanity.yaml @@ -17,7 +17,7 @@ - result.ansible_facts.ansible_net_memfree_mb > 1 - result.ansible_facts.ansible_net_memtotal_mb > 1 -- name: Nxos_facts gather config facts +- name: Nxos_facts gather configuration facts register: result cisco.nxos.nxos_facts: gather_subset: config @@ -30,7 +30,7 @@ - "'interfaces' not in result.ansible_facts.ansible_net_gather_subset" - result.ansible_facts.ansible_net_config is defined -- name: Nxos_facts gather config and hardware facts +- name: Nxos_facts gather configuration and hardware facts register: result cisco.nxos.nxos_facts: gather_subset: diff --git a/tests/integration/targets/nxos_facts/vars/main.yml b/tests/integration/targets/nxos_facts/vars/main.yml new file mode 100644 index 000000000..5965c4191 --- /dev/null +++ b/tests/integration/targets/nxos_facts/vars/main.yml @@ -0,0 +1,30 @@ +--- +available_network_resources: + - acl_interfaces + - acls + - bfd_interfaces + - bgp_address_family + - bgp_global + - bgp_neighbor_address_family + - bgp_templates + - hostname + - hsrp_interfaces + - interfaces + - l2_interfaces + - l3_interfaces + - lacp + - lacp_interfaces + - lag_interfaces + - lldp_global + - lldp_interfaces + - logging_global + - ntp_global + - ospf_interfaces + - ospfv2 + - ospfv3 + - prefix_lists + - route_maps + - snmp_server + - static_routes + - telemetry + - vlans diff --git a/tests/integration/targets/nxos_feature/tasks/cli.yaml b/tests/integration/targets/nxos_feature/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_feature/tasks/cli.yaml +++ b/tests/integration/targets/nxos_feature/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_feature/tasks/main.yaml b/tests/integration/targets/nxos_feature/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_feature/tasks/main.yaml +++ b/tests/integration/targets/nxos_feature/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_feature/tasks/nxapi.yaml b/tests/integration/targets/nxos_feature/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_feature/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_feature/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_feature/tests/common/configure.yaml b/tests/integration/targets/nxos_feature/tests/common/configure.yaml index 1263ce2c8..bc73f56e7 100644 --- a/tests/integration/targets/nxos_feature/tests/common/configure.yaml +++ b/tests/integration/targets/nxos_feature/tests/common/configure.yaml @@ -9,7 +9,7 @@ - no feature fabric forwarding match: none -- name: Enable bgp +- name: Enable BGP register: result cisco.nxos.nxos_feature: feature: bgp @@ -19,7 +19,7 @@ that: - result.changed == true -- name: Verify bgp +- name: Verify BGP register: result cisco.nxos.nxos_feature: feature: bgp @@ -29,7 +29,7 @@ that: - result.changed == false -- name: Disable bgp +- name: Disable BGP register: result cisco.nxos.nxos_feature: feature: bgp @@ -39,7 +39,7 @@ that: - result.changed == true -- name: Verify bgp +- name: Verify BGP register: result cisco.nxos.nxos_feature: feature: bgp diff --git a/tests/integration/targets/nxos_file_copy/tasks/cli.yaml b/tests/integration/targets/nxos_file_copy/tasks/cli.yaml index 959a86621..d3d521f2a 100644 --- a/tests/integration/targets/nxos_file_copy/tasks/cli.yaml +++ b/tests/integration/targets/nxos_file_copy/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,7 +22,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_file_copy/tasks/main.yaml b/tests/integration/targets/nxos_file_copy/tasks/main.yaml index db61568c3..33ba6cb95 100644 --- a/tests/integration/targets/nxos_file_copy/tasks/main.yaml +++ b/tests/integration/targets/nxos_file_copy/tasks/main.yaml @@ -4,13 +4,13 @@ commands: show interface mgmt 0 | json register: result -- name: Store mgmt interface ip address +- name: Store mgmt interface IP address ansible.builtin.set_fact: mgmt0_ip: "{{ result['stdout'][0]['TABLE_interface']['ROW_interface']['eth_ip_addr'] }}" - name: Generate and store random password for temp user ansible.builtin.set_fact: - temp_passwd: "{{ lookup('password', 'length=15 chars=ascii_letters') }}" + temp_passwd: "{{ lookup('password', '/dev/null length=15 chars=ascii_letters') }}" delegate_to: localhost no_log: true @@ -19,13 +19,14 @@ name: temp_user configured_password: "{{ temp_passwd }}" -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_file_copy/tasks/nxapi.yaml b/tests/integration/targets/nxos_file_copy/tasks/nxapi.yaml index c5f0e9199..5fec0f43b 100644 --- a/tests/integration/targets/nxos_file_copy/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_file_copy/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,7 +22,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_file_copy/tests/cli/negative.yaml b/tests/integration/targets/nxos_file_copy/tests/cli/negative.yaml index 0b8d8ef9f..98d64eac3 100644 --- a/tests/integration/targets/nxos_file_copy/tests/cli/negative.yaml +++ b/tests/integration/targets/nxos_file_copy/tests/cli/negative.yaml @@ -56,7 +56,7 @@ # file_pull_timeout > 30s has no effect in this case, since the device # shell gives up connecting to the bad IP after 30s and the response # on the shell triggers a standard error regex. -- name: Try and copy file using an invalid remote scp server ip address +- name: Try and copy file using an invalid remote scp server IP address register: result ignore_errors: true cisco.nxos.nxos_file_copy: diff --git a/tests/integration/targets/nxos_file_copy/tests/cli/sanity.yaml b/tests/integration/targets/nxos_file_copy/tests/cli/sanity.yaml index 3ec2145a6..0f2bdbb0f 100644 --- a/tests/integration/targets/nxos_file_copy/tests/cli/sanity.yaml +++ b/tests/integration/targets/nxos_file_copy/tests/cli/sanity.yaml @@ -23,12 +23,12 @@ - rmdir dir1/dir2 - rmdir dir1 -- name: Setup - turn on feature scp-server +- name: Setup - turn on 'feature scp-server' cisco.nxos.nxos_feature: feature: scp-server state: enabled -- name: Setup - turn on feature sftp-server +- name: Setup - turn on 'feature sftp-server' cisco.nxos.nxos_feature: feature: sftp-server state: enabled @@ -132,11 +132,11 @@ - result.changed == true - "'copy scp:' in result.copy_cmd" - "'bootflash:' in result.file_system" - - "'bootflash:dir1/dir2/dir3/{{ test_destination_file }}_copy' in result.local_file" - - "'/{{ test_destination_file }}' in result.remote_file" + - "'bootflash:dir1/dir2/dir3/test_destination_file_copy' in result.local_file" + - "'/test_destination_file' in result.remote_file" - "'Received: File copied/pulled to nxos device from remote scp server.' in result.transfer_status" - - "'{{ mgmt0_ip }}' in result.remote_scp_server" + - mgmt0_ip in result.remote_scp_server - ansible.builtin.pause: seconds: 60 @@ -147,7 +147,10 @@ - ansible.builtin.assert: *id006 - - name: Initiate copy with sftp from nxos device to copy /bootflash/{{ test_destination_file }} to bootflash:dir2/dir2/dir3/{{ test_destination_file }}_another_copy + - name: >- + Initiate copy with sftp from nxos device to copy + /bootflash/{{ test_destination_file }} to + bootflash:dir2/dir2/dir3/{{ test_destination_file }}_another_copy register: result cisco.nxos.nxos_file_copy: file_pull: true @@ -166,11 +169,11 @@ - result.changed == true - "'copy sftp:' in result.copy_cmd" - "'bootflash:' in result.file_system" - - "'bootflash:dir1/dir2/dir3/{{ test_destination_file }}_another_copy' in result.local_file" - - "'/bootflash/{{ test_destination_file }}' in result.remote_file" + - "'bootflash:dir1/dir2/dir3/test_destination_file_another_copy' in result.local_file" + - "'/bootflash/test_destination_file' in result.remote_file" - "'Received: File copied/pulled to nxos device from remote scp server.' in result.transfer_status" - - "'{{ mgmt0_ip }}' in result.remote_scp_server" + - mgmt0_ip in result.remote_scp_server always: - name: Remove file @@ -184,12 +187,12 @@ no_log: true when: ansible_user != "admin" - - name: Turn off feature scp-server + - name: Turn off 'feature scp-server' cisco.nxos.nxos_feature: feature: scp-server state: disabled - - name: Turn off feature sftp-server + - name: Turn off 'feature sftp-server' cisco.nxos.nxos_feature: feature: sftp-server state: disabled diff --git a/tests/integration/targets/nxos_file_copy/tests/nxapi/badtransport.yaml b/tests/integration/targets/nxos_file_copy/tests/nxapi/badtransport.yaml index 3af96ed0e..aca1e195e 100644 --- a/tests/integration/targets/nxos_file_copy/tests/nxapi/badtransport.yaml +++ b/tests/integration/targets/nxos_file_copy/tests/nxapi/badtransport.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxapi/badtransport.yaml -- name: Sending transport other than cli should fail +- name: Sending transport other than CLI should fail register: result ignore_errors: true cisco.nxos.nxos_file_copy: diff --git a/tests/integration/targets/nxos_gir/tasks/cli.yaml b/tests/integration/targets/nxos_gir/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_gir/tasks/cli.yaml +++ b/tests/integration/targets/nxos_gir/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_gir/tasks/main.yaml b/tests/integration/targets/nxos_gir/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_gir/tasks/main.yaml +++ b/tests/integration/targets/nxos_gir/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_gir/tasks/nxapi.yaml b/tests/integration/targets/nxos_gir/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_gir/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_gir/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_gir_profile_management/tasks/cli.yaml b/tests/integration/targets/nxos_gir_profile_management/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_gir_profile_management/tasks/cli.yaml +++ b/tests/integration/targets/nxos_gir_profile_management/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_gir_profile_management/tasks/main.yaml b/tests/integration/targets/nxos_gir_profile_management/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_gir_profile_management/tasks/main.yaml +++ b/tests/integration/targets/nxos_gir_profile_management/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_gir_profile_management/tasks/nxapi.yaml b/tests/integration/targets/nxos_gir_profile_management/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_gir_profile_management/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_gir_profile_management/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_gir_profile_management/tests/common/sanity.yaml b/tests/integration/targets/nxos_gir_profile_management/tests/common/sanity.yaml index 8bc62c398..ae6c4b07a 100644 --- a/tests/integration/targets/nxos_gir_profile_management/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_gir_profile_management/tests/common/sanity.yaml @@ -14,7 +14,7 @@ mode: normal state: absent -- name: Setup - turn on feature eigrp +- name: Setup - turn on 'feature eigrp' ignore_errors: true cisco.nxos.nxos_feature: feature: eigrp @@ -93,7 +93,7 @@ - name: Remove maintenance mode profile cisco.nxos.nxos_gir_profile_management: *id005 - - name: Turn off feature eigrp + - name: Turn off 'feature eigrp' cisco.nxos.nxos_feature: feature: eigrp state: disabled diff --git a/tests/integration/targets/nxos_hostname/tasks/cli.yaml b/tests/integration/targets/nxos_hostname/tasks/cli.yaml index 507d803cb..e3e64747b 100644 --- a/tests/integration/targets/nxos_hostname/tasks/cli.yaml +++ b/tests/integration/targets/nxos_hostname/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_hostname/tasks/main.yaml b/tests/integration/targets/nxos_hostname/tasks/main.yaml index 116fbdd20..5d9d82223 100644 --- a/tests/integration/targets/nxos_hostname/tasks/main.yaml +++ b/tests/integration/targets/nxos_hostname/tasks/main.yaml @@ -5,7 +5,7 @@ register: hname_result - name: Set current hostname (default) - set_fact: + ansible.builtin.set_fact: current_hostname: "switch" - name: Set current hostname @@ -13,13 +13,14 @@ current_hostname: "{{ hname_result['stdout'][0].split(' ')[1] }}" when: hname_result.stdout[0] != "" -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli.yaml - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_hostname/tasks/nxapi.yaml b/tests/integration/targets/nxos_hostname/tasks/nxapi.yaml index 2e452bb6a..4ae68868c 100644 --- a/tests/integration/targets/nxos_hostname/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_hostname/tasks/nxapi.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_hostname/tests/common/_populate_config.yaml b/tests/integration/targets/nxos_hostname/tests/common/_populate_config.yaml index d77990556..67028c546 100644 --- a/tests/integration/targets/nxos_hostname/tests/common/_populate_config.yaml +++ b/tests/integration/targets/nxos_hostname/tests/common/_populate_config.yaml @@ -1,4 +1,4 @@ --- -- name: Populate config +- name: Populate configuration cisco.nxos.nxos_config: lines: "hostname {{ current_hostname }}" diff --git a/tests/integration/targets/nxos_hostname/tests/common/empty_config.yaml b/tests/integration/targets/nxos_hostname/tests/common/empty_config.yaml index cbcac8458..58ba11014 100644 --- a/tests/integration/targets/nxos_hostname/tests/common/empty_config.yaml +++ b/tests/integration/targets/nxos_hostname/tests/common/empty_config.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxos_hostname empty_config integration tests on connection={{ ansible_connection }} -- name: Merged with empty config should give appropriate error message +- name: Merged with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_hostname: @@ -13,7 +13,7 @@ that: - result.msg == 'value of config parameter must not be empty for state merged' -- name: Replaced with empty config should give appropriate error message +- name: Replaced with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_hostname: @@ -24,7 +24,7 @@ that: - result.msg == 'value of config parameter must not be empty for state replaced' -- name: Overridden with empty config should give appropriate error message +- name: Overridden with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_hostname: @@ -35,7 +35,7 @@ that: - result.msg == 'value of config parameter must not be empty for state overridden' -- name: Rendered with empty config should give appropriate error message +- name: Rendered with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_hostname: @@ -46,7 +46,7 @@ that: - result.msg == 'value of config parameter must not be empty for state rendered' -- name: Parsed with empty config should give appropriate error message +- name: Parsed with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_hostname: diff --git a/tests/integration/targets/nxos_hostname/tests/common/parsed.yaml b/tests/integration/targets/nxos_hostname/tests/common/parsed.yaml index 9c669f3e1..b1ab1d992 100644 --- a/tests/integration/targets/nxos_hostname/tests/common/parsed.yaml +++ b/tests/integration/targets/nxos_hostname/tests/common/parsed.yaml @@ -8,7 +8,7 @@ running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" state: parsed -- name: Assert that config was correctly parsed +- name: Assert that configuration was correctly parsed ansible.builtin.assert: that: - "{{ merged['after'] == result['parsed'] }}" diff --git a/tests/integration/targets/nxos_hsrp/tasks/cli.yaml b/tests/integration/targets/nxos_hsrp/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_hsrp/tasks/cli.yaml +++ b/tests/integration/targets/nxos_hsrp/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_hsrp/tasks/main.yaml b/tests/integration/targets/nxos_hsrp/tasks/main.yaml index 7631f52fe..c9e70304e 100644 --- a/tests/integration/targets/nxos_hsrp/tasks/main.yaml +++ b/tests/integration/targets/nxos_hsrp/tasks/main.yaml @@ -1,11 +1,12 @@ --- -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli always: - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_hsrp/tasks/nxapi.yaml b/tests/integration/targets/nxos_hsrp/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_hsrp/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_hsrp/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_hsrp/tests/common/sanity.yaml b/tests/integration/targets/nxos_hsrp/tests/common/sanity.yaml index da751337c..a4c774787 100644 --- a/tests/integration/targets/nxos_hsrp/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_hsrp/tests/common/sanity.yaml @@ -11,7 +11,7 @@ intname2: "{{ nxos_int2 }}" - block: - - name: Enable feature hsrp + - name: Enable 'feature hsrp' cisco.nxos.nxos_feature: feature: hsrp state: enabled @@ -48,7 +48,7 @@ that: - result.changed == true - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_hsrp: *id001 @@ -70,7 +70,7 @@ - ansible.builtin.assert: *id002 - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_hsrp: *id003 @@ -90,7 +90,7 @@ - ansible.builtin.assert: *id002 - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_hsrp: *id005 @@ -108,7 +108,7 @@ - ansible.builtin.assert: *id002 - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_hsrp: *id006 @@ -126,7 +126,7 @@ - ansible.builtin.assert: *id002 - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_hsrp: *id007 @@ -147,7 +147,7 @@ - ansible.builtin.assert: *id004 always: - - name: Disable feature hsrp + - name: Disable 'feature hsrp' ignore_errors: true cisco.nxos.nxos_feature: feature: hsrp diff --git a/tests/integration/targets/nxos_hsrp_interfaces/tasks/cli.yaml b/tests/integration/targets/nxos_hsrp_interfaces/tasks/cli.yaml index ba1eff1cd..e3e64747b 100644 --- a/tests/integration/targets/nxos_hsrp_interfaces/tasks/cli.yaml +++ b/tests/integration/targets/nxos_hsrp_interfaces/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,11 +23,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_hsrp_interfaces/tasks/main.yaml b/tests/integration/targets/nxos_hsrp_interfaces/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_hsrp_interfaces/tasks/main.yaml +++ b/tests/integration/targets/nxos_hsrp_interfaces/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_hsrp_interfaces/tasks/nxapi.yaml b/tests/integration/targets/nxos_hsrp_interfaces/tasks/nxapi.yaml index 2e452bb6a..4ae68868c 100644 --- a/tests/integration/targets/nxos_hsrp_interfaces/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_hsrp_interfaces/tasks/nxapi.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_hsrp_interfaces/tests/common/_populate_config.yaml b/tests/integration/targets/nxos_hsrp_interfaces/tests/common/_populate_config.yaml index cfeb56095..404430235 100644 --- a/tests/integration/targets/nxos_hsrp_interfaces/tests/common/_populate_config.yaml +++ b/tests/integration/targets/nxos_hsrp_interfaces/tests/common/_populate_config.yaml @@ -1,5 +1,5 @@ --- -- name: Populate config - 1 +- name: Populate configuration - 1 cisco.nxos.nxos_config: lines: - "feature hsrp" @@ -8,7 +8,7 @@ - " no switchport" - " hsrp bfd" -- name: Populate config - 2 +- name: Populate configuration - 2 cisco.nxos.nxos_config: lines: - "interface {{ nxos_int2 }}" diff --git a/tests/integration/targets/nxos_hsrp_interfaces/tests/common/_remove_config.yaml b/tests/integration/targets/nxos_hsrp_interfaces/tests/common/_remove_config.yaml index 002d42eb5..d55e828d5 100644 --- a/tests/integration/targets/nxos_hsrp_interfaces/tests/common/_remove_config.yaml +++ b/tests/integration/targets/nxos_hsrp_interfaces/tests/common/_remove_config.yaml @@ -1,5 +1,5 @@ --- -- name: Remove config +- name: Remove configuration cisco.nxos.nxos_config: lines: - "no feature bfd" diff --git a/tests/integration/targets/nxos_hsrp_interfaces/tests/common/empty_config.yaml b/tests/integration/targets/nxos_hsrp_interfaces/tests/common/empty_config.yaml index 6e38467bc..f80fd63b7 100644 --- a/tests/integration/targets/nxos_hsrp_interfaces/tests/common/empty_config.yaml +++ b/tests/integration/targets/nxos_hsrp_interfaces/tests/common/empty_config.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxos_hsrp_interfaces empty_config integration tests on connection={{ ansible_connection }} -- name: Merged with empty config should give appropriate error message +- name: Merged with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_hsrp_interfaces: @@ -13,7 +13,7 @@ that: - result.msg == 'value of config parameter must not be empty for state merged' -- name: Replaced with empty config should give appropriate error message +- name: Replaced with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_hsrp_interfaces: @@ -24,7 +24,7 @@ that: - result.msg == 'value of config parameter must not be empty for state replaced' -- name: Overridden with empty config should give appropriate error message +- name: Overridden with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_hsrp_interfaces: @@ -35,7 +35,7 @@ that: - result.msg == 'value of config parameter must not be empty for state overridden' -- name: Rendered with empty config should give appropriate error message +- name: Rendered with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_hsrp_interfaces: @@ -46,7 +46,7 @@ that: - result.msg == 'value of config parameter must not be empty for state rendered' -- name: Parsed with empty config should give appropriate error message +- name: Parsed with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_hsrp_interfaces: diff --git a/tests/integration/targets/nxos_hsrp_interfaces/tests/common/parsed.yaml b/tests/integration/targets/nxos_hsrp_interfaces/tests/common/parsed.yaml index 275510df7..eeee8871b 100644 --- a/tests/integration/targets/nxos_hsrp_interfaces/tests/common/parsed.yaml +++ b/tests/integration/targets/nxos_hsrp_interfaces/tests/common/parsed.yaml @@ -4,7 +4,7 @@ - block: # Interfaces used in the task don't actually exist on the appliance - - name: Use parsed state to convert externally supplied config to structured format + - name: Use parsed state to convert externally supplied configuration to structured format register: result cisco.nxos.nxos_hsrp_interfaces: running_config: | diff --git a/tests/integration/targets/nxos_hsrp_interfaces/vars/main.yml b/tests/integration/targets/nxos_hsrp_interfaces/vars/main.yml index 3956fbfef..1a741272f 100644 --- a/tests/integration/targets/nxos_hsrp_interfaces/vars/main.yml +++ b/tests/integration/targets/nxos_hsrp_interfaces/vars/main.yml @@ -1,3 +1,4 @@ +--- gathered: - name: "{{ nxos_int1 }}" bfd: enable diff --git a/tests/integration/targets/nxos_igmp/tasks/cli.yaml b/tests/integration/targets/nxos_igmp/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_igmp/tasks/cli.yaml +++ b/tests/integration/targets/nxos_igmp/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_igmp/tasks/main.yaml b/tests/integration/targets/nxos_igmp/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_igmp/tasks/main.yaml +++ b/tests/integration/targets/nxos_igmp/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_igmp/tasks/nxapi.yaml b/tests/integration/targets/nxos_igmp/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_igmp/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_igmp/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_igmp/tests/common/sanity.yaml b/tests/integration/targets/nxos_igmp/tests/common/sanity.yaml index 0fd4a53ff..7c8704aea 100644 --- a/tests/integration/targets/nxos_igmp/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_igmp/tests/common/sanity.yaml @@ -8,7 +8,7 @@ when: platform is not match("N35") - block: - - name: Configure igmp with non-default values + - name: Configure IGMP with non-default values register: result cisco.nxos.nxos_igmp: &id001 flush_routes: true @@ -20,7 +20,7 @@ that: - result.changed == true - - name: Check idempotence - configure igmp interface with non-default values + - name: Check idempotence - configure IGMP interface with non-default values register: result cisco.nxos.nxos_igmp: *id001 @@ -28,7 +28,7 @@ that: - result.changed == false - - name: Configure igmp defaults + - name: Configure IGMP defaults register: result cisco.nxos.nxos_igmp: &id003 flush_routes: false @@ -38,30 +38,30 @@ - ansible.builtin.assert: *id002 - - name: Check idempotence - configure igmp with defaults + - name: Check idempotence - configure IGMP with defaults register: result cisco.nxos.nxos_igmp: *id003 - ansible.builtin.assert: *id004 - - name: Configure igmp non-defaults again + - name: Configure IGMP non-defaults again register: result cisco.nxos.nxos_igmp: *id001 - - name: Configure igmp state as values + - name: Configure IGMP state as values register: result cisco.nxos.nxos_igmp: &id005 state: default - ansible.builtin.assert: *id002 - - name: Check idempotence - configure igmp with state default + - name: Check idempotence - configure IGMP with state default register: result cisco.nxos.nxos_igmp: *id005 - ansible.builtin.assert: *id004 always: - - name: Configure igmp with default values + - name: Configure IGMP with default values register: result ignore_errors: true cisco.nxos.nxos_igmp: *id005 diff --git a/tests/integration/targets/nxos_igmp_interface/tasks/cli.yaml b/tests/integration/targets/nxos_igmp_interface/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_igmp_interface/tasks/cli.yaml +++ b/tests/integration/targets/nxos_igmp_interface/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_igmp_interface/tasks/main.yaml b/tests/integration/targets/nxos_igmp_interface/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_igmp_interface/tasks/main.yaml +++ b/tests/integration/targets/nxos_igmp_interface/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_igmp_interface/tasks/nxapi.yaml b/tests/integration/targets/nxos_igmp_interface/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_igmp_interface/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_igmp_interface/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_igmp_interface/tests/common/sanity.yaml b/tests/integration/targets/nxos_igmp_interface/tests/common/sanity.yaml index c5d00df19..56b658afc 100644 --- a/tests/integration/targets/nxos_igmp_interface/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_igmp_interface/tests/common/sanity.yaml @@ -11,7 +11,7 @@ restart: true when: platform is not match("N35") -- name: Enable feature pim +- name: Enable 'feature pim' ignore_errors: true cisco.nxos.nxos_feature: feature: pim @@ -25,7 +25,7 @@ match: none - block: - - name: Put interface in l3 and enable pim + - name: Put interface in layer 3 and enable PIM cisco.nxos.nxos_config: commands: - no switchport @@ -34,7 +34,7 @@ - interface {{ intname }} match: none - - name: Configure igmp interface with non-default values + - name: Configure IGMP interface with non-default values register: result cisco.nxos.nxos_igmp_interface: &id001 interface: "{{ intname }}" @@ -59,7 +59,7 @@ that: - result.changed == true - - name: Check idempotence - configure igmp interface with non-default values + - name: Check idempotence - configure IGMP interface with non-default values register: result cisco.nxos.nxos_igmp_interface: *id001 @@ -67,7 +67,7 @@ that: - result.changed == false - - name: Configure igmp interface with some default values + - name: Configure IGMP interface with some default values register: result cisco.nxos.nxos_igmp_interface: &id003 interface: "{{ intname }}" @@ -92,18 +92,18 @@ - ansible.builtin.assert: *id002 - - name: Check idempotence - configure igmp interface with some default values + - name: Check idempotence - configure IGMP interface with some default values register: result cisco.nxos.nxos_igmp_interface: *id003 - ansible.builtin.assert: *id004 - - name: Restart igmp + - name: Restart IGMP cisco.nxos.nxos_igmp_interface: interface: "{{ intname }}" restart: "{{restart|default(omit)}}" - - name: Configure igmp interface with default oif_ps + - name: Configure IGMP interface with default oif_ps register: result cisco.nxos.nxos_igmp_interface: &id005 interface: "{{ intname }}" @@ -112,13 +112,13 @@ - ansible.builtin.assert: *id002 - - name: Check idempotence - configure igmp interface with default oif_ps + - name: Check idempotence - configure IGMP interface with default oif_ps register: result cisco.nxos.nxos_igmp_interface: *id005 - ansible.builtin.assert: *id004 - - name: Configure igmp interface with oif_routemap + - name: Configure IGMP interface with oif_routemap register: result cisco.nxos.nxos_igmp_interface: &id006 interface: "{{ intname }}" @@ -131,13 +131,13 @@ - ansible.builtin.assert: *id002 - - name: Check idempotence - configure igmp interface with oif_routemap + - name: Check idempotence - configure IGMP interface with oif_routemap register: result cisco.nxos.nxos_igmp_interface: *id006 - ansible.builtin.assert: *id004 - - name: Configure igmp interface with default state + - name: Configure IGMP interface with default state register: result cisco.nxos.nxos_igmp_interface: &id007 interface: "{{ intname }}" @@ -145,13 +145,13 @@ - ansible.builtin.assert: *id002 - - name: Check idempotence - configure igmp interface with default state + - name: Check idempotence - configure IGMP interface with default state register: result cisco.nxos.nxos_igmp_interface: *id007 - ansible.builtin.assert: *id004 - - name: Configure igmp interface with absent state + - name: Configure IGMP interface with absent state register: result cisco.nxos.nxos_igmp_interface: &id008 interface: "{{ intname }}" @@ -159,13 +159,13 @@ - ansible.builtin.assert: *id002 - - name: Check idempotence - configure igmp interface with absent state + - name: Check idempotence - configure IGMP interface with absent state register: result cisco.nxos.nxos_igmp_interface: *id008 - ansible.builtin.assert: *id004 always: - - name: Configure igmp interface with absent state + - name: Configure IGMP interface with absent state register: result cisco.nxos.nxos_igmp_interface: *id008 @@ -175,7 +175,7 @@ - default interface {{ intname }} match: none - - name: Disable feature pim + - name: Disable 'feature pim' ignore_errors: true cisco.nxos.nxos_feature: feature: pim diff --git a/tests/integration/targets/nxos_igmp_snooping/tasks/cli.yaml b/tests/integration/targets/nxos_igmp_snooping/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_igmp_snooping/tasks/cli.yaml +++ b/tests/integration/targets/nxos_igmp_snooping/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_igmp_snooping/tasks/main.yaml b/tests/integration/targets/nxos_igmp_snooping/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_igmp_snooping/tasks/main.yaml +++ b/tests/integration/targets/nxos_igmp_snooping/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_igmp_snooping/tasks/nxapi.yaml b/tests/integration/targets/nxos_igmp_snooping/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_igmp_snooping/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_igmp_snooping/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_igmp_snooping/tests/common/sanity.yaml b/tests/integration/targets/nxos_igmp_snooping/tests/common/sanity.yaml index e719a4c8d..e57fc978a 100644 --- a/tests/integration/targets/nxos_igmp_snooping/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_igmp_snooping/tests/common/sanity.yaml @@ -28,7 +28,7 @@ state: default - block: - - name: Configure igmp snooping with non-default values + - name: Configure IGMP snooping with non-default values register: result cisco.nxos.nxos_igmp_snooping: &id001 snooping: false @@ -81,7 +81,7 @@ - assert: *id004 when: gt_run - - name: Configure igmp snooping with default group timeout + - name: Configure IGMP snooping with default group timeout register: result cisco.nxos.nxos_igmp_snooping: &id005 group_timeout: "{{def_group_timeout|default(omit)}}" @@ -98,7 +98,7 @@ - assert: *id004 when: (imagetag and imagetag is not search("D1")) - - name: Configure igmp snooping with default values + - name: Configure IGMP snooping with default values register: result cisco.nxos.nxos_igmp_snooping: *id006 @@ -112,7 +112,7 @@ - assert: *id004 when: (imagetag and imagetag is not search("D1")) always: - - name: Configure igmp snooping with default values + - name: Configure IGMP snooping with default values register: result cisco.nxos.nxos_igmp_snooping: *id006 diff --git a/tests/integration/targets/nxos_install_os/tasks/httpapi.yaml b/tests/integration/targets/nxos_install_os/tasks/httpapi.yaml index 555aa8358..acefd4a4c 100644 --- a/tests/integration/targets/nxos_install_os/tasks/httpapi.yaml +++ b/tests/integration/targets/nxos_install_os/tasks/httpapi.yaml @@ -10,11 +10,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (ansible_connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_install_os/tasks/main.yaml b/tests/integration/targets/nxos_install_os/tasks/main.yaml index 5067603f0..30b50a39a 100644 --- a/tests/integration/targets/nxos_install_os/tasks/main.yaml +++ b/tests/integration/targets/nxos_install_os/tasks/main.yaml @@ -1,6 +1,8 @@ --- -- ansible.builtin.include: network_cli.yaml +- name: Run network_cli tests + ansible.builtin.include_tasks: network_cli.yaml when: ansible_connection == 'ansible.netcommon.network_cli' -- ansible.builtin.include: httpapi.yaml +- name: Run httpapi tests + ansible.builtin.include_tasks: httpapi.yaml when: ansible_connection == 'ansible.netcommon.httpapi' diff --git a/tests/integration/targets/nxos_install_os/tasks/network_cli.yaml b/tests/integration/targets/nxos_install_os/tasks/network_cli.yaml index 476745353..df97b28bc 100644 --- a/tests/integration/targets/nxos_install_os/tasks/network_cli.yaml +++ b/tests/integration/targets/nxos_install_os/tasks/network_cli.yaml @@ -10,11 +10,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (ansible_connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_install_os/tasks/upgrade/clear_persistent_sockets.yaml b/tests/integration/targets/nxos_install_os/tasks/upgrade/clear_persistent_sockets.yaml index d0947d0d6..9cb4efc3b 100644 --- a/tests/integration/targets/nxos_install_os/tasks/upgrade/clear_persistent_sockets.yaml +++ b/tests/integration/targets/nxos_install_os/tasks/upgrade/clear_persistent_sockets.yaml @@ -6,11 +6,12 @@ delegate_to: 127.0.0.1 - name: Display socket info after delete - ansible.builtin.shell: /bin/ls {{ home }}/.ansible + ansible.builtin.shell: /bin/ls {{ home }}/.ansible # noqa command-instead-of-shell no-changed-when args: executable: /bin/bash delegate_to: 127.0.0.1 register: output -- ansible.builtin.debug: +- name: Debug output the local socket information + ansible.builtin.debug: msg: Local Socket Info {{ output['stdout_lines'] }} diff --git a/tests/integration/targets/nxos_install_os/tasks/upgrade/copy_kick_system_images.yaml b/tests/integration/targets/nxos_install_os/tasks/upgrade/copy_kick_system_images.yaml index 9f8115756..0ee795a8f 100644 --- a/tests/integration/targets/nxos_install_os/tasks/upgrade/copy_kick_system_images.yaml +++ b/tests/integration/targets/nxos_install_os/tasks/upgrade/copy_kick_system_images.yaml @@ -8,39 +8,42 @@ ignore_errors_httpapi: true when: ansible_connection == 'ansible.netcommon.httpapi' -- ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/enable_scp_server.yaml +- name: Enable SCP server + ansible.builtin.include_tasks: enable_scp_server.yaml -- name: Remove ssh known_hosts file before scp of image file - ignore_errors: true +- name: Remove SSH known_hosts file before scp of image file + ignore_errors: true # noqa ignore-errors cisco.nxos.nxos_command: commands: run bash rm /var/home/admin/.ssh/known_hosts -- name: Copy {{ si }} to bootflash +- name: Copy file to bootflash {{ si }} register: result cisco.nxos.nxos_file_copy: file_pull: true file_pull_timeout: 1200 - remote_file: "{{image_dir}}{{ si }}" + remote_file: "{{ image_dir }}{{ si }}" remote_scp_server: "{{ remote_scp_server }}" remote_scp_server_user: "{{ remote_scp_user }}" remote_scp_server_password: "{{ remote_scp_password }}" -- ansible.builtin.debug: +- name: Debug output the result from the image copy + ansible.builtin.debug: msg: "{{ item.key }} {{ item.value }}" with_dict: "{{ result }}" -- name: Copy {{ ki }} to bootflash +- name: Copy file to bootflash {{ ki }} when: ki is defined register: result cisco.nxos.nxos_file_copy: file_pull: true file_pull_timeout: 1200 - remote_file: "{{image_dir}}{{ ki }}" + remote_file: "{{ image_dir }}{{ ki }}" remote_scp_server: "{{ remote_scp_server }}" remote_scp_server_user: "{{ remote_scp_user }}" remote_scp_server_password: "{{ remote_scp_password }}" -- ansible.builtin.debug: +- name: Debug out the result from the image copy + ansible.builtin.debug: msg: "{{ item.key }} {{ item.value }}" with_dict: "{{ result }}" when: ki is defined diff --git a/tests/integration/targets/nxos_install_os/tasks/upgrade/delete_files.yaml b/tests/integration/targets/nxos_install_os/tasks/upgrade/delete_files.yaml index 2bfd69f64..d382c3c0e 100644 --- a/tests/integration/targets/nxos_install_os/tasks/upgrade/delete_files.yaml +++ b/tests/integration/targets/nxos_install_os/tasks/upgrade/delete_files.yaml @@ -1,6 +1,6 @@ --- - name: Delete files to make room on bootflash - ignore_errors: true + ignore_errors: true # noqa ignore-errors with_items: "{{ delete_image_list }}" cisco.nxos.nxos_config: lines: diff --git a/tests/integration/targets/nxos_install_os/tasks/upgrade/enable_scp_server.yaml b/tests/integration/targets/nxos_install_os/tasks/upgrade/enable_scp_server.yaml index 8900c60ce..c429f33ac 100644 --- a/tests/integration/targets/nxos_install_os/tasks/upgrade/enable_scp_server.yaml +++ b/tests/integration/targets/nxos_install_os/tasks/upgrade/enable_scp_server.yaml @@ -1,5 +1,5 @@ --- -- name: Setup - turn on feature scp-server +- name: Setup - turn on 'feature scp-server' cisco.nxos.nxos_feature: feature: scp-server state: enabled diff --git a/tests/integration/targets/nxos_install_os/tasks/upgrade/install_os.yaml b/tests/integration/targets/nxos_install_os/tasks/upgrade/install_os.yaml index bfc3d737b..e348d1e22 100644 --- a/tests/integration/targets/nxos_install_os/tasks/upgrade/install_os.yaml +++ b/tests/integration/targets/nxos_install_os/tasks/upgrade/install_os.yaml @@ -1,23 +1,31 @@ --- -- ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/delete_files.yaml +- name: Run delete files tasks + ansible.builtin.include_tasks: delete_files.yaml when: delete_files -- ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/copy_kick_system_images.yaml ansible_connection=ansible.netcommon.network_cli connection={{ cli }} +- name: Copy Kick System images + ansible.builtin.include_tasks: copy_kick_system_images.yaml + vars: + ansible_connection: ansible.netcommon.network_cli connection={{ cli }} when: copy_images -- ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/install_with_kick.yaml +- name: Run install with kick tests + ansible.builtin.include_tasks: install_with_kick.yaml when: ki is defined -- ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/install_system.yaml +- name: Run install system + ansible.builtin.include_tasks: install_system.yaml when: ki is undefined -- ansible.builtin.meta: reset_connection +- name: Reset the connection + ansible.builtin.meta: reset_connection -- name: Check installed os for newly installed version {{ tv }} +- name: Check installed OS for newly installed version {{ tv }} register: output cisco.nxos.nxos_command: commands: - show version | json -- ansible.builtin.debug: +- name: Debug output the version detected + ansible.builtin.debug: msg: Version detected {{ output['stdout_lines'][0]['kickstart_ver_str'] }} diff --git a/tests/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml b/tests/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml index cb2eb5867..fcc403878 100644 --- a/tests/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml +++ b/tests/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml @@ -1,5 +1,5 @@ --- -- name: Install os image {{ si }} +- name: Install OS image {{ si }} check_mode: "{{ checkmode }}" register: result when: not force @@ -8,7 +8,7 @@ issu: "{{ issu }}" - name: Remove old boot pointers if any - ignore_errors: true + ignore_errors: true # noqa ignore-errors when: force cisco.nxos.nxos_config: lines: @@ -17,7 +17,7 @@ - no boot system match: line -- name: Set os image {{ si }} boot pointers +- name: "Set OS image boot pointers: {{ si }}" when: force cisco.nxos.nxos_config: lines: @@ -25,15 +25,16 @@ - copy run start match: line -- name: Boot image {{ si }} using reload - ignore_errors: true +- name: "Boot image using reload: {{ si }}" + ignore_errors: true # noqa ignore-errors when: force cisco.nxos.nxos_config: lines: - terminal dont-ask - reload -- ansible.builtin.debug: +- name: Debug output the result from the image installation + ansible.builtin.debug: msg: " {{ result['install_state'] }}" when: not force @@ -46,10 +47,12 @@ host: "{{ inventory_hostname }}" when: result.changed and not checkmode -- ansible.builtin.debug: +- name: Debug output a warning about the 5 minute wait + ansible.builtin.debug: msg: Wait 5 mins to allow system to stabilize when: result.changed and not checkmode -- ansible.builtin.pause: +- name: Wait for device to come back up with new image + ansible.builtin.pause: seconds: 300 when: result.changed and not checkmode diff --git a/tests/integration/targets/nxos_install_os/tasks/upgrade/install_with_kick.yaml b/tests/integration/targets/nxos_install_os/tasks/upgrade/install_with_kick.yaml index 9d2d1cff2..3a5af1240 100644 --- a/tests/integration/targets/nxos_install_os/tasks/upgrade/install_with_kick.yaml +++ b/tests/integration/targets/nxos_install_os/tasks/upgrade/install_with_kick.yaml @@ -1,5 +1,5 @@ --- -- name: Install os image {{ si }} +- name: Install OS image {{ si }} check_mode: "{{ checkmode }}" register: result when: not force @@ -8,7 +8,7 @@ kickstart_image_file: "{{ ki }}" issu: "{{ issu }}" -- name: Set os image {{ si }} boot pointers +- name: Set boot pointers for OS image {{ si }} when: force cisco.nxos.nxos_config: lines: @@ -19,13 +19,14 @@ - copy run start match: line -- name: Boot image {{ si }} using reload - ignore_errors: true +- name: "Boot image using reload {{ si }}" + ignore_errors: true # noqa ignore-errors when: force cisco.nxos.nxos_command: commands: terminal dont-ask ; reload -- ansible.builtin.debug: +- name: Debug output the result from the image installation + ansible.builtin.debug: msg: " {{ result['install_state'] }}" when: not force @@ -38,10 +39,12 @@ host: "{{ inventory_hostname }}" when: result.changed and not checkmode -- ansible.builtin.debug: +- name: Debug output a warning about the 5 minute wait + ansible.builtin.debug: msg: Wait 5 mins to allow system to stabilize when: result.changed and not checkmode -- ansible.builtin.pause: +- name: Wait for device to come back up with new image + ansible.builtin.pause: seconds: 300 when: result.changed and not checkmode diff --git a/tests/integration/targets/nxos_install_os/tasks/upgrade/main_os_install.yaml b/tests/integration/targets/nxos_install_os/tasks/upgrade/main_os_install.yaml index 6c96c364e..acbf45a56 100644 --- a/tests/integration/targets/nxos_install_os/tasks/upgrade/main_os_install.yaml +++ b/tests/integration/targets/nxos_install_os/tasks/upgrade/main_os_install.yaml @@ -1,7 +1,10 @@ --- -- ansible.builtin.debug: +- name: Debug output a warning about meta endplay + ansible.builtin.debug: msg: "***WARNING*** Remove meta end_play to verify this module ***WARNING***" -- ansible.builtin.meta: end_play +- name: End the play + ansible.builtin.meta: end_play -- ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/install_os.yaml +- name: Run Install OS + ansible.builtin.include_tasks: install_os.yaml diff --git a/tests/integration/targets/nxos_install_os/tests/common/upgrade.yaml b/tests/integration/targets/nxos_install_os/tests/common/upgrade.yaml index 0212cbaed..e4f02dd80 100644 --- a/tests/integration/targets/nxos_install_os/tests/common/upgrade.yaml +++ b/tests/integration/targets/nxos_install_os/tests/common/upgrade.yaml @@ -42,7 +42,7 @@ ki: n3000-uk9-kickstart.6.0.2.U6.1a.bin - name: Upgrade to u6.1a - ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml + ansible.builtin.include_tasks: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml - name: Set a fact for 'si' ansible.builtin.set_fact: @@ -53,7 +53,7 @@ ki: n3000-uk9-kickstart.6.0.2.U6.2a.bin - name: Upgrade to u6.2a - ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml + ansible.builtin.include_tasks: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml - name: Set a fact for 'si' ansible.builtin.set_fact: @@ -64,14 +64,14 @@ ki: n3000-s2-kickstart.8.0.1.bin - name: Upgrade to u6.3a - ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml + ansible.builtin.include_tasks: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml - name: Set a fact for 'si' ansible.builtin.set_fact: si: nxos.7.0.3.I7.2.bin - name: Upgrade to 7.0.3.i7.2 - ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml + ansible.builtin.include_tasks: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml - ansible.builtin.debug: msg: END connection={{ ansible_connection }} nxos_os_install upgrade diff --git a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n3172_greensboro.yaml b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n3172_greensboro.yaml index e5d43344b..15c6748b5 100644 --- a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n3172_greensboro.yaml +++ b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n3172_greensboro.yaml @@ -38,4 +38,4 @@ si: nxos.7.0.3.I7.4.bin - name: Upgrade n3172 device to greensboro release image - ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml + ansible.builtin.include_tasks: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml diff --git a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n3172_u61a.yaml b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n3172_u61a.yaml index c3ea43dc3..b32be6e38 100644 --- a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n3172_u61a.yaml +++ b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n3172_u61a.yaml @@ -42,4 +42,4 @@ ki: n3000-uk9-kickstart.6.0.2.U6.1a.bin - name: Upgrade n3500 device to u61a release image - ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml + ansible.builtin.include_tasks: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml diff --git a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n3172_u62a.yaml b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n3172_u62a.yaml index 55fbf843c..3db45b719 100644 --- a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n3172_u62a.yaml +++ b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n3172_u62a.yaml @@ -42,4 +42,4 @@ ki: n3000-uk9-kickstart.6.0.2.U6.2a.bin - name: Upgrade n3500 device to u62a release image - ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml + ansible.builtin.include_tasks: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml diff --git a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n3172_u63a.yaml b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n3172_u63a.yaml index 0280b76f9..12c246fd6 100644 --- a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n3172_u63a.yaml +++ b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n3172_u63a.yaml @@ -42,4 +42,4 @@ ki: n3000-uk9-kickstart.6.0.2.U6.3a.bin - name: Upgrade n3500 device to u63a release image - ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml + ansible.builtin.include_tasks: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml diff --git a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n35_62a88.yaml b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n35_62a88.yaml index 670c6dee2..7ee9f0c6e 100644 --- a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n35_62a88.yaml +++ b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n35_62a88.yaml @@ -42,4 +42,4 @@ ki: n3500-uk9-kickstart.6.0.2.A8.8.bin - name: Upgrade n3500 device to a8_8 release image - ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml + ansible.builtin.include_tasks: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml diff --git a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n35_greensboro.yaml b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n35_greensboro.yaml index d5ff37113..4b997c8be 100644 --- a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n35_greensboro.yaml +++ b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n35_greensboro.yaml @@ -38,4 +38,4 @@ si: nxos.7.0.3.I7.4.bin - name: Upgrade n3500 device to greensboro release image - ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml + ansible.builtin.include_tasks: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml diff --git a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n5k_730_N11.yaml b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n5k_730_N11.yaml index f93575f1e..b7405ec29 100644 --- a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n5k_730_N11.yaml +++ b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n5k_730_N11.yaml @@ -40,5 +40,5 @@ ansible.builtin.set_fact: ki: n6000-uk9-kickstart.7.3.0.N1.1.bin -- name: Upgrade n5k device to 7.3(0)n1(1) release image - ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml +- name: Upgrade N5K device to 7.3(0)n1(1) release image + ansible.builtin.include_tasks: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml diff --git a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n5k_733_N11.yaml b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n5k_733_N11.yaml index 9d5c85621..03e27f525 100644 --- a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n5k_733_N11.yaml +++ b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n5k_733_N11.yaml @@ -40,5 +40,5 @@ ansible.builtin.set_fact: ki: n6000-uk9-kickstart.7.3.3.N1.1.bin -- name: Upgrade n5k device to 7.3(3)n1(1) release image - ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml +- name: Upgrade N5K device to 7.3(3)n1(1) release image + ansible.builtin.include_tasks: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml diff --git a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n7k_atherton.yaml b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n7k_atherton.yaml index 753cb3bf6..62507228b 100644 --- a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n7k_atherton.yaml +++ b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n7k_atherton.yaml @@ -40,5 +40,5 @@ ansible.builtin.set_fact: ki: n7000-s2-kickstart.8.0.1.bin -- name: Upgrade n7k device to atherton release image - ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml +- name: Upgrade N7K device to atherton release image + ansible.builtin.include_tasks: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml diff --git a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n7k_helsinki.yaml b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n7k_helsinki.yaml index e99db34bc..b8660ea1a 100644 --- a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n7k_helsinki.yaml +++ b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n7k_helsinki.yaml @@ -40,5 +40,5 @@ ansible.builtin.set_fact: ki: n7000-s2-kickstart.7.3.0.D1.1.bin -- name: Upgrade n7k device to helsinki release image - ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml +- name: Upgrade N7K device to helsinki release image + ansible.builtin.include_tasks: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml diff --git a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n9k_greensboro.yaml b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n9k_greensboro.yaml index e2d353814..3da1fe5a2 100644 --- a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n9k_greensboro.yaml +++ b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n9k_greensboro.yaml @@ -46,5 +46,5 @@ ansible.builtin.set_fact: si: nxos.7.0.3.I7.4.bin -- name: Upgrade n9k device to greensboro release image - ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml +- name: Upgrade N9K device to greensboro release image + ansible.builtin.include_tasks: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml diff --git a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n9k_greensboro_force.yaml b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n9k_greensboro_force.yaml index df04c5ae4..3d8599c99 100644 --- a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n9k_greensboro_force.yaml +++ b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n9k_greensboro_force.yaml @@ -46,5 +46,5 @@ ansible.builtin.set_fact: si: nxos.7.0.3.I7.4.bin -- name: Upgrade n9k device to greensboro release image - ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml +- name: Upgrade N9K device to greensboro release image + ansible.builtin.include_tasks: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml diff --git a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n9k_hamilton.yaml b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n9k_hamilton.yaml index cfb7b0029..304e26691 100644 --- a/tests/integration/targets/nxos_install_os/tests/common/upgrade_n9k_hamilton.yaml +++ b/tests/integration/targets/nxos_install_os/tests/common/upgrade_n9k_hamilton.yaml @@ -44,5 +44,5 @@ ansible.builtin.set_fact: si: nxos.9.2.1.bin -- name: Upgrade n9k device to hamilton release image - ansible.builtin.include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml +- name: Upgrade N9K device to hamilton release image + ansible.builtin.include_tasks: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml diff --git a/tests/integration/targets/nxos_interface/defaults/main.yaml b/tests/integration/targets/nxos_interface/defaults/main.yaml deleted file mode 100644 index 5f709c5aa..000000000 --- a/tests/integration/targets/nxos_interface/defaults/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -testcase: "*" diff --git a/tests/integration/targets/nxos_interface/meta/main.yml b/tests/integration/targets/nxos_interface/meta/main.yml deleted file mode 100644 index f504a6ab2..000000000 --- a/tests/integration/targets/nxos_interface/meta/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_nxos_tests diff --git a/tests/integration/targets/nxos_interface/tasks/cli.yaml b/tests/integration/targets/nxos_interface/tasks/cli.yaml deleted file mode 100644 index 90342e6b1..000000000 --- a/tests/integration/targets/nxos_interface/tasks/cli.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect cli test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - connection: local - register: cli_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + cli_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.network_cli) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_interface/tasks/main.yaml b/tests/integration/targets/nxos_interface/tasks/main.yaml deleted file mode 100644 index 62e44ffda..000000000 --- a/tests/integration/targets/nxos_interface/tasks/main.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Include the cli tasks - ansible.builtin.include_tasks: cli.yaml - tags: - - cli - -- name: Include the nx-api tasks - ansible.builtin.include_tasks: nxapi.yaml - tags: - - nxapi diff --git a/tests/integration/targets/nxos_interface/tasks/nxapi.yaml b/tests/integration/targets/nxos_interface/tasks/nxapi.yaml deleted file mode 100644 index cedab80f1..000000000 --- a/tests/integration/targets/nxos_interface/tasks/nxapi.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect nxapi test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/nxapi" - patterns: "{{ testcase }}.yaml" - connection: local - register: nxapi_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + nxapi_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.httpapi) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_interface/tests/common/intent.yaml b/tests/integration/targets/nxos_interface/tests/common/intent.yaml deleted file mode 100644 index 3ca038082..000000000 --- a/tests/integration/targets/nxos_interface/tests/common/intent.yaml +++ /dev/null @@ -1,74 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_interface intent test - -- name: Set a fact for 'testint1' - ansible.builtin.set_fact: - testint1: "{{ nxos_int1 }}" - -- name: Set a fact for 'testint2' - ansible.builtin.set_fact: - testint2: "{{ nxos_int2 }}" - -- name: "Setup: put interfaces into a default state" - ignore_errors: true - cisco.nxos.nxos_config: - lines: - - default interface {{ testint1 }} - - default interface {{ testint2 }} - -- name: Check intent arguments - register: result - cisco.nxos.nxos_interface: - name: "{{ testint2 }}" - admin_state: up - tx_rate: ge(0) - rx_rate: ge(0) - -- ansible.builtin.assert: - that: - - result.failed == false - -- name: Clear interface {{ testint2 }} counters before next task - ignore_errors: true - cisco.nxos.nxos_command: - commands: clear counters interface {{ testint2 }} - -- name: Check intent arguments (failed condition) - ignore_errors: true - register: result - cisco.nxos.nxos_interface: - name: "{{ testint2 }}" - admin_state: down - tx_rate: gt(10000) - rx_rate: lt(0) - -- ansible.builtin.assert: - that: - - result.failed == true - - "'tx_rate gt(10000)' in result.failed_conditions" - - "'rx_rate lt(0)' in result.failed_conditions" - -- name: Aggregate definition of interface - register: result - cisco.nxos.nxos_interface: - aggregate: - - name: "{{ testint1 }}" - description: Test aggregation on first interface - - - name: "{{ testint2 }}" - mode: layer3 - -- ansible.builtin.assert: - that: - - result.changed == true - -- name: "Teardown: put interfaces into a default state" - ignore_errors: true - cisco.nxos.nxos_config: - lines: - - default interface {{ testint1 }} - - default interface {{ testint2 }} - -- ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_interface intent test diff --git a/tests/integration/targets/nxos_interface/tests/common/sanity.yaml b/tests/integration/targets/nxos_interface/tests/common/sanity.yaml deleted file mode 100644 index bb53672ed..000000000 --- a/tests/integration/targets/nxos_interface/tests/common/sanity.yaml +++ /dev/null @@ -1,134 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_interface sanity test - -- name: Set a fact for 'testint' - ansible.builtin.set_fact: - testint: "{{ nxos_int1 }}" - -- name: "Setup: enable feature interface-vlan" - ignore_errors: true - cisco.nxos.nxos_feature: - feature: interface-vlan - state: enabled - -- name: "Setup: put interface {{ testint }} into a default state" - ignore_errors: true - cisco.nxos.nxos_config: &id008 - lines: - - default interface {{ testint }} - -- name: "Setup: remove possibly existing vlan interfaces" - ignore_errors: true - cisco.nxos.nxos_config: &id009 - lines: - - no interface vlan 2 - - no interface vlan 710 - - no interface vlan 711 - - no interface vlan 712 - -- block: - - name: Configure layer3 params - register: result - cisco.nxos.nxos_interface: &id001 - interface: "{{ testint }}" - mode: layer3 - description: Configured by Ansible - Layer3 - admin_state: up - state: present - - - ansible.builtin.assert: &id002 - that: - - result.changed == true - - - name: Check idempotence - register: result - cisco.nxos.nxos_interface: *id001 - - - ansible.builtin.assert: &id004 - that: - - result.changed == false - - - name: Configure layer2 params - register: result - cisco.nxos.nxos_interface: &id003 - interface: "{{ testint }}" - mode: layer2 - description: Configured by Ansible - Layer2 - admin_state: down - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_interface: *id003 - - - ansible.builtin.assert: *id004 - - - name: Create vlan interfaces - with_items: &id005 - - os_svi_int: vlan2 - os_svi_desc: SVI_VLAN2 - - - os_svi_int: vlan710 - os_svi_desc: SVI_VLAN710 - - - os_svi_int: vlan711 - os_svi_desc: SVI_VLAN711 - - - os_svi_int: vlan712 - os_svi_desc: SVI_VLAN712 - register: result - cisco.nxos.nxos_interface: &id006 - interface: "{{ item.os_svi_int }}" - description: "{{ item.os_svi_desc }}" - - - ansible.builtin.assert: *id002 - - - name: Configure required svi - register: result - cisco.nxos.nxos_l3_interface: &id007 - aggregate: - - name: vlan2 - ipv4: 192.168.2.1/24 - - - name: vlan710 - ipv4: 192.168.3.1/24 - - - name: vlan711 - ipv4: 192.168.4.1/24 - - - name: vlan712 - ipv4: 192.168.5.1/24 - - - ansible.builtin.assert: *id002 - - - name: Create vlan interfaces idempotence check - with_items: *id005 - register: result - cisco.nxos.nxos_interface: *id006 - - - ansible.builtin.assert: *id004 - - - name: Configure required svi idempotence check - register: result - cisco.nxos.nxos_l3_interface: *id007 - - - ansible.builtin.assert: *id004 - always: - - name: Set interface back to default - ignore_errors: true - cisco.nxos.nxos_config: *id008 - - - name: Remove vlan interfaces - cisco.nxos.nxos_config: *id009 - - - name: "Setup: disable feature interface-vlan" - ignore_errors: true - cisco.nxos.nxos_feature: - feature: interface-vlan - state: disabled - - - ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_interface sanity test diff --git a/tests/integration/targets/nxos_interface/tests/common/set_state_absent.yaml b/tests/integration/targets/nxos_interface/tests/common/set_state_absent.yaml deleted file mode 100644 index 0140d86f9..000000000 --- a/tests/integration/targets/nxos_interface/tests/common/set_state_absent.yaml +++ /dev/null @@ -1,31 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }}/set_state_absent.yaml - -- name: Setup - cisco.nxos.nxos_config: - lines: - - interface Loopback1 - -- name: Set state=absent - register: result - cisco.nxos.nxos_interface: - interface: Loopback1 - state: absent - -- ansible.builtin.assert: - that: - - result.changed == true - -- name: Verify state=absent - register: result - cisco.nxos.nxos_interface: - interface: Loopback1 - state: absent - -- ansible.builtin.assert: - that: - - result.changed == false - -- ansible.builtin.debug: - msg: END connection={{ ansible_connection }}/set_state_absent.yaml diff --git a/tests/integration/targets/nxos_interface/tests/common/set_state_present.yaml b/tests/integration/targets/nxos_interface/tests/common/set_state_present.yaml deleted file mode 100644 index 5165b2f50..000000000 --- a/tests/integration/targets/nxos_interface/tests/common/set_state_present.yaml +++ /dev/null @@ -1,34 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }}/set_state_present.yaml - -- name: Setup - ignore_errors: true - cisco.nxos.nxos_config: - lines: - - no interface Loopback1 - -- name: Set state=present - register: result - cisco.nxos.nxos_interface: - interface: Loopback1 - state: present - description: Configured by Ansible - Layer3 - -- ansible.builtin.assert: - that: - - result.changed == true - -- name: Verify state=present - register: result - cisco.nxos.nxos_interface: - interface: Loopback1 - state: present - description: Configured by Ansible - Layer3 - -- ansible.builtin.assert: - that: - - result.changed == false - -- ansible.builtin.debug: - msg: END connection={{ ansible_connection }}/set_state_present.yaml diff --git a/tests/integration/targets/nxos_interface/tests/common/sub_int.yaml b/tests/integration/targets/nxos_interface/tests/common/sub_int.yaml deleted file mode 100644 index 358e19651..000000000 --- a/tests/integration/targets/nxos_interface/tests/common/sub_int.yaml +++ /dev/null @@ -1,77 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_interface sub-interface test - -- name: Set a fact for 'testint' - ansible.builtin.set_fact: - testint: "{{ nxos_int1 }}" - -- name: Setup - delete sub-interface - ignore_errors: true - cisco.nxos.nxos_interface: &id003 - name: "{{ testint }}.20" - state: absent - -- name: Setup - ensure the interface is layer3 - cisco.nxos.nxos_interface: - name: "{{ testint }}" - mode: layer3 - -- name: Create sub-interface - register: result - cisco.nxos.nxos_interface: &id001 - name: "{{ testint }}.20" - description: sub-interface Configured by Ansible - admin_state: up - mtu: 800 - -- ansible.builtin.assert: - that: - - result.changed == true - -- name: Create sub-interface (idempotence) - register: result - cisco.nxos.nxos_interface: *id001 - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Make admin_state down - register: result - cisco.nxos.nxos_interface: &id002 - name: "{{ testint }}.20" - description: sub-interface Configured by Ansible - admin_state: down - mtu: 800 - -- ansible.builtin.assert: - that: - - result.changed == true - -- name: Create sub-interface (idempotence) - register: result - cisco.nxos.nxos_interface: *id002 - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Remove sub-interface - register: result - cisco.nxos.nxos_interface: *id003 - -- ansible.builtin.assert: - that: - - result.changed == true - -- name: Remove sub-interface (idempotence) - register: result - cisco.nxos.nxos_interface: *id003 - -- ansible.builtin.assert: - that: - - result.changed == false - -- ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_interface sub-interface test diff --git a/tests/integration/targets/nxos_interface_ospf/defaults/main.yaml b/tests/integration/targets/nxos_interface_ospf/defaults/main.yaml deleted file mode 100644 index 5f709c5aa..000000000 --- a/tests/integration/targets/nxos_interface_ospf/defaults/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -testcase: "*" diff --git a/tests/integration/targets/nxos_interface_ospf/meta/main.yml b/tests/integration/targets/nxos_interface_ospf/meta/main.yml deleted file mode 100644 index f504a6ab2..000000000 --- a/tests/integration/targets/nxos_interface_ospf/meta/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_nxos_tests diff --git a/tests/integration/targets/nxos_interface_ospf/tasks/cli.yaml b/tests/integration/targets/nxos_interface_ospf/tasks/cli.yaml deleted file mode 100644 index 90342e6b1..000000000 --- a/tests/integration/targets/nxos_interface_ospf/tasks/cli.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect cli test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - connection: local - register: cli_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + cli_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.network_cli) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_interface_ospf/tasks/main.yaml b/tests/integration/targets/nxos_interface_ospf/tasks/main.yaml deleted file mode 100644 index 7631f52fe..000000000 --- a/tests/integration/targets/nxos_interface_ospf/tasks/main.yaml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- block: - - name: Include the cli tasks - ansible.builtin.include_tasks: cli.yaml - tags: - - cli - always: - - name: Include the nx-api tasks - ansible.builtin.include_tasks: nxapi.yaml - tags: - - nxapi diff --git a/tests/integration/targets/nxos_interface_ospf/tasks/nxapi.yaml b/tests/integration/targets/nxos_interface_ospf/tasks/nxapi.yaml deleted file mode 100644 index cedab80f1..000000000 --- a/tests/integration/targets/nxos_interface_ospf/tasks/nxapi.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect nxapi test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/nxapi" - patterns: "{{ testcase }}.yaml" - connection: local - register: nxapi_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + nxapi_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.httpapi) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_interface_ospf/tests/common/sanity.yaml b/tests/integration/targets/nxos_interface_ospf/tests/common/sanity.yaml deleted file mode 100644 index e964da31c..000000000 --- a/tests/integration/targets/nxos_interface_ospf/tests/common/sanity.yaml +++ /dev/null @@ -1,295 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_interface_ospf sanity test - -- name: Set a fact for 'testint' - ansible.builtin.set_fact: - testint: "{{ nxos_int1 }}" - -- name: Setup - disable features - loop: - - ospf - - bfd - ignore_errors: true - cisco.nxos.nxos_feature: - feature: "{{ item }}" - state: disabled - -- name: Setup - enable features - loop: - - ospf - - bfd - cisco.nxos.nxos_feature: - feature: "{{ item }}" - state: enabled - -- name: Put interface into default state - ignore_errors: true - cisco.nxos.nxos_config: &id013 - lines: - - default interface {{ testint }} - -- name: Remove switchport config - ignore_errors: true - cisco.nxos.nxos_config: - commands: - - no switchport - parents: - - interface {{ testint }} - -- name: Remove possibly existing port-channel and loopback ints - ignore_errors: true - cisco.nxos.nxos_config: &id014 - commands: - - no interface port-channel10 - - no interface port-channel11 - - no interface loopback55 - - no interface loopback77 - -- block: - - name: Configure ospf interface - register: result - cisco.nxos.nxos_interface_ospf: &id001 - interface: "{{ nxos_int1|upper }}" - ospf: 1 - area: 12345678 - bfd: enable - cost: 55 - passive_interface: true - hello_interval: 15 - dead_interval: 75 - network: point-to-point - state: present - - - ansible.builtin.assert: &id002 - that: - - result.changed == true - - - name: Check idempotence - register: result - cisco.nxos.nxos_interface_ospf: *id001 - - - ansible.builtin.assert: &id004 - that: - - result.changed == false - - - name: Modify properties - register: result - cisco.nxos.nxos_interface_ospf: &id003 - interface: "{{ testint }}" - ospf: 1 - area: 12345678 - cost: 66 - passive_interface: false - hello_interval: 17 - dead_interval: 70 - network: broadcast - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_interface_ospf: *id003 - - - ansible.builtin.assert: *id004 - - - name: Default properties - register: result - cisco.nxos.nxos_interface_ospf: &id005 - interface: "{{ testint }}" - ospf: 1 - area: 12345678 - bfd: default - cost: default - hello_interval: 10 - dead_interval: default - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_interface_ospf: *id005 - - - ansible.builtin.assert: *id004 - - - name: Message_digest properties - register: result - cisco.nxos.nxos_interface_ospf: &id006 - interface: "{{ testint }}" - ospf: 1 - area: 12345678 - message_digest: true - message_digest_key_id: 10 - message_digest_algorithm_type: md5 - message_digest_encryption_type: 3des - message_digest_password: b69f7bc54725b1bfd1ea93afa7b09400 - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_interface_ospf: *id006 - - - ansible.builtin.assert: *id004 - - - name: Message_digest defaults - register: result - cisco.nxos.nxos_interface_ospf: &id007 - interface: "{{ testint }}" - ospf: 1 - area: 12345678 - message_digest: false - message_digest_key_id: default - message_digest_algorithm_type: default - message_digest_encryption_type: default - message_digest_password: default - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_interface_ospf: *id007 - - - ansible.builtin.assert: *id004 - - - name: Create port-channel and loopback interfaces - cisco.nxos.nxos_config: - commands: - - interface port-channel10 - - interface port-channel11 - - interface loopback55 - - interface loopback77 - match: none - - - name: Ensure port-channels are layer3 - with_items: - - port-channel10 - - port-channel11 - cisco.nxos.nxos_config: - commands: - - no switchport - parents: - - interface {{ item }} - - - name: Configure ospf interface port-channel10 - register: result - cisco.nxos.nxos_interface_ospf: &id008 - interface: Port-channel10 - ospf: 1 - area: 429496729 - cost: 55 - passive_interface: true - hello_interval: 15 - dead_interval: 75 - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence for port-channel10 - register: result - cisco.nxos.nxos_interface_ospf: *id008 - - - ansible.builtin.assert: *id004 - - - name: Configure ospf interface port-channel11 using lower case name - register: result - cisco.nxos.nxos_interface_ospf: &id009 - interface: port-channel11 - ospf: 1 - area: 42949672 - cost: 55 - passive_interface: true - hello_interval: 15 - dead_interval: 75 - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence for port-channel11 - register: result - cisco.nxos.nxos_interface_ospf: *id009 - - - ansible.builtin.assert: *id004 - - - name: Configure ospf interface loopback55 - register: result - cisco.nxos.nxos_interface_ospf: &id010 - interface: LOOPBACK55 - ospf: 1 - area: 192.0.2.4 - cost: 55 - hello_interval: 15 - dead_interval: 75 - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence for loopback55 - register: result - cisco.nxos.nxos_interface_ospf: *id010 - - - ansible.builtin.assert: *id004 - - - name: Configure ospf interface loopback77 using lower case name - register: result - cisco.nxos.nxos_interface_ospf: &id011 - interface: loopback77 - ospf: 1 - area: 429496 - cost: 77 - hello_interval: 45 - dead_interval: 75 - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence for loopback77 - register: result - cisco.nxos.nxos_interface_ospf: *id011 - - - ansible.builtin.assert: *id004 - - - name: Remove ospf interface config - register: result - cisco.nxos.nxos_interface_ospf: &id012 - interface: "{{ testint }}" - ospf: 1 - area: 12345678 - bfd: disable - cost: 55 - passive_interface: true - hello_interval: 15 - dead_interval: 75 - state: absent - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_interface_ospf: *id012 - - - ansible.builtin.assert: *id004 - always: - - name: Disable features - loop: - - ospf - - bfd - ignore_errors: true - cisco.nxos.nxos_feature: - feature: "{{ item }}" - state: disabled - - - name: Interface cleanup - ignore_errors: true - cisco.nxos.nxos_config: *id013 - - - name: Remove port-channel and loopback ints - ignore_errors: true - cisco.nxos.nxos_config: *id014 - - - ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_interface_ospf sanity test diff --git a/tests/integration/targets/nxos_interfaces/tasks/cli.yaml b/tests/integration/targets/nxos_interfaces/tasks/cli.yaml index 507d803cb..e3e64747b 100644 --- a/tests/integration/targets/nxos_interfaces/tasks/cli.yaml +++ b/tests/integration/targets/nxos_interfaces/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_interfaces/tasks/main.yaml b/tests/integration/targets/nxos_interfaces/tasks/main.yaml index 6d298eacb..926add4de 100644 --- a/tests/integration/targets/nxos_interfaces/tasks/main.yaml +++ b/tests/integration/targets/nxos_interfaces/tasks/main.yaml @@ -4,12 +4,12 @@ lines: "no system default switchport\nsystem default switchport shutdown\n" connection: ansible.netcommon.network_cli -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_interfaces/tasks/nxapi.yaml b/tests/integration/targets/nxos_interfaces/tasks/nxapi.yaml index 2e452bb6a..4ae68868c 100644 --- a/tests/integration/targets/nxos_interfaces/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_interfaces/tasks/nxapi.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_interfaces/tests/common/_populate_config.yaml b/tests/integration/targets/nxos_interfaces/tests/common/_populate_config.yaml index c17fc4711..15c559f7e 100644 --- a/tests/integration/targets/nxos_interfaces/tests/common/_populate_config.yaml +++ b/tests/integration/targets/nxos_interfaces/tests/common/_populate_config.yaml @@ -1,5 +1,5 @@ --- -- name: "Populate config - {{ nxos_int1 }}" +- name: "Populate configuration - {{ nxos_int1 }}" cisco.nxos.nxos_config: lines: - "description outbound-intf" @@ -7,7 +7,7 @@ - "no shutdown" parents: "interface {{ nxos_int1 }}" -- name: "Populate config - {{ nxos_int2 }}" +- name: "Populate configuration - {{ nxos_int2 }}" cisco.nxos.nxos_config: lines: - "description intf-l3" diff --git a/tests/integration/targets/nxos_interfaces/tests/common/_remove_config.yaml b/tests/integration/targets/nxos_interfaces/tests/common/_remove_config.yaml index 37ee536cf..7ff47cc75 100644 --- a/tests/integration/targets/nxos_interfaces/tests/common/_remove_config.yaml +++ b/tests/integration/targets/nxos_interfaces/tests/common/_remove_config.yaml @@ -1,5 +1,5 @@ --- -- name: Remove config +- name: Remove configuration cisco.nxos.nxos_config: lines: - "default interface {{ nxos_int1 }}" diff --git a/tests/integration/targets/nxos_interfaces/tests/common/empty_config.yaml b/tests/integration/targets/nxos_interfaces/tests/common/empty_config.yaml index 6efc913a6..2e1311f91 100644 --- a/tests/integration/targets/nxos_interfaces/tests/common/empty_config.yaml +++ b/tests/integration/targets/nxos_interfaces/tests/common/empty_config.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxos_interfaces empty_config integration tests on connection={{ ansible_connection }} -- name: Merged with empty config should give appropriate error message +- name: Merged with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_interfaces: @@ -13,7 +13,7 @@ that: - result.msg == 'value of config parameter must not be empty for state merged' -- name: Replaced with empty config should give appropriate error message +- name: Replaced with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_interfaces: @@ -24,7 +24,7 @@ that: - result.msg == 'value of config parameter must not be empty for state replaced' -- name: Overridden with empty config should give appropriate error message +- name: Overridden with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_interfaces: @@ -35,7 +35,7 @@ that: - result.msg == 'value of config parameter must not be empty for state overridden' -- name: Rendered with empty config should give appropriate error message +- name: Rendered with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_interfaces: @@ -46,7 +46,7 @@ that: - result.msg == 'value of config parameter must not be empty for state rendered' -- name: Parsed with empty config should give appropriate error message +- name: Parsed with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_interfaces: diff --git a/tests/integration/targets/nxos_interfaces/tests/common/parsed.yaml b/tests/integration/targets/nxos_interfaces/tests/common/parsed.yaml index e37c4bdb0..b228595bc 100644 --- a/tests/integration/targets/nxos_interfaces/tests/common/parsed.yaml +++ b/tests/integration/targets/nxos_interfaces/tests/common/parsed.yaml @@ -4,7 +4,7 @@ - block: # Interfaces used in the task don't actually exist on the appliance - - name: Use parsed state to convert externally supplied config to structured format + - name: Use parsed state to convert externally supplied configuration to structured format register: result cisco.nxos.nxos_interfaces: running_config: | diff --git a/tests/integration/targets/nxos_interfaces/tests/common/rtt.yaml b/tests/integration/targets/nxos_interfaces/tests/common/rtt.yaml index 9f895fedb..98b70b4b9 100644 --- a/tests/integration/targets/nxos_interfaces/tests/common/rtt.yaml +++ b/tests/integration/targets/nxos_interfaces/tests/common/rtt.yaml @@ -61,7 +61,7 @@ - result.commands|length == 9 - result.changed == true - - name: Revert back to base config using facts round trip + - name: Revert back to base configuration using facts round trip register: revert cisco.nxos.nxos_interfaces: config: "{{ ansible_facts['network_resources']['interfaces'] }}" diff --git a/tests/integration/targets/nxos_interfaces/vars/main.yml b/tests/integration/targets/nxos_interfaces/vars/main.yml index b80e0cb91..bba0dd5c5 100644 --- a/tests/integration/targets/nxos_interfaces/vars/main.yml +++ b/tests/integration/targets/nxos_interfaces/vars/main.yml @@ -1,8 +1,9 @@ +--- gathered: - name: "{{ nxos_int1 }}" description: outbound-intf mode: layer2 - enabled: True + enabled: true - name: "{{ nxos_int2 }}" description: intf-l3 speed: "1000" diff --git a/tests/integration/targets/nxos_l2_interface/defaults/main.yaml b/tests/integration/targets/nxos_l2_interface/defaults/main.yaml deleted file mode 100644 index 5f709c5aa..000000000 --- a/tests/integration/targets/nxos_l2_interface/defaults/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -testcase: "*" diff --git a/tests/integration/targets/nxos_l2_interface/meta/main.yml b/tests/integration/targets/nxos_l2_interface/meta/main.yml deleted file mode 100644 index f504a6ab2..000000000 --- a/tests/integration/targets/nxos_l2_interface/meta/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_nxos_tests diff --git a/tests/integration/targets/nxos_l2_interface/tasks/cli.yaml b/tests/integration/targets/nxos_l2_interface/tasks/cli.yaml deleted file mode 100644 index 90342e6b1..000000000 --- a/tests/integration/targets/nxos_l2_interface/tasks/cli.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect cli test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - connection: local - register: cli_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + cli_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.network_cli) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_l2_interface/tasks/main.yaml b/tests/integration/targets/nxos_l2_interface/tasks/main.yaml deleted file mode 100644 index 62e44ffda..000000000 --- a/tests/integration/targets/nxos_l2_interface/tasks/main.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Include the cli tasks - ansible.builtin.include_tasks: cli.yaml - tags: - - cli - -- name: Include the nx-api tasks - ansible.builtin.include_tasks: nxapi.yaml - tags: - - nxapi diff --git a/tests/integration/targets/nxos_l2_interface/tasks/nxapi.yaml b/tests/integration/targets/nxos_l2_interface/tasks/nxapi.yaml deleted file mode 100644 index cedab80f1..000000000 --- a/tests/integration/targets/nxos_l2_interface/tasks/nxapi.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect nxapi test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/nxapi" - patterns: "{{ testcase }}.yaml" - connection: local - register: nxapi_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + nxapi_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.httpapi) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_l2_interface/tests/common/agg.yaml b/tests/integration/targets/nxos_l2_interface/tests/common/agg.yaml deleted file mode 100644 index 3f3e6e9c3..000000000 --- a/tests/integration/targets/nxos_l2_interface/tests/common/agg.yaml +++ /dev/null @@ -1,119 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_l2_interface aggregate test - -- name: Set a fact for 'intname1' - ansible.builtin.set_fact: - intname1: "{{ nxos_int1 }}" - -- name: Set a fact for 'intname2' - ansible.builtin.set_fact: - intname2: "{{ nxos_int2 }}" - -- name: Setup vlans - cisco.nxos.nxos_vlan: - vlan_range: 6,15 - -- name: Setup - ensure interfaces are layer2 - cisco.nxos.nxos_interface: - aggregate: - - name: "{{ intname1 }}" - - - name: "{{ intname2 }}" - mode: layer2 - -- name: Setup - remove interface aggregate before testing - cisco.nxos.nxos_l2_interface: - aggregate: - - name: "{{ intname1 }}" - mode: access - access_vlan: 6 - - - name: "{{ intname2 }}" - mode: access - access_vlan: 15 - state: absent - -- name: Sleep for 2 seconds on fretta platform - ansible.builtin.wait_for: timeout=2 - when: platform is match("N9K-F") - -- block: - - name: Configure interface for access_vlan aggregate - register: result - cisco.nxos.nxos_l2_interface: &id001 - aggregate: - - name: "{{ intname1 }}" - mode: access - access_vlan: 6 - - - name: "{{ intname2 }}" - mode: access - access_vlan: 15 - - - ansible.builtin.assert: - that: - - result.changed == true - - - name: Sleep for 2 seconds on fretta platform - ansible.builtin.wait_for: timeout=2 - when: platform is match("N9K-F") - - - name: Configure interface for access_vlan aggregate(idempotence) - register: result - cisco.nxos.nxos_l2_interface: *id001 - - - ansible.builtin.assert: - that: - - result.changed == false - - - name: Remove interface aggregate - register: result - cisco.nxos.nxos_l2_interface: &id002 - aggregate: - - name: "{{ intname1 }}" - mode: access - access_vlan: 6 - - - name: "{{ intname2 }}" - mode: access - access_vlan: 15 - state: absent - - - ansible.builtin.assert: - that: - - result.changed == true - - - name: Sleep for 2 seconds on fretta platform - ansible.builtin.wait_for: timeout=2 - when: platform is match("N9K-F") - - - name: Remove interface aggregate(idempotence) - register: result - cisco.nxos.nxos_l2_interface: *id002 - - - ansible.builtin.assert: - that: - - result.changed == false - always: - - name: Remove vlans - ignore_errors: true - cisco.nxos.nxos_vlan: - vlan_range: 6,15 - state: absent - - - name: Remove interface aggregate after testing - ignore_errors: true - cisco.nxos.nxos_l2_interface: - aggregate: - - name: "{{ intname1 }}" - mode: access - access_vlan: 6 - - - name: "{{ intname2 }}" - mode: access - access_vlan: 15 - state: absent - -- ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_l2_interface aggregate test diff --git a/tests/integration/targets/nxos_l2_interface/tests/common/sanity.yaml b/tests/integration/targets/nxos_l2_interface/tests/common/sanity.yaml deleted file mode 100644 index f5cd8826c..000000000 --- a/tests/integration/targets/nxos_l2_interface/tests/common/sanity.yaml +++ /dev/null @@ -1,156 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_l2_interface sanity test - -- name: Set a fact for 'intname' - ansible.builtin.set_fact: - intname: "{{ nxos_int1 }}" - -- name: Interface selected for this test - ansible.builtin.debug: - msg: "{{ intname }}" - -- name: Setup interface - ignore_errors: true - cisco.nxos.nxos_config: &id009 - lines: - - default interface {{ intname }} - -- name: Setup - ensure interface is layer2 - cisco.nxos.nxos_interface: - interface: "{{ intname }}" - mode: layer2 - -- name: Setup vlans - cisco.nxos.nxos_vlan: - vlan_range: 5-10,20 - -- block: - - name: Ensure interface is in its default switchport state - cisco.nxos.nxos_l2_interface: &id008 - name: "{{ intname }}" - state: unconfigured - - - name: Ensure interface is configured for access vlan 20 - register: result - cisco.nxos.nxos_l2_interface: &id001 - name: "{{ intname }}" - mode: access - access_vlan: 20 - - - ansible.builtin.assert: &id002 - that: - - result.changed == true - - - name: Sleep for 2 seconds on fretta platform - ansible.builtin.wait_for: timeout=2 - when: platform is match("N9K-F") - - - name: Access vlan idempotence - register: result - cisco.nxos.nxos_l2_interface: *id001 - - - ansible.builtin.assert: &id004 - that: - - result.changed == false - - - name: Ensure interface only has vlans 5-10 as trunk vlans - register: result - cisco.nxos.nxos_l2_interface: &id003 - name: "{{ intname }}" - mode: trunk - native_vlan: 10 - trunk_allowed_vlans: 5-10 - - - ansible.builtin.assert: *id002 - - - name: Trunk vlan idempotence - register: result - cisco.nxos.nxos_l2_interface: *id003 - - - ansible.builtin.assert: *id004 - - - name: Ensure interface is a trunk port and ensure 2-50 are being tagged (doesn't mean others aren't also being tagged) - register: result - cisco.nxos.nxos_l2_interface: &id005 - name: "{{ intname }}" - mode: trunk - native_vlan: 10 - trunk_vlans: 2-50 - - - ansible.builtin.assert: *id002 - - - name: Tag vlan idempotence - register: result - cisco.nxos.nxos_l2_interface: *id005 - - - ansible.builtin.assert: *id004 - - - name: Remove full trunk vlan range 2-50 - register: result - cisco.nxos.nxos_l2_interface: &id006 - name: "{{ intname }}" - mode: trunk - trunk_vlans: 2-50 - state: absent - - - ansible.builtin.assert: *id002 - - - name: Check idempotence remove full trunk vlan range 2-50 - register: result - cisco.nxos.nxos_l2_interface: *id006 - - - ansible.builtin.assert: *id004 - - - name: Reconfigure interface trunk port and ensure 2-50 are being tagged - register: result - cisco.nxos.nxos_l2_interface: *id005 - - - ansible.builtin.assert: *id002 - - - name: Check idempotence reconfigure interface trunk port and ensure 2-50 are being tagged - register: result - cisco.nxos.nxos_l2_interface: *id005 - - - ansible.builtin.assert: *id004 - - - name: Remove partial trunk vlan range 30-4094 are removed - register: result - cisco.nxos.nxos_l2_interface: &id007 - name: "{{ intname }}" - mode: trunk - trunk_vlans: 30-4094 - state: absent - - - ansible.builtin.assert: *id002 - - - name: Check idempotence remove partial trunk vlan range 30-4094 are removed - register: result - cisco.nxos.nxos_l2_interface: *id007 - - - ansible.builtin.assert: *id004 - - - name: Put interface default state - register: result - cisco.nxos.nxos_l2_interface: *id008 - - - ansible.builtin.assert: *id002 - - - name: Default state idempotence - register: result - cisco.nxos.nxos_l2_interface: *id008 - - - ansible.builtin.assert: *id004 - always: - - name: Remove vlans - ignore_errors: true - cisco.nxos.nxos_vlan: - vlan_range: 5-10,20 - state: absent - - - name: Default interface - ignore_errors: true - cisco.nxos.nxos_config: *id009 - -- ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_l2_interface sanity test diff --git a/tests/integration/targets/nxos_l2_interfaces/tasks/cli.yaml b/tests/integration/targets/nxos_l2_interfaces/tasks/cli.yaml index 507d803cb..e3e64747b 100644 --- a/tests/integration/targets/nxos_l2_interfaces/tasks/cli.yaml +++ b/tests/integration/targets/nxos_l2_interfaces/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_l2_interfaces/tasks/main.yaml b/tests/integration/targets/nxos_l2_interfaces/tasks/main.yaml index b42cad3e3..8d0b94337 100644 --- a/tests/integration/targets/nxos_l2_interfaces/tasks/main.yaml +++ b/tests/integration/targets/nxos_l2_interfaces/tasks/main.yaml @@ -1,9 +1,9 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_l2_interfaces/tasks/nxapi.yaml b/tests/integration/targets/nxos_l2_interfaces/tasks/nxapi.yaml index 2e452bb6a..4ae68868c 100644 --- a/tests/integration/targets/nxos_l2_interfaces/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_l2_interfaces/tasks/nxapi.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_l2_interfaces/tests/common/empty_config.yaml b/tests/integration/targets/nxos_l2_interfaces/tests/common/empty_config.yaml index 381c780dc..0f222dbbf 100644 --- a/tests/integration/targets/nxos_l2_interfaces/tests/common/empty_config.yaml +++ b/tests/integration/targets/nxos_l2_interfaces/tests/common/empty_config.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxos_lacp empty_config integration tests on connection={{ ansible_connection }} -- name: Merged with empty config should give appropriate error message +- name: Merged with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_l2_interfaces: @@ -13,7 +13,7 @@ that: - result.msg == 'value of config parameter must not be empty for state merged' -- name: Replaced with empty config should give appropriate error message +- name: Replaced with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_l2_interfaces: @@ -24,7 +24,7 @@ that: - result.msg == 'value of config parameter must not be empty for state replaced' -- name: Overridden with empty config should give appropriate error message +- name: Overridden with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_l2_interfaces: @@ -35,7 +35,7 @@ that: - result.msg == 'value of config parameter must not be empty for state overridden' -- name: Rendered with empty config should give appropriate error message +- name: Rendered with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_l2_interfaces: @@ -46,7 +46,7 @@ that: - result.msg == 'value of config parameter must not be empty for state rendered' -- name: Parsed with empty config should give appropriate error message +- name: Parsed with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_l2_interfaces: diff --git a/tests/integration/targets/nxos_l2_interfaces/tests/common/parsed.yaml b/tests/integration/targets/nxos_l2_interfaces/tests/common/parsed.yaml index 379a5aa90..023049ee4 100644 --- a/tests/integration/targets/nxos_l2_interfaces/tests/common/parsed.yaml +++ b/tests/integration/targets/nxos_l2_interfaces/tests/common/parsed.yaml @@ -4,7 +4,7 @@ - block: # Interfaces used in the task don't actually exist on the appliance - - name: Use parsed state to convert externally supplied config to structured format + - name: Use parsed state to convert externally supplied configuration to structured format register: result cisco.nxos.nxos_l2_interfaces: running_config: | @@ -13,6 +13,8 @@ host-reachability protocol bgp advertise virtual-rmac source-interface loopback1 + interface Ethernet1/799 + switchport mode dot1q-tunnel interface Ethernet1/800 switchport access vlan 18 switchport trunk allowed vlan 210 diff --git a/tests/integration/targets/nxos_l2_interfaces/tests/common/rtt.yaml b/tests/integration/targets/nxos_l2_interfaces/tests/common/rtt.yaml index 6f18297aa..5ef0b101c 100644 --- a/tests/integration/targets/nxos_l2_interfaces/tests/common/rtt.yaml +++ b/tests/integration/targets/nxos_l2_interfaces/tests/common/rtt.yaml @@ -58,7 +58,7 @@ that: - result.changed == true - - name: Revert back to base config using facts round trip + - name: Revert back to base configuration using facts round trip register: revert cisco.nxos.nxos_l2_interfaces: config: "{{ ansible_facts['network_resources']['l2_interfaces'] }}" diff --git a/tests/integration/targets/nxos_l2_interfaces/vars/main.yml b/tests/integration/targets/nxos_l2_interfaces/vars/main.yml index ee4af5daa..71d7f0b52 100644 --- a/tests/integration/targets/nxos_l2_interfaces/vars/main.yml +++ b/tests/integration/targets/nxos_l2_interfaces/vars/main.yml @@ -1,3 +1,4 @@ +--- gathered: - name: "{{ nxos_int1 }}" access: @@ -11,6 +12,8 @@ gathered: parsed: - name: nve1 + - name: Ethernet1/799 + mode: dot1q-tunnel - name: Ethernet1/800 access: vlan: 18 diff --git a/tests/integration/targets/nxos_l3_interface/defaults/main.yaml b/tests/integration/targets/nxos_l3_interface/defaults/main.yaml deleted file mode 100644 index 5f709c5aa..000000000 --- a/tests/integration/targets/nxos_l3_interface/defaults/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -testcase: "*" diff --git a/tests/integration/targets/nxos_l3_interface/meta/main.yml b/tests/integration/targets/nxos_l3_interface/meta/main.yml deleted file mode 100644 index f504a6ab2..000000000 --- a/tests/integration/targets/nxos_l3_interface/meta/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_nxos_tests diff --git a/tests/integration/targets/nxos_l3_interface/tasks/cli.yaml b/tests/integration/targets/nxos_l3_interface/tasks/cli.yaml deleted file mode 100644 index 90342e6b1..000000000 --- a/tests/integration/targets/nxos_l3_interface/tasks/cli.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect cli test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - connection: local - register: cli_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + cli_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.network_cli) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_l3_interface/tasks/main.yaml b/tests/integration/targets/nxos_l3_interface/tasks/main.yaml deleted file mode 100644 index 62e44ffda..000000000 --- a/tests/integration/targets/nxos_l3_interface/tasks/main.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Include the cli tasks - ansible.builtin.include_tasks: cli.yaml - tags: - - cli - -- name: Include the nx-api tasks - ansible.builtin.include_tasks: nxapi.yaml - tags: - - nxapi diff --git a/tests/integration/targets/nxos_l3_interface/tasks/nxapi.yaml b/tests/integration/targets/nxos_l3_interface/tasks/nxapi.yaml deleted file mode 100644 index cedab80f1..000000000 --- a/tests/integration/targets/nxos_l3_interface/tasks/nxapi.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect nxapi test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/nxapi" - patterns: "{{ testcase }}.yaml" - connection: local - register: nxapi_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + nxapi_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.httpapi) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_l3_interface/tests/cli/sanity.yaml b/tests/integration/targets/nxos_l3_interface/tests/cli/sanity.yaml deleted file mode 100644 index e2a3f3b7b..000000000 --- a/tests/integration/targets/nxos_l3_interface/tests/cli/sanity.yaml +++ /dev/null @@ -1,132 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START TRANSPORT:CLI nxos_l3_interface sanity test - -- name: Set a fact for 'testint2' - ansible.builtin.set_fact: - testint2: "{{ nxos_int2 }}" - -- name: Set a fact for 'testint3' - ansible.builtin.set_fact: - testint3: "{{ nxos_int3 }}" - -- name: Set a fact for 'ipv6_address' - ansible.builtin.set_fact: - ipv6_address: "" - -- name: Set a fact for 'ipv6_address' - ansible.builtin.set_fact: - ipv6_address: 33:db::2/8 - when: ipv6_supported - -- name: Setup - remove address from interface prior to testing(part1) - ignore_errors: true - cisco.nxos.nxos_config: - lines: - - no ip address 192.168.22.1/24 - parents: no switchport - before: interface {{ testint2 }} - -- name: Setup - remove address from interface prior to testing(part2) - ignore_errors: true - cisco.nxos.nxos_config: - lines: - - no ip address 192.168.20.1/24 - - no ipv6 address 33:db::2/8 - parents: no switchport - before: interface {{ testint3 }} - -- name: Setup - ensure interfaces are layer3 - cisco.nxos.nxos_interface: - aggregate: - - name: "{{ testint2 }}" - - - name: "{{ testint3 }}" - mode: layer3 - -- name: Configure ipv4 address to interface - register: result - cisco.nxos.nxos_l3_interface: &id001 - name: "{{ testint2 }}" - ipv4: 192.168.22.1/24 - -- ansible.builtin.assert: - that: - - result.changed == true - -- name: Configure ipv4 address to interface(idempotence) - register: result - cisco.nxos.nxos_l3_interface: *id001 - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Remove ipv4 address from interface - register: result - cisco.nxos.nxos_l3_interface: &id002 - name: "{{ testint2 }}" - ipv4: 192.168.22.1/24 - state: absent - -- ansible.builtin.assert: - that: - - result.changed == true - -- name: Remove ipv4 address from interface(idempotence) - register: result - cisco.nxos.nxos_l3_interface: *id002 - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Configure address to interfaces aggregate - register: result - cisco.nxos.nxos_l3_interface: &id003 - aggregate: - - name: "{{ testint2 }}" - ipv4: 192.168.22.1/24 - - - name: "{{ testint3 }}" - ipv4: 192.168.20.1/24 - ipv6: "{{ ipv6_address }}" - -- ansible.builtin.assert: - that: - - result.changed == true - -- name: Configure address to interfaces aggregate(idempotence) - register: result - cisco.nxos.nxos_l3_interface: *id003 - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Remove address from interfaces aggregate - register: result - cisco.nxos.nxos_l3_interface: &id004 - aggregate: - - name: "{{ testint2 }}" - ipv4: 192.168.22.1/24 - - - name: "{{ testint3 }}" - ipv4: 192.168.20.1/24 - ipv6: "{{ ipv6_address }}" - state: absent - -- ansible.builtin.assert: - that: - - result.changed == true - -- name: Remove address from interfaces aggregate(idempotence) - register: result - cisco.nxos.nxos_l3_interface: *id004 - -- ansible.builtin.assert: - that: - - result.changed == false - -- ansible.builtin.debug: - msg: END TRANSPORT:CLI nxos_l3_interface sanity test diff --git a/tests/integration/targets/nxos_l3_interface/tests/nxapi/sanity.yaml b/tests/integration/targets/nxos_l3_interface/tests/nxapi/sanity.yaml deleted file mode 100644 index 9cd1d6585..000000000 --- a/tests/integration/targets/nxos_l3_interface/tests/nxapi/sanity.yaml +++ /dev/null @@ -1,127 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START TRANSPORT:NXAPI nxos_l3_interface sanity test - -- name: Set a fact for 'testint2' - ansible.builtin.set_fact: - testint2: "{{ nxos_int2 }}" - -- name: Set a fact for 'testint3' - ansible.builtin.set_fact: - testint3: "{{ nxos_int3 }}" - -- name: Set a fact for 'ipv6_address' - ansible.builtin.set_fact: - ipv6_address: "" - -- name: Set a fact for 'ipv6_address' - ansible.builtin.set_fact: - ipv6_address: 33:db::2/8 - when: ipv6_supported - -- name: Setup - remove address from interfaces aggregate - ignore_errors: true - cisco.nxos.nxos_l3_interface: - aggregate: - - name: "{{ testint2 }}" - ipv4: 192.168.22.1/24 - - - name: "{{ testint3 }}" - ipv4: 192.168.20.1/24 - ipv6: "{{ ipv6_address }}" - state: absent - -- name: Setup - ensure interfaces are layer3 - cisco.nxos.nxos_interface: - aggregate: - - name: "{{ testint2 }}" - - - name: "{{ testint3 }}" - mode: layer3 - -- name: Configure ipv4 address to interface - register: result - cisco.nxos.nxos_l3_interface: &id001 - name: "{{ testint2 }}" - ipv4: 192.168.22.1/24 - -- ansible.builtin.assert: - that: - - result.changed == true - -- name: Configure ipv4 address to interface(idempotence) - register: result - cisco.nxos.nxos_l3_interface: *id001 - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Remove ipv4 address from interface - register: result - cisco.nxos.nxos_l3_interface: &id002 - name: "{{ testint2 }}" - ipv4: 192.168.22.1/24 - state: absent - -- ansible.builtin.assert: - that: - - result.changed == true - -- name: Remove ipv4 address from interface(idempotence) - register: result - cisco.nxos.nxos_l3_interface: *id002 - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Configure address to interfaces aggregate - register: result - cisco.nxos.nxos_l3_interface: &id003 - aggregate: - - name: "{{ testint2 }}" - ipv4: 192.168.22.1/24 - - - name: "{{ testint3 }}" - ipv4: 192.168.20.1/24 - ipv6: "{{ ipv6_address }}" - -- ansible.builtin.assert: - that: - - result.changed == true - -- name: Configure address to interfaces aggregate(idempotence) - register: result - cisco.nxos.nxos_l3_interface: *id003 - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Remove address from interfaces aggregate - register: result - cisco.nxos.nxos_l3_interface: &id004 - aggregate: - - name: "{{ testint2 }}" - ipv4: 192.168.22.1/24 - - - name: "{{ testint3 }}" - ipv4: 192.168.20.1/24 - ipv6: "{{ ipv6_address }}" - state: absent - -- ansible.builtin.assert: - that: - - result.changed == true - -- name: Remove address from interfaces aggregate(idempotence) - register: result - cisco.nxos.nxos_l3_interface: *id004 - -- ansible.builtin.assert: - that: - - result.changed == false - -- ansible.builtin.debug: - msg: END TRANSPORT:NXAPI nxos_l3_interface sanity test diff --git a/tests/integration/targets/nxos_l3_interfaces/tasks/cli.yaml b/tests/integration/targets/nxos_l3_interfaces/tasks/cli.yaml index 507d803cb..e3e64747b 100644 --- a/tests/integration/targets/nxos_l3_interfaces/tasks/cli.yaml +++ b/tests/integration/targets/nxos_l3_interfaces/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_l3_interfaces/tasks/main.yaml b/tests/integration/targets/nxos_l3_interfaces/tasks/main.yaml index fefcfa15b..4ef02263b 100644 --- a/tests/integration/targets/nxos_l3_interfaces/tasks/main.yaml +++ b/tests/integration/targets/nxos_l3_interfaces/tasks/main.yaml @@ -1,14 +1,15 @@ --- - name: Set a fact for 'rsvd_intf' ansible.builtin.set_fact: - rsvd_intf: "{{ rsvd_intf|default('mgmt0') }}" + rsvd_intf: "{{ rsvd_intf | default('mgmt0') }}" -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_l3_interfaces/tasks/nxapi.yaml b/tests/integration/targets/nxos_l3_interfaces/tasks/nxapi.yaml index 2e452bb6a..4ae68868c 100644 --- a/tests/integration/targets/nxos_l3_interfaces/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_l3_interfaces/tasks/nxapi.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_l3_interfaces/tests/common/_populate_config.yaml b/tests/integration/targets/nxos_l3_interfaces/tests/common/_populate_config.yaml index 4d18e39e2..d0a293408 100644 --- a/tests/integration/targets/nxos_l3_interfaces/tests/common/_populate_config.yaml +++ b/tests/integration/targets/nxos_l3_interfaces/tests/common/_populate_config.yaml @@ -1,5 +1,5 @@ --- -- name: Populate config - 1 +- name: Populate configuration - 1 cisco.nxos.nxos_config: lines: - "interface {{ nxos_int1 }}" @@ -7,7 +7,7 @@ - " ip redirects" - " ip address 192.0.2.100/24" -- name: Populate config - 2 +- name: Populate configuration - 2 cisco.nxos.nxos_config: lines: - "interface {{ nxos_int2 }}" diff --git a/tests/integration/targets/nxos_l3_interfaces/tests/common/_remove_config.yaml b/tests/integration/targets/nxos_l3_interfaces/tests/common/_remove_config.yaml index 7abe42d8c..d7e662244 100644 --- a/tests/integration/targets/nxos_l3_interfaces/tests/common/_remove_config.yaml +++ b/tests/integration/targets/nxos_l3_interfaces/tests/common/_remove_config.yaml @@ -1,5 +1,5 @@ --- -- name: Remove config +- name: Remove configuration cisco.nxos.nxos_config: lines: - "default interface {{ nxos_int1 }}" diff --git a/tests/integration/targets/nxos_l3_interfaces/tests/common/empty_config.yaml b/tests/integration/targets/nxos_l3_interfaces/tests/common/empty_config.yaml index 8ff0e2557..4c2d37d70 100644 --- a/tests/integration/targets/nxos_l3_interfaces/tests/common/empty_config.yaml +++ b/tests/integration/targets/nxos_l3_interfaces/tests/common/empty_config.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxos_l3_interfaces empty_config integration tests on connection={{ ansible_connection }} -- name: Merged with empty config should give appropriate error message +- name: Merged with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_l3_interfaces: @@ -13,7 +13,7 @@ that: - result.msg == 'value of config parameter must not be empty for state merged' -- name: Replaced with empty config should give appropriate error message +- name: Replaced with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_l3_interfaces: @@ -24,7 +24,7 @@ that: - result.msg == 'value of config parameter must not be empty for state replaced' -- name: Overridden with empty config should give appropriate error message +- name: Overridden with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_l3_interfaces: @@ -35,7 +35,7 @@ that: - result.msg == 'value of config parameter must not be empty for state overridden' -- name: Rendered with empty config should give appropriate error message +- name: Rendered with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_l3_interfaces: @@ -46,7 +46,7 @@ that: - result.msg == 'value of config parameter must not be empty for state rendered' -- name: Parsed with empty config should give appropriate error message +- name: Parsed with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_l3_interfaces: diff --git a/tests/integration/targets/nxos_l3_interfaces/tests/common/multisite.yaml b/tests/integration/targets/nxos_l3_interfaces/tests/common/multisite.yaml index 0be80cedf..c361da1e7 100644 --- a/tests/integration/targets/nxos_l3_interfaces/tests/common/multisite.yaml +++ b/tests/integration/targets/nxos_l3_interfaces/tests/common/multisite.yaml @@ -10,14 +10,14 @@ - ansible.builtin.include_tasks: _remove_config.yaml -- name: Enable feature nv overlay - multisite +- name: Enable 'feature nv overlay' - multisite cisco.nxos.nxos_config: commands: - no feature nv overlay - feature nv overlay match: none -- name: Enable nv overlay evpn - multisite +- name: Enable NV overlay EVPN - multisite when: platform is search('N9K') ignore_errors: true cisco.nxos.nxos_config: @@ -239,7 +239,7 @@ - "!min" gather_network_resources: l3_interfaces - - name: Store reserved interface ip config + - name: Store reserved interface IP configuration ansible.builtin.set_fact: mgmt: "{{ ansible_facts.network_resources.l3_interfaces|selectattr('name', 'equalto', rsvd_intf)|list }}" overriden_config: @@ -335,7 +335,7 @@ - ansible.builtin.include_tasks: _remove_config.yaml # Interfaces used in the task don't actually exist on the appliance - - name: Use parsed state to convert externally supplied config to structured format + - name: Use parsed state to convert externally supplied configuration to structured format register: result cisco.nxos.nxos_l3_interfaces: running_config: | @@ -358,7 +358,7 @@ when: multiout is not search("Invalid command") -- name: Disable nv overlay evpn +- name: Disable NV overlay EVPN when: platform is search('N9K') ignore_errors: true cisco.nxos.nxos_config: @@ -366,7 +366,7 @@ - no nv overlay evpn match: none -- name: Disable feature nv overlay +- name: Disable 'feature nv overlay' ignore_errors: true cisco.nxos.nxos_feature: feature: nve diff --git a/tests/integration/targets/nxos_l3_interfaces/tests/common/overridden.yaml b/tests/integration/targets/nxos_l3_interfaces/tests/common/overridden.yaml index 2c8d5f203..c716b5c4b 100644 --- a/tests/integration/targets/nxos_l3_interfaces/tests/common/overridden.yaml +++ b/tests/integration/targets/nxos_l3_interfaces/tests/common/overridden.yaml @@ -39,7 +39,7 @@ - "!min" gather_network_resources: l3_interfaces - - name: Store reserved interface ip config + - name: Store reserved interface IP configuration ansible.builtin.set_fact: mgmt: "{{ ansible_facts.network_resources.l3_interfaces|selectattr('name', 'equalto', rsvd_intf)|list }}" overriden_config: diff --git a/tests/integration/targets/nxos_l3_interfaces/tests/common/parsed.yaml b/tests/integration/targets/nxos_l3_interfaces/tests/common/parsed.yaml index 8bbeac4a3..ecf23ce05 100644 --- a/tests/integration/targets/nxos_l3_interfaces/tests/common/parsed.yaml +++ b/tests/integration/targets/nxos_l3_interfaces/tests/common/parsed.yaml @@ -4,7 +4,7 @@ - block: # Interfaces used in the task don't actually exist on the appliance - - name: Use parsed state to convert externally supplied config to structured format + - name: Use parsed state to convert externally supplied configuration to structured format register: result cisco.nxos.nxos_l3_interfaces: running_config: | diff --git a/tests/integration/targets/nxos_l3_interfaces/tests/common/rtt.yaml b/tests/integration/targets/nxos_l3_interfaces/tests/common/rtt.yaml index 0253292d0..887876f0d 100644 --- a/tests/integration/targets/nxos_l3_interfaces/tests/common/rtt.yaml +++ b/tests/integration/targets/nxos_l3_interfaces/tests/common/rtt.yaml @@ -44,7 +44,7 @@ gather_network_resources: - l3_interfaces - - name: Set reserved interface ip config and config to revert + - name: Set reserved interface IP configuration and configuration to revert ansible.builtin.set_fact: mgmt: "{{ ansible_facts.network_resources.l3_interfaces|selectattr('name', 'equalto', rsvd_intf)|list }}" config_to_revert: @@ -73,7 +73,7 @@ that: - result.changed == true - - name: Revert back to base config using facts round trip + - name: Revert back to base configuration using facts round trip register: revert cisco.nxos.nxos_l3_interfaces: config: "{{ ansible_facts['network_resources']['l3_interfaces'] }}" diff --git a/tests/integration/targets/nxos_l3_interfaces/vars/main.yml b/tests/integration/targets/nxos_l3_interfaces/vars/main.yml index cfd79b1ce..db2e9700d 100644 --- a/tests/integration/targets/nxos_l3_interfaces/vars/main.yml +++ b/tests/integration/targets/nxos_l3_interfaces/vars/main.yml @@ -1,3 +1,4 @@ +--- gathered: - name: "{{ nxos_int1 }}" ipv4: @@ -7,8 +8,8 @@ gathered: - address: 203.0.113.10/24 ipv6: - address: 2001:db8::1/32 - redirects: False - unreachables: True + redirects: false + unreachables: true rendered: - "interface Ethernet1/800" @@ -23,14 +24,14 @@ parsed: - address: 192.168.1.100/24 tag: 5 - address: 10.1.1.1/24 - secondary: True + secondary: true tag: 10 - redirects: False + redirects: false - name: Ethernet1/801 ipv6: - address: fd5d:12c9:2201:2::1/64 tag: 6 - unreachables: True + unreachables: true - name: mgmt0 ipv4: - address: dhcp @@ -50,15 +51,15 @@ parsed_multi: - address: 192.168.1.100/24 tag: 5 - address: 10.1.1.1/24 - secondary: True + secondary: true tag: 10 - redirects: False + redirects: false evpn_multisite_tracking: fabric-tracking - name: Ethernet1/801 ipv6: - address: fd5d:12c9:2201:2::1/64 tag: 6 - unreachables: True + unreachables: true evpn_multisite_tracking: dci-tracking - name: mgmt0 ipv4: diff --git a/tests/integration/targets/nxos_lacp/tasks/cli.yaml b/tests/integration/targets/nxos_lacp/tasks/cli.yaml index 507d803cb..e3e64747b 100644 --- a/tests/integration/targets/nxos_lacp/tasks/cli.yaml +++ b/tests/integration/targets/nxos_lacp/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_lacp/tasks/main.yaml b/tests/integration/targets/nxos_lacp/tasks/main.yaml index b42cad3e3..8d0b94337 100644 --- a/tests/integration/targets/nxos_lacp/tasks/main.yaml +++ b/tests/integration/targets/nxos_lacp/tasks/main.yaml @@ -1,9 +1,9 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_lacp/tasks/nxapi.yaml b/tests/integration/targets/nxos_lacp/tasks/nxapi.yaml index 2e452bb6a..4ae68868c 100644 --- a/tests/integration/targets/nxos_lacp/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_lacp/tasks/nxapi.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_lacp/tests/common/_remove_config.yaml b/tests/integration/targets/nxos_lacp/tests/common/_remove_config.yaml index b4d9edd85..47b880452 100644 --- a/tests/integration/targets/nxos_lacp/tests/common/_remove_config.yaml +++ b/tests/integration/targets/nxos_lacp/tests/common/_remove_config.yaml @@ -1,5 +1,5 @@ --- -- name: Remove existing lacp config +- name: Remove existing lacp configuration cisco.nxos.nxos_config: lines: - "no lacp system-priority" diff --git a/tests/integration/targets/nxos_lacp/tests/common/deleted.yaml b/tests/integration/targets/nxos_lacp/tests/common/deleted.yaml index 8d2fa3ab5..b2183ea07 100644 --- a/tests/integration/targets/nxos_lacp/tests/common/deleted.yaml +++ b/tests/integration/targets/nxos_lacp/tests/common/deleted.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: Start nxos_lacp deleted integration tests connection={{ ansible_connection }} -- name: Enable lacp feature +- name: Enable 'feature lacp' cisco.nxos.nxos_feature: feature: lacp diff --git a/tests/integration/targets/nxos_lacp/tests/common/empty_config.yaml b/tests/integration/targets/nxos_lacp/tests/common/empty_config.yaml index 27a82ae72..04f9a86af 100644 --- a/tests/integration/targets/nxos_lacp/tests/common/empty_config.yaml +++ b/tests/integration/targets/nxos_lacp/tests/common/empty_config.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxos_lacp empty_config integration tests on connection={{ ansible_connection }} -- name: Merged with empty config should give appropriate error message +- name: Merged with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_lacp: @@ -13,7 +13,7 @@ that: - result.msg == 'value of config parameter must not be empty for state merged' -- name: Replaced with empty config should give appropriate error message +- name: Replaced with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_lacp: @@ -24,7 +24,7 @@ that: - result.msg == 'value of config parameter must not be empty for state replaced' -- name: Rendered with empty config should give appropriate error message +- name: Rendered with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_lacp: @@ -35,7 +35,7 @@ that: - result.msg == 'value of config parameter must not be empty for state rendered' -- name: Parsed with empty config should give appropriate error message +- name: Parsed with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_lacp: diff --git a/tests/integration/targets/nxos_lacp/tests/common/overridden.yaml b/tests/integration/targets/nxos_lacp/tests/common/overridden.yaml new file mode 100644 index 000000000..d6eb4fb93 --- /dev/null +++ b/tests/integration/targets/nxos_lacp/tests/common/overridden.yaml @@ -0,0 +1,104 @@ +--- +- ansible.builtin.debug: + msg: Start nxos_lacp overridden integration tests connection={{ ansible_connection }} + +- name: Enable 'feature lacp' + cisco.nxos.nxos_feature: + feature: lacp + +- name: Set a fact for 'mac1' and 'mac2' + ansible.builtin.set_fact: + mac1: lacp system-mac 00c1.4c00.bd20 role primary + mac2: + address: 00c1.4c00.bd15 + role: secondary + when: platform is search('N9K') and imagetag is not search('I[2-6]') + +- block: + - name: Setup1 + cisco.nxos.nxos_config: + lines: lacp system-priority 11 + + - name: Setup2 + cisco.nxos.nxos_config: + lines: "{{ mac1|default(omit) }}" + + - name: Gather lacp facts + cisco.nxos.nxos_facts: &id001 + gather_subset: + - "!all" + - "!min" + gather_network_resources: lacp + + - name: Run overridden test + register: result + cisco.nxos.nxos_lacp: &id002 + config: + system: + priority: 12 + mac: "{{ mac2|default(omit) }}" + state: overridden + + - ansible.builtin.assert: + that: + - ansible_facts.network_resources.lacp == result.before + - result.changed == true + - result.commands|length == 2 + - "'no lacp system-priority' in result.commands" + - "'lacp system-priority 12' in result.commands" + when: platform is not search('N9K') + + - ansible.builtin.assert: + that: + - ansible_facts.network_resources.lacp == result.before + - result.changed == true + - "'no lacp system-priority' in result.commands" + - "'no lacp system-mac' in result.commands" + - "'lacp system-priority 12' in result.commands" + - "'lacp system-mac 00c1.4c00.bd15 role secondary' in result.commands" + - result.commands|length == 4 + when: platform is search('N9K') and imagetag is not search('I[2-6]') + + - name: Gather lacp interfaces post facts + cisco.nxos.nxos_facts: *id001 + + - ansible.builtin.assert: + that: + - ansible_facts.network_resources.lacp == result.after + when: platform is search('N9K') and imagetag is not search('I[2-6]') + + - name: Idempotence - overridden + register: result + cisco.nxos.nxos_lacp: *id002 + + - ansible.builtin.assert: + that: + - result.changed == false + - result.commands|length == 0 + + - name: Setup3 + cisco.nxos.nxos_config: + lines: "{{ mac1|default(omit) }}" + + - name: overridden + register: result + when: platform is search('N9K') and imagetag is not search('I[2-6]') + cisco.nxos.nxos_lacp: + config: + system: + priority: 1 + state: overridden + + - ansible.builtin.assert: + that: + - result.changed == true + - result.commands|length == 3 + - "'no lacp system-mac' in result.commands" + - "'no lacp system-priority' in result.commands" + - "'lacp system-priority 1' in result.commands" + when: platform is search('N9K') and imagetag is not search('I[2-6]') + always: + - name: Teardown + cisco.nxos.nxos_feature: + feature: lacp + state: disabled diff --git a/tests/integration/targets/nxos_lacp/tests/common/parsed.yaml b/tests/integration/targets/nxos_lacp/tests/common/parsed.yaml index 421a4183d..b75141762 100644 --- a/tests/integration/targets/nxos_lacp/tests/common/parsed.yaml +++ b/tests/integration/targets/nxos_lacp/tests/common/parsed.yaml @@ -3,7 +3,7 @@ msg: START nxos_lacp parsed integration tests on connection={{ ansible_connection }} - block: - - name: Use parsed state to convert externally supplied config to structured format + - name: Use parsed state to convert externally supplied configuration to structured format register: result cisco.nxos.nxos_lacp: running_config: | diff --git a/tests/integration/targets/nxos_lacp/tests/common/replaced.yaml b/tests/integration/targets/nxos_lacp/tests/common/replaced.yaml index dec861b7c..d48d2d854 100644 --- a/tests/integration/targets/nxos_lacp/tests/common/replaced.yaml +++ b/tests/integration/targets/nxos_lacp/tests/common/replaced.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: Start nxos_lacp replaced integration tests connection={{ ansible_connection }} -- name: Enable lacp feature +- name: Enable 'feature lacp' cisco.nxos.nxos_feature: feature: lacp diff --git a/tests/integration/targets/nxos_lacp/vars/main.yml b/tests/integration/targets/nxos_lacp/vars/main.yml index 7c9f248d3..8b5bd3dbb 100644 --- a/tests/integration/targets/nxos_lacp/vars/main.yml +++ b/tests/integration/targets/nxos_lacp/vars/main.yml @@ -1,3 +1,4 @@ +--- # The CI NX-OS image doesn't support `lacp system-mac` gathered: system: diff --git a/tests/integration/targets/nxos_lacp_interfaces/tasks/cli.yaml b/tests/integration/targets/nxos_lacp_interfaces/tasks/cli.yaml index 507d803cb..e3e64747b 100644 --- a/tests/integration/targets/nxos_lacp_interfaces/tasks/cli.yaml +++ b/tests/integration/targets/nxos_lacp_interfaces/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_lacp_interfaces/tasks/main.yaml b/tests/integration/targets/nxos_lacp_interfaces/tasks/main.yaml index b42cad3e3..8d0b94337 100644 --- a/tests/integration/targets/nxos_lacp_interfaces/tasks/main.yaml +++ b/tests/integration/targets/nxos_lacp_interfaces/tasks/main.yaml @@ -1,9 +1,9 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_lacp_interfaces/tasks/nxapi.yaml b/tests/integration/targets/nxos_lacp_interfaces/tasks/nxapi.yaml index c5f0e9199..5fec0f43b 100644 --- a/tests/integration/targets/nxos_lacp_interfaces/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_lacp_interfaces/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,7 +22,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_lacp_interfaces/tests/common/_populate_config.yaml b/tests/integration/targets/nxos_lacp_interfaces/tests/common/_populate_config.yaml index 431ed3bf7..3e3f94acb 100644 --- a/tests/integration/targets/nxos_lacp_interfaces/tests/common/_populate_config.yaml +++ b/tests/integration/targets/nxos_lacp_interfaces/tests/common/_populate_config.yaml @@ -1,5 +1,5 @@ --- -- name: Populate config +- name: Populate configuration cisco.nxos.nxos_config: lines: - "feature lacp" diff --git a/tests/integration/targets/nxos_lacp_interfaces/tests/common/_remove_config.yaml b/tests/integration/targets/nxos_lacp_interfaces/tests/common/_remove_config.yaml index 6dff8b166..e579913ae 100644 --- a/tests/integration/targets/nxos_lacp_interfaces/tests/common/_remove_config.yaml +++ b/tests/integration/targets/nxos_lacp_interfaces/tests/common/_remove_config.yaml @@ -1,5 +1,5 @@ --- -- name: Remove config +- name: Remove configuration cisco.nxos.nxos_config: lines: - "no interface port-channel5" diff --git a/tests/integration/targets/nxos_lacp_interfaces/tests/common/deleted.yaml b/tests/integration/targets/nxos_lacp_interfaces/tests/common/deleted.yaml index 79595dcde..c38b3ef21 100644 --- a/tests/integration/targets/nxos_lacp_interfaces/tests/common/deleted.yaml +++ b/tests/integration/targets/nxos_lacp_interfaces/tests/common/deleted.yaml @@ -5,7 +5,11 @@ - name: Set a fact for 'mode' ansible.builtin.set_fact: mode: delay - when: platform is not search('N3K|N5K|N6K|N7K') and imagetag is not search('A8|I2') and image_version is not search ('9.2') and chassis_type is not search('C95') + when: >- + platform is not search('N3K|N5K|N6K|N7K') and + imagetag is not search('A8|I2') and + image_version is not search ('9.2') and + chassis_type is not search('C95') - name: Setup1 cisco.nxos.nxos_config: &id002 @@ -24,7 +28,7 @@ - "interface port-channel10" - " lacp max-bundle 10" - - name: Setup3 - l2 for mode command + - name: Setup3 - layer 2 for mode command when: mode is defined cisco.nxos.nxos_config: lines: diff --git a/tests/integration/targets/nxos_lacp_interfaces/tests/common/empty_config.yaml b/tests/integration/targets/nxos_lacp_interfaces/tests/common/empty_config.yaml index 668d8b034..80634f8c6 100644 --- a/tests/integration/targets/nxos_lacp_interfaces/tests/common/empty_config.yaml +++ b/tests/integration/targets/nxos_lacp_interfaces/tests/common/empty_config.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxos_lacp_interfaces empty_config integration tests on connection={{ ansible_connection }} -- name: Merged with empty config should give appropriate error message +- name: Merged with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_lacp_interfaces: @@ -13,7 +13,7 @@ that: - result.msg == 'value of config parameter must not be empty for state merged' -- name: Replaced with empty config should give appropriate error message +- name: Replaced with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_lacp_interfaces: @@ -24,7 +24,7 @@ that: - result.msg == 'value of config parameter must not be empty for state replaced' -- name: Overridden with empty config should give appropriate error message +- name: Overridden with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_lacp_interfaces: @@ -35,7 +35,7 @@ that: - result.msg == 'value of config parameter must not be empty for state overridden' -- name: Rendered with empty config should give appropriate error message +- name: Rendered with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_lacp_interfaces: @@ -46,7 +46,7 @@ that: - result.msg == 'value of config parameter must not be empty for state rendered' -- name: Parsed with empty config should give appropriate error message +- name: Parsed with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_lacp_interfaces: diff --git a/tests/integration/targets/nxos_lacp_interfaces/tests/common/merged.yaml b/tests/integration/targets/nxos_lacp_interfaces/tests/common/merged.yaml index 9cb9c7404..ee01bc24d 100644 --- a/tests/integration/targets/nxos_lacp_interfaces/tests/common/merged.yaml +++ b/tests/integration/targets/nxos_lacp_interfaces/tests/common/merged.yaml @@ -5,7 +5,11 @@ - name: Set a fact for 'mode' ansible.builtin.set_fact: mode: delay - when: platform is not search('N3K|N5K|N6K|N7K') and imagetag is not search('A8|I2') and image_version is not search ('9.2') and chassis_type is not search('C95') + when: >- + platform is not search('N3K|N5K|N6K|N7K') and + imagetag is not search('A8|I2') and + image_version is not search ('9.2') and + chassis_type is not search('C95') - name: Setup1 cisco.nxos.nxos_config: &id002 @@ -20,7 +24,7 @@ lines: - "feature lacp" - - name: Setup3 - l2 for mode command + - name: Setup3 - layer 2 for mode command when: mode is defined cisco.nxos.nxos_config: lines: diff --git a/tests/integration/targets/nxos_lacp_interfaces/tests/common/overridden.yaml b/tests/integration/targets/nxos_lacp_interfaces/tests/common/overridden.yaml index 791a25fa9..e3dfb8385 100644 --- a/tests/integration/targets/nxos_lacp_interfaces/tests/common/overridden.yaml +++ b/tests/integration/targets/nxos_lacp_interfaces/tests/common/overridden.yaml @@ -5,7 +5,11 @@ - name: Set a fact for 'mode' ansible.builtin.set_fact: mode: delay - when: platform is not search('N3K|N5K|N6K|N7K') and imagetag is not search('A8|I2') and image_version is not search ('9.2') and chassis_type is not search('C95') + when: >- + platform is not search('N3K|N5K|N6K|N7K') and + imagetag is not search('A8|I2') and + image_version is not search ('9.2') and + chassis_type is not search('C95') - name: Setup1 cisco.nxos.nxos_config: &id003 @@ -25,7 +29,7 @@ - "interface port-channel5" - " lacp max-bundle 10" - - name: Setup3 - l2 for mode command + - name: Setup3 - layer 2 for mode command when: mode is defined cisco.nxos.nxos_config: lines: diff --git a/tests/integration/targets/nxos_lacp_interfaces/tests/common/parsed.yaml b/tests/integration/targets/nxos_lacp_interfaces/tests/common/parsed.yaml index 1dbadb579..37f24b208 100644 --- a/tests/integration/targets/nxos_lacp_interfaces/tests/common/parsed.yaml +++ b/tests/integration/targets/nxos_lacp_interfaces/tests/common/parsed.yaml @@ -4,7 +4,7 @@ - block: # Ethernet interface used in the task don't actually exist on the appliance - - name: Use parsed state to convert externally supplied config to structured format + - name: Use parsed state to convert externally supplied configuration to structured format register: result cisco.nxos.nxos_lacp_interfaces: running_config: | diff --git a/tests/integration/targets/nxos_lacp_interfaces/tests/common/replaced.yaml b/tests/integration/targets/nxos_lacp_interfaces/tests/common/replaced.yaml index fb707b6cf..f76274787 100644 --- a/tests/integration/targets/nxos_lacp_interfaces/tests/common/replaced.yaml +++ b/tests/integration/targets/nxos_lacp_interfaces/tests/common/replaced.yaml @@ -5,7 +5,11 @@ - name: Set a fact for 'mode' ansible.builtin.set_fact: mode: delay - when: platform is not search('N3K|N5K|N6K|N7K') and imagetag is not search('A8|I2') and image_version is not search ('9.2') and chassis_type is not search('C95') + when: >- + platform is not search('N3K|N5K|N6K|N7K') and + imagetag is not search('A8|I2') and + image_version is not search ('9.2') and + chassis_type is not search('C95') - name: Setup1 cisco.nxos.nxos_config: &id003 diff --git a/tests/integration/targets/nxos_lacp_interfaces/vars/main.yml b/tests/integration/targets/nxos_lacp_interfaces/vars/main.yml index bbb0687bf..633e5a08c 100644 --- a/tests/integration/targets/nxos_lacp_interfaces/vars/main.yml +++ b/tests/integration/targets/nxos_lacp_interfaces/vars/main.yml @@ -1,3 +1,4 @@ +--- gathered: - name: "{{ nxos_int1 }}" port_priority: 5 diff --git a/tests/integration/targets/nxos_lag_interfaces/tasks/cli.yaml b/tests/integration/targets/nxos_lag_interfaces/tasks/cli.yaml index 507d803cb..e3e64747b 100644 --- a/tests/integration/targets/nxos_lag_interfaces/tasks/cli.yaml +++ b/tests/integration/targets/nxos_lag_interfaces/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_lag_interfaces/tasks/main.yaml b/tests/integration/targets/nxos_lag_interfaces/tasks/main.yaml index cd57deb3a..bf71b9995 100644 --- a/tests/integration/targets/nxos_lag_interfaces/tasks/main.yaml +++ b/tests/integration/targets/nxos_lag_interfaces/tasks/main.yaml @@ -4,11 +4,11 @@ lines: "system default switchport" connection: ansible.netcommon.network_cli -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_lag_interfaces/tasks/nxapi.yaml b/tests/integration/targets/nxos_lag_interfaces/tasks/nxapi.yaml index c5f0e9199..5fec0f43b 100644 --- a/tests/integration/targets/nxos_lag_interfaces/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_lag_interfaces/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,7 +22,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_lag_interfaces/tests/common/_populate_config.yaml b/tests/integration/targets/nxos_lag_interfaces/tests/common/_populate_config.yaml index f06d82fc4..4715592ee 100644 --- a/tests/integration/targets/nxos_lag_interfaces/tests/common/_populate_config.yaml +++ b/tests/integration/targets/nxos_lag_interfaces/tests/common/_populate_config.yaml @@ -1,5 +1,5 @@ --- -- name: Populate config +- name: Populate configuration cisco.nxos.nxos_config: lines: - "feature lacp" diff --git a/tests/integration/targets/nxos_lag_interfaces/tests/common/_remove_config.yaml b/tests/integration/targets/nxos_lag_interfaces/tests/common/_remove_config.yaml index fd3b74fc7..59c0f3b35 100644 --- a/tests/integration/targets/nxos_lag_interfaces/tests/common/_remove_config.yaml +++ b/tests/integration/targets/nxos_lag_interfaces/tests/common/_remove_config.yaml @@ -1,5 +1,5 @@ --- -- name: Remove config +- name: Remove configuration cisco.nxos.nxos_config: lines: - "default interface {{ nxos_int1 }}" diff --git a/tests/integration/targets/nxos_lag_interfaces/tests/common/deleted.yaml b/tests/integration/targets/nxos_lag_interfaces/tests/common/deleted.yaml index 4b1c6220c..e1deb531e 100644 --- a/tests/integration/targets/nxos_lag_interfaces/tests/common/deleted.yaml +++ b/tests/integration/targets/nxos_lag_interfaces/tests/common/deleted.yaml @@ -12,7 +12,7 @@ - ansible.builtin.include_tasks: _remove_config.yaml -- name: Enable feature lacp +- name: Enable 'feature lacp' cisco.nxos.nxos_feature: feature: lacp @@ -61,7 +61,7 @@ always: - ansible.builtin.include_tasks: _remove_config.yaml - - name: Disable feature lacp + - name: Disable 'feature lacp' cisco.nxos.nxos_feature: feature: lacp state: disabled diff --git a/tests/integration/targets/nxos_lag_interfaces/tests/common/empty_config.yaml b/tests/integration/targets/nxos_lag_interfaces/tests/common/empty_config.yaml index f98231617..558f53eb4 100644 --- a/tests/integration/targets/nxos_lag_interfaces/tests/common/empty_config.yaml +++ b/tests/integration/targets/nxos_lag_interfaces/tests/common/empty_config.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxos_lag_interfaces empty_config integration tests on connection={{ ansible_connection }} -- name: Merged with empty config should give appropriate error message +- name: Merged with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_lag_interfaces: @@ -13,7 +13,7 @@ that: - result.msg == 'value of config parameter must not be empty for state merged' -- name: Replaced with empty config should give appropriate error message +- name: Replaced with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_lag_interfaces: @@ -24,7 +24,7 @@ that: - result.msg == 'value of config parameter must not be empty for state replaced' -- name: Overridden with empty config should give appropriate error message +- name: Overridden with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_lag_interfaces: @@ -35,7 +35,7 @@ that: - result.msg == 'value of config parameter must not be empty for state overridden' -- name: Rendered with empty config should give appropriate error message +- name: Rendered with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_lag_interfaces: @@ -46,7 +46,7 @@ that: - result.msg == 'value of config parameter must not be empty for state rendered' -- name: Parsed with empty config should give appropriate error message +- name: Parsed with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_lag_interfaces: diff --git a/tests/integration/targets/nxos_lag_interfaces/tests/common/merged.yaml b/tests/integration/targets/nxos_lag_interfaces/tests/common/merged.yaml index 251692d1d..3a8e78976 100644 --- a/tests/integration/targets/nxos_lag_interfaces/tests/common/merged.yaml +++ b/tests/integration/targets/nxos_lag_interfaces/tests/common/merged.yaml @@ -10,7 +10,7 @@ ansible.builtin.set_fact: test_int2: "{{ nxos_int2 }}" -- name: Enable feature lacp +- name: Enable 'feature lacp' cisco.nxos.nxos_feature: feature: lacp @@ -35,9 +35,9 @@ - name: port-channel10 members: - member: "{{ test_int1 }}" - - member: "{{ test_int2 }}" - mode: true + mode: on # noqa yaml[truthy] + force: true state: merged - ansible.builtin.assert: @@ -99,7 +99,7 @@ ignore_errors: true cisco.nxos.nxos_lag_interfaces: *id003 - - name: Disable feature lacp + - name: Disable 'feature lacp' cisco.nxos.nxos_feature: feature: lacp state: disabled diff --git a/tests/integration/targets/nxos_lag_interfaces/tests/common/overridden.yaml b/tests/integration/targets/nxos_lag_interfaces/tests/common/overridden.yaml index 7617fc1fb..92c357f1d 100644 --- a/tests/integration/targets/nxos_lag_interfaces/tests/common/overridden.yaml +++ b/tests/integration/targets/nxos_lag_interfaces/tests/common/overridden.yaml @@ -8,7 +8,7 @@ test_int2: "{{ nxos_int2 }}" test_int3: "{{ nxos_int3 }}" -- name: Enable feature lacp +- name: Enable 'feature lacp' cisco.nxos.nxos_feature: feature: lacp @@ -92,14 +92,14 @@ that: - "result.changed == True" - "'interface Ethernet1/9' in result.commands" - - "'channel-group 20 force mode active' in result.commands" + - "'channel-group 20 force mode active' in result.commands" always: - name: Teardown ignore_errors: true cisco.nxos.nxos_lag_interfaces: *id003 - - name: Disable feature lacp + - name: Disable 'feature lacp' cisco.nxos.nxos_feature: feature: lacp state: disabled diff --git a/tests/integration/targets/nxos_lag_interfaces/tests/common/parsed.yaml b/tests/integration/targets/nxos_lag_interfaces/tests/common/parsed.yaml index a5d2eb488..681902bbe 100644 --- a/tests/integration/targets/nxos_lag_interfaces/tests/common/parsed.yaml +++ b/tests/integration/targets/nxos_lag_interfaces/tests/common/parsed.yaml @@ -4,7 +4,7 @@ - block: # Interfaces used in the task don't actually exist on the appliance - - name: Use parsed state to convert externally supplied config to structured format + - name: Use parsed state to convert externally supplied configuration to structured format register: result cisco.nxos.nxos_lag_interfaces: running_config: | diff --git a/tests/integration/targets/nxos_lag_interfaces/tests/common/replaced.yaml b/tests/integration/targets/nxos_lag_interfaces/tests/common/replaced.yaml index 63d7f824d..5461c2c17 100644 --- a/tests/integration/targets/nxos_lag_interfaces/tests/common/replaced.yaml +++ b/tests/integration/targets/nxos_lag_interfaces/tests/common/replaced.yaml @@ -10,7 +10,7 @@ ansible.builtin.set_fact: test_int2: "{{ nxos_int2 }}" -- name: Enable feature lacp +- name: Enable 'feature lacp' cisco.nxos.nxos_feature: feature: lacp @@ -78,7 +78,7 @@ ignore_errors: true cisco.nxos.nxos_lag_interfaces: *id003 - - name: Disable feature lacp + - name: Disable 'feature lacp' cisco.nxos.nxos_feature: feature: lacp state: disabled diff --git a/tests/integration/targets/nxos_lag_interfaces/vars/main.yml b/tests/integration/targets/nxos_lag_interfaces/vars/main.yml index 9791dea47..a82857b95 100644 --- a/tests/integration/targets/nxos_lag_interfaces/vars/main.yml +++ b/tests/integration/targets/nxos_lag_interfaces/vars/main.yml @@ -1,3 +1,4 @@ +--- gathered: - name: port-channel10 members: diff --git a/tests/integration/targets/nxos_linkagg/defaults/main.yaml b/tests/integration/targets/nxos_linkagg/defaults/main.yaml deleted file mode 100644 index 9ef5ba516..000000000 --- a/tests/integration/targets/nxos_linkagg/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "*" -test_items: [] diff --git a/tests/integration/targets/nxos_linkagg/meta/main.yml b/tests/integration/targets/nxos_linkagg/meta/main.yml deleted file mode 100644 index f504a6ab2..000000000 --- a/tests/integration/targets/nxos_linkagg/meta/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_nxos_tests diff --git a/tests/integration/targets/nxos_linkagg/tasks/cli.yaml b/tests/integration/targets/nxos_linkagg/tasks/cli.yaml deleted file mode 100644 index 90342e6b1..000000000 --- a/tests/integration/targets/nxos_linkagg/tasks/cli.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect cli test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - connection: local - register: cli_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + cli_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.network_cli) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_linkagg/tasks/main.yaml b/tests/integration/targets/nxos_linkagg/tasks/main.yaml deleted file mode 100644 index 62e44ffda..000000000 --- a/tests/integration/targets/nxos_linkagg/tasks/main.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Include the cli tasks - ansible.builtin.include_tasks: cli.yaml - tags: - - cli - -- name: Include the nx-api tasks - ansible.builtin.include_tasks: nxapi.yaml - tags: - - nxapi diff --git a/tests/integration/targets/nxos_linkagg/tasks/nxapi.yaml b/tests/integration/targets/nxos_linkagg/tasks/nxapi.yaml deleted file mode 100644 index cedab80f1..000000000 --- a/tests/integration/targets/nxos_linkagg/tasks/nxapi.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect nxapi test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/nxapi" - patterns: "{{ testcase }}.yaml" - connection: local - register: nxapi_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + nxapi_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.httpapi) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_linkagg/tests/common/sanity.yaml b/tests/integration/targets/nxos_linkagg/tests/common/sanity.yaml deleted file mode 100644 index 0d81d16cf..000000000 --- a/tests/integration/targets/nxos_linkagg/tests/common/sanity.yaml +++ /dev/null @@ -1,204 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_linkagg sanity test - -- name: Set a fact for 'testint1' - ansible.builtin.set_fact: - testint1: "{{ nxos_int1 }}" - -- name: Set a fact for 'testint2' - ansible.builtin.set_fact: - testint2: "{{ nxos_int2 }}" - -- name: Enable feature lacp - ignore_errors: true - cisco.nxos.nxos_feature: - feature: lacp - state: enabled - -- name: Setup - remove config used in test(part1) - cisco.nxos.nxos_config: - lines: - - no interface port-channel 20 - - no interface port-channel 100 - -- name: Setup - remove config used in test(part2) - ignore_errors: true - loop: - - interface {{ testint1 }} - - interface {{ testint2 }} - cisco.nxos.nxos_config: - lines: - - no channel-group 20 - parents: "{{ item }}" - -- name: Put interface in l2 mode - when: platform is match("N35") - cisco.nxos.nxos_interface: - aggregate: - - name: "{{testint1}}" - - - name: "{{testint2}}" - mode: layer2 - -- name: Create linkagg - register: result - cisco.nxos.nxos_linkagg: &id001 - group: 20 - state: present - -- ansible.builtin.assert: - that: - - result.changed == true - - '"interface port-channel 20" in result.commands' - -- name: Create linkagg(idempotence) - register: result - cisco.nxos.nxos_linkagg: *id001 - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Set link aggregation group to members declaratively - register: result - cisco.nxos.nxos_linkagg: &id002 - group: 20 - mode: active - force: true - members: - - "{{ testint1 }}" - - "{{ testint2 }}" - -- ansible.builtin.assert: - that: - - result.changed == true - - '"interface {{ testint1 }}" in result.commands' - - '"channel-group 20 force mode active" in result.commands' - - '"interface {{ testint2 }}" in result.commands' - - '"channel-group 20 force mode active" in result.commands' - -- name: Set link aggregation group to members(idempotence) - register: result - cisco.nxos.nxos_linkagg: *id002 - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Remove link aggregation group from member declaratively - register: result - cisco.nxos.nxos_linkagg: &id003 - group: 20 - mode: active - force: true - members: - - "{{ testint2 }}" - -- ansible.builtin.assert: - that: - - result.changed == true - - '"interface {{ testint1 }}" in result.commands' - - '"no channel-group 20" in result.commands' - -- name: Remove link aggregation group from member(idempotence) - register: result - cisco.nxos.nxos_linkagg: *id003 - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Remove linkagg - register: result - cisco.nxos.nxos_linkagg: &id004 - group: 20 - state: absent - -- ansible.builtin.assert: - that: - - result.changed == true - - '"no interface port-channel 20" in result.commands' - -- name: Remove linkagg(idempotence) - register: result - cisco.nxos.nxos_linkagg: *id004 - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Create aggregate of linkagg definitions - register: result - cisco.nxos.nxos_linkagg: &id005 - aggregate: - - group: 20 - min_links: 3 - - - group: 100 - min_links: 4 - -- ansible.builtin.assert: - that: - - result.changed == true - - '"interface port-channel 20" in result.commands' - - '"lacp min-links 3" in result.commands' - - '"interface port-channel 100" in result.commands' - - '"lacp min-links 4" in result.commands' - -- name: Create aggregate of linkagg definitions(idempotence) - register: result - cisco.nxos.nxos_linkagg: *id005 - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Remove aggregate of linkagg definitions - register: result - cisco.nxos.nxos_linkagg: &id006 - aggregate: - - group: 20 - min_links: 3 - - - group: 100 - min_links: 4 - state: absent - -- ansible.builtin.assert: - that: - - result.changed == true - - '"no interface port-channel 20" in result.commands' - - '"no interface port-channel 100" in result.commands' - -- name: Remove aggregate of linkagg definitions(idempotence) - register: result - cisco.nxos.nxos_linkagg: *id006 - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Teardown - remove config used in test(part1) - cisco.nxos.nxos_config: - lines: - - no interface port-channel 20 - - no interface port-channel 100 - -- name: Teardown - remove config used in test(part2) - ignore_errors: true - loop: - - interface {{ testint1 }} - - interface {{ testint2 }} - cisco.nxos.nxos_config: - lines: - - no channel-group 20 - parents: "{{ item }}" - -- name: Disable feature lacp - cisco.nxos.nxos_feature: - feature: lacp - state: disabled - -- ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_linkagg sanity test diff --git a/tests/integration/targets/nxos_lldp/defaults/main.yaml b/tests/integration/targets/nxos_lldp/defaults/main.yaml deleted file mode 100644 index 5f709c5aa..000000000 --- a/tests/integration/targets/nxos_lldp/defaults/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -testcase: "*" diff --git a/tests/integration/targets/nxos_lldp/meta/main.yml b/tests/integration/targets/nxos_lldp/meta/main.yml deleted file mode 100644 index f504a6ab2..000000000 --- a/tests/integration/targets/nxos_lldp/meta/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_nxos_tests diff --git a/tests/integration/targets/nxos_lldp/tasks/cli.yaml b/tests/integration/targets/nxos_lldp/tasks/cli.yaml deleted file mode 100644 index 90342e6b1..000000000 --- a/tests/integration/targets/nxos_lldp/tasks/cli.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect cli test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - connection: local - register: cli_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + cli_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.network_cli) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_lldp/tasks/main.yaml b/tests/integration/targets/nxos_lldp/tasks/main.yaml deleted file mode 100644 index 62e44ffda..000000000 --- a/tests/integration/targets/nxos_lldp/tasks/main.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Include the cli tasks - ansible.builtin.include_tasks: cli.yaml - tags: - - cli - -- name: Include the nx-api tasks - ansible.builtin.include_tasks: nxapi.yaml - tags: - - nxapi diff --git a/tests/integration/targets/nxos_lldp/tasks/nxapi.yaml b/tests/integration/targets/nxos_lldp/tasks/nxapi.yaml deleted file mode 100644 index cedab80f1..000000000 --- a/tests/integration/targets/nxos_lldp/tasks/nxapi.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect nxapi test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/nxapi" - patterns: "{{ testcase }}.yaml" - connection: local - register: nxapi_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + nxapi_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.httpapi) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_lldp/tests/cli/sanity.yaml b/tests/integration/targets/nxos_lldp/tests/cli/sanity.yaml deleted file mode 100644 index d6162dd98..000000000 --- a/tests/integration/targets/nxos_lldp/tests/cli/sanity.yaml +++ /dev/null @@ -1,49 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START TRANSPORT:CLI nxos_lldp sanity test - -- name: Make sure lldp is not running before tests - cisco.nxos.nxos_feature: - feature: lldp - state: disabled - -- name: Enable lldp service - register: result - cisco.nxos.nxos_lldp: - state: present - -- ansible.builtin.assert: - that: - - result.changed == true - - '"feature lldp" in result.commands' - -- name: Enable lldp service again (idempotent) - register: result - cisco.nxos.nxos_lldp: - state: present - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Disable lldp service - register: result - cisco.nxos.nxos_lldp: - state: absent - -- ansible.builtin.assert: - that: - - result.changed == true - - '"no feature lldp" in result.commands' - -- name: Disable lldp service (idempotent) - register: result - cisco.nxos.nxos_lldp: - state: absent - -- ansible.builtin.assert: - that: - - result.changed == false - -- ansible.builtin.debug: - msg: END TRANSPORT:CLI nxos_lldp sanity test diff --git a/tests/integration/targets/nxos_lldp/tests/nxapi/sanity.yaml b/tests/integration/targets/nxos_lldp/tests/nxapi/sanity.yaml deleted file mode 100644 index c2cbdf2a8..000000000 --- a/tests/integration/targets/nxos_lldp/tests/nxapi/sanity.yaml +++ /dev/null @@ -1,49 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START TRANSPORT:NXAPI nxos_lldp sanity test - -- name: Make sure lldp is not running before tests - cisco.nxos.nxos_feature: - feature: lldp - state: disabled - -- name: Enable lldp service - register: result - cisco.nxos.nxos_lldp: - state: present - -- ansible.builtin.assert: - that: - - result.changed == true - - '"feature lldp" in result.commands' - -- name: Enable lldp service again (idempotent) - register: result - cisco.nxos.nxos_lldp: - state: present - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Disable lldp service - register: result - cisco.nxos.nxos_lldp: - state: absent - -- ansible.builtin.assert: - that: - - result.changed == true - - '"no feature lldp" in result.commands' - -- name: Disable lldp service (idempotent) - register: result - cisco.nxos.nxos_lldp: - state: absent - -- ansible.builtin.assert: - that: - - result.changed == false - -- ansible.builtin.debug: - msg: END TRANSPORT:NXAPI nxos_lldp sanity test diff --git a/tests/integration/targets/nxos_lldp_global/tasks/cli.yaml b/tests/integration/targets/nxos_lldp_global/tasks/cli.yaml index 040f8eab4..bb0e65506 100644 --- a/tests/integration/targets/nxos_lldp_global/tasks/cli.yaml +++ b/tests/integration/targets/nxos_lldp_global/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_lldp_global/tasks/main.yaml b/tests/integration/targets/nxos_lldp_global/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_lldp_global/tasks/main.yaml +++ b/tests/integration/targets/nxos_lldp_global/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_lldp_global/tasks/nxapi.yaml b/tests/integration/targets/nxos_lldp_global/tasks/nxapi.yaml index fe9d48a7c..59a0777c5 100644 --- a/tests/integration/targets/nxos_lldp_global/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_lldp_global/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yml" @@ -22,7 +22,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_lldp_global/tests/common/_populate_config.yml b/tests/integration/targets/nxos_lldp_global/tests/common/_populate_config.yml index f8fb81428..a0d64f354 100644 --- a/tests/integration/targets/nxos_lldp_global/tests/common/_populate_config.yml +++ b/tests/integration/targets/nxos_lldp_global/tests/common/_populate_config.yml @@ -1,5 +1,5 @@ --- -- name: Populate config +- name: Populate configuration cisco.nxos.nxos_config: lines: - "feature lldp" diff --git a/tests/integration/targets/nxos_lldp_global/tests/common/_remove_config.yml b/tests/integration/targets/nxos_lldp_global/tests/common/_remove_config.yml index 5a37b064b..42a64ce43 100644 --- a/tests/integration/targets/nxos_lldp_global/tests/common/_remove_config.yml +++ b/tests/integration/targets/nxos_lldp_global/tests/common/_remove_config.yml @@ -1,5 +1,5 @@ --- -- name: Remove config +- name: Remove configuration cisco.nxos.nxos_feature: feature: lldp state: disabled diff --git a/tests/integration/targets/nxos_lldp_global/tests/common/deleted.yml b/tests/integration/targets/nxos_lldp_global/tests/common/deleted.yml index 6cf03dae7..581197d7f 100644 --- a/tests/integration/targets/nxos_lldp_global/tests/common/deleted.yml +++ b/tests/integration/targets/nxos_lldp_global/tests/common/deleted.yml @@ -13,7 +13,7 @@ feature: lldp state: disabled - - name: Enable lldp feature + - name: Enable 'feature lldp' cisco.nxos.nxos_feature: feature: lldp state: enabled diff --git a/tests/integration/targets/nxos_lldp_global/tests/common/overridden.yml b/tests/integration/targets/nxos_lldp_global/tests/common/overridden.yml new file mode 100644 index 000000000..58c41c1f8 --- /dev/null +++ b/tests/integration/targets/nxos_lldp_global/tests/common/overridden.yml @@ -0,0 +1,92 @@ +--- +- ansible.builtin.debug: + msg: Start nxos_lldp_global overridden integration tests connection = {{ansible_connection}} + +- block: + - name: Set a fact for 'port_id' and 'tlv_power_mgmt' + ansible.builtin.set_fact: + port_id: 1 + tlv_power_mgmt: + power_management: false + when: platform is not search('N[567]K') and imagetag is not search("I[2345]") + + - name: Feature off to cleanup lldp + cisco.nxos.nxos_feature: &id002 + feature: lldp + state: disabled + + - name: Enable lldp feature + cisco.nxos.nxos_feature: + feature: lldp + state: enabled + + - name: Setup + cisco.nxos.nxos_config: + lines: + - "lldp holdtime 125" + - "lldp tlv-select system-name" + - "no lldp tlv-select port-vlan" + + - name: Setup2 + when: port_id is defined + cisco.nxos.nxos_config: + lines: + - "lldp portid-subtype 1" + - "no lldp tlv-select power-management" + + - name: Run overridden tests + register: result + cisco.nxos.nxos_lldp_global: &id001 + config: + holdtime: 125 + timer: 35 + tlv_select: + system: + name: false + description: false + port: + vlan: false + dcbxp: false + state: overridden + + - ansible.builtin.assert: + that: + - result.changed == true + - "'lldp timer 35' in result.commands" + - "'no lldp tlv-select system-name' in result.commands" + - "'no lldp tlv-select system-description' in result.commands" + - "'no lldp tlv-select dcbxp' in result.commands" + + - ansible.builtin.assert: + that: + - "'no lldp portid-subtype 1' in result.commands" + when: port_id is defined + + - ansible.builtin.assert: + that: + - "'lldp tlv-select power-management' in result.commands" + when: tlv_power_mgmt is defined + + - name: Gather lldp_global post facts + cisco.nxos.nxos_facts: + gather_subset: + - "!all" + - "!min" + gather_network_resources: lldp_global + + - ansible.builtin.assert: + that: + - ansible_facts.network_resources.lldp_global == result.after + + - name: Idempotence - overridden + register: result + cisco.nxos.nxos_lldp_global: *id001 + + - ansible.builtin.assert: + that: + - result.changed == false + - result.commands|length == 0 + always: + - name: Teardown + cisco.nxos.nxos_feature: *id002 + when: platform is not search('N35') diff --git a/tests/integration/targets/nxos_lldp_global/tests/common/parsed.yml b/tests/integration/targets/nxos_lldp_global/tests/common/parsed.yml index 7d9cf94cd..ce8de23ab 100644 --- a/tests/integration/targets/nxos_lldp_global/tests/common/parsed.yml +++ b/tests/integration/targets/nxos_lldp_global/tests/common/parsed.yml @@ -3,7 +3,7 @@ msg: START nxos_lldp_global parsed integration tests on connection={{ ansible_connection }} - block: - - name: Use parsed state to convert externally supplied config to structured format + - name: Use parsed state to convert externally supplied configuration to structured format register: result cisco.nxos.nxos_lldp_global: running_config: | diff --git a/tests/integration/targets/nxos_lldp_global/vars/main.yml b/tests/integration/targets/nxos_lldp_global/vars/main.yml index 7bca43e23..4a3dc8100 100644 --- a/tests/integration/targets/nxos_lldp_global/vars/main.yml +++ b/tests/integration/targets/nxos_lldp_global/vars/main.yml @@ -1,9 +1,10 @@ +--- gathered: reinit: 5 timer: 35 tlv_select: system: - name: False + name: false holdtime: 129 rendered: diff --git a/tests/integration/targets/nxos_lldp_interfaces/tasks/cli.yaml b/tests/integration/targets/nxos_lldp_interfaces/tasks/cli.yaml index 95d6a016b..3e5e72a07 100644 --- a/tests/integration/targets/nxos_lldp_interfaces/tasks/cli.yaml +++ b/tests/integration/targets/nxos_lldp_interfaces/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yml" @@ -22,7 +22,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_lldp_interfaces/tasks/main.yaml b/tests/integration/targets/nxos_lldp_interfaces/tasks/main.yaml index b42cad3e3..8d0b94337 100644 --- a/tests/integration/targets/nxos_lldp_interfaces/tasks/main.yaml +++ b/tests/integration/targets/nxos_lldp_interfaces/tasks/main.yaml @@ -1,9 +1,9 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_lldp_interfaces/tasks/nxapi.yaml b/tests/integration/targets/nxos_lldp_interfaces/tasks/nxapi.yaml index fe9d48a7c..59a0777c5 100644 --- a/tests/integration/targets/nxos_lldp_interfaces/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_lldp_interfaces/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yml" @@ -22,7 +22,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_lldp_interfaces/tests/common/deleted.yml b/tests/integration/targets/nxos_lldp_interfaces/tests/common/deleted.yml index 37513bb1e..639254f52 100644 --- a/tests/integration/targets/nxos_lldp_interfaces/tests/common/deleted.yml +++ b/tests/integration/targets/nxos_lldp_interfaces/tests/common/deleted.yml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: Start nxos_lldp_interfaces deleted integration tests connection = {{ ansible_connection }} -- name: Enable lldp feature +- name: Enable 'feature lldp' cisco.nxos.nxos_feature: feature: lldp state: enabled diff --git a/tests/integration/targets/nxos_lldp_interfaces/tests/common/gathered.yml b/tests/integration/targets/nxos_lldp_interfaces/tests/common/gathered.yml index 08acbb878..f9d3e6032 100644 --- a/tests/integration/targets/nxos_lldp_interfaces/tests/common/gathered.yml +++ b/tests/integration/targets/nxos_lldp_interfaces/tests/common/gathered.yml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: Start nxos_lldp_interfaces gathered integration tests connection={{ansible_connection}}" -- name: Enable lldp feature +- name: Enable 'feature lldp' cisco.nxos.nxos_feature: feature: lldp state: enabled diff --git a/tests/integration/targets/nxos_lldp_interfaces/tests/common/overridden.yml b/tests/integration/targets/nxos_lldp_interfaces/tests/common/overridden.yml index d336115c4..cb54a42a1 100644 --- a/tests/integration/targets/nxos_lldp_interfaces/tests/common/overridden.yml +++ b/tests/integration/targets/nxos_lldp_interfaces/tests/common/overridden.yml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: Start nxos_lldp_interfaces overridden tests connection={{ ansible_connection }} -- name: Enable lldp feature +- name: Enable 'feature lldp' cisco.nxos.nxos_feature: feature: lldp state: enabled diff --git a/tests/integration/targets/nxos_lldp_interfaces/tests/common/replaced.yml b/tests/integration/targets/nxos_lldp_interfaces/tests/common/replaced.yml index 34d443178..601950528 100644 --- a/tests/integration/targets/nxos_lldp_interfaces/tests/common/replaced.yml +++ b/tests/integration/targets/nxos_lldp_interfaces/tests/common/replaced.yml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: Start nxos_lldp_interfaces replaced integration tests connection = {{ansible_connection}} -- name: Enable lldp feature +- name: Enable 'feature lldp' cisco.nxos.nxos_feature: feature: lldp state: enabled diff --git a/tests/integration/targets/nxos_lldp_interfaces/tests/common/rtt.yml b/tests/integration/targets/nxos_lldp_interfaces/tests/common/rtt.yml index 69a313720..516fb3fe8 100644 --- a/tests/integration/targets/nxos_lldp_interfaces/tests/common/rtt.yml +++ b/tests/integration/targets/nxos_lldp_interfaces/tests/common/rtt.yml @@ -59,7 +59,7 @@ config: "{{ ansible_facts['network_resources']['lldp_interfaces'] }}" state: overridden - - name: Assert that config was reverted + - name: Assert that configuration was reverted ansible.builtin.assert: that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length == 0 }}" always: diff --git a/tests/integration/targets/nxos_logging/tasks/cli.yaml b/tests/integration/targets/nxos_logging/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_logging/tasks/cli.yaml +++ b/tests/integration/targets/nxos_logging/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_logging/tasks/main.yaml b/tests/integration/targets/nxos_logging/tasks/main.yaml index e7f88d7b4..ccb324f33 100644 --- a/tests/integration/targets/nxos_logging/tasks/main.yaml +++ b/tests/integration/targets/nxos_logging/tasks/main.yaml @@ -1,11 +1,12 @@ --- -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_logging/tasks/nxapi.yaml b/tests/integration/targets/nxos_logging/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_logging/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_logging/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_logging/tests/common/basic.yaml b/tests/integration/targets/nxos_logging/tests/common/basic.yaml index 577a95165..72bf146d1 100644 --- a/tests/integration/targets/nxos_logging/tests/common/basic.yaml +++ b/tests/integration/targets/nxos_logging/tests/common/basic.yaml @@ -16,7 +16,7 @@ register: result cisco.nxos.nxos_logging: &id001 dest: console - dest_level: 00 + dest_level: 0 state: present - ansible.builtin.assert: diff --git a/tests/integration/targets/nxos_logging/tests/common/net_logging.yaml b/tests/integration/targets/nxos_logging/tests/common/net_logging.yaml deleted file mode 100644 index fc0ff0acb..000000000 --- a/tests/integration/targets/nxos_logging/tests/common/net_logging.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos common/net_logging.yaml - -- name: Delete/disable console logging - setup - register: result - ansible.netcommon.net_logging: - dest: console - dest_level: 00 - state: absent - -- name: Set up console logging using platform agnostic module - register: result - ansible.netcommon.net_logging: - dest: console - dest_level: 00 - state: present - -- ansible.builtin.assert: - that: - - result.changed == true - - '"logging console 0" in result.commands' - -- name: Delete/disable console logging - teardown - register: result - ansible.netcommon.net_logging: - dest: console - dest_level: 00 - state: absent - -- ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos common/net_logging.yaml diff --git a/tests/integration/targets/nxos_logging/tests/common/purge.yaml b/tests/integration/targets/nxos_logging/tests/common/purge.yaml index 6badf4a67..fa773b58a 100644 --- a/tests/integration/targets/nxos_logging/tests/common/purge.yaml +++ b/tests/integration/targets/nxos_logging/tests/common/purge.yaml @@ -11,7 +11,7 @@ register: result cisco.nxos.nxos_logging: dest: console - dest_level: 00 + dest_level: 0 state: present - ansible.builtin.assert: @@ -87,7 +87,7 @@ cisco.nxos.nxos_logging: aggregate: - dest: console - dest_level: 00 + dest_level: 0 - dest: monitor dest_level: 3 diff --git a/tests/integration/targets/nxos_logging_global/tasks/cli.yaml b/tests/integration/targets/nxos_logging_global/tasks/cli.yaml index 507d803cb..e3e64747b 100644 --- a/tests/integration/targets/nxos_logging_global/tasks/cli.yaml +++ b/tests/integration/targets/nxos_logging_global/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_logging_global/tasks/main.yaml b/tests/integration/targets/nxos_logging_global/tasks/main.yaml index 490861ca1..b62ef52ee 100644 --- a/tests/integration/targets/nxos_logging_global/tasks/main.yaml +++ b/tests/integration/targets/nxos_logging_global/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli.yaml -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_logging_global/tasks/nxapi.yaml b/tests/integration/targets/nxos_logging_global/tasks/nxapi.yaml index 2e452bb6a..4ae68868c 100644 --- a/tests/integration/targets/nxos_logging_global/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_logging_global/tasks/nxapi.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_logging_global/tests/common/_populate_config.yaml b/tests/integration/targets/nxos_logging_global/tests/common/_populate_config.yaml index cba00c59c..532e4e058 100644 --- a/tests/integration/targets/nxos_logging_global/tests/common/_populate_config.yaml +++ b/tests/integration/targets/nxos_logging_global/tests/common/_populate_config.yaml @@ -1,5 +1,5 @@ --- -- name: Populate config +- name: Populate configuration cisco.nxos.nxos_config: lines: - "logging console 3" diff --git a/tests/integration/targets/nxos_logging_global/tests/common/empty_config.yaml b/tests/integration/targets/nxos_logging_global/tests/common/empty_config.yaml index 408b461f3..22a95f77e 100644 --- a/tests/integration/targets/nxos_logging_global/tests/common/empty_config.yaml +++ b/tests/integration/targets/nxos_logging_global/tests/common/empty_config.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxos_logging_global empty_config integration tests on connection={{ ansible_connection }} -- name: Merged with empty config should give appropriate error message +- name: Merged with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_logging_global: @@ -13,7 +13,7 @@ that: - result.msg == 'value of config parameter must not be empty for state merged' -- name: Replaced with empty config should give appropriate error message +- name: Replaced with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_logging_global: @@ -24,7 +24,7 @@ that: - result.msg == 'value of config parameter must not be empty for state replaced' -- name: Overridden with empty config should give appropriate error message +- name: Overridden with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_logging_global: @@ -35,7 +35,7 @@ that: - result.msg == 'value of config parameter must not be empty for state overridden' -- name: Rendered with empty config should give appropriate error message +- name: Rendered with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_logging_global: @@ -46,7 +46,7 @@ that: - result.msg == 'value of config parameter must not be empty for state rendered' -- name: Parsed with empty config should give appropriate error message +- name: Parsed with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_logging_global: diff --git a/tests/integration/targets/nxos_logging_global/tests/common/parsed.yaml b/tests/integration/targets/nxos_logging_global/tests/common/parsed.yaml index 2a14a83be..d959f00a6 100644 --- a/tests/integration/targets/nxos_logging_global/tests/common/parsed.yaml +++ b/tests/integration/targets/nxos_logging_global/tests/common/parsed.yaml @@ -8,7 +8,7 @@ running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" state: parsed -- name: Assert that config was correctly parsed +- name: Assert that configuration was correctly parsed ansible.builtin.assert: that: - "{{ merged['after'] == result['parsed'] }}" diff --git a/tests/integration/targets/nxos_ntp/tasks/cli.yaml b/tests/integration/targets/nxos_ntp/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_ntp/tasks/cli.yaml +++ b/tests/integration/targets/nxos_ntp/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_ntp/tasks/main.yaml b/tests/integration/targets/nxos_ntp/tasks/main.yaml index 7631f52fe..c9e70304e 100644 --- a/tests/integration/targets/nxos_ntp/tasks/main.yaml +++ b/tests/integration/targets/nxos_ntp/tasks/main.yaml @@ -1,11 +1,12 @@ --- -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli always: - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_ntp/tasks/nxapi.yaml b/tests/integration/targets/nxos_ntp/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_ntp/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_ntp/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_ntp/tests/common/sanity.yaml b/tests/integration/targets/nxos_ntp/tests/common/sanity.yaml index 20a4400ad..f22c99f55 100644 --- a/tests/integration/targets/nxos_ntp/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_ntp/tests/common/sanity.yaml @@ -53,7 +53,7 @@ - ansible.builtin.assert: *id004 - - name: Remove ntp config + - name: Remove ntp configuration register: result cisco.nxos.nxos_ntp: *id005 @@ -107,7 +107,7 @@ - ansible.builtin.assert: *id004 always: - - name: Remove ntp config + - name: Remove ntp configuration cisco.nxos.nxos_ntp: *id005 - ansible.builtin.debug: diff --git a/tests/integration/targets/nxos_ntp_auth/tasks/cli.yaml b/tests/integration/targets/nxos_ntp_auth/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_ntp_auth/tasks/cli.yaml +++ b/tests/integration/targets/nxos_ntp_auth/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_ntp_auth/tasks/main.yaml b/tests/integration/targets/nxos_ntp_auth/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_ntp_auth/tasks/main.yaml +++ b/tests/integration/targets/nxos_ntp_auth/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_ntp_auth/tasks/nxapi.yaml b/tests/integration/targets/nxos_ntp_auth/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_ntp_auth/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_ntp_auth/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_ntp_auth/tests/common/sanity.yaml b/tests/integration/targets/nxos_ntp_auth/tests/common/sanity.yaml index e43f5191c..3ceb9e122 100644 --- a/tests/integration/targets/nxos_ntp_auth/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_ntp_auth/tests/common/sanity.yaml @@ -125,7 +125,7 @@ - ansible.builtin.assert: *id004 always: - - name: Cleanup ntp auth config + - name: Cleanup ntp auth configuration ignore_errors: true cisco.nxos.nxos_ntp_auth: *id009 diff --git a/tests/integration/targets/nxos_ntp_global/tasks/cli.yaml b/tests/integration/targets/nxos_ntp_global/tasks/cli.yaml index 507d803cb..e3e64747b 100644 --- a/tests/integration/targets/nxos_ntp_global/tasks/cli.yaml +++ b/tests/integration/targets/nxos_ntp_global/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_ntp_global/tasks/main.yaml b/tests/integration/targets/nxos_ntp_global/tasks/main.yaml index 490861ca1..b62ef52ee 100644 --- a/tests/integration/targets/nxos_ntp_global/tasks/main.yaml +++ b/tests/integration/targets/nxos_ntp_global/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli.yaml -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_ntp_global/tasks/nxapi.yaml b/tests/integration/targets/nxos_ntp_global/tasks/nxapi.yaml index 2e452bb6a..4ae68868c 100644 --- a/tests/integration/targets/nxos_ntp_global/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_ntp_global/tasks/nxapi.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_ntp_global/tests/common/_populate_config.yaml b/tests/integration/targets/nxos_ntp_global/tests/common/_populate_config.yaml index e4a77143a..2c2e860cb 100644 --- a/tests/integration/targets/nxos_ntp_global/tests/common/_populate_config.yaml +++ b/tests/integration/targets/nxos_ntp_global/tests/common/_populate_config.yaml @@ -1,5 +1,5 @@ --- -- name: Populate config +- name: Populate configuration cisco.nxos.nxos_config: lines: - "ntp authenticate" diff --git a/tests/integration/targets/nxos_ntp_global/tests/common/empty_config.yaml b/tests/integration/targets/nxos_ntp_global/tests/common/empty_config.yaml index 048c53d21..16c6144a8 100644 --- a/tests/integration/targets/nxos_ntp_global/tests/common/empty_config.yaml +++ b/tests/integration/targets/nxos_ntp_global/tests/common/empty_config.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxos_ntp_global empty_config integration tests on connection={{ ansible_connection }} -- name: Merged with empty config should give appropriate error message +- name: Merged with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_ntp_global: @@ -13,7 +13,7 @@ that: - result.msg == 'value of config parameter must not be empty for state merged' -- name: Replaced with empty config should give appropriate error message +- name: Replaced with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_ntp_global: @@ -24,7 +24,7 @@ that: - result.msg == 'value of config parameter must not be empty for state replaced' -- name: Overridden with empty config should give appropriate error message +- name: Overridden with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_ntp_global: @@ -35,7 +35,7 @@ that: - result.msg == 'value of config parameter must not be empty for state overridden' -- name: Rendered with empty config should give appropriate error message +- name: Rendered with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_ntp_global: @@ -46,7 +46,7 @@ that: - result.msg == 'value of config parameter must not be empty for state rendered' -- name: Parsed with empty config should give appropriate error message +- name: Parsed with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_ntp_global: diff --git a/tests/integration/targets/nxos_ntp_global/tests/common/parsed.yaml b/tests/integration/targets/nxos_ntp_global/tests/common/parsed.yaml index ab7c5ab38..321c2a9fb 100644 --- a/tests/integration/targets/nxos_ntp_global/tests/common/parsed.yaml +++ b/tests/integration/targets/nxos_ntp_global/tests/common/parsed.yaml @@ -8,7 +8,7 @@ running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" state: parsed -- name: Assert that config was correctly parsed +- name: Assert that configuration was correctly parsed ansible.builtin.assert: that: - "{{ merged['after'] == result['parsed'] }}" diff --git a/tests/integration/targets/nxos_ntp_global/vars/main.yml b/tests/integration/targets/nxos_ntp_global/vars/main.yml index e65524fc0..65b3d6e52 100644 --- a/tests/integration/targets/nxos_ntp_global/vars/main.yml +++ b/tests/integration/targets/nxos_ntp_global/vars/main.yml @@ -17,8 +17,8 @@ merged: - access_list: PeerAcl1 serve: - access_list: ServeAcl1 - authenticate: True - logging: True + authenticate: true + logging: true master: stratum: 2 peers: @@ -29,7 +29,7 @@ merged: vrf: default - peer: 192.0.2.2 key_id: 2 - prefer: True + prefer: true vrf: siteA servers: - server: 198.51.100.1 @@ -55,7 +55,7 @@ replaced: - access_list: PeerAcl2 serve: - access_list: ServeAcl2 - logging: True + logging: true master: stratum: 2 peers: @@ -66,7 +66,7 @@ replaced: vrf: default - peer: 192.0.2.5 key_id: 2 - prefer: True + prefer: true vrf: siteA servers: - server: 198.51.100.1 diff --git a/tests/integration/targets/nxos_ntp_options/tasks/cli.yaml b/tests/integration/targets/nxos_ntp_options/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_ntp_options/tasks/cli.yaml +++ b/tests/integration/targets/nxos_ntp_options/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_ntp_options/tasks/main.yaml b/tests/integration/targets/nxos_ntp_options/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_ntp_options/tasks/main.yaml +++ b/tests/integration/targets/nxos_ntp_options/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_ntp_options/tasks/nxapi.yaml b/tests/integration/targets/nxos_ntp_options/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_ntp_options/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_ntp_options/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_ntp_options/tests/common/sanity.yaml b/tests/integration/targets/nxos_ntp_options/tests/common/sanity.yaml index aef6442c3..1ee9433ef 100644 --- a/tests/integration/targets/nxos_ntp_options/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_ntp_options/tests/common/sanity.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START connection={{ ansible_connection }} nxos_ntp_options sanity test -- name: Apply default ntp config +- name: Apply default ntp configuration ignore_errors: true cisco.nxos.nxos_ntp_options: &id007 state: absent @@ -91,7 +91,7 @@ - ansible.builtin.assert: *id004 always: - - name: Cleanup ntp config + - name: Cleanup ntp configuration register: result cisco.nxos.nxos_ntp_options: *id007 diff --git a/tests/integration/targets/nxos_nxapi/tasks/cli.yaml b/tests/integration/targets/nxos_nxapi/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_nxapi/tasks/cli.yaml +++ b/tests/integration/targets/nxos_nxapi/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_nxapi/tasks/main.yaml b/tests/integration/targets/nxos_nxapi/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_nxapi/tasks/main.yaml +++ b/tests/integration/targets/nxos_nxapi/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_nxapi/tasks/nxapi.yaml b/tests/integration/targets/nxos_nxapi/tasks/nxapi.yaml index 8a869025c..0b2e4f778 100644 --- a/tests/integration/targets/nxos_nxapi/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_nxapi/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,20 +22,18 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run - vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" -- name: Run test cases (connection=local) + +- name: Run test cases with connection local ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: local - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_nxapi/tests/cli/configure.yaml b/tests/integration/targets/nxos_nxapi/tests/cli/configure.yaml index af6b23f65..fb0f380fb 100644 --- a/tests/integration/targets/nxos_nxapi/tests/cli/configure.yaml +++ b/tests/integration/targets/nxos_nxapi/tests/cli/configure.yaml @@ -7,12 +7,12 @@ nxapi_sandbox_option: true when: platform is search('N7K') -- name: Setup - put nxapi in stopped state +- name: Setup - put NX-API in stopped state cisco.nxos.nxos_nxapi: state: absent - block: - - name: Configure nxapi https + - name: Configure NX-API https register: result cisco.nxos.nxos_nxapi: &id001 enable_http: false @@ -25,16 +25,16 @@ commands: - show nxapi | json - - ansible.builtin.include: tasks/platform/n7k/assert_changes_https.yaml + - ansible.builtin.include_tasks: tasks/platform/n7k/assert_changes_https.yaml when: platform is match('N7K') - - ansible.builtin.include: tasks/platform/n5k/assert_changes_https.yaml + - ansible.builtin.include_tasks: tasks/platform/n5k/assert_changes_https.yaml when: platform is search('N5K|N6K') - - ansible.builtin.include: tasks/platform/default/assert_changes_https.yaml + - ansible.builtin.include_tasks: tasks/platform/default/assert_changes_https.yaml when: platform is not search('N35|N5K|N6K|N7K') - - name: Configure nxapi https again + - name: Configure NX-API https again register: result cisco.nxos.nxos_nxapi: *id001 @@ -43,7 +43,7 @@ that: - result.changed == false - - name: Configure nxapi https & http + - name: Configure NX-API https & http register: result cisco.nxos.nxos_nxapi: &id002 enable_http: true @@ -56,23 +56,23 @@ commands: - show nxapi | json - - ansible.builtin.include: tasks/platform/n7k/assert_changes_https_http.yaml + - ansible.builtin.include_tasks: tasks/platform/n7k/assert_changes_https_http.yaml when: platform is match('N7K') - - ansible.builtin.include: tasks/platform/n5k/assert_changes_https_http.yaml + - ansible.builtin.include_tasks: tasks/platform/n5k/assert_changes_https_http.yaml when: platform is match('N5K') - - ansible.builtin.include: tasks/platform/default/assert_changes_https_http.yaml + - ansible.builtin.include_tasks: tasks/platform/default/assert_changes_https_http.yaml when: platform is not search('N35|N5K|N6K|N7K') - - name: Configure nxapi https & http again + - name: Configure NX-API https & http again register: result cisco.nxos.nxos_nxapi: *id002 - name: Assert configuration is idempotent ansible.builtin.assert: *id003 - - name: Configure different nxapi https & http ports + - name: Configure different NX-API https & http ports register: result cisco.nxos.nxos_nxapi: &id004 enable_http: true @@ -86,23 +86,23 @@ commands: - show nxapi | json - - ansible.builtin.include: tasks/platform/n7k/assert_changes_https_http_ports.yaml + - ansible.builtin.include_tasks: tasks/platform/n7k/assert_changes_https_http_ports.yaml when: platform is match('N7K') - - ansible.builtin.include: tasks/platform/n5k/assert_changes_https_http_ports.yaml + - ansible.builtin.include_tasks: tasks/platform/n5k/assert_changes_https_http_ports.yaml when: platform is match('N5K') - - ansible.builtin.include: tasks/platform/default/assert_changes_https_http_ports.yaml + - ansible.builtin.include_tasks: tasks/platform/default/assert_changes_https_http_ports.yaml when: platform is not search('N35|N5K|N6K|N7K') - - name: Configure different nxapi https & http ports again + - name: Configure different NX-API https & http ports again register: result cisco.nxos.nxos_nxapi: *id004 - name: Assert configuration is idempotent ansible.builtin.assert: *id003 - - name: Configure nxapi http + - name: Configure NX-API http register: result cisco.nxos.nxos_nxapi: &id005 enable_http: true @@ -114,28 +114,28 @@ commands: - show nxapi | json - - ansible.builtin.include: tasks/platform/n7k/assert_changes_http.yaml + - ansible.builtin.include_tasks: tasks/platform/n7k/assert_changes_http.yaml when: platform is match('N7K') - - ansible.builtin.include: tasks/platform/n5k/assert_changes_http.yaml + - ansible.builtin.include_tasks: tasks/platform/n5k/assert_changes_http.yaml when: platform is match('N5K') - - ansible.builtin.include: tasks/platform/default/assert_changes_http.yaml + - ansible.builtin.include_tasks: tasks/platform/default/assert_changes_http.yaml when: platform is not search('N35|N5K|N6K|N7K') - - name: Configure nxapi http again + - name: Configure NX-API http again register: result cisco.nxos.nxos_nxapi: *id005 - name: Assert configuration is idempotent ansible.builtin.assert: *id003 always: - - name: Cleanup - disable nxapi + - name: Cleanup - disable NX-API register: result cisco.nxos.nxos_nxapi: state: absent - - name: Cleanup - re-enable nxapi + - name: Cleanup - re-enable NX-API register: result cisco.nxos.nxos_nxapi: state: present diff --git a/tests/integration/targets/nxos_nxapi/tests/cli/disable.yaml b/tests/integration/targets/nxos_nxapi/tests/cli/disable.yaml index 8b232ad25..54eea69ab 100644 --- a/tests/integration/targets/nxos_nxapi/tests/cli/disable.yaml +++ b/tests/integration/targets/nxos_nxapi/tests/cli/disable.yaml @@ -2,22 +2,22 @@ - ansible.builtin.debug: msg: START cli/disable.yaml -- name: Disable nxapi +- name: Disable NX-API register: result cisco.nxos.nxos_nxapi: state: absent -- name: Check nxapi state +- name: Check NX-API state register: result cisco.nxos.nxos_command: commands: - show feature | grep nxapi -- name: Assert nxapi is disabled +- name: Assert NX-API is disabled ansible.builtin.assert: that: result.stdout[0] is search('disabled') -- name: Disable nxapi again +- name: Disable NX-API again register: result cisco.nxos.nxos_nxapi: state: absent diff --git a/tests/integration/targets/nxos_nxapi/tests/cli/enable.yaml b/tests/integration/targets/nxos_nxapi/tests/cli/enable.yaml index 13c5e95b0..267d075d4 100644 --- a/tests/integration/targets/nxos_nxapi/tests/cli/enable.yaml +++ b/tests/integration/targets/nxos_nxapi/tests/cli/enable.yaml @@ -2,27 +2,27 @@ - ansible.builtin.debug: msg: START cli/enable.yaml -- name: Setup - put nxapi in stopped state +- name: Setup - put NX-API in stopped state register: result cisco.nxos.nxos_nxapi: state: absent -- name: Enable nxapi +- name: Enable NX-API register: result cisco.nxos.nxos_nxapi: state: present -- name: Check nxapi state +- name: Check NX-API state register: result cisco.nxos.nxos_command: commands: - show feature | grep nxapi -- name: Assert nxapi is enabled +- name: Assert NX-API is enabled ansible.builtin.assert: that: result.stdout[0] is search('enabled') -- name: Enable nxapi again +- name: Enable NX-API again register: result cisco.nxos.nxos_nxapi: diff --git a/tests/integration/targets/nxos_nxapi/tests/cli/nxapi_ssl.yaml b/tests/integration/targets/nxos_nxapi/tests/cli/nxapi_ssl.yaml index 01d232066..6e4a8c21c 100644 --- a/tests/integration/targets/nxos_nxapi/tests/cli/nxapi_ssl.yaml +++ b/tests/integration/targets/nxos_nxapi/tests/cli/nxapi_ssl.yaml @@ -3,7 +3,7 @@ - ansible.builtin.debug: msg: START cli/nxapi_ssl.yaml - - name: Configure nxapi https w/weak ciphers + - name: Configure NX-API https w/weak ciphers register: result cisco.nxos.nxos_nxapi: &id001 enable_https: true @@ -20,7 +20,7 @@ that: - result.stdout_lines[0][0] == 'nxapi ssl ciphers weak' - - name: Configure nxapi http w/weak ciphers again + - name: Configure NX-API http w/weak ciphers again register: result cisco.nxos.nxos_nxapi: *id001 @@ -29,7 +29,7 @@ that: - result.changed == false - - name: Configure nxapi https w/strong ciphers + - name: Configure NX-API https w/strong ciphers register: result cisco.nxos.nxos_nxapi: &id002 enable_https: true @@ -46,14 +46,14 @@ that: - result.stdout_lines[0][0] == 'no nxapi ssl ciphers weak' - - name: Configure nxapi https w/strong ciphers again + - name: Configure NX-API https w/strong ciphers again register: result cisco.nxos.nxos_nxapi: *id002 - name: Assert configuration is idempotent ansible.builtin.assert: *id003 - - name: Configure nxapi https w/default tlsv1 + - name: Configure NX-API https w/default tlsv1 register: result cisco.nxos.nxos_nxapi: &id004 enable_https: true @@ -64,19 +64,19 @@ commands: - show run all | inc nxapi | inc protocols - - name: Assert nxapi https w/default tlsv1 configuration + - name: Assert NX-API https w/default tlsv1 configuration ansible.builtin.assert: that: - result.stdout_lines[0][0] == 'nxapi ssl protocols TLSv1' - - name: Configure nxapi https w/default again + - name: Configure NX-API https w/default again register: result cisco.nxos.nxos_nxapi: *id004 - name: Assert configuration is idempotent ansible.builtin.assert: *id003 - - name: Configure nxapi https tlsv1.1 -default tlsv1 + - name: Configure NX-API https tlsv1.1 -default tlsv1 register: result cisco.nxos.nxos_nxapi: &id005 enable_https: true @@ -89,19 +89,19 @@ commands: - show run all | inc nxapi | inc protocols - - name: Assert nxapi https w/tlsv1.1 configuration + - name: Assert NX-API https w/tlsv1.1 configuration ansible.builtin.assert: that: - result.stdout_lines[0][0] == 'nxapi ssl protocols TLSv1.1' - - name: Configure nxapi https w/tlsv1.1 -default tlsv1 again + - name: Configure NX-API https w/tlsv1.1 -default tlsv1 again register: result cisco.nxos.nxos_nxapi: *id005 - name: Assert configuration is idempotent ansible.builtin.assert: *id003 - - name: Configure nxapi https tlsv1.2 -default tlsv1 + - name: Configure NX-API https tlsv1.2 -default tlsv1 register: result cisco.nxos.nxos_nxapi: &id006 enable_https: true @@ -114,19 +114,19 @@ commands: - show run all | inc nxapi | inc protocols - - name: Assert nxapi https w/tlsv1.2 configuration + - name: Assert NX-API https w/tlsv1.2 configuration ansible.builtin.assert: that: - result.stdout_lines[0][0] == 'nxapi ssl protocols TLSv1.2' - - name: Configure nxapi https w/tlsv1.2 -default tlsv1 again + - name: Configure NX-API https w/tlsv1.2 -default tlsv1 again register: result cisco.nxos.nxos_nxapi: *id006 - name: Assert configuration is idempotent ansible.builtin.assert: *id003 - - name: Configure nxapi https w/tls1.2 +default tlsv1 + - name: Configure NX-API https w/tls1.2 +default tlsv1 register: result cisco.nxos.nxos_nxapi: &id007 enable_https: true @@ -139,19 +139,19 @@ commands: - show run all | inc nxapi | inc protocols - - name: Assert nxapi https w/tls1.2 +default tlsv1 configuration + - name: Assert NX-API https w/tls1.2 +default tlsv1 configuration ansible.builtin.assert: that: - result.stdout_lines[0][0] == 'nxapi ssl protocols TLSv1 TLSv1.2' - - name: Configure nxapi https w/tls1.2 again + - name: Configure NX-API https w/tls1.2 again register: result cisco.nxos.nxos_nxapi: *id007 - name: Assert configuration is idempotent ansible.builtin.assert: *id003 - - name: Configure nxapi https w/tls1.2 tls1.1 -default tlsv1 + - name: Configure NX-API https w/tls1.2 tls1.1 -default tlsv1 register: result cisco.nxos.nxos_nxapi: &id008 enable_https: true @@ -166,19 +166,19 @@ commands: - show run all | inc nxapi | inc protocols - - name: Assert nxapi https w/tls1.2 tls1.2 -default tlsv1 configuration + - name: Assert NX-API https w/tls1.2 tls1.2 -default tlsv1 configuration ansible.builtin.assert: that: - result.stdout_lines[0][0] == 'nxapi ssl protocols TLSv1.1 TLSv1.2' - - name: Configure nxapi https w/tls1.2 tls1.1 -default tlsv1 again + - name: Configure NX-API https w/tls1.2 tls1.1 -default tlsv1 again register: result cisco.nxos.nxos_nxapi: *id008 - name: Assert configuration is idempotent ansible.builtin.assert: *id003 - - name: Configure nxapi https w/tls1.2 tls1.1 +default tlsv1 + - name: Configure NX-API https w/tls1.2 tls1.1 +default tlsv1 register: result cisco.nxos.nxos_nxapi: &id009 enable_https: true @@ -192,19 +192,19 @@ commands: - show run all | inc nxapi | inc protocols - - name: Assert nxapi https w/tls1.2 tls1.1 +default tlsv1 configuration + - name: Assert NX-API https w/tls1.2 tls1.1 +default tlsv1 configuration ansible.builtin.assert: that: - result.stdout_lines[0][0] == 'nxapi ssl protocols TLSv1 TLSv1.1 TLSv1.2' - - name: Configure nxapi https w/tls1.2 tls1.1 +default tlsv1 again + - name: Configure NX-API https w/tls1.2 tls1.1 +default tlsv1 again register: result cisco.nxos.nxos_nxapi: *id009 - name: Assert configuration is idempotent ansible.builtin.assert: *id003 - - name: Configure nxapi https with explicit tls1.2 tls1.1 tlsv1 + - name: Configure NX-API https with explicit tls1.2 tls1.1 tlsv1 register: result cisco.nxos.nxos_nxapi: &id010 enable_https: true @@ -219,30 +219,33 @@ commands: - show run all | inc nxapi | inc protocols - - name: Assert nxapi https w/tls1.2 tls1.2 tlsv1 configuration + - name: Assert NX-API https w/tls1.2 tls1.2 tlsv1 configuration ansible.builtin.assert: that: - result.stdout_lines[0][0] == 'nxapi ssl protocols TLSv1 TLSv1.1 TLSv1.2' - - name: Configure nxapi https w/tls1.2 tls1.1 tlsv1 again + - name: Configure NX-API https w/tls1.2 tls1.1 tlsv1 again register: result cisco.nxos.nxos_nxapi: *id010 - name: Assert configuration is idempotent ansible.builtin.assert: *id003 always: - - name: Cleanup - disable nxapi + - name: Cleanup - disable NX-API register: result cisco.nxos.nxos_nxapi: state: absent - - name: Cleanup - re-enable nxapi + - name: Cleanup - re-enable NX-API register: result cisco.nxos.nxos_nxapi: state: present - ansible.builtin.debug: msg: END cli/nxapi_ssl.yaml - when: - (platform is match("N9K") or platform is match("N3K") or platform is match("N9K-F") or platform is match("N35") or platform is match("N3L")) and major_version - is version('9.2', '>=') + when: >- + (platform is match("N9K") or + platform is match("N3K") or + platform is match("N9K-F") or + platform is match("N35") or + platform is match("N3L")) and major_version is version('9.2', '>=') diff --git a/tests/integration/targets/nxos_nxapi/tests/nxapi/badtransport.yaml b/tests/integration/targets/nxos_nxapi/tests/nxapi/badtransport.yaml index 7e4875eea..5e81ff9be 100644 --- a/tests/integration/targets/nxos_nxapi/tests/nxapi/badtransport.yaml +++ b/tests/integration/targets/nxos_nxapi/tests/nxapi/badtransport.yaml @@ -2,14 +2,13 @@ - ansible.builtin.debug: msg: START nxapi/badtransport.yaml -- name: Sending transport other than cli should fail +- name: Sending transport other than CLI should fail register: result ignore_errors: true cisco.nxos.nxos_nxapi: enable_http: false enable_sandbox: false https_port: 9443 - provider: "{{ nxapi }}" - ansible.builtin.assert: that: diff --git a/tests/integration/targets/nxos_ospf/defaults/main.yaml b/tests/integration/targets/nxos_ospf/defaults/main.yaml deleted file mode 100644 index 5f709c5aa..000000000 --- a/tests/integration/targets/nxos_ospf/defaults/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -testcase: "*" diff --git a/tests/integration/targets/nxos_ospf/meta/main.yml b/tests/integration/targets/nxos_ospf/meta/main.yml deleted file mode 100644 index f504a6ab2..000000000 --- a/tests/integration/targets/nxos_ospf/meta/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_nxos_tests diff --git a/tests/integration/targets/nxos_ospf/tasks/cli.yaml b/tests/integration/targets/nxos_ospf/tasks/cli.yaml deleted file mode 100644 index 90342e6b1..000000000 --- a/tests/integration/targets/nxos_ospf/tasks/cli.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect cli test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - connection: local - register: cli_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + cli_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.network_cli) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_ospf/tasks/main.yaml b/tests/integration/targets/nxos_ospf/tasks/main.yaml deleted file mode 100644 index 7631f52fe..000000000 --- a/tests/integration/targets/nxos_ospf/tasks/main.yaml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- block: - - name: Include the cli tasks - ansible.builtin.include_tasks: cli.yaml - tags: - - cli - always: - - name: Include the nx-api tasks - ansible.builtin.include_tasks: nxapi.yaml - tags: - - nxapi diff --git a/tests/integration/targets/nxos_ospf/tasks/nxapi.yaml b/tests/integration/targets/nxos_ospf/tasks/nxapi.yaml deleted file mode 100644 index cedab80f1..000000000 --- a/tests/integration/targets/nxos_ospf/tasks/nxapi.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect nxapi test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/nxapi" - patterns: "{{ testcase }}.yaml" - connection: local - register: nxapi_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + nxapi_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.httpapi) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_ospf/tests/common/sanity.yaml b/tests/integration/targets/nxos_ospf/tests/common/sanity.yaml deleted file mode 100644 index 110ed3189..000000000 --- a/tests/integration/targets/nxos_ospf/tests/common/sanity.yaml +++ /dev/null @@ -1,51 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_ospf sanity test - -- name: Enable feature ospf - ignore_errors: true - cisco.nxos.nxos_feature: - feature: ospf - state: enabled - -- block: - - name: Configure ospf - register: result - cisco.nxos.nxos_ospf: &id001 - ospf: 1 - state: present - - - ansible.builtin.assert: &id002 - that: - - result.changed == true - - - name: Check idempotence - register: result - cisco.nxos.nxos_ospf: *id001 - - - ansible.builtin.assert: &id004 - that: - - result.changed == false - rescue: - - name: Disable feature ospf - ignore_errors: true - cisco.nxos.nxos_feature: - feature: ospf - state: disabled - always: - - name: Unconfigure ospf - register: result - cisco.nxos.nxos_ospf: &id003 - ospf: 1 - state: absent - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_ospf: *id003 - - - ansible.builtin.assert: *id004 - - - ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_ospf sanity test diff --git a/tests/integration/targets/nxos_ospf_interfaces/tasks/cli.yaml b/tests/integration/targets/nxos_ospf_interfaces/tasks/cli.yaml index 507d803cb..e3e64747b 100644 --- a/tests/integration/targets/nxos_ospf_interfaces/tasks/cli.yaml +++ b/tests/integration/targets/nxos_ospf_interfaces/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_ospf_interfaces/tasks/main.yaml b/tests/integration/targets/nxos_ospf_interfaces/tasks/main.yaml index 9f3d5d1dc..1621aacab 100644 --- a/tests/integration/targets/nxos_ospf_interfaces/tasks/main.yaml +++ b/tests/integration/targets/nxos_ospf_interfaces/tasks/main.yaml @@ -1,5 +1,5 @@ --- -- name: Enable ospf v2 and v3 features +- name: Enable OSPF v2 and v3 features cisco.nxos.nxos_config: lines: - feature ospf @@ -7,19 +7,20 @@ vars: ansible_connection: ansible.netcommon.network_cli -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli.yaml - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi always: - - name: Disable ospf v2 and v3 features + - name: Disable OSPF v2 and v3 features cisco.nxos.nxos_config: lines: - feature ospf diff --git a/tests/integration/targets/nxos_ospf_interfaces/tasks/nxapi.yaml b/tests/integration/targets/nxos_ospf_interfaces/tasks/nxapi.yaml index 2e452bb6a..4ae68868c 100644 --- a/tests/integration/targets/nxos_ospf_interfaces/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_ospf_interfaces/tasks/nxapi.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_ospf_interfaces/tests/common/_populate_config.yaml b/tests/integration/targets/nxos_ospf_interfaces/tests/common/_populate_config.yaml index 377c527d0..d3cae2c42 100644 --- a/tests/integration/targets/nxos_ospf_interfaces/tests/common/_populate_config.yaml +++ b/tests/integration/targets/nxos_ospf_interfaces/tests/common/_populate_config.yaml @@ -1,5 +1,5 @@ --- -- name: Populate config +- name: Populate configuration cisco.nxos.nxos_config: lines: - "interface {{ nxos_int1 }}" diff --git a/tests/integration/targets/nxos_ospf_interfaces/tests/common/deleted.yaml b/tests/integration/targets/nxos_ospf_interfaces/tests/common/deleted.yaml index 32c90432b..93835760f 100644 --- a/tests/integration/targets/nxos_ospf_interfaces/tests/common/deleted.yaml +++ b/tests/integration/targets/nxos_ospf_interfaces/tests/common/deleted.yaml @@ -18,7 +18,7 @@ name: "{{ nxos_int3 }}" - block: - - name: Delete ospf config from a single interface + - name: Delete OSPF configuration from a single interface cisco.nxos.nxos_ospf_interfaces: &id001 config: - name: "{{ nxos_int1 }}" @@ -51,7 +51,7 @@ - result["after"][1] == merged["after"][1] - result["after"][2] == merged["after"][2] - - name: Delete ospf config from a single interface (idempotent) + - name: Delete OSPF configuration from a single interface (idempotent) register: result cisco.nxos.nxos_ospf_interfaces: *id001 @@ -63,7 +63,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - - name: Delete ospf config from all interfaces + - name: Delete OSPF configuration from all interfaces cisco.nxos.nxos_ospf_interfaces: &id002 state: deleted register: result @@ -87,7 +87,7 @@ - result["after"][1] == int2 - result["after"][2] == int3 - - name: Delete ospf config from all interfaces (idempotent) + - name: Delete OSPF configuration from all interfaces (idempotent) register: result cisco.nxos.nxos_ospf_interfaces: *id002 diff --git a/tests/integration/targets/nxos_ospf_interfaces/tests/common/empty_config.yaml b/tests/integration/targets/nxos_ospf_interfaces/tests/common/empty_config.yaml index d1d05439a..485e94cbb 100644 --- a/tests/integration/targets/nxos_ospf_interfaces/tests/common/empty_config.yaml +++ b/tests/integration/targets/nxos_ospf_interfaces/tests/common/empty_config.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxos_ospf_interfaces empty_config integration tests on connection={{ ansible_connection }} -- name: Merged with empty config should give appropriate error message +- name: Merged with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_ospf_interfaces: @@ -13,7 +13,7 @@ that: - result.msg == 'value of config parameter must not be empty for state merged' -- name: Replaced with empty config should give appropriate error message +- name: Replaced with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_ospf_interfaces: @@ -24,7 +24,7 @@ that: - result.msg == 'value of config parameter must not be empty for state replaced' -- name: Overridden with empty config should give appropriate error message +- name: Overridden with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_ospf_interfaces: @@ -35,7 +35,7 @@ that: - result.msg == 'value of config parameter must not be empty for state overridden' -- name: Rendered with empty config should give appropriate error message +- name: Rendered with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_ospf_interfaces: @@ -46,7 +46,7 @@ that: - result.msg == 'value of config parameter must not be empty for state rendered' -- name: Parsed with empty config should give appropriate error message +- name: Parsed with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_ospf_interfaces: diff --git a/tests/integration/targets/nxos_ospf_interfaces/tests/common/gathered.yaml b/tests/integration/targets/nxos_ospf_interfaces/tests/common/gathered.yaml index 15f8a6b4b..39cca32a4 100644 --- a/tests/integration/targets/nxos_ospf_interfaces/tests/common/gathered.yaml +++ b/tests/integration/targets/nxos_ospf_interfaces/tests/common/gathered.yaml @@ -9,7 +9,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - block: - - name: Gather ospf interfaces facts using gathered + - name: Gather OSPF interfaces facts using gathered register: result cisco.nxos.nxos_ospf_interfaces: state: gathered diff --git a/tests/integration/targets/nxos_ospf_interfaces/tests/common/overridden.yaml b/tests/integration/targets/nxos_ospf_interfaces/tests/common/overridden.yaml index 564d58a22..9f4941c81 100644 --- a/tests/integration/targets/nxos_ospf_interfaces/tests/common/overridden.yaml +++ b/tests/integration/targets/nxos_ospf_interfaces/tests/common/overridden.yaml @@ -9,7 +9,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - block: - - name: Override all ospf interfaces configuration with provided configuration + - name: Override all OSPF interfaces configuration with provided configuration cisco.nxos.nxos_ospf_interfaces: &id001 config: - name: Ethernet1/1 @@ -44,7 +44,7 @@ - result['after'][1] == overridden['after'][1] - result['after'][2] == overridden['after'][2] - - name: Override all ospf interfaces configuration with provided configuration (idempotent) + - name: Override all OSPF interfaces configuration with provided configuration (idempotent) register: result cisco.nxos.nxos_ospf_interfaces: *id001 diff --git a/tests/integration/targets/nxos_ospf_interfaces/tests/common/parsed.yaml b/tests/integration/targets/nxos_ospf_interfaces/tests/common/parsed.yaml index 6e2769fae..eb94fcdc9 100644 --- a/tests/integration/targets/nxos_ospf_interfaces/tests/common/parsed.yaml +++ b/tests/integration/targets/nxos_ospf_interfaces/tests/common/parsed.yaml @@ -2,13 +2,13 @@ - ansible.builtin.debug: msg: START nxos_ospf_interfaces parsed integration tests on connection={{ ansible_connection }} -- name: Parse externally provided ospf interfaces config +- name: Parse externally provided OSPF interfaces configuration register: result cisco.nxos.nxos_ospf_interfaces: running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" state: parsed -- name: Assert that config was correctly parsed +- name: Assert that configuration was correctly parsed ansible.builtin.assert: that: - "{{ merged['after'] | symmetric_difference(result['parsed']) |length == 0 }}" diff --git a/tests/integration/targets/nxos_ospf_interfaces/tests/common/replaced.yaml b/tests/integration/targets/nxos_ospf_interfaces/tests/common/replaced.yaml index a63b195b5..ace52da02 100644 --- a/tests/integration/targets/nxos_ospf_interfaces/tests/common/replaced.yaml +++ b/tests/integration/targets/nxos_ospf_interfaces/tests/common/replaced.yaml @@ -9,7 +9,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - block: - - name: Replace ospf configurations of listed interfaces with provided configurations + - name: Replace OSPF configurations of listed interfaces with provided configurations cisco.nxos.nxos_ospf_interfaces: &id001 config: - name: "{{ nxos_int1 }}" @@ -45,7 +45,7 @@ - result['after'][1] == replaced['after'][1] - result['after'][2] == replaced['after'][2] - - name: Replace ospf configurations of listed interfaces with provided configurations (idempotent) + - name: Replace OSPF configurations of listed interfaces with provided configurations (idempotent) register: result cisco.nxos.nxos_ospf_interfaces: *id001 diff --git a/tests/integration/targets/nxos_ospf_interfaces/vars/main.yml b/tests/integration/targets/nxos_ospf_interfaces/vars/main.yml index 5d2f6c140..29df4d48f 100644 --- a/tests/integration/targets/nxos_ospf_interfaces/vars/main.yml +++ b/tests/integration/targets/nxos_ospf_interfaces/vars/main.yml @@ -44,12 +44,12 @@ merged: address_family: - afi: ipv4 authentication: - enable: True + enable: true key_chain: test-1 cost: 100 - afi: ipv6 network: broadcast - shutdown: True + shutdown: true - name: "{{ nxos_int3 }}" address_family: - afi: ipv4 @@ -74,19 +74,19 @@ replaced: - process_id: "100" area: area_id: 1.1.1.1 - secondaries: False + secondaries: false multi_areas: - 11.11.11.12 - name: "{{ nxos_int2 }}" address_family: - afi: ipv4 authentication: - enable: True + enable: true key_chain: test-1 cost: 100 - afi: ipv6 network: broadcast - shutdown: True + shutdown: true - name: "{{ nxos_int3 }}" overridden: commands: @@ -113,7 +113,7 @@ overridden: - process_id: "100" area: area_id: 1.1.1.1 - secondaries: False + secondaries: false multi_areas: - 11.11.11.12 - name: "{{ nxos_int2 }}" diff --git a/tests/integration/targets/nxos_ospf_vrf/defaults/main.yaml b/tests/integration/targets/nxos_ospf_vrf/defaults/main.yaml deleted file mode 100644 index 5f709c5aa..000000000 --- a/tests/integration/targets/nxos_ospf_vrf/defaults/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -testcase: "*" diff --git a/tests/integration/targets/nxos_ospf_vrf/meta/main.yml b/tests/integration/targets/nxos_ospf_vrf/meta/main.yml deleted file mode 100644 index f504a6ab2..000000000 --- a/tests/integration/targets/nxos_ospf_vrf/meta/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_nxos_tests diff --git a/tests/integration/targets/nxos_ospf_vrf/tasks/cli.yaml b/tests/integration/targets/nxos_ospf_vrf/tasks/cli.yaml deleted file mode 100644 index 90342e6b1..000000000 --- a/tests/integration/targets/nxos_ospf_vrf/tasks/cli.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect cli test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - connection: local - register: cli_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + cli_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.network_cli) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_ospf_vrf/tasks/main.yaml b/tests/integration/targets/nxos_ospf_vrf/tasks/main.yaml deleted file mode 100644 index 7631f52fe..000000000 --- a/tests/integration/targets/nxos_ospf_vrf/tasks/main.yaml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- block: - - name: Include the cli tasks - ansible.builtin.include_tasks: cli.yaml - tags: - - cli - always: - - name: Include the nx-api tasks - ansible.builtin.include_tasks: nxapi.yaml - tags: - - nxapi diff --git a/tests/integration/targets/nxos_ospf_vrf/tasks/nxapi.yaml b/tests/integration/targets/nxos_ospf_vrf/tasks/nxapi.yaml deleted file mode 100644 index cedab80f1..000000000 --- a/tests/integration/targets/nxos_ospf_vrf/tasks/nxapi.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect nxapi test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/nxapi" - patterns: "{{ testcase }}.yaml" - connection: local - register: nxapi_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + nxapi_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.httpapi) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_ospf_vrf/tests/common/sanity.yaml b/tests/integration/targets/nxos_ospf_vrf/tests/common/sanity.yaml deleted file mode 100644 index 2d562a751..000000000 --- a/tests/integration/targets/nxos_ospf_vrf/tests/common/sanity.yaml +++ /dev/null @@ -1,141 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_ospf_vrf sanity test - -- name: Set a fact for 'def_met_default' - ansible.builtin.set_fact: - def_met_default: default - when: imagetag is not search("I7") - -- name: "Setup: disable features for initial cleanup" - loop: - - ospf - - bfd - ignore_errors: true - cisco.nxos.nxos_feature: - feature: "{{ item }}" - state: disabled - -- name: Enable features - loop: - - ospf - - bfd - cisco.nxos.nxos_feature: - feature: "{{ item }}" - state: enabled - -- block: - - name: Configure ospf vrf - register: result - cisco.nxos.nxos_ospf_vrf: &id001 - ospf: 1 - router_id: 192.0.2.1 - timer_throttle_spf_start: 50 - timer_throttle_spf_hold: 1000 - timer_throttle_spf_max: 2000 - timer_throttle_lsa_start: 60 - timer_throttle_lsa_hold: 1100 - timer_throttle_lsa_max: 3000 - vrf: test - bfd: enable - passive_interface: true - state: present - - - ansible.builtin.assert: &id002 - that: - - result.changed == true - - - name: Check idempotence - register: result - cisco.nxos.nxos_ospf_vrf: *id001 - - - ansible.builtin.assert: &id004 - that: - - result.changed == false - - - name: Configure ospf vrf - register: result - cisco.nxos.nxos_ospf_vrf: &id003 - ospf: 2 - auto_cost: 5000 - timer_throttle_spf_hold: 1100 - timer_throttle_lsa_hold: 2220 - timer_throttle_lsa_max: 2222 - default_metric: 1000 - log_adjacency: log - vrf: default - bfd: disable - passive_interface: true - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_ospf_vrf: *id003 - - - ansible.builtin.assert: *id004 - - - name: Configure ospf vrf - register: result - cisco.nxos.nxos_ospf_vrf: &id005 - ospf: 2 - auto_cost: default - default_metric: "{{def_met_default|default(omit)}}" - log_adjacency: default - timer_throttle_spf_hold: default - passive_interface: false - vrf: default - state: present - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_ospf_vrf: *id005 - - - ansible.builtin.assert: *id004 - - - name: Unconfigure ospf vrf - register: result - cisco.nxos.nxos_ospf_vrf: &id006 - ospf: 2 - vrf: default - state: absent - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_ospf_vrf: *id006 - - - ansible.builtin.assert: *id004 - when: def_met_default is defined - - - name: Unconfigure ospf vrf - register: result - cisco.nxos.nxos_ospf_vrf: &id007 - ospf: 1 - vrf: test - state: absent - - - ansible.builtin.assert: *id002 - - - name: Check idempotence - register: result - cisco.nxos.nxos_ospf_vrf: *id007 - - - ansible.builtin.assert: *id004 - when: def_met_default is defined - always: - - name: Disable features - loop: - - ospf - - bfd - ignore_errors: true - cisco.nxos.nxos_feature: - feature: "{{ item }}" - state: disabled - -- ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_ospf_vrf sanity test diff --git a/tests/integration/targets/nxos_ospfv2/meta/main.yml b/tests/integration/targets/nxos_ospfv2/meta/main.yml index e69de29bb..ed97d539c 100644 --- a/tests/integration/targets/nxos_ospfv2/meta/main.yml +++ b/tests/integration/targets/nxos_ospfv2/meta/main.yml @@ -0,0 +1 @@ +--- diff --git a/tests/integration/targets/nxos_ospfv2/tasks/cli.yaml b/tests/integration/targets/nxos_ospfv2/tasks/cli.yaml index 507d803cb..e3e64747b 100644 --- a/tests/integration/targets/nxos_ospfv2/tasks/cli.yaml +++ b/tests/integration/targets/nxos_ospfv2/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_ospfv2/tasks/main.yaml b/tests/integration/targets/nxos_ospfv2/tasks/main.yaml index 2dfea601a..4e36581ee 100644 --- a/tests/integration/targets/nxos_ospfv2/tasks/main.yaml +++ b/tests/integration/targets/nxos_ospfv2/tasks/main.yaml @@ -1,23 +1,24 @@ --- -- name: Enable ospf feature +- name: Enable 'feature ospf' cisco.nxos.nxos_feature: feature: ospf vars: ansible_connection: ansible.netcommon.network_cli -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli.yaml - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi always: - - name: Disable ospf feature + - name: Disable 'feature ospf' cisco.nxos.nxos_feature: feature: ospf state: disabled diff --git a/tests/integration/targets/nxos_ospfv2/tasks/nxapi.yaml b/tests/integration/targets/nxos_ospfv2/tasks/nxapi.yaml index 2e452bb6a..4ae68868c 100644 --- a/tests/integration/targets/nxos_ospfv2/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_ospfv2/tasks/nxapi.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_ospfv2/tests/common/_remove_config.yaml b/tests/integration/targets/nxos_ospfv2/tests/common/_remove_config.yaml index b0b8884bb..3a3248e65 100644 --- a/tests/integration/targets/nxos_ospfv2/tests/common/_remove_config.yaml +++ b/tests/integration/targets/nxos_ospfv2/tests/common/_remove_config.yaml @@ -1,5 +1,5 @@ --- -- name: Remove pre-existing ospf processes +- name: Remove pre-existing OSPF processes cisco.nxos.nxos_config: lines: - no router ospf 100 diff --git a/tests/integration/targets/nxos_ospfv2/tests/common/deleted.yaml b/tests/integration/targets/nxos_ospfv2/tests/common/deleted.yaml index 919564354..23fab8f35 100644 --- a/tests/integration/targets/nxos_ospfv2/tests/common/deleted.yaml +++ b/tests/integration/targets/nxos_ospfv2/tests/common/deleted.yaml @@ -7,7 +7,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - block: - - name: Delete a single ospf process + - name: Delete a single OSPF process cisco.nxos.nxos_ospfv2: &id001 config: processes: @@ -31,7 +31,7 @@ that: - "{{ deleted['after']['processes'] | symmetric_difference(result['after']['processes']) |length == 0 }}" - - name: Delete a single ospf process (idempotent) + - name: Delete a single OSPF process (idempotent) register: result cisco.nxos.nxos_ospfv2: *id001 @@ -48,7 +48,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - - name: Delete all ospf processes from the device + - name: Delete all OSPF processes from the device cisco.nxos.nxos_ospfv2: &id002 state: deleted register: result @@ -70,7 +70,7 @@ that: - "{{ result['after'] == {} }}" - - name: Delete all ospf processes from the device (idempotent) + - name: Delete all OSPF processes from the device (idempotent) register: result cisco.nxos.nxos_ospfv2: *id002 diff --git a/tests/integration/targets/nxos_ospfv2/tests/common/overridden.yaml b/tests/integration/targets/nxos_ospfv2/tests/common/overridden.yaml index cbb5de455..c98483e75 100644 --- a/tests/integration/targets/nxos_ospfv2/tests/common/overridden.yaml +++ b/tests/integration/targets/nxos_ospfv2/tests/common/overridden.yaml @@ -7,7 +7,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - block: - - name: Override all ospf configuration with provided configuration + - name: Override all OSPF configuration with provided configuration cisco.nxos.nxos_ospfv2: &id001 config: processes: @@ -34,7 +34,7 @@ that: - "{{ overridden['after']['processes'] | symmetric_difference(result['after']['processes']) |length == 0 }}" - - name: Override all ospf configuration with provided configuration (idempotent) + - name: Override all OSPF configuration with provided configuration (idempotent) register: result cisco.nxos.nxos_ospfv2: *id001 diff --git a/tests/integration/targets/nxos_ospfv2/tests/common/parsed.yaml b/tests/integration/targets/nxos_ospfv2/tests/common/parsed.yaml index 7d6c5bf3a..8606c5d72 100644 --- a/tests/integration/targets/nxos_ospfv2/tests/common/parsed.yaml +++ b/tests/integration/targets/nxos_ospfv2/tests/common/parsed.yaml @@ -2,13 +2,13 @@ - ansible.builtin.debug: msg: START nxos_ospfv2 parsed integration tests on connection={{ ansible_connection }} -- name: Parse externally provided ospfv2 config +- name: Parse externally provided ospfv2 configuration register: result cisco.nxos.nxos_ospfv2: running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" state: parsed -- name: Assert that config was correctly parsed +- name: Assert that configuration was correctly parsed ansible.builtin.assert: that: - "{{ merged['after']['processes'] | symmetric_difference(result['parsed']['processes']) |length == 0 }}" diff --git a/tests/integration/targets/nxos_ospfv2/tests/common/replaced.yaml b/tests/integration/targets/nxos_ospfv2/tests/common/replaced.yaml index b8f6b35ca..f59f487c8 100644 --- a/tests/integration/targets/nxos_ospfv2/tests/common/replaced.yaml +++ b/tests/integration/targets/nxos_ospfv2/tests/common/replaced.yaml @@ -7,7 +7,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - block: - - name: Replace device configurations of listed ospf processes with provided configurations + - name: Replace device configurations of listed OSPF processes with provided configurations cisco.nxos.nxos_ospfv2: &id001 config: processes: @@ -60,7 +60,7 @@ that: - "{{ replaced['after']['processes'] | symmetric_difference(result['after']['processes']) |length == 0 }}" - - name: Replace device configurations of listed ospf processes with provided configurarions (idempotent) + - name: Replace device configurations of listed OSPF processes with provided configurarions (idempotent) register: result cisco.nxos.nxos_ospfv2: *id001 diff --git a/tests/integration/targets/nxos_ospfv2/vars/main.yml b/tests/integration/targets/nxos_ospfv2/vars/main.yml index a9192261d..25419c857 100644 --- a/tests/integration/targets/nxos_ospfv2/vars/main.yml +++ b/tests/integration/targets/nxos_ospfv2/vars/main.yml @@ -57,7 +57,7 @@ merged: no_summary: true - area_id: 0.0.0.103 nssa: - no_summary: True + no_summary: true translate: type7: always: true @@ -150,7 +150,7 @@ overridden: router_id: 203.0.113.20 - process_id: "102" router_id: 198.51.100.1 - shutdown: True + shutdown: true deleted: after: processes: diff --git a/tests/integration/targets/nxos_ospfv3/meta/main.yml b/tests/integration/targets/nxos_ospfv3/meta/main.yml index e69de29bb..ed97d539c 100644 --- a/tests/integration/targets/nxos_ospfv3/meta/main.yml +++ b/tests/integration/targets/nxos_ospfv3/meta/main.yml @@ -0,0 +1 @@ +--- diff --git a/tests/integration/targets/nxos_ospfv3/tasks/cli.yaml b/tests/integration/targets/nxos_ospfv3/tasks/cli.yaml index 507d803cb..e3e64747b 100644 --- a/tests/integration/targets/nxos_ospfv3/tasks/cli.yaml +++ b/tests/integration/targets/nxos_ospfv3/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_ospfv3/tasks/main.yaml b/tests/integration/targets/nxos_ospfv3/tasks/main.yaml index 61d5c1b2b..8be45e21c 100644 --- a/tests/integration/targets/nxos_ospfv3/tasks/main.yaml +++ b/tests/integration/targets/nxos_ospfv3/tasks/main.yaml @@ -1,23 +1,24 @@ --- -- name: Enable ospfv3 feature +- name: Enable 'feature ospfv3' cisco.nxos.nxos_feature: feature: ospfv3 vars: ansible_connection: ansible.netcommon.network_cli -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli.yaml - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi always: - - name: Disable ospfv3 feature + - name: Disable 'feature ospfv3' cisco.nxos.nxos_feature: feature: ospfv3 state: disabled diff --git a/tests/integration/targets/nxos_ospfv3/tasks/nxapi.yaml b/tests/integration/targets/nxos_ospfv3/tasks/nxapi.yaml index 2e452bb6a..4ae68868c 100644 --- a/tests/integration/targets/nxos_ospfv3/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_ospfv3/tasks/nxapi.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_ospfv3/tests/common/_remove_config.yaml b/tests/integration/targets/nxos_ospfv3/tests/common/_remove_config.yaml index e01aa8325..5ea2b6dc2 100644 --- a/tests/integration/targets/nxos_ospfv3/tests/common/_remove_config.yaml +++ b/tests/integration/targets/nxos_ospfv3/tests/common/_remove_config.yaml @@ -1,5 +1,5 @@ --- -- name: Remove pre-existing ospf processes +- name: Remove pre-existing OSPF processes cisco.nxos.nxos_config: lines: - no router ospfv3 100 diff --git a/tests/integration/targets/nxos_ospfv3/tests/common/deleted.yaml b/tests/integration/targets/nxos_ospfv3/tests/common/deleted.yaml index 9ecea72bd..bf860b012 100644 --- a/tests/integration/targets/nxos_ospfv3/tests/common/deleted.yaml +++ b/tests/integration/targets/nxos_ospfv3/tests/common/deleted.yaml @@ -7,7 +7,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - block: - - name: Delete a single ospf process + - name: Delete a single OSPF process cisco.nxos.nxos_ospfv3: &id001 config: processes: @@ -31,7 +31,7 @@ that: - "{{ deleted['after']['processes'] | symmetric_difference(result['after']['processes']) |length == 0 }}" - - name: Delete a single ospf process (idempotent) + - name: Delete a single OSPF process (idempotent) register: result cisco.nxos.nxos_ospfv3: *id001 @@ -70,7 +70,7 @@ that: - "{{ result['after'] == {} }}" - - name: Delete all ospf processes from the device (idempotent) + - name: Delete all OSPF processes from the device (idempotent) register: result cisco.nxos.nxos_ospfv3: *id002 diff --git a/tests/integration/targets/nxos_ospfv3/tests/common/empty_config.yaml b/tests/integration/targets/nxos_ospfv3/tests/common/empty_config.yaml index c2fd15274..34996cf3f 100644 --- a/tests/integration/targets/nxos_ospfv3/tests/common/empty_config.yaml +++ b/tests/integration/targets/nxos_ospfv3/tests/common/empty_config.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxos_ospfv3 empty_config integration tests on connection={{ ansible_connection }} -- name: Merged with empty config should give appropriate error message +- name: Merged with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_ospfv3: @@ -13,7 +13,7 @@ that: - result.msg == 'value of config parameter must not be empty for state merged' -- name: Replaced with empty config should give appropriate error message +- name: Replaced with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_ospfv3: @@ -24,7 +24,7 @@ that: - result.msg == 'value of config parameter must not be empty for state replaced' -- name: Overridden with empty config should give appropriate error message +- name: Overridden with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_ospfv3: @@ -35,7 +35,7 @@ that: - result.msg == 'value of config parameter must not be empty for state overridden' -- name: Rendered with empty config should give appropriate error message +- name: Rendered with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_ospfv3: @@ -46,7 +46,7 @@ that: - result.msg == 'value of config parameter must not be empty for state rendered' -- name: Parsed with empty config should give appropriate error message +- name: Parsed with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_ospfv3: diff --git a/tests/integration/targets/nxos_ospfv3/tests/common/overridden.yaml b/tests/integration/targets/nxos_ospfv3/tests/common/overridden.yaml index 3338bbcdb..7d9bc6c9b 100644 --- a/tests/integration/targets/nxos_ospfv3/tests/common/overridden.yaml +++ b/tests/integration/targets/nxos_ospfv3/tests/common/overridden.yaml @@ -34,7 +34,7 @@ that: - "{{ overridden['after']['processes'] | symmetric_difference(result['after']['processes']) |length == 0 }}" - - name: Override all ospf configuration with provided configuration (idempotent) + - name: Override all OSPF configuration with provided configuration (idempotent) register: result cisco.nxos.nxos_ospfv3: *id001 diff --git a/tests/integration/targets/nxos_ospfv3/tests/common/parsed.yaml b/tests/integration/targets/nxos_ospfv3/tests/common/parsed.yaml index 7dd384969..3f4c2d2a2 100644 --- a/tests/integration/targets/nxos_ospfv3/tests/common/parsed.yaml +++ b/tests/integration/targets/nxos_ospfv3/tests/common/parsed.yaml @@ -2,13 +2,13 @@ - ansible.builtin.debug: msg: START nxos_ospfv3 parsed integration tests on connection={{ ansible_connection }} -- name: Parse externally provided ospfv3 config +- name: Parse externally provided ospfv3 configuration register: result cisco.nxos.nxos_ospfv3: running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" state: parsed -- name: Assert that config was correctly parsed +- name: Assert that configuration was correctly parsed ansible.builtin.assert: that: - "{{ merged['after']['processes'] | symmetric_difference(result['parsed']['processes']) |length == 0 }}" diff --git a/tests/integration/targets/nxos_ospfv3/tests/common/replaced.yaml b/tests/integration/targets/nxos_ospfv3/tests/common/replaced.yaml index 7d0ff642c..f819c559a 100644 --- a/tests/integration/targets/nxos_ospfv3/tests/common/replaced.yaml +++ b/tests/integration/targets/nxos_ospfv3/tests/common/replaced.yaml @@ -56,7 +56,7 @@ that: - "{{ replaced['after']['processes'] | symmetric_difference(result['after']['processes']) |length == 0 }}" - - name: Replace device configurations of listed ospf processes with provided configurarions (idempotent) + - name: Replace device configurations of listed OSPF processes with provided configurarions (idempotent) register: result cisco.nxos.nxos_ospfv3: *id001 diff --git a/tests/integration/targets/nxos_ospfv3/vars/main.yml b/tests/integration/targets/nxos_ospfv3/vars/main.yml index 1b31b9874..ddfd096b8 100644 --- a/tests/integration/targets/nxos_ospfv3/vars/main.yml +++ b/tests/integration/targets/nxos_ospfv3/vars/main.yml @@ -54,7 +54,7 @@ merged: no_summary: true - area_id: 0.0.0.103 nssa: - no_summary: True + no_summary: true translate: type7: always: true @@ -131,7 +131,7 @@ overridden: router_id: 203.0.113.20 - process_id: "102" router_id: 198.51.100.1 - shutdown: True + shutdown: true address_family: afi: ipv6 safi: unicast diff --git a/tests/integration/targets/nxos_overlay_global/tasks/cli.yaml b/tests/integration/targets/nxos_overlay_global/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_overlay_global/tasks/cli.yaml +++ b/tests/integration/targets/nxos_overlay_global/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_overlay_global/tasks/main.yaml b/tests/integration/targets/nxos_overlay_global/tasks/main.yaml index 7631f52fe..c9e70304e 100644 --- a/tests/integration/targets/nxos_overlay_global/tasks/main.yaml +++ b/tests/integration/targets/nxos_overlay_global/tasks/main.yaml @@ -1,11 +1,12 @@ --- -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli always: - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_overlay_global/tasks/nxapi.yaml b/tests/integration/targets/nxos_overlay_global/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_overlay_global/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_overlay_global/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_overlay_global/tasks/platform/n7k/cleanup.yaml b/tests/integration/targets/nxos_overlay_global/tasks/platform/n7k/cleanup.yaml index ea15558fc..6de2a7ac2 100644 --- a/tests/integration/targets/nxos_overlay_global/tasks/platform/n7k/cleanup.yaml +++ b/tests/integration/targets/nxos_overlay_global/tasks/platform/n7k/cleanup.yaml @@ -1,6 +1,6 @@ --- -- name: Unconfigure vdc setting limit-resource module-type f3 - ignore_errors: true +- name: Unconfigure VDC setting limit-resource module-type f3 + ignore_errors: true # noqa ignore-errors cisco.nxos.nxos_config: commands: - terminal dont-ask ; vdc {{ vdcid }} ; no limit-resource module-type f3 @@ -10,8 +10,8 @@ ansible.builtin.pause: seconds: 45 -- name: Configure vdc setting allocate interface unallocated-interfaces - ignore_errors: true +- name: Configure VDC setting allocate interface unallocated-interfaces + ignore_errors: true # noqa ignore-errors cisco.nxos.nxos_config: commands: - terminal dont-ask ; vdc {{ vdcid }} ; allocate interface unallocated-interfaces diff --git a/tests/integration/targets/nxos_overlay_global/tasks/platform/n7k/setup.yaml b/tests/integration/targets/nxos_overlay_global/tasks/platform/n7k/setup.yaml index e7cee7b2e..856dae1ff 100644 --- a/tests/integration/targets/nxos_overlay_global/tasks/platform/n7k/setup.yaml +++ b/tests/integration/targets/nxos_overlay_global/tasks/platform/n7k/setup.yaml @@ -1,5 +1,5 @@ --- -- name: Get default vdc id +- name: Get default VDC id register: vdcout cisco.nxos.nxos_command: commands: @@ -9,8 +9,8 @@ ansible.builtin.set_fact: vdcid: "{{ vdcout.stdout_lines[0].name }}" -- name: Configure vdc setting limit-resource module-type f3 - ignore_errors: true +- name: Configure VDC setting limit-resource module-type f3 + ignore_errors: true # noqa ignore-errors cisco.nxos.nxos_config: commands: - terminal dont-ask ; vdc {{ vdcid }} ; limit-resource module-type f3 @@ -20,8 +20,8 @@ ansible.builtin.pause: seconds: 45 -- name: Configure vdc setting allocate interface unallocated-interfaces - ignore_errors: true +- name: Configure VDC setting allocate interface unallocated-interfaces + ignore_errors: true # noqa ignore-errors cisco.nxos.nxos_config: commands: - terminal dont-ask ; vdc {{ vdcid }} ; allocate interface unallocated-interfaces @@ -31,7 +31,7 @@ ansible.builtin.pause: seconds: 45 -- name: Configure additional n7k requiste features +- name: Configure additional N7K requiste features cisco.nxos.nxos_config: commands: - feature-set fabric diff --git a/tests/integration/targets/nxos_overlay_global/tests/common/sanity.yaml b/tests/integration/targets/nxos_overlay_global/tests/common/sanity.yaml index 2fcb3c099..6ad8399a0 100644 --- a/tests/integration/targets/nxos_overlay_global/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_overlay_global/tests/common/sanity.yaml @@ -16,15 +16,15 @@ when: overlay_global_supported - block: - - name: Enable nv overlay evpn + - name: Enable NV overlay EVPN cisco.nxos.nxos_evpn_global: nv_overlay_evpn: true - - name: Apply n7k specific setup config - ansible.builtin.include: tasks/platform/n7k/setup.yaml + - name: Apply N7K specific setup configuration + ansible.builtin.include_tasks: tasks/platform/n7k/setup.yaml when: platform is match('N7K') - - name: Configure additional n7k requiste features + - name: Configure additional N7K requiste features when: platform is match('N7K') cisco.nxos.nxos_config: commands: @@ -83,11 +83,11 @@ - ansible.builtin.assert: *id004 when: overlay_global_supported always: - - name: Apply n7k specific cleanup config - ansible.builtin.include: tasks/platform/n7k/cleanup.yaml + - name: Apply N7K specific cleanup configuration + ansible.builtin.include_tasks: tasks/platform/n7k/cleanup.yaml when: platform is match('N7K') - - name: Disable nv overlay evpn + - name: Disable NV overlay EVPN ignore_errors: true when: overlay_global_supported cisco.nxos.nxos_evpn_global: diff --git a/tests/integration/targets/nxos_pim/tasks/cli.yaml b/tests/integration/targets/nxos_pim/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_pim/tasks/cli.yaml +++ b/tests/integration/targets/nxos_pim/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_pim/tasks/main.yaml b/tests/integration/targets/nxos_pim/tasks/main.yaml index 7631f52fe..c9e70304e 100644 --- a/tests/integration/targets/nxos_pim/tasks/main.yaml +++ b/tests/integration/targets/nxos_pim/tasks/main.yaml @@ -1,11 +1,12 @@ --- -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli always: - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_pim/tasks/nxapi.yaml b/tests/integration/targets/nxos_pim/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_pim/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_pim/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_pim/tests/common/sanity.yaml b/tests/integration/targets/nxos_pim/tests/common/sanity.yaml index c3b46f55e..5b7525644 100644 --- a/tests/integration/targets/nxos_pim/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_pim/tests/common/sanity.yaml @@ -24,7 +24,7 @@ ssm_range: none - block: - - name: Initial config from none + - name: Initial configuration from none register: result cisco.nxos.nxos_pim: &id001 bfd: enable @@ -36,7 +36,7 @@ that: - result.changed == true - - name: Initial config idempotence + - name: Initial configuration idempotence register: result cisco.nxos.nxos_pim: *id001 diff --git a/tests/integration/targets/nxos_pim_interface/tasks/cli.yaml b/tests/integration/targets/nxos_pim_interface/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_pim_interface/tasks/cli.yaml +++ b/tests/integration/targets/nxos_pim_interface/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_pim_interface/tasks/main.yaml b/tests/integration/targets/nxos_pim_interface/tasks/main.yaml index 7631f52fe..c9e70304e 100644 --- a/tests/integration/targets/nxos_pim_interface/tasks/main.yaml +++ b/tests/integration/targets/nxos_pim_interface/tasks/main.yaml @@ -1,11 +1,12 @@ --- -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli always: - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_pim_interface/tasks/nxapi.yaml b/tests/integration/targets/nxos_pim_interface/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_pim_interface/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_pim_interface/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_pim_interface/tests/common/sanity.yaml b/tests/integration/targets/nxos_pim_interface/tests/common/sanity.yaml index e8d32d2a1..36a4cf45c 100644 --- a/tests/integration/targets/nxos_pim_interface/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_pim_interface/tests/common/sanity.yaml @@ -30,12 +30,13 @@ - default interface {{ testint }} - name: Ensure {{testint}} is layer3 - cisco.nxos.nxos_interface: - interface: "{{ testint }}" - mode: layer3 - description: Configured by Ansible - Layer3 - admin_state: up - state: present + cisco.nxos.nxos_interfaces: + config: + - name: "{{ testint }}" + mode: layer3 + description: Configured by Ansible - Layer3 + enabled: true + state: merged - block: - name: Configure nxos_pim_interface state absent @@ -107,7 +108,7 @@ - ansible.builtin.assert: *id002 - - name: Configure pim other params + - name: Configure PIM other params register: result cisco.nxos.nxos_pim_interface: &id006 interface: "{{ testint }}" @@ -187,7 +188,7 @@ - ansible.builtin.assert: *id004 always: - - name: Disable feature pim + - name: Disable 'feature pim' loop: - pim - bfd diff --git a/tests/integration/targets/nxos_pim_rp_address/tasks/cli.yaml b/tests/integration/targets/nxos_pim_rp_address/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_pim_rp_address/tasks/cli.yaml +++ b/tests/integration/targets/nxos_pim_rp_address/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_pim_rp_address/tasks/main.yaml b/tests/integration/targets/nxos_pim_rp_address/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_pim_rp_address/tasks/main.yaml +++ b/tests/integration/targets/nxos_pim_rp_address/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_pim_rp_address/tasks/nxapi.yaml b/tests/integration/targets/nxos_pim_rp_address/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_pim_rp_address/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_pim_rp_address/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_pim_rp_address/tests/common/configure.yaml b/tests/integration/targets/nxos_pim_rp_address/tests/common/configure.yaml index c681b9b7c..62298058d 100644 --- a/tests/integration/targets/nxos_pim_rp_address/tests/common/configure.yaml +++ b/tests/integration/targets/nxos_pim_rp_address/tests/common/configure.yaml @@ -23,12 +23,12 @@ when: platform is not search('N3L|N7K') - block: - - name: Disable feature pim + - name: Disable 'feature pim' cisco.nxos.nxos_feature: &id014 feature: pim state: disabled - - name: Enable feature pim + - name: Enable 'feature pim' cisco.nxos.nxos_feature: feature: pim state: enabled @@ -216,7 +216,7 @@ - ansible.builtin.assert: *id004 always: - - name: Disable feature pim + - name: Disable 'feature pim' cisco.nxos.nxos_feature: *id014 - ansible.builtin.debug: diff --git a/tests/integration/targets/nxos_prefix_lists/tasks/cli.yaml b/tests/integration/targets/nxos_prefix_lists/tasks/cli.yaml index 507d803cb..e3e64747b 100644 --- a/tests/integration/targets/nxos_prefix_lists/tasks/cli.yaml +++ b/tests/integration/targets/nxos_prefix_lists/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_prefix_lists/tasks/main.yaml b/tests/integration/targets/nxos_prefix_lists/tasks/main.yaml index 490861ca1..b62ef52ee 100644 --- a/tests/integration/targets/nxos_prefix_lists/tasks/main.yaml +++ b/tests/integration/targets/nxos_prefix_lists/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli.yaml -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_prefix_lists/tasks/nxapi.yaml b/tests/integration/targets/nxos_prefix_lists/tasks/nxapi.yaml index 2e452bb6a..4ae68868c 100644 --- a/tests/integration/targets/nxos_prefix_lists/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_prefix_lists/tasks/nxapi.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_prefix_lists/tests/common/_populate_config.yaml b/tests/integration/targets/nxos_prefix_lists/tests/common/_populate_config.yaml index 07dc57df2..0b99bb816 100644 --- a/tests/integration/targets/nxos_prefix_lists/tests/common/_populate_config.yaml +++ b/tests/integration/targets/nxos_prefix_lists/tests/common/_populate_config.yaml @@ -1,5 +1,5 @@ --- -- name: Populate config +- name: Populate configuration cisco.nxos.nxos_config: lines: - "ipv6 prefix-list AllowIPv6Prefix description allows engineering IPv6 networks" diff --git a/tests/integration/targets/nxos_prefix_lists/tests/common/deleted.yaml b/tests/integration/targets/nxos_prefix_lists/tests/common/deleted.yaml index a88b68fe4..c5647aebe 100644 --- a/tests/integration/targets/nxos_prefix_lists/tests/common/deleted.yaml +++ b/tests/integration/targets/nxos_prefix_lists/tests/common/deleted.yaml @@ -7,7 +7,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - block: - - name: Delete all prefix-lists for an afi + - name: Delete all prefix-lists for an AFI cisco.nxos.nxos_prefix_lists: config: - afi: ipv4 diff --git a/tests/integration/targets/nxos_prefix_lists/tests/common/empty_config.yaml b/tests/integration/targets/nxos_prefix_lists/tests/common/empty_config.yaml index f9619ceff..aca1e30da 100644 --- a/tests/integration/targets/nxos_prefix_lists/tests/common/empty_config.yaml +++ b/tests/integration/targets/nxos_prefix_lists/tests/common/empty_config.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxos_prefix_lists empty_config integration tests on connection={{ ansible_connection }} -- name: Merged with empty config should give appropriate error message +- name: Merged with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_prefix_lists: @@ -13,7 +13,7 @@ that: - result.msg == 'value of config parameter must not be empty for state merged' -- name: Replaced with empty config should give appropriate error message +- name: Replaced with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_prefix_lists: @@ -24,7 +24,7 @@ that: - result.msg == 'value of config parameter must not be empty for state replaced' -- name: Overridden with empty config should give appropriate error message +- name: Overridden with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_prefix_lists: @@ -35,7 +35,7 @@ that: - result.msg == 'value of config parameter must not be empty for state overridden' -- name: Rendered with empty config should give appropriate error message +- name: Rendered with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_prefix_lists: @@ -46,7 +46,7 @@ that: - result.msg == 'value of config parameter must not be empty for state rendered' -- name: Parsed with empty config should give appropriate error message +- name: Parsed with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_prefix_lists: diff --git a/tests/integration/targets/nxos_prefix_lists/tests/common/parsed.yaml b/tests/integration/targets/nxos_prefix_lists/tests/common/parsed.yaml index d7404df44..260fe12e9 100644 --- a/tests/integration/targets/nxos_prefix_lists/tests/common/parsed.yaml +++ b/tests/integration/targets/nxos_prefix_lists/tests/common/parsed.yaml @@ -8,7 +8,7 @@ running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" state: parsed -- name: Assert that config was correctly parsed +- name: Assert that configuration was correctly parsed ansible.builtin.assert: that: - "{{ merged['after'][0] == result['parsed'][0] }}" diff --git a/tests/integration/targets/nxos_reboot/tasks/cli.yaml b/tests/integration/targets/nxos_reboot/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_reboot/tasks/cli.yaml +++ b/tests/integration/targets/nxos_reboot/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_reboot/tasks/main.yaml b/tests/integration/targets/nxos_reboot/tasks/main.yaml index 605600c6a..cbbbcb242 100644 --- a/tests/integration/targets/nxos_reboot/tasks/main.yaml +++ b/tests/integration/targets/nxos_reboot/tasks/main.yaml @@ -1,8 +1,8 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: nxapi diff --git a/tests/integration/targets/nxos_reboot/tasks/nxapi.yaml b/tests/integration/targets/nxos_reboot/tasks/nxapi.yaml index df9e12782..cdee9a584 100644 --- a/tests/integration/targets/nxos_reboot/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_reboot/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,7 +22,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: @@ -30,4 +30,3 @@ tags: nxapi_httpapi vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_rollback/tasks/cli.yaml b/tests/integration/targets/nxos_rollback/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_rollback/tasks/cli.yaml +++ b/tests/integration/targets/nxos_rollback/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_rollback/tasks/main.yaml b/tests/integration/targets/nxos_rollback/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_rollback/tasks/main.yaml +++ b/tests/integration/targets/nxos_rollback/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_rollback/tasks/nxapi.yaml b/tests/integration/targets/nxos_rollback/tasks/nxapi.yaml index cedab80f1..74961c395 100644 --- a/tests/integration/targets/nxos_rollback/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_rollback/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_route_maps/tasks/cli.yaml b/tests/integration/targets/nxos_route_maps/tasks/cli.yaml index 507d803cb..e3e64747b 100644 --- a/tests/integration/targets/nxos_route_maps/tasks/cli.yaml +++ b/tests/integration/targets/nxos_route_maps/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_route_maps/tasks/main.yaml b/tests/integration/targets/nxos_route_maps/tasks/main.yaml index 490861ca1..b62ef52ee 100644 --- a/tests/integration/targets/nxos_route_maps/tasks/main.yaml +++ b/tests/integration/targets/nxos_route_maps/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli.yaml -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_route_maps/tasks/nxapi.yaml b/tests/integration/targets/nxos_route_maps/tasks/nxapi.yaml index 2e452bb6a..4ae68868c 100644 --- a/tests/integration/targets/nxos_route_maps/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_route_maps/tasks/nxapi.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_route_maps/tests/common/_populate_config.yaml b/tests/integration/targets/nxos_route_maps/tests/common/_populate_config.yaml index 2780daeab..3bcd50a70 100644 --- a/tests/integration/targets/nxos_route_maps/tests/common/_populate_config.yaml +++ b/tests/integration/targets/nxos_route_maps/tests/common/_populate_config.yaml @@ -1,5 +1,5 @@ --- -- name: Populate config +- name: Populate configuration cisco.nxos.nxos_config: lines: - "route-map rmap1 permit 10" diff --git a/tests/integration/targets/nxos_route_maps/tests/common/empty_config.yaml b/tests/integration/targets/nxos_route_maps/tests/common/empty_config.yaml index 93178b888..898bea2da 100644 --- a/tests/integration/targets/nxos_route_maps/tests/common/empty_config.yaml +++ b/tests/integration/targets/nxos_route_maps/tests/common/empty_config.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxos_route_maps empty_config integration tests on connection={{ ansible_connection }} -- name: Merged with empty config should give appropriate error message +- name: Merged with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_route_maps: @@ -13,7 +13,7 @@ that: - result.msg == 'value of config parameter must not be empty for state merged' -- name: Replaced with empty config should give appropriate error message +- name: Replaced with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_route_maps: @@ -24,7 +24,7 @@ that: - result.msg == 'value of config parameter must not be empty for state replaced' -- name: Overridden with empty config should give appropriate error message +- name: Overridden with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_route_maps: @@ -35,7 +35,7 @@ that: - result.msg == 'value of config parameter must not be empty for state overridden' -- name: Rendered with empty config should give appropriate error message +- name: Rendered with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_route_maps: @@ -46,7 +46,7 @@ that: - result.msg == 'value of config parameter must not be empty for state rendered' -- name: Parsed with empty config should give appropriate error message +- name: Parsed with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_route_maps: diff --git a/tests/integration/targets/nxos_route_maps/tests/common/parsed.yaml b/tests/integration/targets/nxos_route_maps/tests/common/parsed.yaml index 9d80c2146..68b6e4104 100644 --- a/tests/integration/targets/nxos_route_maps/tests/common/parsed.yaml +++ b/tests/integration/targets/nxos_route_maps/tests/common/parsed.yaml @@ -8,7 +8,7 @@ running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" state: parsed -- name: Assert that config was correctly parsed +- name: Assert that configuration was correctly parsed ansible.builtin.assert: that: - "{{ merged['after'] | symmetric_difference(result['parsed']) |length == 0 }}" diff --git a/tests/integration/targets/nxos_route_maps/vars/main.yml b/tests/integration/targets/nxos_route_maps/vars/main.yml index 8a191eecf..7e14dc286 100644 --- a/tests/integration/targets/nxos_route_maps/vars/main.yml +++ b/tests/integration/targets/nxos_route_maps/vars/main.yml @@ -129,7 +129,7 @@ replaced: - AllowPrefix1 set: community: - local_as: True + local_as: true - route_map: rmap2 entries: @@ -202,7 +202,7 @@ overridden: - AllowPrefix1 set: community: - local_as: True + local_as: true deleted: commands: diff --git a/tests/integration/targets/nxos_rpm/tasks/cli.yaml b/tests/integration/targets/nxos_rpm/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_rpm/tasks/cli.yaml +++ b/tests/integration/targets/nxos_rpm/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_rpm/tasks/main.yaml b/tests/integration/targets/nxos_rpm/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_rpm/tasks/main.yaml +++ b/tests/integration/targets/nxos_rpm/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_rpm/tasks/nxapi.yaml b/tests/integration/targets/nxos_rpm/tasks/nxapi.yaml index cedab80f1..74961c395 100644 --- a/tests/integration/targets/nxos_rpm/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_rpm/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_smoke/meta/main.yml b/tests/integration/targets/nxos_smoke/meta/main.yml index ae741cbdc..f504a6ab2 100644 --- a/tests/integration/targets/nxos_smoke/meta/main.yml +++ b/tests/integration/targets/nxos_smoke/meta/main.yml @@ -1,2 +1,3 @@ +--- dependencies: - prepare_nxos_tests diff --git a/tests/integration/targets/nxos_smoke/tasks/cli.yaml b/tests/integration/targets/nxos_smoke/tasks/cli.yaml index ca596aeb1..b335e711c 100644 --- a/tests/integration/targets/nxos_smoke/tasks/cli.yaml +++ b/tests/integration/targets/nxos_smoke/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -28,23 +28,26 @@ transport: cli authorize: true -- name: Run test cases (connection=network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: network_cli - connection: "{{ cli }}" # Temporarily disabling connection=local tests for CI issues -#- name: run test cases (connection=local) -# include: "{{ test_case_to_run }} ansible_connection=local connection={{ cli }}" -# with_items: "{{ test_items }}" -# loop_control: -# loop_var: test_case_to_run +# - name: run test cases (connection=local) +# ansible.builtin.include_tasks: "{{ test_case_to_run }} +# vars: +# ansible_connection: local +# connection: "{{ cli }}" +# with_items: "{{ test_items }}" +# loop_control: +# loop_var: test_case_to_run -- name: Run test cases (connection=network_cli) - ansible.builtin.include: - "{{ role_path }}/tests/common/caching.yaml ansible_connection=ansible.netcommon.network_cli ansible_network_single_user_mode=True connection={{\ - \ cli }}" +- name: Run test cases with connection network_cli + ansible.builtin.include_tasks: "{{ role_path }}/tests/common/caching.yaml" + vars: + ansible_connection: ansible.netcommon.network_cli + ansible_network_single_user_mode: true diff --git a/tests/integration/targets/nxos_smoke/tasks/main.yaml b/tests/integration/targets/nxos_smoke/tasks/main.yaml index 33f5864f6..144efbb59 100644 --- a/tests/integration/targets/nxos_smoke/tasks/main.yaml +++ b/tests/integration/targets/nxos_smoke/tasks/main.yaml @@ -2,19 +2,20 @@ # Some of the tests in this suite change the hostname to switch. # This block/always ensures the hostname gets changed back to # the correct name. -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - "cli" - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - "nxapi" always: - name: "Change hostname back to {{ inventory_hostname_short }}" - nxos_config: + cisco.nxos.nxos_config: lines: - "hostname {{ inventory_hostname_short }}" match: none diff --git a/tests/integration/targets/nxos_smoke/tasks/nxapi.yaml b/tests/integration/targets/nxos_smoke/tasks/nxapi.yaml index 9009e1058..52aa1a100 100644 --- a/tests/integration/targets/nxos_smoke/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_smoke/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,17 +22,18 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: httpapi - connection: "{{ nxapi }}" # Temporarily disabling connection=local tests for CI issues -#- name: run test cases (connection=local) -# include: "{{ test_case_to_run }} ansible_connection=local connection={{ nxapi }}" -# with_items: "{{ test_items }}" -# loop_control: +# - name: run test cases (connection=local) +# ansible.builtin.include_tasks: "{{ test_case_to_run }} +# vars: +# ansible_connection: local connection={{ nxapi }} +# with_items: "{{ test_items }}" +# loop_control: # loop_var: test_case_to_run diff --git a/tests/integration/targets/nxos_smoke/tests/cli/misc_tests.yaml b/tests/integration/targets/nxos_smoke/tests/cli/misc_tests.yaml index ed47994b4..e26c0c131 100644 --- a/tests/integration/targets/nxos_smoke/tests/cli/misc_tests.yaml +++ b/tests/integration/targets/nxos_smoke/tests/cli/misc_tests.yaml @@ -6,6 +6,5 @@ - name: Test that provider values are properly ignored cisco.nxos.nxos_command: commands: show version - provider: "{{ nxapi }}" when: "ansible_connection != 'local'" diff --git a/tests/integration/targets/nxos_smoke/tests/common/caching.yaml b/tests/integration/targets/nxos_smoke/tests/common/caching.yaml index 727b4577f..f0a95deb1 100644 --- a/tests/integration/targets/nxos_smoke/tests/common/caching.yaml +++ b/tests/integration/targets/nxos_smoke/tests/common/caching.yaml @@ -42,7 +42,7 @@ that: - result.changed == False - - name: Merge l2 interfaces configuration + - name: Merge layer 2 interfaces configuration register: result cisco.nxos.nxos_l2_interfaces: &mergedl2 config: @@ -59,7 +59,7 @@ - '"switchport trunk allowed vlan 2,4,15" in result.commands' - result.commands|length == 3 - - name: Merge l2 interfaces configuration (idempotent) + - name: Merge layer 2 interfaces configuration (idempotent) register: result cisco.nxos.nxos_l2_interfaces: *mergedl2 @@ -67,7 +67,7 @@ that: - result.changed == False - - name: Merge l3 interfaces configuration + - name: Merge layer 3 interfaces configuration register: result cisco.nxos.nxos_l3_interfaces: &mergedl3 config: @@ -82,7 +82,7 @@ - '"ip address 203.0.113.1/24" in result.commands' - result.commands|length == 2 - - name: Merge l3 interfaces configuration (idempotent) + - name: Merge layer 3 interfaces configuration (idempotent) register: result cisco.nxos.nxos_l3_interfaces: *mergedl3 diff --git a/tests/integration/targets/nxos_smoke/tests/common/common_config.yaml b/tests/integration/targets/nxos_smoke/tests/common/common_config.yaml index b4be2399a..29c9ea8c8 100644 --- a/tests/integration/targets/nxos_smoke/tests/common/common_config.yaml +++ b/tests/integration/targets/nxos_smoke/tests/common/common_config.yaml @@ -6,9 +6,6 @@ # Select interface for test - ansible.builtin.debug: msg: START connection={{ ansible_connection }} common/common_config.yaml -- ansible.builtin.debug: - msg: Using provider={{ connection.transport }} - when: ansible_connection == "local" - name: Set a fact for 'intname' ansible.builtin.set_fact: @@ -22,7 +19,6 @@ parents: - "interface {{ intname }}" match: none - provider: "{{ connection }}" - name: Collect any backup files ansible.builtin.find: &backups @@ -37,7 +33,7 @@ state: absent with_items: "{{backup_files.files|default([])}}" -- name: Configure device with config +- name: Configure device with configuration cisco.nxos.nxos_config: commands: - description this is a test @@ -45,7 +41,6 @@ parents: - "interface {{ intname }}" backup: true - provider: "{{ connection }}" register: result - ansible.builtin.assert: @@ -66,7 +61,6 @@ - name: Setup cisco.nxos.nxos_config: &clear lines: no ip access-list test - provider: "{{ connection }}" match: none ignore_errors: true @@ -80,7 +74,6 @@ - 40 permit ip 192.0.2.4/32 any log parents: ip access-list test replace: block - provider: "{{ connection }}" match: exact register: result @@ -103,64 +96,8 @@ - 40 permit ip 192.0.2.4/32 any log parents: ip access-list test replace: block - provider: "{{ connection }}" match: strict register: result - name: Teardown nxos_config: *clear - -# hit CustomNetworkConfig -- block: - - name: Create static route - cisco.nxos.nxos_static_route: - prefix: "192.168.20.64/24" - next_hop: "192.0.2.3" - route_name: testing - pref: 100 - tag: 5500 - vrf: testing - provider: "{{ connection }}" - register: result - - - ansible.builtin.assert: &true - that: - - "result.changed == true" - - - name: Remove static route - cisco.nxos.nxos_static_route: - prefix: "192.168.20.64/24" - next_hop: "192.0.2.3" - route_name: testing - pref: 100 - tag: 5500 - vrf: testing - state: absent - provider: "{{ connection }}" - register: result - - - ansible.builtin.assert: *true - - always: - - name: Remove static route - cisco.nxos.nxos_static_route: - prefix: "192.168.20.64/24" - next_hop: "192.0.2.3" - route_name: testing - pref: 100 - tag: 5500 - vrf: testing - state: absent - provider: "{{ connection }}" - ignore_errors: true - - - name: Remove static route aggregate - cisco.nxos.nxos_static_route: - aggregate: - - prefix: "192.168.22.64/24" - next_hop: "192.0.2.3" - - prefix: "192.168.24.64/24" - next_hop: "192.0.2.3" - state: absent - provider: "{{ connection }}" - ignore_errors: true diff --git a/tests/integration/targets/nxos_smoke/tests/common/common_utils.yaml b/tests/integration/targets/nxos_smoke/tests/common/common_utils.yaml index 9908e2464..9472c65c7 100644 --- a/tests/integration/targets/nxos_smoke/tests/common/common_utils.yaml +++ b/tests/integration/targets/nxos_smoke/tests/common/common_utils.yaml @@ -1,32 +1,25 @@ --- # nxos_command -> ComplexList # nxos_config -> to_list -# nxos_interface -> conditional, remove_default_spec - ansible.builtin.debug: msg: START connection={{ ansible_connection }} common/common_utils.yaml -- ansible.builtin.debug: - msg: Using provider={{ connection.transport }} - when: ansible_connection == "local" # hit ComplexList - name: Test contains operator cisco.nxos.nxos_command: commands: - show version - provider: "{{ connection }}" # hit to_list() - name: Setup cisco.nxos.nxos_config: lines: hostname switch - provider: "{{ connection }}" match: none - name: Configure top level command cisco.nxos.nxos_config: lines: hostname foo - provider: "{{ connection }}" register: result - ansible.builtin.assert: @@ -37,7 +30,6 @@ - name: Setup cisco.nxos.nxos_config: lines: hostname switch - provider: "{{ connection }}" match: none # hit conditional() @@ -53,58 +45,13 @@ lines: - "default interface {{ testint1 }}" - "default interface {{ testint2 }}" - provider: "{{ connection }}" - ignore_errors: true - - register: result - -- name: Check intent arguments - cisco.nxos.nxos_interface: - name: "{{ testint2 }}" - admin_state: up - tx_rate: ge(0) - rx_rate: ge(0) - provider: "{{ connection }}" - register: result - -- ansible.builtin.assert: - that: - - "result.failed == false" - -- name: Check intent arguments (failed condition) - cisco.nxos.nxos_interface: - name: "{{ testint2 }}" - admin_state: down - tx_rate: lt(0) - rx_rate: lt(0) - provider: "{{ connection }}" ignore_errors: true - register: result - -- ansible.builtin.assert: - that: - - "result.failed == true" - - "'tx_rate lt(0)' in result.failed_conditions" - - "'rx_rate lt(0)' in result.failed_conditions" -- name: Aggregate definition of interface - cisco.nxos.nxos_interface: - aggregate: - - name: "{{ testint1 }}" - description: "Test aggregation on first interface" - - name: "{{ testint2 }}" - mode: layer3 - provider: "{{ connection }}" register: result -- ansible.builtin.assert: - that: - - "result.changed == true" - - name: "Teardown: put interfaces into a default state" cisco.nxos.nxos_config: lines: - "default interface {{ testint1 }}" - "default interface {{ testint2 }}" - provider: "{{ connection }}" ignore_errors: true diff --git a/tests/integration/targets/nxos_smoke/tests/common/misc_tests.yaml b/tests/integration/targets/nxos_smoke/tests/common/misc_tests.yaml index 85f3f39bf..d1f2c4414 100644 --- a/tests/integration/targets/nxos_smoke/tests/common/misc_tests.yaml +++ b/tests/integration/targets/nxos_smoke/tests/common/misc_tests.yaml @@ -1,9 +1,6 @@ --- - ansible.builtin.debug: msg: START connection={{ ansible_connection }} common/misc_tests.yaml -- ansible.builtin.debug: - msg: Using provider={{ connection.transport }} - when: ansible_connection == "local" - name: Hit conditional for lists of 10 or more commands cisco.nxos.nxos_command: @@ -18,7 +15,6 @@ - show hostname - show hostname - show hostname - provider: "{{ connection }}" register: result - ansible.builtin.assert: @@ -29,4 +25,3 @@ cisco.nxos.nxos_command: commands: - show hostname - provider: "{{ connection | combine({'timeout': 500}) }}" diff --git a/tests/integration/targets/nxos_snapshot/tasks/cli.yaml b/tests/integration/targets/nxos_snapshot/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_snapshot/tasks/cli.yaml +++ b/tests/integration/targets/nxos_snapshot/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_snapshot/tasks/main.yaml b/tests/integration/targets/nxos_snapshot/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_snapshot/tasks/main.yaml +++ b/tests/integration/targets/nxos_snapshot/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_snapshot/tasks/nxapi.yaml b/tests/integration/targets/nxos_snapshot/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_snapshot/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_snapshot/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_snapshot/tests/common/sanity.yaml b/tests/integration/targets/nxos_snapshot/tests/common/sanity.yaml index e518f2864..7def15904 100644 --- a/tests/integration/targets/nxos_snapshot/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_snapshot/tests/common/sanity.yaml @@ -38,7 +38,7 @@ that: - result.changed == true - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_snapshot: *id001 @@ -79,7 +79,7 @@ - ansible.builtin.assert: *id002 - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_snapshot: *id005 @@ -102,7 +102,7 @@ - ansible.builtin.assert: *id002 - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_snapshot: *id006 @@ -115,7 +115,7 @@ - ansible.builtin.assert: *id002 - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_snapshot: *id007 diff --git a/tests/integration/targets/nxos_snmp_community/tasks/cli.yaml b/tests/integration/targets/nxos_snmp_community/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_snmp_community/tasks/cli.yaml +++ b/tests/integration/targets/nxos_snmp_community/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_snmp_community/tasks/main.yaml b/tests/integration/targets/nxos_snmp_community/tasks/main.yaml index 7631f52fe..c9e70304e 100644 --- a/tests/integration/targets/nxos_snmp_community/tasks/main.yaml +++ b/tests/integration/targets/nxos_snmp_community/tasks/main.yaml @@ -1,11 +1,12 @@ --- -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli always: - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_snmp_community/tasks/nxapi.yaml b/tests/integration/targets/nxos_snmp_community/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_snmp_community/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_snmp_community/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_snmp_community/tests/common/sanity.yaml b/tests/integration/targets/nxos_snmp_community/tests/common/sanity.yaml index acfc423e3..c83ec6176 100644 --- a/tests/integration/targets/nxos_snmp_community/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_snmp_community/tests/common/sanity.yaml @@ -106,7 +106,7 @@ - ansible.builtin.assert: *id004 - - name: Change acl + - name: Change ACL register: result cisco.nxos.nxos_snmp_community: &id008 community: TESTING7 @@ -122,7 +122,7 @@ - ansible.builtin.assert: *id004 - - name: Remove acl + - name: Remove ACL register: result cisco.nxos.nxos_snmp_community: &id009 community: TESTING7 diff --git a/tests/integration/targets/nxos_snmp_contact/tasks/cli.yaml b/tests/integration/targets/nxos_snmp_contact/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_snmp_contact/tasks/cli.yaml +++ b/tests/integration/targets/nxos_snmp_contact/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_snmp_contact/tasks/main.yaml b/tests/integration/targets/nxos_snmp_contact/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_snmp_contact/tasks/main.yaml +++ b/tests/integration/targets/nxos_snmp_contact/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_snmp_contact/tasks/nxapi.yaml b/tests/integration/targets/nxos_snmp_contact/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_snmp_contact/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_snmp_contact/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_snmp_contact/tests/common/sanity.yaml b/tests/integration/targets/nxos_snmp_contact/tests/common/sanity.yaml index 3cf3ea6c6..a5757c89b 100644 --- a/tests/integration/targets/nxos_snmp_contact/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_snmp_contact/tests/common/sanity.yaml @@ -8,7 +8,7 @@ state: absent - block: - - name: Configure snmp contact + - name: Configure SNMP contact register: result cisco.nxos.nxos_snmp_contact: &id001 contact: Testing @@ -26,7 +26,7 @@ that: - result.changed == false - - name: Change snmp contact + - name: Change SNMP contact register: result cisco.nxos.nxos_snmp_contact: &id003 contact: Test @@ -40,7 +40,7 @@ - ansible.builtin.assert: *id004 - - name: Remove snmp contact + - name: Remove SNMP contact register: result cisco.nxos.nxos_snmp_contact: *id005 diff --git a/tests/integration/targets/nxos_snmp_host/tasks/cli.yaml b/tests/integration/targets/nxos_snmp_host/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_snmp_host/tasks/cli.yaml +++ b/tests/integration/targets/nxos_snmp_host/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_snmp_host/tasks/main.yaml b/tests/integration/targets/nxos_snmp_host/tasks/main.yaml index 7631f52fe..c9e70304e 100644 --- a/tests/integration/targets/nxos_snmp_host/tasks/main.yaml +++ b/tests/integration/targets/nxos_snmp_host/tasks/main.yaml @@ -1,11 +1,12 @@ --- -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli always: - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_snmp_host/tasks/nxapi.yaml b/tests/integration/targets/nxos_snmp_host/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_snmp_host/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_snmp_host/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_snmp_host/tests/common/sanity_snmp_v1_trap.yaml b/tests/integration/targets/nxos_snmp_host/tests/common/sanity_snmp_v1_trap.yaml index 50cc754b6..f0420f99d 100644 --- a/tests/integration/targets/nxos_snmp_host/tests/common/sanity_snmp_v1_trap.yaml +++ b/tests/integration/targets/nxos_snmp_host/tests/common/sanity_snmp_v1_trap.yaml @@ -29,7 +29,7 @@ state: absent - block: - - name: Configure snmp host + - name: Configure SNMP host register: result cisco.nxos.nxos_snmp_host: &id001 snmp_host: 192.0.2.3 diff --git a/tests/integration/targets/nxos_snmp_host/tests/common/sanity_snmp_v2_inform.yaml b/tests/integration/targets/nxos_snmp_host/tests/common/sanity_snmp_v2_inform.yaml index 87a1849d0..664bea9eb 100644 --- a/tests/integration/targets/nxos_snmp_host/tests/common/sanity_snmp_v2_inform.yaml +++ b/tests/integration/targets/nxos_snmp_host/tests/common/sanity_snmp_v2_inform.yaml @@ -29,7 +29,7 @@ state: absent - block: - - name: Configure snmp host + - name: Configure SNMP host register: result cisco.nxos.nxos_snmp_host: &id001 snmp_host: 192.0.2.3 diff --git a/tests/integration/targets/nxos_snmp_host/tests/common/sanity_snmp_v3_inform.yaml b/tests/integration/targets/nxos_snmp_host/tests/common/sanity_snmp_v3_inform.yaml index e860ac4d7..03dcbd333 100644 --- a/tests/integration/targets/nxos_snmp_host/tests/common/sanity_snmp_v3_inform.yaml +++ b/tests/integration/targets/nxos_snmp_host/tests/common/sanity_snmp_v3_inform.yaml @@ -42,7 +42,7 @@ state: absent - block: - - name: Configure snmp host + - name: Configure SNMP host register: result cisco.nxos.nxos_snmp_host: &id001 snmp_host: 192.0.2.3 diff --git a/tests/integration/targets/nxos_snmp_host/tests/common/sanity_snmp_v3_trap.yaml b/tests/integration/targets/nxos_snmp_host/tests/common/sanity_snmp_v3_trap.yaml index 9ef332044..a77318d32 100644 --- a/tests/integration/targets/nxos_snmp_host/tests/common/sanity_snmp_v3_trap.yaml +++ b/tests/integration/targets/nxos_snmp_host/tests/common/sanity_snmp_v3_trap.yaml @@ -34,7 +34,7 @@ state: absent - block: - - name: Configure snmp host + - name: Configure SNMP host register: result cisco.nxos.nxos_snmp_host: &id001 snmp_host: 192.0.2.3 diff --git a/tests/integration/targets/nxos_snmp_location/tasks/cli.yaml b/tests/integration/targets/nxos_snmp_location/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_snmp_location/tasks/cli.yaml +++ b/tests/integration/targets/nxos_snmp_location/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_snmp_location/tasks/main.yaml b/tests/integration/targets/nxos_snmp_location/tasks/main.yaml index 7631f52fe..c9e70304e 100644 --- a/tests/integration/targets/nxos_snmp_location/tasks/main.yaml +++ b/tests/integration/targets/nxos_snmp_location/tasks/main.yaml @@ -1,11 +1,12 @@ --- -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli always: - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_snmp_location/tasks/nxapi.yaml b/tests/integration/targets/nxos_snmp_location/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_snmp_location/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_snmp_location/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_snmp_location/tests/common/sanity.yaml b/tests/integration/targets/nxos_snmp_location/tests/common/sanity.yaml index d83085543..4e8ecf0b2 100644 --- a/tests/integration/targets/nxos_snmp_location/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_snmp_location/tests/common/sanity.yaml @@ -8,7 +8,7 @@ state: absent - block: - - name: Configure snmp location + - name: Configure SNMP location register: result cisco.nxos.nxos_snmp_location: &id001 location: Testing @@ -26,7 +26,7 @@ that: - result.changed == false - - name: Change snmp location + - name: Change SNMP location register: result cisco.nxos.nxos_snmp_location: &id003 location: Test @@ -40,7 +40,7 @@ - ansible.builtin.assert: *id004 - - name: Remove snmp location + - name: Remove SNMP location register: result cisco.nxos.nxos_snmp_location: *id005 diff --git a/tests/integration/targets/nxos_snmp_server/tasks/cli.yaml b/tests/integration/targets/nxos_snmp_server/tasks/cli.yaml index 507d803cb..e3e64747b 100644 --- a/tests/integration/targets/nxos_snmp_server/tasks/cli.yaml +++ b/tests/integration/targets/nxos_snmp_server/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_snmp_server/tasks/main.yaml b/tests/integration/targets/nxos_snmp_server/tasks/main.yaml index b4e4ac99c..b46cbf998 100644 --- a/tests/integration/targets/nxos_snmp_server/tasks/main.yaml +++ b/tests/integration/targets/nxos_snmp_server/tasks/main.yaml @@ -1,39 +1,49 @@ --- -- name: Get admin user snmp data +- name: Get admin user SNMP data cisco.nxos.nxos_command: commands: show running | section '^snmp-server user' register: result -- name: Grep admin user snmp localized key +- name: Grep admin user SNMP localized key ansible.builtin.set_fact: - admin_snmp_passwd: "{{ result['stdout'][0] | regex_search('snmp-server user admin network-admin auth (md5|sha) (\\S+)', '\\2') }}" + # noqa jinja[spacing] + admin_snmp_passwd: "{{ result['stdout'][0] | regex_search('snmp-server user admin network-admin auth (md5|sha|sha-256) (\\S+)', '\\2') }}" -- name: Find admin user snmp localized key +- name: Find admin user SNMP localized key ansible.builtin.set_fact: admin_snmp_passwd: "{{ admin_snmp_passwd[0] }}" -- name: Grep admin user snmp localized key (second) +- name: Grep admin user SNMP localized key (second) ansible.builtin.set_fact: - admin_snmp_passwd_2: "{{ result['stdout'][0] | regex_search('snmp-server user admin auth (md5|sha) (\\S+)', '\\2') }}" + admin_snmp_passwd_2: "{{ result['stdout'][0] | regex_search('snmp-server user admin auth (md5|sha|sha-256) (\\S+)', '\\2') }}" # noqa jinja[spacing] -- name: Find admin user snmp localized key (second) +- name: Find admin user SNMP localized key (second) ansible.builtin.set_fact: admin_snmp_passwd_2: "{{ admin_snmp_passwd_2[0] }}" -- name: Grep admin user snmp engineid (second) +- name: Grep admin user SNMP engineid (second) ansible.builtin.set_fact: - admin_snmp_engineid_2: "{{ result['stdout'][0] | regex_search('admin auth (md5|sha) (\\S+) priv (\\S+) localizedkey engineID (\\S+)', '\\4') }}" + # # noqa jinja[spacing] + admin_snmp_engineid_2: "{{ result['stdout'][0] | regex_search('admin auth (md5|sha|sha-256) (\\S+) priv (\\S+) localizedkey engineID (\\S+)', '\\4') }}" -- name: Find admin user snmp engineid (second) +- name: Find admin user SNMP engineid (second) ansible.builtin.set_fact: admin_snmp_engineid_2: "{{ admin_snmp_engineid_2[0] }}" -- name: Include the cli tasks +- name: Grep zuul user SNMP localized key + ansible.builtin.set_fact: + zuul_snmp_passwd: "{{ result['stdout'][0] | regex_search('zuul network-admin auth (md5|sha) (\\S+)', '\\2') }}" + +- name: Find zuul user SNMP localized key + ansible.builtin.set_fact: + zuul_snmp_passwd: "{{ zuul_snmp_passwd[0] }}" + +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli.yaml -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_snmp_server/tasks/nxapi.yaml b/tests/integration/targets/nxos_snmp_server/tasks/nxapi.yaml index 2e452bb6a..4ae68868c 100644 --- a/tests/integration/targets/nxos_snmp_server/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_snmp_server/tasks/nxapi.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_snmp_server/tests/common/_populate_config.yaml b/tests/integration/targets/nxos_snmp_server/tests/common/_populate_config.yaml index 7aa4cd8af..08cf504a4 100644 --- a/tests/integration/targets/nxos_snmp_server/tests/common/_populate_config.yaml +++ b/tests/integration/targets/nxos_snmp_server/tests/common/_populate_config.yaml @@ -1,5 +1,5 @@ --- -- name: Populate config +- name: Populate configuration cisco.nxos.nxos_config: lines: - snmp-server contact nxosswitchadmin@localhost diff --git a/tests/integration/targets/nxos_snmp_server/tests/common/_remove_config.yaml b/tests/integration/targets/nxos_snmp_server/tests/common/_remove_config.yaml index db53f4e09..ce86eaec3 100644 --- a/tests/integration/targets/nxos_snmp_server/tests/common/_remove_config.yaml +++ b/tests/integration/targets/nxos_snmp_server/tests/common/_remove_config.yaml @@ -21,7 +21,3 @@ - no snmp-server host 192.0.2.2 informs version 3 auth NMS - no snmp-server host 192.0.3.2 informs version 3 auth NMS ignore_errors: true - -- name: Remove remaining config - cisco.nxos.nxos_snmp_server: - state: deleted diff --git a/tests/integration/targets/nxos_snmp_server/tests/common/empty_config.yaml b/tests/integration/targets/nxos_snmp_server/tests/common/empty_config.yaml index 0e125fd40..b83d1f940 100644 --- a/tests/integration/targets/nxos_snmp_server/tests/common/empty_config.yaml +++ b/tests/integration/targets/nxos_snmp_server/tests/common/empty_config.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxos_snmp_server empty_config integration tests on connection={{ ansible_connection }} -- name: Merged with empty config should give appropriate error message +- name: Merged with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_snmp_server: @@ -13,7 +13,7 @@ that: - result.msg == 'value of config parameter must not be empty for state merged' -- name: Replaced with empty config should give appropriate error message +- name: Replaced with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_snmp_server: @@ -24,7 +24,7 @@ that: - result.msg == 'value of config parameter must not be empty for state replaced' -- name: Overridden with empty config should give appropriate error message +- name: Overridden with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_snmp_server: @@ -35,7 +35,7 @@ that: - result.msg == 'value of config parameter must not be empty for state overridden' -- name: Rendered with empty config should give appropriate error message +- name: Rendered with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_snmp_server: @@ -46,7 +46,7 @@ that: - result.msg == 'value of config parameter must not be empty for state rendered' -- name: Parsed with empty config should give appropriate error message +- name: Parsed with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_snmp_server: diff --git a/tests/integration/targets/nxos_snmp_server/tests/common/overridden.yaml b/tests/integration/targets/nxos_snmp_server/tests/common/overridden.yaml index 47ab9d666..7438475a7 100644 --- a/tests/integration/targets/nxos_snmp_server/tests/common/overridden.yaml +++ b/tests/integration/targets/nxos_snmp_server/tests/common/overridden.yaml @@ -69,6 +69,16 @@ priv: privacy_password: "0x5632724fb8ac3699296af26281e1d0f1" aes_128: true + + - authentication: + algorithm: md5 + localized_key: true + password: "{{ zuul_snmp_passwd }}" + priv: + privacy_password: "{{ zuul_snmp_passwd }}" + group: network-admin + user: zuul + use_acls: - user: snmp_user_1 ipv4: acl1 diff --git a/tests/integration/targets/nxos_snmp_server/tests/common/parsed.yaml b/tests/integration/targets/nxos_snmp_server/tests/common/parsed.yaml index c2b16b497..aecccf9b3 100644 --- a/tests/integration/targets/nxos_snmp_server/tests/common/parsed.yaml +++ b/tests/integration/targets/nxos_snmp_server/tests/common/parsed.yaml @@ -8,7 +8,7 @@ running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" state: parsed -- name: Assert that config was correctly parsed +- name: Assert that configuration was correctly parsed ansible.builtin.assert: that: - "{{ parsed == result['parsed'] }}" diff --git a/tests/integration/targets/nxos_snmp_server/tests/common/replaced.yaml b/tests/integration/targets/nxos_snmp_server/tests/common/replaced.yaml index 35b492296..590657d96 100644 --- a/tests/integration/targets/nxos_snmp_server/tests/common/replaced.yaml +++ b/tests/integration/targets/nxos_snmp_server/tests/common/replaced.yaml @@ -69,6 +69,16 @@ priv: privacy_password: "0x5632724fb8ac3699296af26281e1d0f1" aes_128: true + + - authentication: + algorithm: md5 + localized_key: true + password: "{{ zuul_snmp_passwd }}" + priv: + privacy_password: "{{ zuul_snmp_passwd }}" + group: network-admin + user: zuul + use_acls: - user: snmp_user_1 ipv4: acl1 diff --git a/tests/integration/targets/nxos_snmp_server/vars/main.yml b/tests/integration/targets/nxos_snmp_server/vars/main.yml index 76a6f1dfd..33b13d451 100644 --- a/tests/integration/targets/nxos_snmp_server/vars/main.yml +++ b/tests/integration/targets/nxos_snmp_server/vars/main.yml @@ -8,7 +8,7 @@ merged: authentication: algorithm: md5 password: "{{ admin_snmp_passwd }}" - localized_key: True + localized_key: true priv: privacy_password: "{{ admin_snmp_passwd }}" - authentication: @@ -19,6 +19,14 @@ merged: priv: privacy_password: "{{ admin_snmp_passwd_2 }}" user: admin + - authentication: + algorithm: md5 + localized_key: true + password: "{{ zuul_snmp_passwd }}" + priv: + privacy_password: "{{ zuul_snmp_passwd }}" + group: network-admin + user: zuul commands: - snmp-server contact nxosswitchadmin@localhost - snmp-server location serverroom-1 @@ -93,6 +101,14 @@ merged: privacy_password: "0x5632724fb8ac3699296af26281e1d0f1" group: network-operator user: snmp_user_2 + - authentication: + algorithm: md5 + localized_key: true + password: "{{ zuul_snmp_passwd }}" + priv: + privacy_password: "{{ zuul_snmp_passwd }}" + group: network-admin + user: zuul use_acls: - ipv4: acl1 ipv6: acl2 @@ -123,16 +139,16 @@ replaced: location: serverroom-2 traps: aaa: - server_state_change: True + server_state_change: true hosts: - host: 192.0.2.1 - traps: True + traps: true version: "1" community: public - host: 192.0.2.1 source_interface: Ethernet1/1 - host: 192.0.3.2 - informs: True + informs: true version: "3" auth: NMS users: @@ -142,7 +158,7 @@ replaced: authentication: algorithm: md5 password: "{{ admin_snmp_passwd }}" - localized_key: True + localized_key: true priv: privacy_password: "{{ admin_snmp_passwd }}" @@ -160,17 +176,27 @@ replaced: authentication: algorithm: md5 password: "0x5632724fb8ac3699296af26281e1d0f1" - localized_key: True + localized_key: true - user: snmp_user_2 group: network-operator authentication: algorithm: md5 password: "0x5632724fb8ac3699296af26281e1d0f1" - localized_key: True + localized_key: true priv: privacy_password: "0x5632724fb8ac3699296af26281e1d0f1" - aes_128: True + aes_128: true + + - authentication: + algorithm: md5 + localized_key: true + password: "{{ zuul_snmp_passwd }}" + priv: + privacy_password: "{{ zuul_snmp_passwd }}" + group: network-admin + user: zuul + use_acls: - user: snmp_user_1 ipv4: acl1 @@ -188,18 +214,18 @@ parsed: location: serverroom-1 traps: aaa: - server_state_change: True + server_state_change: true system: - clock_change_notification: True + clock_change_notification: true hosts: - host: 192.0.2.1 - traps: True + traps: true version: "1" community: public - host: 192.0.2.1 source_interface: Ethernet1/1 - host: 192.0.2.2 - informs: True + informs: true version: "3" auth: NMS users: @@ -209,16 +235,16 @@ parsed: authentication: algorithm: md5 password: "0x5632724fb8ac3699296af26281e1d0f1" - localized_key: True + localized_key: true - user: snmp_user_2 group: network-operator authentication: algorithm: md5 password: "0x5632724fb8ac3699296af26281e1d0f1" - localized_key: True + localized_key: true priv: privacy_password: "0x5632724fb8ac3699296af26281e1d0f1" - aes_128: True + aes_128: true use_acls: - user: snmp_user_1 ipv4: acl1 diff --git a/tests/integration/targets/nxos_snmp_traps/tasks/cli.yaml b/tests/integration/targets/nxos_snmp_traps/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_snmp_traps/tasks/cli.yaml +++ b/tests/integration/targets/nxos_snmp_traps/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_snmp_traps/tasks/main.yaml b/tests/integration/targets/nxos_snmp_traps/tasks/main.yaml index 7631f52fe..c9e70304e 100644 --- a/tests/integration/targets/nxos_snmp_traps/tasks/main.yaml +++ b/tests/integration/targets/nxos_snmp_traps/tasks/main.yaml @@ -1,11 +1,12 @@ --- -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli always: - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_snmp_traps/tasks/nxapi.yaml b/tests/integration/targets/nxos_snmp_traps/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_snmp_traps/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_snmp_traps/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_snmp_traps/tests/common/sanity.yaml b/tests/integration/targets/nxos_snmp_traps/tests/common/sanity.yaml index 6d0d8d9ed..787d223b3 100644 --- a/tests/integration/targets/nxos_snmp_traps/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_snmp_traps/tests/common/sanity.yaml @@ -8,7 +8,7 @@ state: disabled - block: - - name: Configure one snmp trap group + - name: Configure one SNMP trap group register: result cisco.nxos.nxos_snmp_traps: &id001 group: bridge @@ -26,7 +26,7 @@ that: - result.changed == false - - name: Remove snmp trap group + - name: Remove SNMP trap group register: result cisco.nxos.nxos_snmp_traps: &id003 group: bridge @@ -40,7 +40,7 @@ - ansible.builtin.assert: *id004 - - name: Configure all snmp trap groups + - name: Configure all SNMP trap groups register: result cisco.nxos.nxos_snmp_traps: &id005 group: all diff --git a/tests/integration/targets/nxos_snmp_user/tasks/cli.yaml b/tests/integration/targets/nxos_snmp_user/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_snmp_user/tasks/cli.yaml +++ b/tests/integration/targets/nxos_snmp_user/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_snmp_user/tasks/main.yaml b/tests/integration/targets/nxos_snmp_user/tasks/main.yaml index 7631f52fe..c9e70304e 100644 --- a/tests/integration/targets/nxos_snmp_user/tasks/main.yaml +++ b/tests/integration/targets/nxos_snmp_user/tasks/main.yaml @@ -1,11 +1,12 @@ --- -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli always: - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_snmp_user/tasks/nxapi.yaml b/tests/integration/targets/nxos_snmp_user/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_snmp_user/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_snmp_user/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_snmp_user/tests/common/sanity.yaml b/tests/integration/targets/nxos_snmp_user/tests/common/sanity.yaml index 15f518c11..ed6ca2c94 100644 --- a/tests/integration/targets/nxos_snmp_user/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_snmp_user/tests/common/sanity.yaml @@ -16,7 +16,7 @@ delete_last_user_allowed: false when: platform is search('N5K|N6K|N9K-F') -- name: Remove snmp user +- name: Remove SNMP user ignore_errors: true when: platform is not search('N5K|N6K|N9K-F') cisco.nxos.nxos_snmp_user: &id006 @@ -34,7 +34,7 @@ seconds: 5 - block: - - name: Create snmp user + - name: Create SNMP user register: result cisco.nxos.nxos_snmp_user: user: ntc @@ -102,7 +102,7 @@ - assert: *id004 when: delete_last_user_allowed always: - - name: Delete snmp user + - name: Delete SNMP user when: platform is not search('N5K|N6K|N9K-F') cisco.nxos.nxos_snmp_user: *id006 diff --git a/tests/integration/targets/nxos_static_route/defaults/main.yaml b/tests/integration/targets/nxos_static_route/defaults/main.yaml deleted file mode 100644 index 525b7aab9..000000000 --- a/tests/integration/targets/nxos_static_route/defaults/main.yaml +++ /dev/null @@ -1,5 +0,0 @@ ---- -testcase: "*" -vrfs: - - default - - myvrf diff --git a/tests/integration/targets/nxos_static_route/meta/main.yml b/tests/integration/targets/nxos_static_route/meta/main.yml deleted file mode 100644 index f504a6ab2..000000000 --- a/tests/integration/targets/nxos_static_route/meta/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_nxos_tests diff --git a/tests/integration/targets/nxos_static_route/tasks/cli.yaml b/tests/integration/targets/nxos_static_route/tasks/cli.yaml deleted file mode 100644 index 90342e6b1..000000000 --- a/tests/integration/targets/nxos_static_route/tasks/cli.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect cli test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - connection: local - register: cli_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + cli_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.network_cli) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_static_route/tasks/main.yaml b/tests/integration/targets/nxos_static_route/tasks/main.yaml deleted file mode 100644 index 7631f52fe..000000000 --- a/tests/integration/targets/nxos_static_route/tasks/main.yaml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- block: - - name: Include the cli tasks - ansible.builtin.include_tasks: cli.yaml - tags: - - cli - always: - - name: Include the nx-api tasks - ansible.builtin.include_tasks: nxapi.yaml - tags: - - nxapi diff --git a/tests/integration/targets/nxos_static_route/tasks/nxapi.yaml b/tests/integration/targets/nxos_static_route/tasks/nxapi.yaml deleted file mode 100644 index cedab80f1..000000000 --- a/tests/integration/targets/nxos_static_route/tasks/nxapi.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect nxapi test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/nxapi" - patterns: "{{ testcase }}.yaml" - connection: local - register: nxapi_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + nxapi_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.httpapi) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_static_route/tests/common/sanity.yaml b/tests/integration/targets/nxos_static_route/tests/common/sanity.yaml deleted file mode 100644 index c3f405c74..000000000 --- a/tests/integration/targets/nxos_static_route/tests/common/sanity.yaml +++ /dev/null @@ -1,213 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_static_route sanity test - -- name: Set a fact for 'test_track_feature' - ansible.builtin.set_fact: - test_track_feature: true - -- name: Configure track - register: cmd_result - ignore_errors: true - cisco.nxos.nxos_config: - lines: - - track 1 ip sla 1 - -- ansible.builtin.debug: - msg: cmd result {{ cmd_result }} - -- name: Set a fact for 'test_track_feature' - ansible.builtin.set_fact: - test_track_feature: false - when: cmd_result.failed - -- ansible.builtin.debug: - msg: Test Track Feature {{ test_track_feature }} - -- name: Setup and teardown, remove test routes if present - with_items: "{{ vrfs }}" - ignore_errors: true - cisco.nxos.nxos_static_route: &id009 - aggregate: - - prefix: 192.168.1.164/32 - next_hop: 192.0.2.3 - - - prefix: 192.168.20.64/24 - next_hop: 192.0.2.3 - - - prefix: 192.168.22.64/24 - next_hop: 192.0.2.3 - - - prefix: 192.168.24.64/24 - next_hop: 192.0.2.3 - vrf: "{{ item }}" - state: absent - -- name: Setup noise routes to ensure testing while non-test routes present - with_items: "{{ vrfs }}" - cisco.nxos.nxos_static_route: - prefix: 192.168.1.164/32 - next_hop: 192.0.2.3 - vrf: "{{ item }}" - state: present - -- block: - - name: Create static route - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_static_route: &id001 - prefix: 192.168.20.64/24 - next_hop: 192.0.2.3 - route_name: testing - pref: 100 - tag: 5500 - vrf: "{{ item }}" - - - ansible.builtin.assert: &id002 - that: - - result.changed == true - - - name: Conf static idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_static_route: *id001 - - - ansible.builtin.assert: &id004 - that: - - result.changed == false - - - name: Change static route - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_static_route: &id003 - prefix: 192.168.20.64/24 - next_hop: 192.0.2.3 - route_name: default - pref: 10 - tag: default - vrf: "{{ item }}" - - - ansible.builtin.assert: *id002 - - - name: Change idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_static_route: *id003 - - - ansible.builtin.assert: *id004 - - - name: Configure static route with track - with_items: "{{ vrfs }}" - register: result - when: test_track_feature - cisco.nxos.nxos_static_route: &id005 - prefix: 192.168.20.64/24 - next_hop: 192.0.2.3 - route_name: default - pref: 10 - tag: default - track: 1 - vrf: "{{ item }}" - - - ansible.builtin.assert: *id002 - when: test_track_feature - - - name: Config track idempotence - with_items: "{{ vrfs }}" - register: result - when: test_track_feature - cisco.nxos.nxos_static_route: *id005 - - - ansible.builtin.assert: *id004 - when: test_track_feature - - - name: Configure static route with not configured track - with_items: "{{ vrfs }}" - register: result - ignore_errors: true - when: test_track_feature - cisco.nxos.nxos_static_route: - prefix: 192.168.20.64/24 - next_hop: 192.0.2.3 - route_name: default - pref: 10 - tag: default - track: 2 - vrf: "{{ item }}" - - - ansible.builtin.assert: - that: - - result.failed == True - when: test_track_feature - - - name: Remove static route - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_static_route: &id006 - prefix: 192.168.20.64/24 - next_hop: 192.0.2.3 - route_name: testing - pref: 100 - vrf: "{{ item }}" - state: absent - - - ansible.builtin.assert: *id002 - - - name: Remove idempotence - with_items: "{{ vrfs }}" - register: result - cisco.nxos.nxos_static_route: *id006 - - - ansible.builtin.assert: *id004 - - - name: Configure static route(aggregate) - register: result - cisco.nxos.nxos_static_route: &id007 - aggregate: - - prefix: 192.168.22.64/24 - next_hop: 192.0.2.3 - - - prefix: 192.168.24.64/24 - next_hop: 192.0.2.3 - - - ansible.builtin.assert: *id002 - - - name: Configure static route aggregate(idempotence) - register: result - cisco.nxos.nxos_static_route: *id007 - - - ansible.builtin.assert: *id004 - - - name: Remove static route aggregate - register: result - cisco.nxos.nxos_static_route: &id008 - aggregate: - - prefix: 192.168.22.64/24 - next_hop: 192.0.2.3 - - - prefix: 192.168.24.64/24 - next_hop: 192.0.2.3 - state: absent - - - ansible.builtin.assert: *id002 - - - name: Remove static route aggregate(idempotence) - register: result - cisco.nxos.nxos_static_route: *id008 - - - ansible.builtin.assert: *id004 - always: - - name: Remove track - ignore_errors: true - when: test_track_feature - cisco.nxos.nxos_config: - lines: - - no track 1 - - - name: Teardown test routes - with_items: "{{ vrfs }}" - ignore_errors: true - cisco.nxos.nxos_static_route: *id009 - -- ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_static_route sanity test diff --git a/tests/integration/targets/nxos_static_routes/meta/main.yml b/tests/integration/targets/nxos_static_routes/meta/main.yml index ae741cbdc..f504a6ab2 100644 --- a/tests/integration/targets/nxos_static_routes/meta/main.yml +++ b/tests/integration/targets/nxos_static_routes/meta/main.yml @@ -1,2 +1,3 @@ +--- dependencies: - prepare_nxos_tests diff --git a/tests/integration/targets/nxos_static_routes/tasks/cli.yaml b/tests/integration/targets/nxos_static_routes/tasks/cli.yaml index 3adda1dad..fd8d12e79 100644 --- a/tests/integration/targets/nxos_static_routes/tasks/cli.yaml +++ b/tests/integration/targets/nxos_static_routes/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_static_routes/tasks/main.yaml b/tests/integration/targets/nxos_static_routes/tasks/main.yaml index 09b5ab67b..10be7ff19 100644 --- a/tests/integration/targets/nxos_static_routes/tasks/main.yaml +++ b/tests/integration/targets/nxos_static_routes/tasks/main.yaml @@ -1,5 +1,20 @@ --- -- name: Include the cli tasks +- name: Fetch vrf confext management output + cisco.nxos.nxos_command: + commands: show running-config | section 'vrf context management' + register: vrf_conf + +- name: Parse the config to structured data + cisco.nxos.nxos_static_routes: + state: parsed + running_config: "{{ vrf_conf['stdout'][0] }}" + register: vrf_mgmt + +- name: Setting booleans facts of management vrf + ansible.builtin.set_fact: + var_vrf_mgmt: "{{ vrf_mgmt['parsed'][0] }}" + +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - "cli" diff --git a/tests/integration/targets/nxos_static_routes/tests/common/_populate_config.yaml b/tests/integration/targets/nxos_static_routes/tests/common/_populate_config.yaml index d0a8d79a2..e4de1e60e 100644 --- a/tests/integration/targets/nxos_static_routes/tests/common/_populate_config.yaml +++ b/tests/integration/targets/nxos_static_routes/tests/common/_populate_config.yaml @@ -1,5 +1,5 @@ --- -- name: Populate config +- name: Populate configuration cisco.nxos.nxos_config: lines: - "ip route 192.0.2.16/28 192.0.2.24 name new_route" diff --git a/tests/integration/targets/nxos_static_routes/tests/common/_remove_config.yaml b/tests/integration/targets/nxos_static_routes/tests/common/_remove_config.yaml index ea1626ce4..dcc3f18aa 100644 --- a/tests/integration/targets/nxos_static_routes/tests/common/_remove_config.yaml +++ b/tests/integration/targets/nxos_static_routes/tests/common/_remove_config.yaml @@ -1,5 +1,5 @@ --- -- name: Remove config +- name: Remove configuration cisco.nxos.nxos_config: lines: - "no ip route 192.0.2.16/28 192.0.2.24 name new_route" @@ -12,4 +12,4 @@ - "no vrf context trial_vrf" - "default interface {{ nxos_int2 }}" ignore_errors: true - #error is thrown if we deleted trial_vrf when it is not present already. ignore_errors circumvents it + # error is thrown if we deleted trial_vrf when it is not present already. ignore_errors circumvents it diff --git a/tests/integration/targets/nxos_static_routes/tests/common/deleted.yml b/tests/integration/targets/nxos_static_routes/tests/common/deleted.yml index 452883205..fbf316b41 100644 --- a/tests/integration/targets/nxos_static_routes/tests/common/deleted.yml +++ b/tests/integration/targets/nxos_static_routes/tests/common/deleted.yml @@ -12,7 +12,7 @@ - "!min" gather_network_resources: static_routes - - name: Delete all routes based on vrf + - name: Delete all routes based on VRF cisco.nxos.nxos_static_routes: config: - vrf: trial_vrf @@ -29,7 +29,7 @@ - ansible.builtin.include_tasks: _populate_config.yaml - - name: Delete routes based on afi in a vrf + - name: Delete routes based on AFI in a VRF cisco.nxos.nxos_static_routes: config: - vrf: trial_vrf @@ -46,36 +46,5 @@ - "'no ip route 192.0.2.64/28 192.0.2.23 name merged_route 1' in result.commands" - "result.commands | length == 3" - - ansible.builtin.include_tasks: _remove_config.yaml - - - ansible.builtin.include_tasks: _populate_config.yaml - - - name: Deleted (all routes) - cisco.nxos.nxos_static_routes: &deleted - state: deleted - register: result - - - name: Gather static_routes post facts - cisco.nxos.nxos_facts: *facts - - - ansible.builtin.assert: - that: - - "'vrf context trial_vrf' in result.commands" - - "'no ip route 192.0.2.64/28 192.0.2.22 tag 4' in result.commands" - - "'no ip route 192.0.2.64/28 192.0.2.23 name merged_route 1' in result.commands" - - "'configure terminal' in result.commands" - - "'no ip route 192.0.2.16/28 192.0.2.24 name new_route' in result.commands" - - "'no ip route 192.0.2.80/28 192.0.2.26 tag 12' in result.commands" - - "result.changed == true" - - "result.commands | length == 6" - - - name: Idempotence - deleted - cisco.nxos.nxos_static_routes: *deleted - register: result - - - ansible.builtin.assert: - that: - - "result.changed == false" - always: - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/nxos_static_routes/tests/common/merged.yml b/tests/integration/targets/nxos_static_routes/tests/common/merged.yml index 6ba0a1b6a..11b748793 100644 --- a/tests/integration/targets/nxos_static_routes/tests/common/merged.yml +++ b/tests/integration/targets/nxos_static_routes/tests/common/merged.yml @@ -18,11 +18,9 @@ next_hops: - forward_router_address: 192.0.2.22 tag: 4 - - forward_router_address: 192.0.2.23 route_name: merged_route admin_distance: 1 - - address_families: - afi: ipv4 routes: @@ -30,7 +28,6 @@ next_hops: - forward_router_address: 192.0.2.24 route_name: new_route - - dest: 192.0.2.80/28 next_hops: - forward_router_address: 192.0.2.26 @@ -41,13 +38,12 @@ - ansible.builtin.assert: that: - "result.changed == true" - - "'configure terminal' in result.commands" - "'ip route 192.0.2.16/28 192.0.2.24 name new_route' in result.commands" - "'ip route 192.0.2.80/28 192.0.2.26 tag 12' in result.commands" - "'vrf context trial_vrf' in result.commands" - "'ip route 192.0.2.64/28 192.0.2.22 tag 4' in result.commands" - "'ip route 192.0.2.64/28 192.0.2.23 name merged_route 1' in result.commands" - - "result.commands | length == 6" + - "result.commands | length == 5" - name: Idempotence - merged cisco.nxos.nxos_static_routes: *merged diff --git a/tests/integration/targets/nxos_static_routes/tests/common/overridden.yml b/tests/integration/targets/nxos_static_routes/tests/common/overridden.yml index ae03e947f..e90c3cfbb 100644 --- a/tests/integration/targets/nxos_static_routes/tests/common/overridden.yml +++ b/tests/integration/targets/nxos_static_routes/tests/common/overridden.yml @@ -26,12 +26,11 @@ - forward_router_address: 192.0.2.23 route_name: overridden_route1 admin_distance: 3 - - forward_router_address: 192.0.2.45 route_name: overridden_route2 dest_vrf: destinationVRF interface: "{{ nxos_int2 }}" - + - "{{ var_vrf_mgmt }}" state: overridden register: result @@ -43,10 +42,9 @@ - "'no ip route 192.0.2.64/28 192.0.2.23 name merged_route 1' in result.commands" - "'ip route 192.0.2.16/28 192.0.2.23 name overridden_route1 3' in result.commands" - "'ip route 192.0.2.16/28 {{ nxos_int2 }} 192.0.2.45 vrf destinationVRF name overridden_route2' in result.commands" - - "'configure terminal' in result.commands" - "'no ip route 192.0.2.16/28 192.0.2.24 name new_route' in result.commands" - "'no ip route 192.0.2.80/28 192.0.2.26 tag 12' in result.commands" - - "result.commands | length == 8" + - "result.commands | length == 7" - name: Idempotence - overridden cisco.nxos.nxos_static_routes: *overridden diff --git a/tests/integration/targets/nxos_static_routes/tests/common/parsed.yml b/tests/integration/targets/nxos_static_routes/tests/common/parsed.yml index 32cd5bd83..8590c4e3f 100644 --- a/tests/integration/targets/nxos_static_routes/tests/common/parsed.yml +++ b/tests/integration/targets/nxos_static_routes/tests/common/parsed.yml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: "Start nxos_static_routes parsed tests connection={{ ansible_connection }}" -- name: Parsed +- name: Parsed test cisco.nxos.nxos_static_routes: &parsed running_config: | ip route 192.0.2.16/28 192.0.2.24 name new_route @@ -13,14 +13,8 @@ state: parsed register: result -- ansible.builtin.assert: +- name: Assert parsed test + ansible.builtin.assert: that: - "result.changed == false" - "result.parsed == parsed" - -- name: Idempotence - parsed - cisco.nxos.nxos_static_routes: *parsed - register: result - -- ansible.builtin.assert: - that: "result.changed == false" diff --git a/tests/integration/targets/nxos_static_routes/tests/common/rendered.yml b/tests/integration/targets/nxos_static_routes/tests/common/rendered.yml index 2348a64b6..99581bb11 100644 --- a/tests/integration/targets/nxos_static_routes/tests/common/rendered.yml +++ b/tests/integration/targets/nxos_static_routes/tests/common/rendered.yml @@ -14,7 +14,6 @@ - forward_router_address: 2001:db8::1001 route_name: rendered_route admin_distance: 3 - - address_families: - afi: ipv4 routes: @@ -22,7 +21,6 @@ next_hops: - forward_router_address: 192.0.2.24 route_name: new_route - - dest: 192.0.2.80/28 next_hops: - forward_router_address: 192.0.2.26 @@ -33,12 +31,11 @@ - ansible.builtin.assert: that: - "result.changed == false" - - "'configure terminal' in result.rendered" - "'ip route 192.0.2.16/28 192.0.2.24 name new_route' in result.rendered" - "'ip route 192.0.2.80/28 192.0.2.26 tag 12' in result.rendered" - "'vrf context trial_vrf' in result.rendered" - "'ipv6 route 2001:db8:12::/32 2001:db8::1001 name rendered_route 3' in result.rendered" - - "result.rendered | length == 5" + - "result.rendered | length == 4" - name: Idempotence - rendered nxos_static_routes: *rendered diff --git a/tests/integration/targets/nxos_static_routes/tests/common/replaced.yml b/tests/integration/targets/nxos_static_routes/tests/common/replaced.yml index 73c122198..ca61c48e5 100644 --- a/tests/integration/targets/nxos_static_routes/tests/common/replaced.yml +++ b/tests/integration/targets/nxos_static_routes/tests/common/replaced.yml @@ -23,7 +23,6 @@ - forward_router_address: 192.0.2.23 route_name: replaced_route1 admin_distance: 3 - - forward_router_address: 192.0.2.45 route_name: replaced_route2 dest_vrf: destinationVRF @@ -34,7 +33,6 @@ - ansible.builtin.assert: that: - "result.changed == true" - - "'configure terminal' in result.commands" - "'no ip route 192.0.2.16/28 192.0.2.24 name new_route' in result.commands" - "'ip route 192.0.2.16/28 192.0.2.23 name replaced_route1 3' in result.commands" - "'ip route 192.0.2.16/28 {{ nxos_int2 }} 192.0.2.45 vrf destinationVRF name replaced_route2' in result.commands" diff --git a/tests/integration/targets/nxos_static_routes/tests/common/rtt.yml b/tests/integration/targets/nxos_static_routes/tests/common/rtt.yml index 1ee36a936..24b9fe9cf 100644 --- a/tests/integration/targets/nxos_static_routes/tests/common/rtt.yml +++ b/tests/integration/targets/nxos_static_routes/tests/common/rtt.yml @@ -16,11 +16,9 @@ - forward_router_address: 192.0.2.32 route_name: test_route1 tag: 14 - - forward_router_address: 192.0.2.48 route_name: test_route2 admin_distance: 2 - - vrf: trial_vrf address_families: - afi: ipv4 @@ -51,6 +49,7 @@ - forward_router_address: 192.0.2.55 tag: 1 admin_distance: 1 + - "{{ var_vrf_mgmt }}" state: overridden register: result @@ -58,13 +57,12 @@ ansible.builtin.assert: that: - "result.changed == true" - - "'configure terminal' in result.commands" - "'no ip route 192.0.2.36/30 192.0.2.32 name test_route1 tag 14' in result.commands" - "'no ip route 192.0.2.36/30 192.0.2.48 name test_route2 2'" - "'ip route 192.0.2.44/30 192.0.2.55 tag 1 1' in result.commands" - "'vrf context trial_vrf' in result.commands" - "'no ip route 192.0.2.32/30 192.0.2.105 vrf test_dest_vrf' in result.commands" - - "result.commands | length == 6" + - "result.commands | length == 5" - name: Revert back to base configuration cisco.nxos.nxos_static_routes: diff --git a/tests/integration/targets/nxos_static_routes/vars/main.yml b/tests/integration/targets/nxos_static_routes/vars/main.yml index b0c6d454a..82b180899 100644 --- a/tests/integration/targets/nxos_static_routes/vars/main.yml +++ b/tests/integration/targets/nxos_static_routes/vars/main.yml @@ -1,53 +1,24 @@ -"parsed": - [ - { - "address_families": - [ - { - "afi": "ipv4", - "routes": - [ - { - "dest": "192.0.2.64/28", - "next_hops": - [ - { "forward_router_address": "192.0.2.22", "tag": 4 }, - { - "admin_distance": 1, - "forward_router_address": "192.0.2.23", - "route_name": "merged_route", - }, - ], - }, - ], - }, - ], - "vrf": "trial_vrf", - }, - { - "address_families": - [ - { - "afi": "ipv4", - "routes": - [ - { - "dest": "192.0.2.16/28", - "next_hops": - [ - { - "forward_router_address": "192.0.2.24", - "route_name": "new_route", - }, - ], - }, - { - "dest": "192.0.2.80/28", - "next_hops": - [{ "forward_router_address": "192.0.2.26", "tag": 12 }], - }, - ], - }, - ], - }, - ] +--- +parsed: + - address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.16/28 + next_hops: + - forward_router_address: 192.0.2.24 + route_name: new_route + - dest: 192.0.2.80/28 + next_hops: + - forward_router_address: 192.0.2.26 + tag: 12 + - address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.64/28 + next_hops: + - forward_router_address: 192.0.2.22 + tag: 4 + - admin_distance: 1 + forward_router_address: 192.0.2.23 + route_name: merged_route + vrf: trial_vrf diff --git a/tests/integration/targets/nxos_system/tasks/cli.yaml b/tests/integration/targets/nxos_system/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_system/tasks/cli.yaml +++ b/tests/integration/targets/nxos_system/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_system/tasks/main.yaml b/tests/integration/targets/nxos_system/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_system/tasks/main.yaml +++ b/tests/integration/targets/nxos_system/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_system/tasks/nxapi.yaml b/tests/integration/targets/nxos_system/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_system/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_system/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_system/tests/cli/net_system.yaml b/tests/integration/targets/nxos_system/tests/cli/net_system.yaml deleted file mode 100644 index c26d986f4..000000000 --- a/tests/integration/targets/nxos_system/tests/cli/net_system.yaml +++ /dev/null @@ -1,33 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START nxos cli/net_system.yaml on connection={{ ansible_connection }} - -- name: Setup - cisco.nxos.nxos_config: - lines: - - no ip domain-list ansible.com - - no ip domain-list redhat.com - match: none - -- name: Configure domain_list using platform agnostic module - register: result - ansible.netcommon.net_system: - domain_search: - - ansible.com - - redhat.com - -- ansible.builtin.assert: - that: - - result.changed == true - - "'ip domain-list ansible.com' in result.commands" - - "'ip domain-list redhat.com' in result.commands" - -- name: Setup - cisco.nxos.nxos_config: - lines: - - no ip domain-list ansible.com - - no ip domain-list redhat.com - match: none - -- ansible.builtin.debug: - msg: END nxos cli/net_system.yaml on connection={{ ansible_connection }} diff --git a/tests/integration/targets/nxos_system/tests/common/sanity.yaml b/tests/integration/targets/nxos_system/tests/common/sanity.yaml index c361d173b..ffd325c0b 100644 --- a/tests/integration/targets/nxos_system/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_system/tests/common/sanity.yaml @@ -48,7 +48,7 @@ - ansible.builtin.assert: *id004 - - name: Configure name servers with vrf support + - name: Configure name servers with VRF support register: result cisco.nxos.nxos_system: &id005 name_servers: diff --git a/tests/integration/targets/nxos_system/tests/nxapi/net_system.yaml b/tests/integration/targets/nxos_system/tests/nxapi/net_system.yaml deleted file mode 100644 index 40ae623e8..000000000 --- a/tests/integration/targets/nxos_system/tests/nxapi/net_system.yaml +++ /dev/null @@ -1,34 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START nxos nxapi/net_system.yaml on connection={{ ansible_connection }} - -- name: Setup - ignore_errors: true - cisco.nxos.nxos_config: - lines: - - no ip domain-list ansible.com - - no ip domain-list redhat.com - match: none - -- name: Configure domain_list using platform agnostic module - register: result - ansible.netcommon.net_system: - domain_search: - - ansible.com - - redhat.com - -- ansible.builtin.assert: - that: - - result.changed == true - - "'ip domain-list ansible.com' in result.commands" - - "'ip domain-list redhat.com' in result.commands" - -- name: Setup - cisco.nxos.nxos_config: - lines: - - no ip domain-list ansible.com - - no ip domain-list redhat.com - match: none - -- ansible.builtin.debug: - msg: END nxos nxapi/net_system.yaml on connection={{ ansible_connection }} diff --git a/tests/integration/targets/nxos_telemetry/tasks/cli.yaml b/tests/integration/targets/nxos_telemetry/tasks/cli.yaml index 959a86621..d3d521f2a 100644 --- a/tests/integration/targets/nxos_telemetry/tasks/cli.yaml +++ b/tests/integration/targets/nxos_telemetry/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,7 +22,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_telemetry/tasks/main.yaml b/tests/integration/targets/nxos_telemetry/tasks/main.yaml index 486d1f83b..cb0d40859 100644 --- a/tests/integration/targets/nxos_telemetry/tasks/main.yaml +++ b/tests/integration/targets/nxos_telemetry/tasks/main.yaml @@ -18,13 +18,13 @@ commands: show interface mgmt 0 | json register: result -- name: Store mgmt interface ip address +- name: Store mgmt interface IP address ansible.builtin.set_fact: mgmt0_ip: "{{ result['stdout'][0]['TABLE_interface']['ROW_interface']['eth_ip_addr'] }}" - name: Generate and store random password for temp user ansible.builtin.set_fact: - temp_passwd: "{{ lookup('password', 'length=15 chars=ascii_letters') }}" + temp_passwd: "{{ lookup('password', '/dev/null length=15 chars=ascii_letters') }}" delegate_to: localhost no_log: true @@ -34,7 +34,7 @@ configured_password: "{{ temp_passwd }}" no_log: true -- name: Setup - turn on feature scp-server +- name: Setup - turn on 'feature scp-server' cisco.nxos.nxos_feature: feature: scp-server state: enabled @@ -58,7 +58,7 @@ cisco.nxos.nxos_file_copy: local_file: "{{ role_path }}/tests/common/fixtures/{{ item }}" file_system: "bootflash:" - connect_ssh_port: "{{ ansible_ssh_port|d(22) }}" + connect_ssh_port: "{{ ansible_ssh_port | d(22) }}" loop: - server.crt - new_server.crt @@ -66,13 +66,14 @@ vars: ansible_connection: ansible.netcommon.network_cli -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: cli when: run_test - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: nxapi when: run_test @@ -82,13 +83,13 @@ name: temp_user state: absent - - name: Turn off feature scp-server + - name: Turn off 'feature scp-server' cisco.nxos.nxos_feature: feature: scp-server state: disabled - name: Setup - remove existing file - ignore_errors: true + ignore_errors: true # noqa ignore-errors cisco.nxos.nxos_command: commands: - terminal dont-ask diff --git a/tests/integration/targets/nxos_telemetry/tasks/nxapi.yaml b/tests/integration/targets/nxos_telemetry/tasks/nxapi.yaml index c5f0e9199..5fec0f43b 100644 --- a/tests/integration/targets/nxos_telemetry/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_telemetry/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,7 +22,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_telemetry/tests/common/deleted.yaml b/tests/integration/targets/nxos_telemetry/tests/common/deleted.yaml index 4c2aacd2e..3c9556b92 100644 --- a/tests/integration/targets/nxos_telemetry/tests/common/deleted.yaml +++ b/tests/integration/targets/nxos_telemetry/tests/common/deleted.yaml @@ -65,7 +65,7 @@ data_source: NX-API path: name: '"show bgp l2vpn evpn summary"' - depth: 00 + depth: 0 query_condition: foo filter_condition: foo @@ -81,7 +81,7 @@ data_source: DME path: name: sys/bgp/inst/dom-default/peer-[10.10.10.11]/ent-[10.10.10.11] - depth: 00 + depth: 0 query_condition: foo filter_condition: foo @@ -89,7 +89,7 @@ data_source: DME path: name: sys/ospf - depth: 00 + depth: 0 query_condition: foo filter_condition: or(eq(ethpmPhysIf.operSt,"down"),eq(ethpmPhysIf.operSt,"up")) subscriptions: diff --git a/tests/integration/targets/nxos_telemetry/tests/common/merged.yaml b/tests/integration/targets/nxos_telemetry/tests/common/merged.yaml index 384156c92..37109e9ee 100644 --- a/tests/integration/targets/nxos_telemetry/tests/common/merged.yaml +++ b/tests/integration/targets/nxos_telemetry/tests/common/merged.yaml @@ -75,7 +75,7 @@ data_source: NX-API path: name: '"show bgp l2vpn evpn summary"' - depth: 00 + depth: 0 query_condition: foo filter_condition: foo @@ -91,7 +91,7 @@ data_source: DME path: name: sys/bgp/inst/dom-default/peer-[10.10.10.11]/ent-[10.10.10.11] - depth: 00 + depth: 0 query_condition: foo filter_condition: foo @@ -99,7 +99,7 @@ data_source: DME path: name: sys/ospf - depth: 00 + depth: 0 query_condition: foo filter_condition: or(eq(ethpmPhysIf.operSt,"down"),eq(ethpmPhysIf.operSt,"up")) subscriptions: @@ -226,7 +226,7 @@ data_source: NX-API path: name: '"show bgp l2vpn evpn summary"' - depth: 00 + depth: 0 query_condition: foo filter_condition: foo @@ -242,7 +242,7 @@ data_source: DME path: name: sys/bgp/inst/dom-default/peer-[10.10.10.11]/ent-[10.10.10.11] - depth: 00 + depth: 0 query_condition: foo filter_condition: foo @@ -250,7 +250,7 @@ data_source: DME path: name: sys/ospf - depth: 00 + depth: 0 query_condition: foo filter_condition: or(eq(ethpmPhysIf.operSt,"down"),eq(ethpmPhysIf.operSt,"up")) subscriptions: diff --git a/tests/integration/targets/nxos_telemetry/tests/common/replaced.yaml b/tests/integration/targets/nxos_telemetry/tests/common/replaced.yaml index 679463a28..e3b6ce0fc 100644 --- a/tests/integration/targets/nxos_telemetry/tests/common/replaced.yaml +++ b/tests/integration/targets/nxos_telemetry/tests/common/replaced.yaml @@ -25,22 +25,22 @@ dict_facts_length: 7 when: imagetag and (major_version is version_compare('9.1', 'ge')) -- name: Setup - disable feature telemetry +- name: Setup - disable 'feature telemetry' ignore_errors: true cisco.nxos.nxos_feature: &id003 feature: telemetry state: disabled -- name: Setup - enable feature telemetry +- name: Setup - enable 'feature telemetry' cisco.nxos.nxos_feature: feature: telemetry state: enabled -- name: Setup - add initial telemetry config +- name: Setup - add initial telemetry configuration cisco.nxos.nxos_config: src: populate_config.cfg -- name: Setup - add initial source-interface telemetry config +- name: Setup - add initial source-interface telemetry configuration when: imagetag and (major_version is version_compare('9.1', 'ge')) cisco.nxos.nxos_config: lines: diff --git a/tests/integration/targets/nxos_telemetry/vars/main.yaml b/tests/integration/targets/nxos_telemetry/vars/main.yaml index fa3a93dd1..92825d4df 100644 --- a/tests/integration/targets/nxos_telemetry/vars/main.yaml +++ b/tests/integration/targets/nxos_telemetry/vars/main.yaml @@ -1,3 +1,4 @@ +--- gathered: destination_groups: - destination: diff --git a/tests/integration/targets/nxos_udld/tasks/cli.yaml b/tests/integration/targets/nxos_udld/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_udld/tasks/cli.yaml +++ b/tests/integration/targets/nxos_udld/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_udld/tasks/main.yaml b/tests/integration/targets/nxos_udld/tasks/main.yaml index 7631f52fe..c9e70304e 100644 --- a/tests/integration/targets/nxos_udld/tasks/main.yaml +++ b/tests/integration/targets/nxos_udld/tasks/main.yaml @@ -1,11 +1,12 @@ --- -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli always: - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_udld/tasks/nxapi.yaml b/tests/integration/targets/nxos_udld/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_udld/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_udld/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_udld/tests/common/sanity.yaml b/tests/integration/targets/nxos_udld/tests/common/sanity.yaml index e24c40973..114792d0a 100644 --- a/tests/integration/targets/nxos_udld/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_udld/tests/common/sanity.yaml @@ -17,7 +17,7 @@ when: titanium - block: - - name: Enable feature udld + - name: Enable 'feature udld' cisco.nxos.nxos_feature: feature: udld state: enabled @@ -76,7 +76,7 @@ - ansible.builtin.assert: *id002 - - name: Remove udld config + - name: Remove udld configuration register: result cisco.nxos.nxos_udld: &id006 state: absent diff --git a/tests/integration/targets/nxos_udld_interface/tasks/cli.yaml b/tests/integration/targets/nxos_udld_interface/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_udld_interface/tasks/cli.yaml +++ b/tests/integration/targets/nxos_udld_interface/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_udld_interface/tasks/main.yaml b/tests/integration/targets/nxos_udld_interface/tasks/main.yaml index 7631f52fe..c9e70304e 100644 --- a/tests/integration/targets/nxos_udld_interface/tasks/main.yaml +++ b/tests/integration/targets/nxos_udld_interface/tasks/main.yaml @@ -1,11 +1,12 @@ --- -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli always: - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_udld_interface/tasks/nxapi.yaml b/tests/integration/targets/nxos_udld_interface/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_udld_interface/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_udld_interface/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_udld_interface/tests/common/sanity.yaml b/tests/integration/targets/nxos_udld_interface/tests/common/sanity.yaml index 549e3acd5..9ad5f697e 100644 --- a/tests/integration/targets/nxos_udld_interface/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_udld_interface/tests/common/sanity.yaml @@ -30,7 +30,7 @@ intname: "{{ nxos_int1 }}" - block: - - name: Enable feature udld + - name: Enable 'feature udld' cisco.nxos.nxos_feature: feature: udld state: enabled @@ -104,7 +104,7 @@ - assert: *id004 when: udld_enable - - name: Remove the config + - name: Remove the configuration cisco.nxos.nxos_udld_interface: interface: "{{ intname }}" mode: enabled diff --git a/tests/integration/targets/nxos_user/tasks/cli.yaml b/tests/integration/targets/nxos_user/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_user/tasks/cli.yaml +++ b/tests/integration/targets/nxos_user/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_user/tasks/main.yaml b/tests/integration/targets/nxos_user/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_user/tasks/main.yaml +++ b/tests/integration/targets/nxos_user/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_user/tasks/nxapi.yaml b/tests/integration/targets/nxos_user/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_user/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_user/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_user/tests/common/auth.yaml b/tests/integration/targets/nxos_user/tests/common/auth.yaml index f092eeaa3..99903b6bc 100644 --- a/tests/integration/targets/nxos_user/tests/common/auth.yaml +++ b/tests/integration/targets/nxos_user/tests/common/auth.yaml @@ -9,16 +9,24 @@ - name: Test login ansible.builtin.expect: - command: - ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o PubkeyAuthentication=no + command: >- + ssh auth_user@{{ ansible_ssh_host }} + -p {{ ansible_ssh_port|default(22) }} + -o UserKnownHostsFile=/dev/null + -o StrictHostKeyChecking=no + -o PubkeyAuthentication=no show version responses: (?i)password: pasS!123 - name: Test login with invalid password (should fail) ansible.builtin.expect: - command: - ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o PubkeyAuthentication=no + command: >- + ssh auth_user@{{ ansible_ssh_host }} + -p {{ ansible_ssh_port|default(22) }} + -o UserKnownHostsFile=/dev/null + -o StrictHostKeyChecking=no + -o PubkeyAuthentication=no show version responses: (?i)password: badpass diff --git a/tests/integration/targets/nxos_user/tests/common/net_user.yaml b/tests/integration/targets/nxos_user/tests/common/net_user.yaml deleted file mode 100644 index ab5f95009..000000000 --- a/tests/integration/targets/nxos_user/tests/common/net_user.yaml +++ /dev/null @@ -1,29 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos common/net_user.yaml - -- name: Remove old entries of user - setup - ansible.netcommon.net_user: - name: ansibletest1 - state: absent - -- name: Create user with platform agnostic module - register: result - ansible.netcommon.net_user: - name: ansibletest1 - roles: network-operator - state: present - -- ansible.builtin.assert: - that: - - result.changed == true - - '"username" in result.commands[0]' - - '"role network-operator" in result.commands[0]' - -- name: Teardown - ansible.netcommon.net_user: - name: ansibletest1 - state: absent - -- ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos common/net_user.yaml diff --git a/tests/integration/targets/nxos_vlan/defaults/main.yaml b/tests/integration/targets/nxos_vlan/defaults/main.yaml deleted file mode 100644 index 5f709c5aa..000000000 --- a/tests/integration/targets/nxos_vlan/defaults/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -testcase: "*" diff --git a/tests/integration/targets/nxos_vlan/meta/main.yml b/tests/integration/targets/nxos_vlan/meta/main.yml deleted file mode 100644 index f504a6ab2..000000000 --- a/tests/integration/targets/nxos_vlan/meta/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_nxos_tests diff --git a/tests/integration/targets/nxos_vlan/tasks/cli.yaml b/tests/integration/targets/nxos_vlan/tasks/cli.yaml deleted file mode 100644 index 90342e6b1..000000000 --- a/tests/integration/targets/nxos_vlan/tasks/cli.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect cli test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - connection: local - register: cli_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + cli_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.network_cli) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_vlan/tasks/main.yaml b/tests/integration/targets/nxos_vlan/tasks/main.yaml deleted file mode 100644 index 62e44ffda..000000000 --- a/tests/integration/targets/nxos_vlan/tasks/main.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Include the cli tasks - ansible.builtin.include_tasks: cli.yaml - tags: - - cli - -- name: Include the nx-api tasks - ansible.builtin.include_tasks: nxapi.yaml - tags: - - nxapi diff --git a/tests/integration/targets/nxos_vlan/tasks/nxapi.yaml b/tests/integration/targets/nxos_vlan/tasks/nxapi.yaml deleted file mode 100644 index cedab80f1..000000000 --- a/tests/integration/targets/nxos_vlan/tasks/nxapi.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Collect common test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/common" - patterns: "{{ testcase }}.yaml" - connection: local - register: test_cases - -- name: Collect nxapi test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/nxapi" - patterns: "{{ testcase }}.yaml" - connection: local - register: nxapi_cases - -- name: Set a fact for 'test_cases' - ansible.builtin.set_fact: - test_cases: - files: "{{ test_cases.files + nxapi_cases.files }}" - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test cases (connection=ansible.netcommon.httpapi) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - vars: - ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_vlan/tests/common/agg.yaml b/tests/integration/targets/nxos_vlan/tests/common/agg.yaml deleted file mode 100644 index aefb383f2..000000000 --- a/tests/integration/targets/nxos_vlan/tests/common/agg.yaml +++ /dev/null @@ -1,122 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }}/agg.yaml - -- name: Setup - remove vlan used in test - ignore_errors: true - cisco.nxos.nxos_config: &id005 - lines: - - no vlan 102 - - no vlan 103 - - no vlan 104 - -- name: Configure vlan with aggregate - register: result - cisco.nxos.nxos_vlan: &id001 - aggregate: - - name: app02 - vlan_id: 102 - - - name: app03 - vlan_id: 103 - vlan_state: active - admin_state: up - -- ansible.builtin.assert: - that: - - result.changed == true - - '"vlan 102" in result.commands' - - '"vlan 103" in result.commands' - - '"no shutdown" in result.commands' - - '"state active" in result.commands' - -- name: Conf1 - idempotence - register: result - cisco.nxos.nxos_vlan: *id001 - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Change property of existing vlan - admin_state down - register: result - cisco.nxos.nxos_vlan: &id002 - aggregate: - - name: app02 - vlan_id: 102 - - - name: app03 - vlan_id: 103 - vlan_state: active - admin_state: down - -- ansible.builtin.assert: - that: - - result.changed == true - - '"vlan 102" in result.commands' - - '"vlan 103" in result.commands' - - '"shutdown" in result.commands' - -- name: Conf2 - idempotence - register: result - cisco.nxos.nxos_vlan: *id002 - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Purge - register: result - cisco.nxos.nxos_vlan: &id003 - vlan_id: 1 - purge: true - -- ansible.builtin.assert: - that: - - result.changed == true - - '"no vlan 102" in result.commands' - - '"no vlan 103" in result.commands' - -- name: Purge - idempotence - register: result - cisco.nxos.nxos_vlan: *id003 - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Setup for purge test with aggregate add - cisco.nxos.nxos_vlan: - vlan_id: 104 - purge: true - -- name: Purge 104 with aggregate add 102-103 - register: result - cisco.nxos.nxos_vlan: &id004 - aggregate: - - vlan_id: 102 - - - vlan_id: 103 - purge: true - -- ansible.builtin.assert: - that: - - result.changed == true - - '"vlan 102" in result.commands' - - '"vlan 103" in result.commands' - - '"no vlan 104" in result.commands' - -- name: Purge_add - idempotence - register: result - cisco.nxos.nxos_vlan: *id004 - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Teardown - ignore_errors: true - cisco.nxos.nxos_config: *id005 - -- ansible.builtin.debug: - msg: END connection={{ ansible_connection }}/agg.yaml diff --git a/tests/integration/targets/nxos_vlan/tests/common/interface.yaml b/tests/integration/targets/nxos_vlan/tests/common/interface.yaml deleted file mode 100644 index 1e6fdc7fa..000000000 --- a/tests/integration/targets/nxos_vlan/tests/common/interface.yaml +++ /dev/null @@ -1,129 +0,0 @@ ---- -- name: Set a fact for 'testint1' - ansible.builtin.set_fact: - testint1: "{{ nxos_int1 }}" - -- name: Set a fact for 'testint2' - ansible.builtin.set_fact: - testint2: "{{ nxos_int2 }}" - -- name: Setup - remove vlan used in test - ignore_errors: true - cisco.nxos.nxos_config: - lines: - - no vlan 100 - -- name: Setup - remove vlan from interfaces used in test(part1) - cisco.nxos.nxos_config: - lines: - - no switchport access vlan 100 - parents: switchport - before: interface {{ testint1 }} - -- name: Setup - remove vlan from interfaces used in test(part2) - cisco.nxos.nxos_config: - lines: - - no switchport access vlan 100 - parents: switchport - before: interface {{ testint2 }} - -- name: Create vlan - cisco.nxos.nxos_vlan: - vlan_id: 100 - -- name: Add interfaces to vlan and check intent (config + intent) - register: result - cisco.nxos.nxos_vlan: &id001 - vlan_id: 100 - interfaces: - - "{{ testint1 }}" - - "{{ testint2 }}" - associated_interfaces: - - "{{ testint1 }}" - - "{{ testint2 }}" - -- ansible.builtin.assert: - that: - - result.changed == true - - '"interface {{ testint1 }}" in result.commands' - - '"switchport" in result.commands' - - '"switchport mode access" in result.commands' - - '"switchport access vlan 100" in result.commands' - - '"interface {{ testint2 }}" in result.commands' - - '"switchport" in result.commands' - - '"switchport mode access" in result.commands' - - '"switchport access vlan 100" in result.commands' - -- name: Add interfaces to vlan(idempotence) - register: result - cisco.nxos.nxos_vlan: *id001 - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Check interfaces intent - register: result - cisco.nxos.nxos_vlan: - vlan_id: 100 - associated_interfaces: - - "{{ testint1 }}" - - "{{ testint2 }}" - -- ansible.builtin.assert: - that: - - result.failed == false - -- name: Check interfaces intent fail - register: result - ignore_errors: true - cisco.nxos.nxos_vlan: - vlan_id: 100 - associated_interfaces: - - test - -- ansible.builtin.assert: - that: - - result.failed == True - -- name: Remove interface from vlan - register: result - cisco.nxos.nxos_vlan: &id002 - vlan_id: 100 - interfaces: - - "{{ testint2 }}" - -- ansible.builtin.assert: - that: - - result.changed == true - - '"interface {{ testint1 }}" in result.commands' - - '"switchport" in result.commands' - - '"switchport mode access" in result.commands' - - '"no switchport access vlan 100" in result.commands' - -- name: Remove interface from vlan(idempotence) - register: result - cisco.nxos.nxos_vlan: *id002 - -- ansible.builtin.assert: - that: - - result.changed == false - -- name: Teardown(part1) - cisco.nxos.nxos_config: - lines: - - no vlan 100 - -- name: Teardown - remove vlan from interfaces used in test(part1) - cisco.nxos.nxos_config: - lines: - - no switchport access vlan 100 - parents: switchport - before: interface {{ testint1 }} - -- name: Teardown - remove vlan from interfaces used in test(part2) - cisco.nxos.nxos_config: - lines: - - no switchport access vlan 100 - parents: switchport - before: interface {{ testint2 }} diff --git a/tests/integration/targets/nxos_vlan/tests/common/sanity.yaml b/tests/integration/targets/nxos_vlan/tests/common/sanity.yaml deleted file mode 100644 index db260a1f0..000000000 --- a/tests/integration/targets/nxos_vlan/tests/common/sanity.yaml +++ /dev/null @@ -1,230 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START connection={{ ansible_connection }} nxos_vlan sanity test - -- name: Set a fact for 'testint1' - ansible.builtin.set_fact: - testint1: "{{ nxos_int1 }}" - -- name: Set a fact for 'testint2' - ansible.builtin.set_fact: - testint2: "{{ nxos_int2 }}" - -- block: - - name: Install and enable fabricpath feature set - when: platform is search('N5K|N7K') - cisco.nxos.nxos_config: - lines: - - install feature-set fabricpath - - feature-set fabricpath - - - name: Enable feature vn segment - when: platform is search('N9K') - cisco.nxos.nxos_config: - commands: - - feature vn-segment-vlan-based - match: none - - - name: Vlan teardown - ignore_errors: true - cisco.nxos.nxos_vlan: &id013 - vlan_range: 2-200 - state: absent - - - name: Ensure a range of vlans are present on the switch - register: result - cisco.nxos.nxos_vlan: &id001 - vlan_range: 2-10,20,50,55-60,100-150 - - - ansible.builtin.assert: &id002 - that: - - result.changed == true - - - name: Vlan idempotence - register: result - cisco.nxos.nxos_vlan: *id001 - - - ansible.builtin.assert: &id004 - that: - - result.changed == false - - - name: Ensure vlan 50 exists with the name web and is in the shutdown state - register: result - when: platform is search('N9K') - cisco.nxos.nxos_vlan: &id003 - vlan_id: 50 - vlan_state: suspend - admin_state: down - name: WEB - mapped_vni: 5555 - - - ansible.builtin.assert: *id002 - when: platform is search('N9K') - - - name: Web1 idempotence - register: result - when: platform is search('N9K') - cisco.nxos.nxos_vlan: *id003 - - - ansible.builtin.assert: *id004 - when: platform is search('N9K') - - - name: Change name and vni to default - register: result - when: platform is search('N9K') - cisco.nxos.nxos_vlan: &id005 - vlan_id: 50 - vlan_state: active - admin_state: up - name: default - mapped_vni: default - - - ansible.builtin.assert: *id002 - when: platform is search('N9K') - - - name: Web2 idempotence - register: result - when: platform is search('N9K') - cisco.nxos.nxos_vlan: *id005 - - - ansible.builtin.assert: *id004 - when: platform is search('N9K') - - - name: Ensure vlan 50 exists with the name web and is in the shutdown state - register: result - when: platform is search('N3K|N7K') - cisco.nxos.nxos_vlan: &id006 - vlan_id: 50 - vlan_state: suspend - admin_state: down - name: WEB - - - ansible.builtin.assert: *id002 - when: platform is search('N3K|N7K') - - - name: Web3 idempotence - register: result - when: platform is search('N3K|N7K') - cisco.nxos.nxos_vlan: *id006 - - - ansible.builtin.assert: *id004 - when: platform is search('N3K|N7K') - - - name: Change name to default - register: result - when: platform is search('N3K|N7K') - cisco.nxos.nxos_vlan: &id007 - vlan_id: 50 - vlan_state: active - admin_state: up - name: default - - - ansible.builtin.assert: *id002 - when: platform is search('N3K|N7K') - - - name: Web4 idempotence - register: result - when: platform is search('N3K|N7K') - cisco.nxos.nxos_vlan: *id007 - - - ansible.builtin.assert: *id004 - when: platform is search('N3K|N7K') - - - name: Change mode - register: result - when: platform is search('N5K|N7K') - cisco.nxos.nxos_vlan: &id008 - vlan_id: 50 - mode: fabricpath - - - ansible.builtin.assert: *id002 - when: platform is search('N5K|N7K') - - - name: Mode1 idempotence - register: result - when: platform is search('N5K|N7K') - cisco.nxos.nxos_vlan: *id008 - - - ansible.builtin.assert: *id004 - when: platform is search('N5K|N7K') - - - name: Change mode again - register: result - when: platform is search('N5K|N7K') - cisco.nxos.nxos_vlan: &id009 - vlan_id: 50 - mode: ce - - - ansible.builtin.assert: *id002 - when: platform is search('N5K|N7K') - - - name: Mode2 idempotence - register: result - when: platform is search('N5K|N7K') - cisco.nxos.nxos_vlan: *id009 - - - ansible.builtin.assert: *id004 - when: platform is search('N5K|N7K') - - - name: Ensure vlan is not on the device - register: result - cisco.nxos.nxos_vlan: &id010 - vlan_id: 50 - state: absent - - - ansible.builtin.assert: *id002 - - - name: No vlan idempotence - register: result - cisco.nxos.nxos_vlan: *id010 - - - ansible.builtin.assert: *id004 - - - name: Add interfaces to vlan - register: result - cisco.nxos.nxos_vlan: &id011 - vlan_id: 101 - vlan_state: suspend - interfaces: - - "{{ testint1 }}" - - "{{ testint2 }}" - - - ansible.builtin.assert: *id002 - - - name: Addint idempotence - register: result - cisco.nxos.nxos_vlan: *id011 - - - ansible.builtin.assert: *id004 - - - name: Remove interfaces from vlan - register: result - cisco.nxos.nxos_vlan: &id012 - vlan_id: 101 - interfaces: default - - - ansible.builtin.assert: *id002 - - - name: Remint idempotence - register: result - cisco.nxos.nxos_vlan: *id012 - - - ansible.builtin.assert: *id004 - always: - - name: Remove int from vlan - ignore_errors: true - cisco.nxos.nxos_vlan: *id012 - - - name: Vlan teardown final - ignore_errors: true - cisco.nxos.nxos_vlan: *id013 - - - name: Disable feature vn segement - ignore_errors: true - when: platform is search('N9K') - cisco.nxos.nxos_feature: - feature: vn-segment-vlan-based - state: disabled - -- ansible.builtin.debug: - msg: END connection={{ ansible_connection }} nxos_vlan sanity test diff --git a/tests/integration/targets/nxos_vlans/tasks/cli.yaml b/tests/integration/targets/nxos_vlans/tasks/cli.yaml index 507d803cb..e3e64747b 100644 --- a/tests/integration/targets/nxos_vlans/tasks/cli.yaml +++ b/tests/integration/targets/nxos_vlans/tasks/cli.yaml @@ -7,7 +7,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -23,7 +23,7 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: diff --git a/tests/integration/targets/nxos_vlans/tasks/main.yaml b/tests/integration/targets/nxos_vlans/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_vlans/tasks/main.yaml +++ b/tests/integration/targets/nxos_vlans/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_vlans/tasks/nxapi.yaml b/tests/integration/targets/nxos_vlans/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_vlans/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_vlans/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_vlans/tests/common/_populate_config.yaml b/tests/integration/targets/nxos_vlans/tests/common/_populate_config.yaml index 6a991317b..63d297e15 100644 --- a/tests/integration/targets/nxos_vlans/tests/common/_populate_config.yaml +++ b/tests/integration/targets/nxos_vlans/tests/common/_populate_config.yaml @@ -1,5 +1,5 @@ --- -- name: Populate config +- name: Populate configuration cisco.nxos.nxos_config: lines: - "feature vn-segment-vlan-based" diff --git a/tests/integration/targets/nxos_vlans/tests/common/_remove_config.yaml b/tests/integration/targets/nxos_vlans/tests/common/_remove_config.yaml index 7f0413d30..0fc5ff730 100644 --- a/tests/integration/targets/nxos_vlans/tests/common/_remove_config.yaml +++ b/tests/integration/targets/nxos_vlans/tests/common/_remove_config.yaml @@ -1,5 +1,5 @@ --- -- name: Remove config +- name: Remove configuration cisco.nxos.nxos_config: lines: - "no vlan 2-100" diff --git a/tests/integration/targets/nxos_vlans/tests/common/empty_config.yaml b/tests/integration/targets/nxos_vlans/tests/common/empty_config.yaml index a9275a39e..1f8b10420 100644 --- a/tests/integration/targets/nxos_vlans/tests/common/empty_config.yaml +++ b/tests/integration/targets/nxos_vlans/tests/common/empty_config.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START nxos_vlans empty_config integration tests on connection={{ ansible_connection }} -- name: Merged with empty config should give appropriate error message +- name: Merged with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_vlans: @@ -13,7 +13,7 @@ that: - result.msg == 'value of config parameter must not be empty for state merged' -- name: Replaced with empty config should give appropriate error message +- name: Replaced with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_vlans: @@ -24,7 +24,7 @@ that: - result.msg == 'value of config parameter must not be empty for state replaced' -- name: Overridden with empty config should give appropriate error message +- name: Overridden with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_vlans: @@ -35,7 +35,7 @@ that: - result.msg == 'value of config parameter must not be empty for state overridden' -- name: Rendered with empty config should give appropriate error message +- name: Rendered with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_vlans: @@ -46,7 +46,7 @@ that: - result.msg == 'value of config parameter must not be empty for state rendered' -- name: Parsed with empty config should give appropriate error message +- name: Parsed with empty configuration should give appropriate error message register: result ignore_errors: true cisco.nxos.nxos_vlans: diff --git a/tests/integration/targets/nxos_vlans/tests/common/overridden.yaml b/tests/integration/targets/nxos_vlans/tests/common/overridden.yaml index f2c7c9f9f..386907949 100644 --- a/tests/integration/targets/nxos_vlans/tests/common/overridden.yaml +++ b/tests/integration/targets/nxos_vlans/tests/common/overridden.yaml @@ -23,7 +23,7 @@ - "!min" gather_network_resources: vlans - - name: Set default vlan (vlan1) config and config to revert + - name: Set default VLAN (vlan1) configuration and configuration to revert ansible.builtin.set_fact: default_vlan: "{{ ansible_facts.network_resources.vlans|selectattr('vlan_id', 'equalto', 1)|list }}" config_to_override: diff --git a/tests/integration/targets/nxos_vlans/tests/common/parsed.yaml b/tests/integration/targets/nxos_vlans/tests/common/parsed.yaml index 306f5f8ce..4bb03d422 100644 --- a/tests/integration/targets/nxos_vlans/tests/common/parsed.yaml +++ b/tests/integration/targets/nxos_vlans/tests/common/parsed.yaml @@ -3,7 +3,7 @@ msg: START nxos_vlans parsed integration tests on connection={{ ansible_connection }} - block: - - name: Use parsed state to convert externally supplied config to structured format + - name: Use parsed state to convert externally supplied configuration to structured format register: result cisco.nxos.nxos_vlans: running_config: "{{ lookup('file', '{{ role_path }}/fixtures/parsed.cfg') }}" diff --git a/tests/integration/targets/nxos_vlans/tests/common/rtt.yaml b/tests/integration/targets/nxos_vlans/tests/common/rtt.yaml index 17e335127..fc5a66043 100644 --- a/tests/integration/targets/nxos_vlans/tests/common/rtt.yaml +++ b/tests/integration/targets/nxos_vlans/tests/common/rtt.yaml @@ -27,7 +27,7 @@ gather_network_resources: - "vlans" - - name: Set default vlan (vlan1) config and config to revert + - name: Set default VLAN (vlan1) configuration and configuration to revert ansible.builtin.set_fact: default_vlan: "{{ ansible_facts.network_resources.vlans|selectattr('vlan_id', 'equalto', 1)|list }}" config_to_revert: @@ -49,7 +49,7 @@ that: - result.changed == true - - name: Revert back to base config using facts round trip + - name: Revert back to base configuration using facts round trip register: revert cisco.nxos.nxos_vlans: config: "{{ ansible_facts['network_resources']['vlans'] }}" diff --git a/tests/integration/targets/nxos_vlans/vars/main.yml b/tests/integration/targets/nxos_vlans/vars/main.yml index ff08ef416..8e7fb87b8 100644 --- a/tests/integration/targets/nxos_vlans/vars/main.yml +++ b/tests/integration/targets/nxos_vlans/vars/main.yml @@ -1,23 +1,24 @@ +--- gathered: - vlan_id: 1 - enabled: True + enabled: true mode: "ce" state: active name: default - vlan_id: 5 - enabled: True + enabled: true mode: "ce" name: "vlan5" state: suspend - vlan_id: 6 - enabled: True + enabled: true mode: "ce" state: active - vlan_id: 7 - enabled: False + enabled: false mode: "ce" name: "vlan7" state: active @@ -25,24 +26,24 @@ gathered: parsed: - vlan_id: 1 - enabled: True + enabled: true mode: "ce" state: active name: default - vlan_id: 5 - enabled: True + enabled: true mode: "ce" name: "vlan5" state: suspend - vlan_id: 6 - enabled: True + enabled: true mode: "ce" state: active - vlan_id: 7 - enabled: True + enabled: true mode: "ce" name: "vlan7" state: active diff --git a/tests/integration/targets/nxos_vpc/tasks/cli.yaml b/tests/integration/targets/nxos_vpc/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_vpc/tasks/cli.yaml +++ b/tests/integration/targets/nxos_vpc/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_vpc/tasks/main.yaml b/tests/integration/targets/nxos_vpc/tasks/main.yaml index 7631f52fe..c9e70304e 100644 --- a/tests/integration/targets/nxos_vpc/tasks/main.yaml +++ b/tests/integration/targets/nxos_vpc/tasks/main.yaml @@ -1,11 +1,12 @@ --- -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli always: - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_vpc/tasks/nxapi.yaml b/tests/integration/targets/nxos_vpc/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_vpc/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_vpc/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_vpc/tests/common/sanity.yaml b/tests/integration/targets/nxos_vpc/tests/common/sanity.yaml index 5ca2998c4..fb073afb3 100644 --- a/tests/integration/targets/nxos_vpc/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_vpc/tests/common/sanity.yaml @@ -13,17 +13,17 @@ when: platform is not search("N35|N5K|N6K") - block: - - name: Disable vpc for initial vpc config cleanup + - name: Disable vpc for initial vpc configuration cleanup cisco.nxos.nxos_feature: feature: vpc state: disabled - - name: Enable feature vpc + - name: Enable 'feature vpc' cisco.nxos.nxos_feature: feature: vpc state: enabled - - name: Ensure ntc vrf exists on switch + - name: Ensure NTC VRF exists on switch cisco.nxos.nxos_vrf: vrf: ntc @@ -40,7 +40,7 @@ that: - result.changed == true - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_vpc: *id001 @@ -62,7 +62,7 @@ - ansible.builtin.assert: *id002 - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_vpc: *id003 @@ -111,7 +111,7 @@ - ansible.builtin.assert: *id002 - - name: Conf idempotence auto-recovery reload-delay + - name: Configure idempotence auto-recovery reload-delay register: result cisco.nxos.nxos_vpc: *id007 @@ -131,7 +131,7 @@ - ansible.builtin.assert: *id002 - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_vpc: *id008 @@ -146,7 +146,7 @@ - ansible.builtin.assert: *id002 - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_vpc: *id009 @@ -166,13 +166,13 @@ - ansible.builtin.assert: *id004 always: - - name: Remove vrf + - name: Remove VRF ignore_errors: true cisco.nxos.nxos_vrf: vrf: ntc state: absent - - name: Disable feature vpc + - name: Disable 'feature vpc' ignore_errors: true cisco.nxos.nxos_feature: feature: vpc diff --git a/tests/integration/targets/nxos_vpc_interface/tasks/cli.yaml b/tests/integration/targets/nxos_vpc_interface/tasks/cli.yaml index 90342e6b1..988ef2894 100644 --- a/tests/integration/targets/nxos_vpc_interface/tasks/cli.yaml +++ b/tests/integration/targets/nxos_vpc_interface/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_vpc_interface/tasks/main.yaml b/tests/integration/targets/nxos_vpc_interface/tasks/main.yaml index 7631f52fe..c9e70304e 100644 --- a/tests/integration/targets/nxos_vpc_interface/tasks/main.yaml +++ b/tests/integration/targets/nxos_vpc_interface/tasks/main.yaml @@ -1,11 +1,12 @@ --- -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli always: - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_vpc_interface/tasks/nxapi.yaml b/tests/integration/targets/nxos_vpc_interface/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_vpc_interface/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_vpc_interface/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_vpc_interface/tests/common/sanity.yaml b/tests/integration/targets/nxos_vpc_interface/tests/common/sanity.yaml index e51ddf92c..e74930c73 100644 --- a/tests/integration/targets/nxos_vpc_interface/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_vpc_interface/tests/common/sanity.yaml @@ -3,7 +3,7 @@ msg: START connection={{ ansible_connection }} nxos_vpc_interface sanity test - block: - - name: Enable feature vpc + - name: Enable 'feature vpc' cisco.nxos.nxos_feature: feature: vpc state: enabled @@ -43,7 +43,7 @@ that: - result.changed == true - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_vpc_interface: *id001 @@ -61,7 +61,7 @@ - ansible.builtin.assert: *id002 when: image_version != "7.0(3)I5(1)" - - name: Conf idempotence + - name: Configure idempotence register: result when: image_version != "7.0(3)I5(1)" cisco.nxos.nxos_vpc_interface: *id003 @@ -79,7 +79,7 @@ - ansible.builtin.assert: *id002 when: image_version != "7.0(3)I5(1)" - - name: Conf idempotence + - name: Configure idempotence register: result when: image_version != "7.0(3)I5(1)" cisco.nxos.nxos_vpc_interface: *id005 @@ -129,7 +129,7 @@ - no interface port-channel11 match: none - - name: Disable feature vpc + - name: Disable 'feature vpc' cisco.nxos.nxos_feature: feature: vpc state: disabled diff --git a/tests/integration/targets/nxos_vrf/tasks/cli.yaml b/tests/integration/targets/nxos_vrf/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_vrf/tasks/cli.yaml +++ b/tests/integration/targets/nxos_vrf/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_vrf/tasks/main.yaml b/tests/integration/targets/nxos_vrf/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_vrf/tasks/main.yaml +++ b/tests/integration/targets/nxos_vrf/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_vrf/tasks/nxapi.yaml b/tests/integration/targets/nxos_vrf/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_vrf/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_vrf/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_vrf/tests/common/intent.yaml b/tests/integration/targets/nxos_vrf/tests/common/intent.yaml index 5bc90aede..f95da2fb9 100644 --- a/tests/integration/targets/nxos_vrf/tests/common/intent.yaml +++ b/tests/integration/targets/nxos_vrf/tests/common/intent.yaml @@ -10,7 +10,7 @@ ansible.builtin.set_fact: testint2: "{{ nxos_int2 }}" -- name: Setup - remove vrf from interfaces used in test(part1) +- name: Setup - remove VRF from interfaces used in test(part1) ignore_errors: true cisco.nxos.nxos_config: lines: @@ -18,7 +18,7 @@ parents: no switchport before: interface {{ testint1 }} -- name: Setup - remove vrf from interfaces used in test(part2) +- name: Setup - remove VRF from interfaces used in test(part2) ignore_errors: true cisco.nxos.nxos_config: lines: @@ -26,13 +26,13 @@ parents: no switchport before: interface {{ testint2 }} -- name: Setup - delete vrf test1 used in test +- name: Setup - delete VRF test1 used in test ignore_errors: true cisco.nxos.nxos_config: lines: - no vrf context test1 -- name: Setup - remove vrf test2 used in test +- name: Setup - remove VRF test2 used in test ignore_errors: true cisco.nxos.nxos_config: lines: @@ -67,7 +67,7 @@ that: - result.changed == false -- name: Assign interfaces to vrf (config + intent) +- name: Assign interfaces to VRF (config + intent) register: result cisco.nxos.nxos_vrf: &id002 name: test1 @@ -95,7 +95,7 @@ that: - result.changed == false -- name: Check interfaces assigned to vrf (intent) +- name: Check interfaces assigned to VRF (intent) register: result cisco.nxos.nxos_vrf: name: test1 @@ -107,7 +107,7 @@ that: - result.failed == false -- name: Assign interfaces to vrf (intent fail) +- name: Assign interfaces to VRF (intent fail) register: result ignore_errors: true cisco.nxos.nxos_vrf: @@ -119,7 +119,7 @@ that: - result.failed == True -- name: Remove interface from vrf +- name: Remove interface from VRF register: result cisco.nxos.nxos_vrf: &id003 name: test1 @@ -166,7 +166,7 @@ that: - result.changed == false -- name: Setup - remove vrf from interfaces used in test(part1) +- name: Setup - remove VRF from interfaces used in test(part1) ignore_errors: true cisco.nxos.nxos_config: lines: @@ -174,7 +174,7 @@ parents: no switchport before: interface {{ testint1 }} -- name: Setup - remove vrf from interfaces used in test(part2) +- name: Setup - remove VRF from interfaces used in test(part2) ignore_errors: true cisco.nxos.nxos_config: lines: @@ -182,13 +182,13 @@ parents: no switchport before: interface {{ testint2 }} -- name: Setup - delete vrf test1 used in test +- name: Setup - delete VRF test1 used in test ignore_errors: true cisco.nxos.nxos_config: lines: - no vrf context test1 -- name: Setup - remove vrf test2 used in test +- name: Setup - remove VRF test2 used in test ignore_errors: true cisco.nxos.nxos_config: lines: diff --git a/tests/integration/targets/nxos_vrf/tests/common/sanity.yaml b/tests/integration/targets/nxos_vrf/tests/common/sanity.yaml index 93dbcc1e1..c4ef8c1ca 100644 --- a/tests/integration/targets/nxos_vrf/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_vrf/tests/common/sanity.yaml @@ -30,22 +30,21 @@ vnid: default when: platform is not match("N35|N7K|N3L") -- name: Enable feature bgp +- name: Enable 'feature bgp' ignore_errors: true cisco.nxos.nxos_feature: feature: bgp state: enabled -- name: "Setup: enable nv overlay evpn" +- name: "Setup: enable NV overlay EVPN" ignore_errors: true when: platform is match("N5K|N6K") cisco.nxos.nxos_config: commands: - nv overlay evpn - provider: "{{ connection }}" - block: - - name: Ensure ntc vrf exists on switch + - name: Ensure NTC VRF exists on switch register: result cisco.nxos.nxos_vrf: &id001 vrf: ntc @@ -61,7 +60,7 @@ that: - result.changed == true - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_vrf: *id001 @@ -72,7 +71,7 @@ - ansible.builtin.pause: seconds: 30 - - name: Remove config + - name: Remove configuration register: result cisco.nxos.nxos_vrf: &id003 vrf: ntc @@ -83,13 +82,13 @@ - ansible.builtin.assert: *id002 - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_vrf: *id003 - ansible.builtin.assert: *id004 - - name: Ensure ntc vrf does not exist on switch + - name: Ensure NTC VRF does not exist on switch register: result cisco.nxos.nxos_vrf: &id005 vrf: ntc @@ -106,15 +105,14 @@ - ansible.builtin.assert: *id004 always: - - name: "Setup: disable nv overlay evpn" + - name: "Setup: disable NV overlay EVPN" ignore_errors: true when: platform is match("N5K|N6K") cisco.nxos.nxos_config: commands: - no nv overlay evpn - provider: "{{ connection }}" - - name: Disable feature bgp + - name: Disable 'feature bgp' ignore_errors: true cisco.nxos.nxos_feature: feature: bgp diff --git a/tests/integration/targets/nxos_vrf_af/tasks/cli.yaml b/tests/integration/targets/nxos_vrf_af/tasks/cli.yaml index 90342e6b1..988ef2894 100644 --- a/tests/integration/targets/nxos_vrf_af/tasks/cli.yaml +++ b/tests/integration/targets/nxos_vrf_af/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_vrf_af/tasks/main.yaml b/tests/integration/targets/nxos_vrf_af/tasks/main.yaml index 7631f52fe..c9e70304e 100644 --- a/tests/integration/targets/nxos_vrf_af/tasks/main.yaml +++ b/tests/integration/targets/nxos_vrf_af/tasks/main.yaml @@ -1,11 +1,12 @@ --- -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli always: - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_vrf_af/tasks/nxapi.yaml b/tests/integration/targets/nxos_vrf_af/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_vrf_af/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_vrf_af/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_vrf_af/tests/common/sanity.yaml b/tests/integration/targets/nxos_vrf_af/tests/common/sanity.yaml index 124c4c187..3e276fa19 100644 --- a/tests/integration/targets/nxos_vrf_af/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_vrf_af/tests/common/sanity.yaml @@ -2,23 +2,23 @@ - ansible.builtin.debug: msg: START connection={{ ansible_connection }} nxos_vrf_af sanity test -- name: Configure feature bgp +- name: Configure 'feature bgp' cisco.nxos.nxos_feature: feature: bgp state: enabled -- name: Configure feature nv overlay +- name: Configure 'feature nv overlay' ignore_errors: true cisco.nxos.nxos_config: commands: feature nv overlay -- name: Configure nv overlay evpn +- name: Configure NV overlay EVPN ignore_errors: true cisco.nxos.nxos_config: commands: nv overlay evpn - block: - - name: Configure vrf af ipv4 + - name: Configure VRF AF ipv4 register: result cisco.nxos.nxos_vrf_af: &id001 vrf: ansible @@ -29,7 +29,7 @@ that: - result.changed == true - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_vrf_af: *id001 @@ -37,7 +37,7 @@ that: - result.changed == false - - name: Configure vrf af ipv6 + - name: Configure VRF AF ipv6 register: result cisco.nxos.nxos_vrf_af: &id003 vrf: ansible @@ -46,7 +46,7 @@ - ansible.builtin.assert: *id002 - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_vrf_af: *id003 @@ -61,7 +61,7 @@ - ansible.builtin.assert: *id002 - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_vrf_af: *id005 @@ -76,13 +76,13 @@ - ansible.builtin.assert: *id002 - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_vrf_af: *id006 - ansible.builtin.assert: *id004 - - name: Remove vrf af v6 + - name: Remove VRF AF v6 register: result cisco.nxos.nxos_vrf_af: &id007 vrf: ansible @@ -101,7 +101,7 @@ - ansible.builtin.assert: *id004 - - name: Remove vrf af v4 + - name: Remove VRF AF v4 register: result cisco.nxos.nxos_vrf_af: &id008 vrf: ansible @@ -121,22 +121,22 @@ - ansible.builtin.assert: *id004 when: not platform is search("N35|N3L") always: - - name: Remove vrf + - name: Remove VRF ignore_errors: true cisco.nxos.nxos_config: commands: no vrf context ansible - - name: Remove nv overlay evpn + - name: Remove NV overlay EVPN ignore_errors: true cisco.nxos.nxos_config: commands: no nv overlay evpn - - name: Remove feature nv overlay + - name: Remove 'feature nv overlay' ignore_errors: true cisco.nxos.nxos_config: commands: no feature nv overlay - - name: Remove feature bgp + - name: Remove 'feature bgp' ignore_errors: true cisco.nxos.nxos_feature: feature: bgp diff --git a/tests/integration/targets/nxos_vrf_interface/tasks/cli.yaml b/tests/integration/targets/nxos_vrf_interface/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_vrf_interface/tasks/cli.yaml +++ b/tests/integration/targets/nxos_vrf_interface/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_vrf_interface/tasks/main.yaml b/tests/integration/targets/nxos_vrf_interface/tasks/main.yaml index 7631f52fe..c9e70304e 100644 --- a/tests/integration/targets/nxos_vrf_interface/tasks/main.yaml +++ b/tests/integration/targets/nxos_vrf_interface/tasks/main.yaml @@ -1,11 +1,12 @@ --- -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli always: - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_vrf_interface/tasks/nxapi.yaml b/tests/integration/targets/nxos_vrf_interface/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_vrf_interface/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_vrf_interface/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_vrf_interface/tests/common/sanity.yaml b/tests/integration/targets/nxos_vrf_interface/tests/common/sanity.yaml index 5d1ce4a6b..dbe8baf93 100644 --- a/tests/integration/targets/nxos_vrf_interface/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_vrf_interface/tests/common/sanity.yaml @@ -7,7 +7,7 @@ intname: "{{ nxos_int1 }}" - block: - - name: Put interface in l3 + - name: Put interface in layer 3 cisco.nxos.nxos_config: commands: - no switchport @@ -15,7 +15,7 @@ - interface {{ intname }} match: none - - name: Ensure vrf ntc exists on interface + - name: Ensure VRF NTC exists on interface register: result cisco.nxos.nxos_vrf_interface: &id001 vrf: ntc @@ -26,7 +26,7 @@ that: - result.changed == true - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_vrf_interface: *id001 @@ -34,7 +34,7 @@ that: - result.changed == false - - name: Ensure ntc vrf does not exist on interface + - name: Ensure NTC VRF does not exist on interface register: result cisco.nxos.nxos_vrf_interface: &id003 vrf: ntc diff --git a/tests/integration/targets/nxos_vrrp/tasks/cli.yaml b/tests/integration/targets/nxos_vrrp/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_vrrp/tasks/cli.yaml +++ b/tests/integration/targets/nxos_vrrp/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_vrrp/tasks/main.yaml b/tests/integration/targets/nxos_vrrp/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_vrrp/tasks/main.yaml +++ b/tests/integration/targets/nxos_vrrp/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_vrrp/tasks/nxapi.yaml b/tests/integration/targets/nxos_vrrp/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_vrrp/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_vrrp/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_vrrp/tests/common/sanity.yaml b/tests/integration/targets/nxos_vrrp/tests/common/sanity.yaml index 577baecea..4e3ba70fa 100644 --- a/tests/integration/targets/nxos_vrrp/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_vrrp/tests/common/sanity.yaml @@ -13,7 +13,7 @@ feature: vrrp state: enabled - - name: Create int vlan 10 + - name: Create int VLAN 10 cisco.nxos.nxos_config: commands: int vlan 10 @@ -29,7 +29,7 @@ that: - result.changed == true - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_vrrp: *id001 @@ -47,13 +47,13 @@ - ansible.builtin.assert: *id002 - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_vrrp: *id003 - ansible.builtin.assert: *id004 - - name: Ensure removal of the vrrp group config + - name: Ensure removal of the vrrp group configuration register: result cisco.nxos.nxos_vrrp: &id005 interface: vlan10 diff --git a/tests/integration/targets/nxos_vsan/tasks/cli.yaml b/tests/integration/targets/nxos_vsan/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_vsan/tasks/cli.yaml +++ b/tests/integration/targets/nxos_vsan/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_vsan/tasks/main.yaml b/tests/integration/targets/nxos_vsan/tasks/main.yaml index eb055621b..477fbd41f 100644 --- a/tests/integration/targets/nxos_vsan/tasks/main.yaml +++ b/tests/integration/targets/nxos_vsan/tasks/main.yaml @@ -1,5 +1,5 @@ --- -- name: Check platform type and skip if not mds +- name: Check platform type and skip if not MDS register: result cisco.nxos.nxos_command: commands: show version | grep MDS @@ -8,12 +8,12 @@ ansible.builtin.set_fact: skip_test: false -- name: Set skip_test flag to true if not mds +- name: Set skip_test flag to true if not MDS ansible.builtin.set_fact: skip_test: true when: result.stdout[0] is not search('MDS') -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: cli when: not skip_test diff --git a/tests/integration/targets/nxos_vsan/tests/common/sanity.yaml b/tests/integration/targets/nxos_vsan/tests/common/sanity.yaml index 34e899be1..fd6a1f21e 100644 --- a/tests/integration/targets/nxos_vsan/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_vsan/tests/common/sanity.yaml @@ -3,10 +3,13 @@ msg: "START nxos_vsan sanity test with connection={{ ansible_connection }} " - ansible.builtin.debug: - msg: Using vsans {{ vsan1 }}, {{ vsan2 }} for running this sanity test, please make sure these are not used in the setup, these will be deleted after the tests + msg: >- + Using vsans {{ vsan1 }}, {{ vsan2 }} for running this sanity test, + please make sure these are not used in the setup, + these will be deleted after the tests - block: - - name: Setup - remove vsan if configured + - name: Setup - remove VSAN if configured ignore_errors: true cisco.nxos.nxos_vsan: &id002 vsan: @@ -16,7 +19,7 @@ - id: "{{ vsan2 | int }}" remove: true - - name: Configure vsan + - name: Configure VSAN register: result cisco.nxos.nxos_vsan: &id001 vsan: @@ -39,8 +42,20 @@ - ansible.builtin.assert: that: - - result.commands == ["terminal dont-ask", "vsan database", "vsan 922", "vsan 922 name vsan-SAN-A", "vsan 922 suspend", "vsan 922 interface fc1/1", "vsan - 923", "vsan 923 name vsan-SAN-B", "no vsan 923 suspend", "vsan 923 interface fc1/2", "no terminal dont-ask"] + - result.commands == desired + vars: + desired: + - "terminal dont-ask" + - "vsan database" + - "vsan 922" + - "vsan 922 name vsan-SAN-A" + - "vsan 922 suspend" + - "vsan 922 interface fc1/1" + - "vsan 923" + - "vsan 923 name vsan-SAN-B" + - "no vsan 923 suspend" + - "vsan 923 interface fc1/2" + - "no terminal dont-ask" - name: Idempotence check register: result @@ -54,5 +69,5 @@ that: - result.commands == [] always: - - name: Remove vsan config + - name: Remove VSAN configuration cisco.nxos.nxos_vsan: *id002 diff --git a/tests/integration/targets/nxos_vsan/vars/main.yml b/tests/integration/targets/nxos_vsan/vars/main.yml index 9c8077a47..41b2fdb0d 100644 --- a/tests/integration/targets/nxos_vsan/vars/main.yml +++ b/tests/integration/targets/nxos_vsan/vars/main.yml @@ -1,5 +1,5 @@ --- vsan1: 922 vsan2: 923 -intA1: fc1/1 -intB1: fc1/2 +intA1: fc1/1 # noqa var-naming +intB1: fc1/2 # noqa var-naming diff --git a/tests/integration/targets/nxos_vtp_domain/tasks/cli.yaml b/tests/integration/targets/nxos_vtp_domain/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_vtp_domain/tasks/cli.yaml +++ b/tests/integration/targets/nxos_vtp_domain/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_vtp_domain/tasks/main.yaml b/tests/integration/targets/nxos_vtp_domain/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_vtp_domain/tasks/main.yaml +++ b/tests/integration/targets/nxos_vtp_domain/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_vtp_domain/tasks/nxapi.yaml b/tests/integration/targets/nxos_vtp_domain/tasks/nxapi.yaml index cedab80f1..74961c395 100644 --- a/tests/integration/targets/nxos_vtp_domain/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_vtp_domain/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_vtp_domain/tests/common/sanity.yaml b/tests/integration/targets/nxos_vtp_domain/tests/common/sanity.yaml index 413c00427..6c2a43f49 100644 --- a/tests/integration/targets/nxos_vtp_domain/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_vtp_domain/tests/common/sanity.yaml @@ -12,18 +12,18 @@ when: platform is search('N3K-F|N9K-F') - block: - - name: Disable feature vtp + - name: Disable 'feature vtp' ignore_errors: true cisco.nxos.nxos_feature: feature: vtp state: disabled - - name: Enable feature vtp + - name: Enable 'feature vtp' cisco.nxos.nxos_feature: feature: vtp state: enabled - - name: Configure vtp domain + - name: Configure VTP domain register: result cisco.nxos.nxos_vtp_domain: &id001 domain: ntc @@ -32,7 +32,7 @@ that: - result.changed == true - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_vtp_domain: *id001 @@ -41,7 +41,7 @@ - result.changed == false when: vtp_run always: - - name: Disable feature vtp + - name: Disable 'feature vtp' cisco.nxos.nxos_feature: feature: vtp state: disabled diff --git a/tests/integration/targets/nxos_vtp_password/tasks/cli.yaml b/tests/integration/targets/nxos_vtp_password/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_vtp_password/tasks/cli.yaml +++ b/tests/integration/targets/nxos_vtp_password/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_vtp_password/tasks/main.yaml b/tests/integration/targets/nxos_vtp_password/tasks/main.yaml index 7631f52fe..c9e70304e 100644 --- a/tests/integration/targets/nxos_vtp_password/tasks/main.yaml +++ b/tests/integration/targets/nxos_vtp_password/tasks/main.yaml @@ -1,11 +1,12 @@ --- -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli always: - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_vtp_password/tasks/nxapi.yaml b/tests/integration/targets/nxos_vtp_password/tasks/nxapi.yaml index cedab80f1..5fec0f43b 100644 --- a/tests/integration/targets/nxos_vtp_password/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_vtp_password/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_vtp_password/tests/common/sanity.yaml b/tests/integration/targets/nxos_vtp_password/tests/common/sanity.yaml index 0f0f5323c..a0f0e1f2c 100644 --- a/tests/integration/targets/nxos_vtp_password/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_vtp_password/tests/common/sanity.yaml @@ -12,22 +12,22 @@ when: platform is search('N3K-F|N9K-F') - block: - - name: Disable feature vtp + - name: Disable 'feature vtp' ignore_errors: true cisco.nxos.nxos_feature: feature: vtp state: disabled - - name: Enable feature vtp + - name: Enable 'feature vtp' cisco.nxos.nxos_feature: feature: vtp state: enabled - - name: Configure vtp domain + - name: Configure VTP domain cisco.nxos.nxos_vtp_domain: domain: testing - - name: Configure vtp password + - name: Configure VTP password register: result cisco.nxos.nxos_vtp_password: &id001 vtp_password: ntc @@ -37,7 +37,7 @@ that: - result.changed == true - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_vtp_password: *id001 @@ -45,7 +45,7 @@ that: - result.changed == false - - name: Remove vtp password + - name: Remove VTP password register: result cisco.nxos.nxos_vtp_password: &id003 vtp_password: ntc @@ -60,7 +60,7 @@ - ansible.builtin.assert: *id004 when: vtp_run always: - - name: Disable feature vtp + - name: Disable 'feature vtp' cisco.nxos.nxos_feature: feature: vtp state: disabled diff --git a/tests/integration/targets/nxos_vtp_version/tasks/cli.yaml b/tests/integration/targets/nxos_vtp_version/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_vtp_version/tasks/cli.yaml +++ b/tests/integration/targets/nxos_vtp_version/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_vtp_version/tasks/main.yaml b/tests/integration/targets/nxos_vtp_version/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_vtp_version/tasks/main.yaml +++ b/tests/integration/targets/nxos_vtp_version/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_vtp_version/tasks/nxapi.yaml b/tests/integration/targets/nxos_vtp_version/tasks/nxapi.yaml index cedab80f1..74961c395 100644 --- a/tests/integration/targets/nxos_vtp_version/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_vtp_version/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_vtp_version/tests/common/sanity.yaml b/tests/integration/targets/nxos_vtp_version/tests/common/sanity.yaml index 08d9fa901..248c5c475 100644 --- a/tests/integration/targets/nxos_vtp_version/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_vtp_version/tests/common/sanity.yaml @@ -12,22 +12,22 @@ when: platform is search('N3K-F|N9K-F') - block: - - name: Disable feature vtp + - name: Disable 'feature vtp' ignore_errors: true cisco.nxos.nxos_feature: feature: vtp state: disabled - - name: Enable feature vtp + - name: Enable 'feature vtp' cisco.nxos.nxos_feature: feature: vtp state: enabled - - name: Configure supporting vtp domain + - name: Configure supporting VTP domain cisco.nxos.nxos_vtp_domain: domain: foo - - name: Configure vtp version + - name: Configure VTP version register: result cisco.nxos.nxos_vtp_version: &id001 version: 2 @@ -36,7 +36,7 @@ that: - result.changed == true - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_vtp_version: *id001 @@ -45,7 +45,7 @@ - result.changed == false when: vtp_run | bool always: - - name: Disable feature vtp + - name: Disable 'feature vtp' cisco.nxos.nxos_feature: feature: vtp state: disabled diff --git a/tests/integration/targets/nxos_vxlan_vtep/tasks/cli.yaml b/tests/integration/targets/nxos_vxlan_vtep/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_vxlan_vtep/tasks/cli.yaml +++ b/tests/integration/targets/nxos_vxlan_vtep/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_vxlan_vtep/tasks/main.yaml b/tests/integration/targets/nxos_vxlan_vtep/tasks/main.yaml index 62e44ffda..a1da90e57 100644 --- a/tests/integration/targets/nxos_vxlan_vtep/tasks/main.yaml +++ b/tests/integration/targets/nxos_vxlan_vtep/tasks/main.yaml @@ -1,10 +1,10 @@ --- -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli -- name: Include the nx-api tasks +- name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_vxlan_vtep/tasks/nxapi.yaml b/tests/integration/targets/nxos_vxlan_vtep/tasks/nxapi.yaml index cedab80f1..74961c395 100644 --- a/tests/integration/targets/nxos_vxlan_vtep/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_vxlan_vtep/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_vxlan_vtep/tasks/platform/n7k/cleanup.yaml b/tests/integration/targets/nxos_vxlan_vtep/tasks/platform/n7k/cleanup.yaml index ea15558fc..6de2a7ac2 100644 --- a/tests/integration/targets/nxos_vxlan_vtep/tasks/platform/n7k/cleanup.yaml +++ b/tests/integration/targets/nxos_vxlan_vtep/tasks/platform/n7k/cleanup.yaml @@ -1,6 +1,6 @@ --- -- name: Unconfigure vdc setting limit-resource module-type f3 - ignore_errors: true +- name: Unconfigure VDC setting limit-resource module-type f3 + ignore_errors: true # noqa ignore-errors cisco.nxos.nxos_config: commands: - terminal dont-ask ; vdc {{ vdcid }} ; no limit-resource module-type f3 @@ -10,8 +10,8 @@ ansible.builtin.pause: seconds: 45 -- name: Configure vdc setting allocate interface unallocated-interfaces - ignore_errors: true +- name: Configure VDC setting allocate interface unallocated-interfaces + ignore_errors: true # noqa ignore-errors cisco.nxos.nxos_config: commands: - terminal dont-ask ; vdc {{ vdcid }} ; allocate interface unallocated-interfaces diff --git a/tests/integration/targets/nxos_vxlan_vtep/tasks/platform/n7k/setup.yaml b/tests/integration/targets/nxos_vxlan_vtep/tasks/platform/n7k/setup.yaml index 499b275f8..52a8aad85 100644 --- a/tests/integration/targets/nxos_vxlan_vtep/tasks/platform/n7k/setup.yaml +++ b/tests/integration/targets/nxos_vxlan_vtep/tasks/platform/n7k/setup.yaml @@ -1,5 +1,5 @@ --- -- name: Get default vdc id +- name: Get default VDC id register: vdcout cisco.nxos.nxos_command: commands: @@ -9,8 +9,8 @@ ansible.builtin.set_fact: vdcid: "{{ vdcout.stdout_lines[0].name }}" -- name: Configure vdc setting limit-resource module-type f3 - ignore_errors: true +- name: Configure VDC setting limit-resource module-type f3 + ignore_errors: true # noqa ignore-errors cisco.nxos.nxos_config: commands: - terminal dont-ask ; vdc {{ vdcid }} ; limit-resource module-type f3 @@ -20,8 +20,8 @@ ansible.builtin.pause: seconds: 45 -- name: Configure vdc setting allocate interface unallocated-interfaces - ignore_errors: true +- name: Configure VDC setting allocate interface unallocated-interfaces + ignore_errors: true # noqa ignore-errors cisco.nxos.nxos_config: commands: - terminal dont-ask ; vdc {{ vdcid }} ; allocate interface unallocated-interfaces diff --git a/tests/integration/targets/nxos_vxlan_vtep/tests/common/multisite.yaml b/tests/integration/targets/nxos_vxlan_vtep/tests/common/multisite.yaml index ff9f8a844..b2ffc5a1d 100644 --- a/tests/integration/targets/nxos_vxlan_vtep/tests/common/multisite.yaml +++ b/tests/integration/targets/nxos_vxlan_vtep/tests/common/multisite.yaml @@ -2,13 +2,13 @@ - ansible.builtin.debug: msg: START connection={{ ansible_connection }} nxos_vxlan_vtep multisite sanity test -- name: Enable feature nv overlay - multisite +- name: Enable 'feature nv overlay' - multisite cisco.nxos.nxos_config: commands: - feature nv overlay match: none -- name: Enable nv overlay evpn - multisite +- name: Enable NV overlay EVPN - multisite when: platform is search('N9K') cisco.nxos.nxos_config: lines: @@ -38,7 +38,7 @@ that: - result.changed == true - - name: Conf idempotence + - name: Configure idempotence register: result cisco.nxos.nxos_vxlan_vtep: *id001 @@ -95,7 +95,7 @@ - no evpn multisite border-gateway 10 when: multiout is not search("Invalid command") -- name: Disable nv overlay evpn +- name: Disable NV overlay EVPN when: platform is search('N9K') ignore_errors: true cisco.nxos.nxos_config: @@ -103,7 +103,7 @@ - no nv overlay evpn match: none -- name: Disable feature nv overlay +- name: Disable 'feature nv overlay' ignore_errors: true cisco.nxos.nxos_feature: feature: nve diff --git a/tests/integration/targets/nxos_vxlan_vtep/tests/common/sanity.yaml b/tests/integration/targets/nxos_vxlan_vtep/tests/common/sanity.yaml index b35b236b9..11f53ed54 100644 --- a/tests/integration/targets/nxos_vxlan_vtep/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_vxlan_vtep/tests/common/sanity.yaml @@ -37,11 +37,11 @@ when: platform is search('N9K') and (major_version is version('9.2', 'ge')) - block: - - name: Apply n7k specific setup config - ansible.builtin.include: targets/nxos_vxlan_vtep/tasks/platform/n7k/setup.yaml + - name: Apply N7K specific setup configuration + ansible.builtin.include_tasks: targets/nxos_vxlan_vtep/tasks/platform/n7k/setup.yaml when: platform is match('N7K') - - name: Enable feature nv overlay + - name: Enable 'feature nv overlay' cisco.nxos.nxos_config: commands: - feature nv overlay @@ -198,18 +198,18 @@ - result.changed == false when: (platform is search("N7K|N9K")) always: - - name: Apply n7k specific cleanup config - ansible.builtin.include: targets/nxos_vxlan_vtep/tasks/platform/n7k/cleanup.yaml + - name: Apply N7K specific cleanup configuration + ansible.builtin.include_tasks: targets/nxos_vxlan_vtep/tasks/platform/n7k/cleanup.yaml when: platform is match('N7K') - - name: Disable nv overlay evpn + - name: Disable NV overlay EVPN ignore_errors: true cisco.nxos.nxos_config: commands: - no nv overlay evpn match: none - - name: Disable feature nv overlay + - name: Disable 'feature nv overlay' ignore_errors: true cisco.nxos.nxos_feature: feature: nve diff --git a/tests/integration/targets/nxos_vxlan_vtep_vni/tasks/cli.yaml b/tests/integration/targets/nxos_vxlan_vtep_vni/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_vxlan_vtep_vni/tasks/cli.yaml +++ b/tests/integration/targets/nxos_vxlan_vtep_vni/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_vxlan_vtep_vni/tasks/main.yaml b/tests/integration/targets/nxos_vxlan_vtep_vni/tasks/main.yaml index 7631f52fe..c9e70304e 100644 --- a/tests/integration/targets/nxos_vxlan_vtep_vni/tasks/main.yaml +++ b/tests/integration/targets/nxos_vxlan_vtep_vni/tasks/main.yaml @@ -1,11 +1,12 @@ --- -- block: - - name: Include the cli tasks +- name: Run the CLI and NX-API tests + block: + - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - cli always: - - name: Include the nx-api tasks + - name: Include the NX-API tasks ansible.builtin.include_tasks: nxapi.yaml tags: - nxapi diff --git a/tests/integration/targets/nxos_vxlan_vtep_vni/tasks/nxapi.yaml b/tests/integration/targets/nxos_vxlan_vtep_vni/tasks/nxapi.yaml index cedab80f1..6a7129481 100644 --- a/tests/integration/targets/nxos_vxlan_vtep_vni/tasks/nxapi.yaml +++ b/tests/integration/targets/nxos_vxlan_vtep_vni/tasks/nxapi.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect nxapi test cases +- name: Collect NX-API test cases ansible.builtin.find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.httpapi) +- name: Run test cases with connection httpapi ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.httpapi - connection: "{{ nxapi }}" diff --git a/tests/integration/targets/nxos_vxlan_vtep_vni/tests/common/multisite.yaml b/tests/integration/targets/nxos_vxlan_vtep_vni/tests/common/multisite.yaml index 3d76704e3..13ab21fd8 100644 --- a/tests/integration/targets/nxos_vxlan_vtep_vni/tests/common/multisite.yaml +++ b/tests/integration/targets/nxos_vxlan_vtep_vni/tests/common/multisite.yaml @@ -2,19 +2,19 @@ - ansible.builtin.debug: msg: START connection={{ ansible_connection }} nxos_vxlan_vtep_vni multisite sanity test -- name: Disable feature nv overlay - multisite +- name: Disable 'feature nv overlay' - multisite ignore_errors: true cisco.nxos.nxos_feature: feature: nv overlay state: disabled -- name: Enable feature nv overlay - multisite +- name: Enable 'feature nv overlay' - multisite ignore_errors: true cisco.nxos.nxos_feature: feature: nv overlay state: enabled -- name: Enable nv overlay evpn - multisite +- name: Enable NV overlay EVPN - multisite when: platform is search('N9K') cisco.nxos.nxos_config: lines: @@ -88,7 +88,7 @@ - no evpn multisite border-gateway 10 when: multiout is not search("Invalid command") -- name: Disable feature nv overlay - multisite +- name: Disable 'feature nv overlay' - multisite ignore_errors: true cisco.nxos.nxos_feature: feature: nv overlay @@ -97,7 +97,7 @@ - ansible.builtin.pause: seconds: 5 -- name: Remove nv overlay evpn - multisite +- name: Remove NV overlay EVPN - multisite when: platform is search('N9K') cisco.nxos.nxos_config: lines: diff --git a/tests/integration/targets/nxos_vxlan_vtep_vni/tests/common/sanity.yaml b/tests/integration/targets/nxos_vxlan_vtep_vni/tests/common/sanity.yaml index 808662125..ac478b9a2 100644 --- a/tests/integration/targets/nxos_vxlan_vtep_vni/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_vxlan_vtep_vni/tests/common/sanity.yaml @@ -3,11 +3,11 @@ msg: START connection={{ ansible_connection }} nxos_vxlan_vtep_vni sanity test - block: - - name: Apply n7k specific setup config - ansible.builtin.include: targets/nxos_vxlan_vtep/tasks/platform/n7k/setup.yaml + - name: Apply N7K specific setup configuration + ansible.builtin.include_tasks: targets/nxos_vxlan_vtep/tasks/platform/n7k/setup.yaml when: platform is match('N7K') - - name: Enable feature nv overlay + - name: Enable 'feature nv overlay' cisco.nxos.nxos_config: commands: - feature nv overlay @@ -29,7 +29,7 @@ that: - result.changed == true - - name: Conf 1 idempotence + - name: Configure 1 idempotence register: result cisco.nxos.nxos_vxlan_vtep_vni: *id001 @@ -61,7 +61,7 @@ - ansible.builtin.assert: *id002 - - name: Conf 3 idempotence + - name: Configure 3 idempotence register: result cisco.nxos.nxos_vxlan_vtep_vni: *id003 @@ -76,13 +76,13 @@ - ansible.builtin.assert: *id002 - - name: Conf 4 idempotence + - name: Configure 4 idempotence register: result cisco.nxos.nxos_vxlan_vtep_vni: *id005 - ansible.builtin.assert: *id004 - - name: Remove config + - name: Remove configuration cisco.nxos.nxos_vxlan_vtep_vni: &id013 interface: nve1 vni: 8000 @@ -229,8 +229,8 @@ when: (platform is search('N9K')) when: (platform is search("N7K|N9K")) always: - - name: Apply n7k specific cleanup config - ansible.builtin.include: targets/nxos_vxlan_vtep/tasks/platform/n7k/cleanup.yaml + - name: Apply N7K specific cleanup configuration + ansible.builtin.include_tasks: targets/nxos_vxlan_vtep/tasks/platform/n7k/cleanup.yaml when: platform is match('N7K') - name: Remove vxlan_vtep @@ -240,7 +240,7 @@ shutdown: true state: absent - - name: Disable feature nv overlay + - name: Disable 'feature nv overlay' ignore_errors: true cisco.nxos.nxos_feature: feature: nve diff --git a/tests/integration/targets/nxos_zone_zoneset/tasks/cli.yaml b/tests/integration/targets/nxos_zone_zoneset/tasks/cli.yaml index 90342e6b1..d3d521f2a 100644 --- a/tests/integration/targets/nxos_zone_zoneset/tasks/cli.yaml +++ b/tests/integration/targets/nxos_zone_zoneset/tasks/cli.yaml @@ -6,7 +6,7 @@ connection: local register: test_cases -- name: Collect cli test cases +- name: Collect CLI test cases ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" @@ -22,11 +22,10 @@ ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test cases with connection network_cli ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run vars: ansible_connection: ansible.netcommon.network_cli - connection: "{{ cli }}" diff --git a/tests/integration/targets/nxos_zone_zoneset/tasks/main.yaml b/tests/integration/targets/nxos_zone_zoneset/tasks/main.yaml index eb055621b..477fbd41f 100644 --- a/tests/integration/targets/nxos_zone_zoneset/tasks/main.yaml +++ b/tests/integration/targets/nxos_zone_zoneset/tasks/main.yaml @@ -1,5 +1,5 @@ --- -- name: Check platform type and skip if not mds +- name: Check platform type and skip if not MDS register: result cisco.nxos.nxos_command: commands: show version | grep MDS @@ -8,12 +8,12 @@ ansible.builtin.set_fact: skip_test: false -- name: Set skip_test flag to true if not mds +- name: Set skip_test flag to true if not MDS ansible.builtin.set_fact: skip_test: true when: result.stdout[0] is not search('MDS') -- name: Include the cli tasks +- name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: cli when: not skip_test diff --git a/tests/integration/targets/nxos_zone_zoneset/tests/common/sanity.yaml b/tests/integration/targets/nxos_zone_zoneset/tests/common/sanity.yaml index fdcce0473..a0b5948c7 100644 --- a/tests/integration/targets/nxos_zone_zoneset/tests/common/sanity.yaml +++ b/tests/integration/targets/nxos_zone_zoneset/tests/common/sanity.yaml @@ -3,10 +3,13 @@ msg: "START nxos_zone_zoneset sanity test with connection={{ ansible_connection }} " - ansible.builtin.debug: - msg: Using vsans {{ vsan1 }}, {{ vsan2 }} for running this sanity test, please make sure these are not used in the setup, these will be deleted after the tests + msg: >- + Using vsans {{ vsan1 }}, {{ vsan2 }} for running this sanity test, + please make sure these are not used in the setup, + these will be deleted after the tests - always: - - name: Remove vsan config + - name: Remove VSAN configuration cisco.nxos.nxos_vsan: vsan: - id: "{{ vsan1 | int }}" @@ -15,7 +18,7 @@ - id: "{{ vsan2 | int }}" remove: true block: - - name: Setup - remove vsan if configured + - name: Setup - remove VSAN if configured ignore_errors: true cisco.nxos.nxos_vsan: vsan: @@ -25,7 +28,7 @@ - id: "{{ vsan2 | int }}" remove: true - - name: Configure vsan + - name: Configure VSAN cisco.nxos.nxos_vsan: vsan: - id: "{{ vsan1 | int }}" @@ -110,12 +113,35 @@ - ansible.builtin.assert: that: - - result.commands == ["terminal dont-ask", "zone mode enhanced vsan 922", "zone name zoneA vsan 922", "member pwwn 11:11:11:11:11:11:11:11", "member device-alias - test123", "zone name zoneB vsan 922", "member pwwn 10:11:11:11:11:11:11:11", "member pwwn 62:62:62:62:21:21:21:21", "zoneset name zsetname1 vsan 922", - "member zoneA", "member zoneB", "zoneset activate name zsetname1 vsan 922", "zone commit vsan 922", "zone smart-zoning enable vsan 923", "zone name zone21A - vsan 923", "member pwwn 11:11:11:11:11:11:11:11 both", "member pwwn 62:62:62:62:12:12:12:12", "zone name zone21B vsan 923", "member pwwn 10:11:11:11:11:11:11:11", - "member pwwn 62:62:62:62:21:21:21:21", "member device-alias somedummyname", "zoneset name zsetname21 vsan 923", "member zone21A", "member zone21B", "zoneset - activate name zsetname21 vsan 923", "no terminal dont-ask"] + - result.commands == desired + vars: + desired: + - "terminal dont-ask" + - "zone mode enhanced vsan 922" + - "zone name zoneA vsan 922" + - "member pwwn 11:11:11:11:11:11:11:11" + - "member device-alias test123" + - "zone name zoneB vsan 922" + - "member pwwn 10:11:11:11:11:11:11:11" + - "member pwwn 62:62:62:62:21:21:21:21" + - "zoneset name zsetname1 vsan 922" + - "member zoneA" + - "member zoneB" + - "zoneset activate name zsetname1 vsan 922" + - "zone commit vsan 922" + - "zone smart-zoning enable vsan 923" + - "zone name zone21A vsan 923" + - "member pwwn 11:11:11:11:11:11:11:11 both" + - "member pwwn 62:62:62:62:12:12:12:12" + - "zone name zone21B vsan 923" + - "member pwwn 10:11:11:11:11:11:11:11" + - "member pwwn 62:62:62:62:21:21:21:21" + - "member device-alias somedummyname" + - "zoneset name zsetname21 vsan 923" + - "member zone21A" + - "member zone21B" + - "zoneset activate name zsetname21 vsan 923" + - "no terminal dont-ask" - name: Idempotence check register: result @@ -175,8 +201,18 @@ - ansible.builtin.assert: that: - - result.commands == ["terminal dont-ask", "no zone name zoneA vsan 922", "no zone name zoneB vsan 922", "no zoneset name zsetname1 vsan 922", "zone commit - vsan 922", "no zone name zone21A vsan 923", "no zone name zone21B vsan 923", "no zoneset name zsetname21 vsan 923", "no terminal dont-ask"] + - result.commands == desired + vars: + desired: + - "terminal dont-ask" + - "no zone name zoneA vsan 922" + - "no zone name zoneB vsan 922" + - "no zoneset name zsetname1 vsan 922" + - "zone commit vsan 922" + - "no zone name zone21A vsan 923" + - "no zone name zone21B vsan 923" + - "no zoneset name zsetname21 vsan 923" + - "no terminal dont-ask" - name: Idempotence check for zone/zoneset removal register: result diff --git a/tests/integration/targets/nxos_zone_zoneset/vars/main.yml b/tests/integration/targets/nxos_zone_zoneset/vars/main.yml index 9c8077a47..41b2fdb0d 100644 --- a/tests/integration/targets/nxos_zone_zoneset/vars/main.yml +++ b/tests/integration/targets/nxos_zone_zoneset/vars/main.yml @@ -1,5 +1,5 @@ --- vsan1: 922 vsan2: 923 -intA1: fc1/1 -intB1: fc1/2 +intA1: fc1/1 # noqa var-naming +intB1: fc1/2 # noqa var-naming diff --git a/tests/integration/targets/prepare_nxos_tests/tasks/main.yml b/tests/integration/targets/prepare_nxos_tests/tasks/main.yml index 78729cdd2..e89e80269 100644 --- a/tests/integration/targets/prepare_nxos_tests/tasks/main.yml +++ b/tests/integration/targets/prepare_nxos_tests/tasks/main.yml @@ -22,6 +22,11 @@ prepare_nxos_tests_task: false titanium: false +- name: Reload golden config + cisco.nxos.nxos_command: + commands: configure replace bootflash:///golden_config non-interactive + when: reload_nxos_config | default(False) | bool + - name: Run the prepare steps if requested ansible.builtin.include_tasks: prepare.yml when: prepare_nxos_tests_task | default(False) | bool diff --git a/tests/integration/targets/prepare_nxos_tests/tasks/prepare.yml b/tests/integration/targets/prepare_nxos_tests/tasks/prepare.yml index 052e40d7f..52d385973 100644 --- a/tests/integration/targets/prepare_nxos_tests/tasks/prepare.yml +++ b/tests/integration/targets/prepare_nxos_tests/tasks/prepare.yml @@ -1,19 +1,19 @@ --- - name: Enable feature privilege connection: ansible.netcommon.network_cli - ignore_errors: true + ignore_errors: true # noqa ignore-errors cisco.nxos.nxos_config: lines: - feature privilege -- name: Enable feature nxapi +- name: Enable feature NX-API connection: ansible.netcommon.network_cli cisco.nxos.nxos_nxapi: state: present - name: Enable lldp connection: ansible.netcommon.network_cli - ignore_errors: true + ignore_errors: true # noqa ignore-errors cisco.nxos.nxos_config: lines: - feature lldp @@ -75,12 +75,12 @@ - name: Set a fact for 'platform' ansible.builtin.set_fact: platform: N3K-F - when: ( platform is match("N3K")) and ( fretta is search("true")) + when: (platform is match("N3K")) and (fretta is search("true")) - name: Set a fact for 'platform' ansible.builtin.set_fact: platform: N9K-F - when: ( platform is match("N9K")) and ( fretta is search("true")) + when: (platform is match("N9K")) and (fretta is search("true")) - name: Set a fact for 'titanium' ansible.builtin.set_fact: @@ -94,17 +94,17 @@ - name: Set a fact for 'platform' ansible.builtin.set_fact: platform: N35 - when: ( chassis_type is search("C35")) + when: (chassis_type is search("C35")) - name: Set a fact for 'platform' ansible.builtin.set_fact: platform: N35NG - when: ( chassis_type is search("C35")) and image_version is search("7.0\(3\)I7") + when: (chassis_type is search("C35")) and image_version is search("7.0\(3\)I7") - name: Set a fact for 'platform' ansible.builtin.set_fact: platform: N3L - when: ( chassis_type is search("C3048")) + when: (chassis_type is search("C3048")) - name: Set a fact for 'imagetag' ansible.builtin.set_fact: @@ -148,13 +148,16 @@ imagemr: "{{ image_version[11:12] }}" when: image_version is search("\d\.\d\(\d\)\S\S\S\S\(\d\)") -- ansible.builtin.debug: +- name: Debug output the image version + ansible.builtin.debug: msg: IMAGE VERSION {{ image_version }} -- ansible.builtin.debug: +- name: Debug output the image tag + ansible.builtin.debug: msg: IMAGE TAG {{ imagetag }} -- ansible.builtin.debug: +- name: Debug output the image maintenance release + ansible.builtin.debug: msg: IMAGE MR {{ imagemr }} - name: Set a fact for 'ipv6_supported' diff --git a/tests/sanity/ignore-2.12.txt b/tests/sanity/ignore-2.12.txt index 33c91076f..d7b9bbd97 100644 --- a/tests/sanity/ignore-2.12.txt +++ b/tests/sanity/ignore-2.12.txt @@ -34,5 +34,3 @@ plugins/module_utils/network/nxos/config/ntp_global/ntp_global.py import-2.6!ski plugins/module_utils/network/nxos/config/ntp_global/ntp_global.py compile-2.6!skip plugins/module_utils/network/nxos/utils/utils.py import-2.6!skip plugins/module_utils/network/nxos/utils/utils.py compile-2.6!skip -plugins/cliconf/nxos.py pylint:arguments-renamed -tests/unit/mock/loader.py pylint:arguments-renamed diff --git a/tests/sanity/ignore-2.13.txt b/tests/sanity/ignore-2.13.txt index c2ac0a10b..46cfbc643 100644 --- a/tests/sanity/ignore-2.13.txt +++ b/tests/sanity/ignore-2.13.txt @@ -1,3 +1 @@ plugins/action/nxos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` -plugins/cliconf/nxos.py pylint:arguments-renamed -tests/unit/mock/loader.py pylint:arguments-renamed diff --git a/tests/sanity/ignore-2.14.txt b/tests/sanity/ignore-2.14.txt index c2ac0a10b..46cfbc643 100644 --- a/tests/sanity/ignore-2.14.txt +++ b/tests/sanity/ignore-2.14.txt @@ -1,3 +1 @@ plugins/action/nxos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` -plugins/cliconf/nxos.py pylint:arguments-renamed -tests/unit/mock/loader.py pylint:arguments-renamed diff --git a/tests/sanity/ignore-2.15.txt b/tests/sanity/ignore-2.15.txt new file mode 100644 index 000000000..46cfbc643 --- /dev/null +++ b/tests/sanity/ignore-2.15.txt @@ -0,0 +1 @@ +plugins/action/nxos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` diff --git a/tests/sanity/ignore-2.16.txt b/tests/sanity/ignore-2.16.txt new file mode 100644 index 000000000..46cfbc643 --- /dev/null +++ b/tests/sanity/ignore-2.16.txt @@ -0,0 +1 @@ +plugins/action/nxos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` diff --git a/tests/sanity/ignore-2.17.txt b/tests/sanity/ignore-2.17.txt new file mode 100644 index 000000000..46cfbc643 --- /dev/null +++ b/tests/sanity/ignore-2.17.txt @@ -0,0 +1 @@ +plugins/action/nxos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt index 3a367994c..ada896a7b 100644 --- a/tests/sanity/ignore-2.9.txt +++ b/tests/sanity/ignore-2.9.txt @@ -1,40 +1,6 @@ -plugins/modules/nxos_acl.py validate-modules:deprecation-mismatch # 2.9 expects METADATA -plugins/modules/nxos_acl.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict -plugins/modules/nxos_acl_interface.py validate-modules:deprecation-mismatch # 2.9 expects METADATA -plugins/modules/nxos_acl_interface.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict -plugins/modules/nxos_interface.py validate-modules:deprecation-mismatch # 2.9 expects METADATA -plugins/modules/nxos_interface.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict -plugins/modules/nxos_l2_interface.py validate-modules:deprecation-mismatch # 2.9 expects METADATA -plugins/modules/nxos_l2_interface.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict -plugins/modules/nxos_l3_interface.py validate-modules:deprecation-mismatch # 2.9 expects METADATA -plugins/modules/nxos_l3_interface.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict -plugins/modules/nxos_linkagg.py validate-modules:deprecation-mismatch # 2.9 expects METADATA -plugins/modules/nxos_linkagg.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict -plugins/modules/nxos_lldp.py validate-modules:deprecation-mismatch # 2.9 expects METADATA -plugins/modules/nxos_lldp.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict plugins/modules/nxos_logging.py validate-modules:deprecation-mismatch # 2.9 expects METADATA -plugins/modules/nxos_logging.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict -plugins/modules/nxos_ospf.py validate-modules:deprecation-mismatch # 2.9 expects METADATA -plugins/modules/nxos_ospf.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict -plugins/modules/nxos_static_route.py validate-modules:deprecation-mismatch # 2.9 expects METADATA -plugins/modules/nxos_static_route.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict -plugins/modules/nxos_vlan.py validate-modules:deprecation-mismatch # 2.9 expects METADATA -plugins/modules/nxos_vlan.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict -plugins/modules/nxos_ospf_vrf.py validate-modules:deprecation-mismatch # 2.9 expects METADATA -plugins/modules/nxos_ospf_vrf.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict +plugins/modules/nxos_logging.py validate-modules:invalid-documentation # removed_at_date not plugins/action/nxos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` -plugins/modules/nxos_smu.py validate-modules:deprecation-mismatch # 2.9 expects METADATA -plugins/modules/nxos_smu.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict -plugins/modules/nxos_interface_ospf.py validate-modules:deprecation-mismatch # 2.9 expects METADATA -plugins/modules/nxos_interface_ospf.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict -plugins/modules/nxos_bgp.py validate-modules:deprecation-mismatch # 2.9 expects METADATA -plugins/modules/nxos_bgp.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict -plugins/modules/nxos_bgp_neighbor.py validate-modules:deprecation-mismatch # 2.9 expects METADATA -plugins/modules/nxos_bgp_neighbor.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict -plugins/modules/nxos_bgp_af.py validate-modules:deprecation-mismatch # 2.9 expects METADATA -plugins/modules/nxos_bgp_af.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict -plugins/modules/nxos_bgp_neighbor_af.py validate-modules:deprecation-mismatch # 2.9 expects METADATA -plugins/modules/nxos_bgp_neighbor_af.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict plugins/modules/nxos_ntp.py validate-modules:deprecation-mismatch # 2.9 expects METADATA plugins/modules/nxos_ntp.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict plugins/modules/nxos_ntp_auth.py validate-modules:deprecation-mismatch # 2.9 expects METADATA diff --git a/tests/unit/compat/builtins.py b/tests/unit/compat/builtins.py deleted file mode 100644 index bfc8adfbe..000000000 --- a/tests/unit/compat/builtins.py +++ /dev/null @@ -1,34 +0,0 @@ -# (c) 2014, Toshio Kuratomi -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# Make coding more python3-ish -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - -# -# Compat for python2.7 -# - -# One unittest needs to import builtins via __import__() so we need to have -# the string that represents it -try: - import __builtin__ -except ImportError: - BUILTINS = "builtins" -else: - BUILTINS = "__builtin__" diff --git a/tests/unit/compat/mock.py b/tests/unit/compat/mock.py index b45d6b5c6..50583cd6f 100644 --- a/tests/unit/compat/mock.py +++ b/tests/unit/compat/mock.py @@ -18,6 +18,7 @@ # Make coding more python3-ish from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -25,6 +26,7 @@ """ import sys + # Python 2.7 # Note: Could use the pypi mock library on python3.x as well as python2.x. It @@ -102,9 +104,7 @@ def _readline_side_effect(): if file_spec is None: import _io - file_spec = list( - set(dir(_io.TextIOWrapper)).union(set(dir(_io.BytesIO))) - ) + file_spec = list(set(dir(_io.TextIOWrapper)).union(set(dir(_io.BytesIO)))) if mock is None: mock = MagicMock(name="open", spec=open) diff --git a/tests/unit/compat/unittest.py b/tests/unit/compat/unittest.py index df3379b82..df4266ec9 100644 --- a/tests/unit/compat/unittest.py +++ b/tests/unit/compat/unittest.py @@ -18,6 +18,7 @@ # Make coding more python3-ish from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -26,6 +27,7 @@ import sys + # Allow wildcard import because we really do want to import all of # unittests's symbols into this compat shim # pylint: disable=wildcard-import,unused-wildcard-import diff --git a/tests/unit/mock/loader.py b/tests/unit/mock/loader.py index c21188ee3..0fc53edcd 100644 --- a/tests/unit/mock/loader.py +++ b/tests/unit/mock/loader.py @@ -18,19 +18,20 @@ # Make coding more python3-ish from __future__ import absolute_import, division, print_function + __metaclass__ = type import os from ansible.errors import AnsibleParserError -from ansible.parsing.dataloader import DataLoader from ansible.module_utils._text import to_bytes, to_text +from ansible.parsing.dataloader import DataLoader class DictDataLoader(DataLoader): def __init__(self, file_mapping=None): file_mapping = {} if file_mapping is None else file_mapping - assert type(file_mapping) == dict + assert isinstance(file_mapping, dict) super(DictDataLoader, self).__init__() @@ -46,12 +47,12 @@ def load_from_file(self, path, cache=True, unsafe=False): # TODO: the real _get_file_contents returns a bytestring, so we actually convert the # unicode/text it's created with to utf-8 - def _get_file_contents(self, path): - path = to_text(path) - if path in self._file_mapping: - return (to_bytes(self._file_mapping[path]), False) + def _get_file_contents(self, file_name): + file_name = to_text(file_name) + if file_name in self._file_mapping: + return (to_bytes(self._file_mapping[file_name]), False) else: - raise AnsibleParserError("file not found: %s" % path) + raise AnsibleParserError("file not found: %s" % file_name) def path_exists(self, path): path = to_text(path) diff --git a/tests/unit/mock/path.py b/tests/unit/mock/path.py index 8db8e0418..d15430fde 100644 --- a/tests/unit/mock/path.py +++ b/tests/unit/mock/path.py @@ -1,10 +1,10 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from ansible_collections.cisco.nxos.tests.unit.compat.mock import MagicMock from ansible.utils.path import unfrackpath +from ansible_collections.cisco.nxos.tests.unit.compat.mock import MagicMock + -mock_unfrackpath_noop = MagicMock( - spec_set=unfrackpath, side_effect=lambda x, *args, **kwargs: x -) +mock_unfrackpath_noop = MagicMock(spec_set=unfrackpath, side_effect=lambda x, *args, **kwargs: x) diff --git a/tests/unit/mock/procenv.py b/tests/unit/mock/procenv.py index 59fc1978a..e14ad0ece 100644 --- a/tests/unit/mock/procenv.py +++ b/tests/unit/mock/procenv.py @@ -19,16 +19,19 @@ # Make coding more python3-ish from __future__ import absolute_import, division, print_function + __metaclass__ = type -import sys import json +import sys from contextlib import contextmanager from io import BytesIO, StringIO -from ansible_collections.cisco.nxos.tests.unit.compat import unittest -from ansible.module_utils.six import PY3 + from ansible.module_utils._text import to_bytes +from ansible.module_utils.six import PY3 + +from ansible_collections.cisco.nxos.tests.unit.compat import unittest @contextmanager diff --git a/tests/unit/mock/vault_helper.py b/tests/unit/mock/vault_helper.py index b34ae1340..6006ba965 100644 --- a/tests/unit/mock/vault_helper.py +++ b/tests/unit/mock/vault_helper.py @@ -14,10 +14,10 @@ # Make coding more python3-ish from __future__ import absolute_import, division, print_function + __metaclass__ = type from ansible.module_utils._text import to_bytes - from ansible.parsing.vault import VaultSecret @@ -37,6 +37,4 @@ def __init__(self, text, encoding=None, errors=None, _bytes=None): @property def bytes(self): """The text encoded with encoding, unless we specifically set _bytes.""" - return self._bytes or to_bytes( - self.text, encoding=self.encoding, errors=self.errors - ) + return self._bytes or to_bytes(self.text, encoding=self.encoding, errors=self.errors) diff --git a/tests/unit/mock/yaml_helper.py b/tests/unit/mock/yaml_helper.py index 5df30aaed..2e857592a 100644 --- a/tests/unit/mock/yaml_helper.py +++ b/tests/unit/mock/yaml_helper.py @@ -1,12 +1,14 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type import io + import yaml from ansible.module_utils.six import PY3 -from ansible.parsing.yaml.loader import AnsibleLoader from ansible.parsing.yaml.dumper import AnsibleDumper +from ansible.parsing.yaml.loader import AnsibleLoader class YamlTestUtils(object): @@ -44,9 +46,7 @@ def _dump_load_cycle(self, obj): obj_2 = loader.get_data() # dump the gen 2 objects directory to strings - string_from_object_dump_2 = self._dump_string( - obj_2, dumper=AnsibleDumper - ) + string_from_object_dump_2 = self._dump_string(obj_2, dumper=AnsibleDumper) # The gen 1 and gen 2 yaml strings self.assertEqual(string_from_object_dump, string_from_object_dump_2) @@ -58,9 +58,7 @@ def _dump_load_cycle(self, obj): loader_3 = self._loader(stream_3) obj_3 = loader_3.get_data() - string_from_object_dump_3 = self._dump_string( - obj_3, dumper=AnsibleDumper - ) + string_from_object_dump_3 = self._dump_string(obj_3, dumper=AnsibleDumper) self.assertEqual(obj, obj_3) # should be transitive, but... @@ -92,12 +90,8 @@ def _old_dump_load_cycle(self, obj): stream_obj_from_string = io.StringIO() if PY3: - yaml.dump( - obj_from_stream, stream_obj_from_stream, Dumper=AnsibleDumper - ) - yaml.dump( - obj_from_stream, stream_obj_from_string, Dumper=AnsibleDumper - ) + yaml.dump(obj_from_stream, stream_obj_from_stream, Dumper=AnsibleDumper) + yaml.dump(obj_from_stream, stream_obj_from_string, Dumper=AnsibleDumper) else: yaml.dump( obj_from_stream, @@ -119,26 +113,22 @@ def _old_dump_load_cycle(self, obj): stream_obj_from_string.seek(0) if PY3: - yaml_string_obj_from_stream = yaml.dump( - obj_from_stream, Dumper=AnsibleDumper - ) - yaml_string_obj_from_string = yaml.dump( - obj_from_string, Dumper=AnsibleDumper - ) + yaml_string_obj_from_stream = yaml.dump(obj_from_stream, Dumper=AnsibleDumper) + yaml_string_obj_from_string = yaml.dump(obj_from_string, Dumper=AnsibleDumper) else: yaml_string_obj_from_stream = yaml.dump( - obj_from_stream, Dumper=AnsibleDumper, encoding=None + obj_from_stream, + Dumper=AnsibleDumper, + encoding=None, ) yaml_string_obj_from_string = yaml.dump( - obj_from_string, Dumper=AnsibleDumper, encoding=None + obj_from_string, + Dumper=AnsibleDumper, + encoding=None, ) assert yaml_string == yaml_string_obj_from_stream - assert ( - yaml_string - == yaml_string_obj_from_stream - == yaml_string_obj_from_string - ) + assert yaml_string == yaml_string_obj_from_stream == yaml_string_obj_from_string assert ( yaml_string == yaml_string_obj_from_stream diff --git a/tests/unit/modules/conftest.py b/tests/unit/modules/conftest.py index e19a1e04c..41465c300 100644 --- a/tests/unit/modules/conftest.py +++ b/tests/unit/modules/conftest.py @@ -2,15 +2,16 @@ # 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 import json import pytest -from ansible.module_utils.six import string_types from ansible.module_utils._text import to_bytes from ansible.module_utils.common._collections_compat import MutableMapping +from ansible.module_utils.six import string_types @pytest.fixture @@ -21,20 +22,11 @@ def patch_ansible_module(request, mocker): if "ANSIBLE_MODULE_ARGS" not in request.param: request.param = {"ANSIBLE_MODULE_ARGS": request.param} if "_ansible_remote_tmp" not in request.param["ANSIBLE_MODULE_ARGS"]: - request.param["ANSIBLE_MODULE_ARGS"][ - "_ansible_remote_tmp" - ] = "/tmp" - if ( - "_ansible_keep_remote_files" - not in request.param["ANSIBLE_MODULE_ARGS"] - ): - request.param["ANSIBLE_MODULE_ARGS"][ - "_ansible_keep_remote_files" - ] = False + request.param["ANSIBLE_MODULE_ARGS"]["_ansible_remote_tmp"] = "/tmp" + if "_ansible_keep_remote_files" not in request.param["ANSIBLE_MODULE_ARGS"]: + request.param["ANSIBLE_MODULE_ARGS"]["_ansible_keep_remote_files"] = False args = json.dumps(request.param) else: - raise Exception( - "Malformed data to the patch_ansible_module pytest fixture" - ) + raise Exception("Malformed data to the patch_ansible_module pytest fixture") mocker.patch("ansible.module_utils.basic._ANSIBLE_ARGS", to_bytes(args)) diff --git a/tests/unit/modules/network/nxos/nxos_module.py b/tests/unit/modules/network/nxos/nxos_module.py index 0c7b90c15..99e324da0 100644 --- a/tests/unit/modules/network/nxos/nxos_module.py +++ b/tests/unit/modules/network/nxos/nxos_module.py @@ -18,10 +18,11 @@ # Make coding more python3-ish from __future__ import absolute_import, division, print_function + __metaclass__ = type -import os import json +import os from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( AnsibleExitJson, @@ -34,9 +35,6 @@ def set_module_args(args, ignore_provider=None): - if "provider" not in args and not ignore_provider: - args["provider"] = {"transport": args.get("transport") or "cli"} - return _set_module_args(args) @@ -86,16 +84,11 @@ def execute_module_devices( retvals = {} for model in models: - retvals[model] = self.execute_module( - failed, changed, commands, sort, device=model - ) + retvals[model] = self.execute_module(failed, changed, commands, sort, device=model) return retvals - def execute_module( - self, failed=False, changed=False, commands=None, sort=True, device="" - ): - + def execute_module(self, failed=False, changed=False, commands=None, sort=True, device=""): self.load_fixtures(commands, device=device) if failed: @@ -112,9 +105,7 @@ def execute_module( result["commands"], ) else: - self.assertEqual( - commands, result["commands"], result["commands"] - ) + self.assertEqual(commands, result["commands"], result["commands"]) return result diff --git a/tests/unit/modules/network/nxos/test_nxos.py b/tests/unit/modules/network/nxos/test_nxos.py index fe465c339..fd5cdb36f 100644 --- a/tests/unit/modules/network/nxos/test_nxos.py +++ b/tests/unit/modules/network/nxos/test_nxos.py @@ -18,19 +18,22 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type from os import path + try: from unittest.mock import MagicMock except ImportError: from mock import MagicMock -from ansible_collections.cisco.nxos.tests.unit.compat import unittest -from ansible_collections.cisco.nxos.plugins.cliconf import nxos from ansible.module_utils._text import to_bytes, to_text +from ansible_collections.cisco.nxos.plugins.cliconf import nxos +from ansible_collections.cisco.nxos.tests.unit.compat import unittest + class TestPluginCLIConfNXOS(unittest.TestCase): """Test class for NXOS CLI Conf Methods""" @@ -58,7 +61,7 @@ def _connection_side_effect(*args, **kwargs): value = kwargs.get("command") fixture_path = path.abspath( - b"%s/%s" % (b_FIXTURE_DIR, b"_".join(value.split(b" "))) + b"%s/%s" % (b_FIXTURE_DIR, b"_".join(value.split(b" "))), ) with open(fixture_path, "rb") as file_desc: return to_text(file_desc.read()) @@ -109,17 +112,13 @@ def test_get_device_info_mds(self): def test_get_command_with_output_nxos(self): """Test _get_command_with_output for nxos""" self._prepare() - cmd = self._cliconf._get_command_with_output( - command="show version", output="json" - ) + cmd = self._cliconf._get_command_with_output(command="show version", output="json") self.assertEqual(cmd, "show version | json") def test_get_command_with_output_mds(self): """Test _get_command_with_output for mds""" self._prepare(platform="mds") - cmd = self._cliconf._get_command_with_output( - command="show version", output="json" - ) + cmd = self._cliconf._get_command_with_output(command="show version", output="json") self.assertEqual(cmd, "show version | json native") diff --git a/tests/unit/modules/network/nxos/test_nxos_acl.py b/tests/unit/modules/network/nxos/test_nxos_acl.py deleted file mode 100644 index b548dcb7f..000000000 --- a/tests/unit/modules/network/nxos/test_nxos_acl.py +++ /dev/null @@ -1,104 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# Make coding more python3-ish -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - -import json - -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.plugins.modules import nxos_acl -from .nxos_module import TestNxosModule, load_fixture, set_module_args - - -class TestNxosAclModule(TestNxosModule): - - module = nxos_acl - - def setUp(self): - super(TestNxosAclModule, self).setUp() - - self.mock_run_commands = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_acl.run_commands" - ) - self.run_commands = self.mock_run_commands.start() - - self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_acl.load_config" - ) - self.load_config = self.mock_load_config.start() - - def tearDown(self): - super(TestNxosAclModule, self).tearDown() - self.mock_run_commands.stop() - self.mock_load_config.stop() - - def load_fixtures(self, commands=None, device=""): - def load_from_file(*args, **kwargs): - module, commands = args - output = list() - - for item in commands: - try: - obj = json.loads(item) - command = obj["command"] - except ValueError: - command = item - filename = "%s.txt" % str(command).split(" | ", 1)[0].replace( - " ", "_" - ) - output.append(load_fixture("nxos_acl", filename)) - return output - - self.run_commands.side_effect = load_from_file - self.load_config.return_value = None - - def test_nxos_acl(self): - set_module_args( - dict( - name="ANSIBLE", - seq=10, - action="permit", - proto="tcp", - src="192.0.2.1/24", - dest="any", - ) - ) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], - ["ip access-list ANSIBLE", "10 permit tcp 192.0.2.1/24 any"], - ) - - def test_nxos_acl_remove(self): - set_module_args( - dict(name="copp-system-p-acl-bgp", seq=10, state="absent") - ) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], - ["ip access-list copp-system-p-acl-bgp", "no 10"], - ) - - def test_nxos_acl_delete_acl(self): - set_module_args(dict(name="copp-system-p-acl-bgp", state="delete_acl")) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], ["no ip access-list copp-system-p-acl-bgp"] - ) diff --git a/tests/unit/modules/network/nxos/test_nxos_acl_interface.py b/tests/unit/modules/network/nxos/test_nxos_acl_interface.py deleted file mode 100644 index 211e66696..000000000 --- a/tests/unit/modules/network/nxos/test_nxos_acl_interface.py +++ /dev/null @@ -1,98 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# Make coding more python3-ish - -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - -__metacl_interfaceass__ = type - -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.plugins.modules import nxos_acl_interface -from .nxos_module import TestNxosModule, load_fixture, set_module_args - - -class TestNxosAclInterfaceModule(TestNxosModule): - - module = nxos_acl_interface - - def setUp(self): - super(TestNxosAclInterfaceModule, self).setUp() - - self.mock_run_commands = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_acl_interface.run_commands" - ) - self.run_commands = self.mock_run_commands.start() - - self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_acl_interface.load_config" - ) - self.load_config = self.mock_load_config.start() - - def tearDown(self): - super(TestNxosAclInterfaceModule, self).tearDown() - self.mock_run_commands.stop() - self.mock_load_config.stop() - - def load_fixtures(self, commands=None, device=""): - def load_from_file(*args, **kwargs): - module, commands = args - output = list() - - for item in commands: - try: - command = item["command"] - except ValueError: - command = item - filename = "%s.txt" % str(command).split(" | ", 1)[0].replace( - " ", "_" - ) - output.append(load_fixture("nxos_acl_interface", filename)) - return output - - self.run_commands.side_effect = load_from_file - self.load_config.return_value = None - - def test_nxos_acl_interface(self): - set_module_args( - dict(name="ANSIBLE", interface="ethernet1/41", direction="egress") - ) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], - ["interface ethernet1/41", "ip access-group ANSIBLE out"], - ) - - def test_nxos_acl_interface_remove(self): - set_module_args( - dict( - name="copp-system-p-acl-bgp", - interface="ethernet1/41", - direction="egress", - state="absent", - ) - ) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], - [ - "interface ethernet1/41", - "no ip access-group copp-system-p-acl-bgp out", - ], - ) diff --git a/tests/unit/modules/network/nxos/test_nxos_acl_interfaces.py b/tests/unit/modules/network/nxos/test_nxos_acl_interfaces.py index 99eaf6c1f..ae56208fd 100644 --- a/tests/unit/modules/network/nxos/test_nxos_acl_interfaces.py +++ b/tests/unit/modules/network/nxos/test_nxos_acl_interfaces.py @@ -5,57 +5,49 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type from ansible_collections.cisco.nxos.plugins.modules import nxos_acl_interfaces -from ansible_collections.cisco.nxos.tests.unit.compat.mock import ( - patch, - MagicMock, -) -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - set_module_args, -) -from .nxos_module import TestNxosModule, load_fixture +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch +from ansible_collections.cisco.nxos.tests.unit.modules.utils import set_module_args +from .nxos_module import TestNxosModule -class TestNxosAclInterfacesModule(TestNxosModule): +class TestNxosAclInterfacesModule(TestNxosModule): module = nxos_acl_interfaces def setUp(self): super(TestNxosAclInterfacesModule, self).setUp() self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config" + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", ) self.get_config = self.mock_get_config.start() self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config" + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", ) self.load_config = self.mock_load_config.start() self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection" - ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection", ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" - ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection", ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_edit_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.acl_interfaces.acl_interfaces.Acl_interfaces.edit_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.acl_interfaces.acl_interfaces.Acl_interfaces.edit_config", ) self.edit_config = self.mock_edit_config.start() self.mock_execute_show_command = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.acl_interfaces.acl_interfaces.Acl_interfacesFacts.get_device_data" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.acl_interfaces.acl_interfaces.Acl_interfacesFacts.get_device_data", ) self.execute_show_command = self.mock_execute_show_command.start() @@ -85,12 +77,12 @@ def test_nxos_acl_interfaces_merged(self): dict( afi="ipv4", acls=[dict(name="ACL1-v4", direction="in")], - ) + ), ], - ) + ), ], state="merged", - ) + ), ) commands = ["interface Ethernet1/3", "ip access-group ACL1-v4 in"] self.execute_module(changed=True, commands=commands) @@ -105,7 +97,7 @@ def test_nxos_acl_interfaces_merged_idempotent(self): dict( afi="ipv4", acls=[dict(name="ACL1v4", direction="out")], - ) + ), ], ), dict( @@ -118,14 +110,14 @@ def test_nxos_acl_interfaces_merged_idempotent(self): name="ACL2v6", direction="in", port=True, - ) + ), ], - ) + ), ], ), ], state="merged", - ) + ), ) self.execute_module(changed=False, commands=[]) @@ -143,9 +135,9 @@ def test_nxos_acl_interfaces_replaced(self): name="ACL1v6", direction="in", port=True, - ) + ), ], - ) + ), ], ), dict( @@ -158,14 +150,14 @@ def test_nxos_acl_interfaces_replaced(self): name="ACL2v4", direction="in", port=True, - ) + ), ], - ) + ), ], ), ], state="replaced", - ) + ), ) commands = [ "interface Ethernet1/2", @@ -186,12 +178,12 @@ def test_nxos_acl_interfaces_replaced_idempotent(self): dict( afi="ipv4", acls=[dict(name="ACL1v4", direction="out")], - ) + ), ], - ) + ), ], state="replaced", - ) + ), ) self.execute_module(changed=False, commands=[]) @@ -212,12 +204,12 @@ def test_nxos_acl_interfaces_overridden(self): port=True, ), ], - ) + ), ], - ) + ), ], state="overridden", - ) + ), ) commands = [ "interface Ethernet1/2", @@ -240,7 +232,7 @@ def test_nxos_acl_interfaces_overridden_idempotent(self): dict( afi="ipv4", acls=[dict(name="ACL1v4", direction="out")], - ) + ), ], ), dict( @@ -253,32 +245,28 @@ def test_nxos_acl_interfaces_overridden_idempotent(self): name="ACL2v6", direction="in", port=True, - ) + ), ], - ) + ), ], ), ], state="overridden", - ) + ), ) self.execute_module(changed=False, commands=[]) def test_nxos_acl_interfaces_deletedname(self): - set_module_args( - dict(config=[dict(name="Ethernet1/2")], state="deleted") - ) + set_module_args(dict(config=[dict(name="Ethernet1/2")], state="deleted")) commands = ["interface Ethernet1/2", "no ip access-group ACL1v4 out"] self.execute_module(changed=True, commands=commands) def test_nxos_acl_interfaces_deletedafi(self): set_module_args( dict( - config=[ - dict(name="Ethernet1/2", access_groups=[dict(afi="ipv4")]) - ], + config=[dict(name="Ethernet1/2", access_groups=[dict(afi="ipv4")])], state="deleted", - ) + ), ) commands = ["interface Ethernet1/2", "no ip access-group ACL1v4 out"] self.execute_module(changed=True, commands=commands) @@ -293,12 +281,12 @@ def test_nxos_acl_interfaces_deletedacl(self): dict( afi="ipv4", acls=[dict(name="ACL1v4", direction="out")], - ) + ), ], - ) + ), ], state="deleted", - ) + ), ) commands = ["interface Ethernet1/2", "no ip access-group ACL1v4 out"] self.execute_module(changed=True, commands=commands) @@ -313,7 +301,7 @@ def test_nxos_acl_interfaces_rendered(self): dict( afi="ipv4", acls=[dict(name="ACL1v4", direction="out")], - ) + ), ], ), dict( @@ -326,14 +314,14 @@ def test_nxos_acl_interfaces_rendered(self): name="ACL2v6", direction="in", port=True, - ) + ), ], - ) + ), ], ), ], state="rendered", - ) + ), ) commands = [ "interface Ethernet1/2", @@ -342,9 +330,7 @@ def test_nxos_acl_interfaces_rendered(self): "ipv6 port traffic-filter ACL2v6 in", ] result = self.execute_module(changed=False) - self.assertEqual( - sorted(result["rendered"]), sorted(commands), result["rendered"] - ) + self.assertEqual(sorted(result["rendered"]), sorted(commands), result["rendered"]) def test_nxos_acl_interfaces_parsed(self): set_module_args( @@ -352,7 +338,7 @@ def test_nxos_acl_interfaces_parsed(self): running_config="""interface Ethernet1/2\n ip access-group ACL1v4 out\n interface Ethernet1/4\n \ ipv6 port traffic-filter ACL2v6 in""", state="parsed", - ) + ), ) result = self.execute_module(changed=False) compare_list = [ @@ -361,18 +347,16 @@ def test_nxos_acl_interfaces_parsed(self): { "acls": [{"direction": "out", "name": "ACL1v4"}], "afi": "ipv4", - } + }, ], "name": "Ethernet1/2", }, { "access_groups": [ { - "acls": [ - {"direction": "in", "name": "ACL2v6", "port": True} - ], + "acls": [{"direction": "in", "name": "ACL2v6", "port": True}], "afi": "ipv6", - } + }, ], "name": "Ethernet1/4", }, @@ -388,18 +372,16 @@ def test_nxos_acl_interfaces_gathered(self): { "acls": [{"direction": "out", "name": "ACL1v4"}], "afi": "ipv4", - } + }, ], "name": "Ethernet1/2", }, { "access_groups": [ { - "acls": [ - {"direction": "in", "name": "ACL2v6", "port": True} - ], + "acls": [{"direction": "in", "name": "ACL2v6", "port": True}], "afi": "ipv6", - } + }, ], "name": "Ethernet1/4", }, diff --git a/tests/unit/modules/network/nxos/test_nxos_acls.py b/tests/unit/modules/network/nxos/test_nxos_acls.py index c9b26d722..b7c0e8663 100644 --- a/tests/unit/modules/network/nxos/test_nxos_acls.py +++ b/tests/unit/modules/network/nxos/test_nxos_acls.py @@ -5,58 +5,51 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type +from textwrap import dedent + from ansible_collections.cisco.nxos.plugins.modules import nxos_acls -from ansible_collections.cisco.nxos.tests.unit.compat.mock import ( - patch, - MagicMock, -) -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch +from ansible_collections.cisco.nxos.tests.unit.modules.utils import set_module_args + from .nxos_module import TestNxosModule -from textwrap import dedent class TestNxosAclsModule(TestNxosModule): - module = nxos_acls def setUp(self): super(TestNxosAclsModule, self).setUp() self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config" + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", ) self.get_config = self.mock_get_config.start() self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config" + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", ) self.load_config = self.mock_load_config.start() self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection" - ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection", ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" - ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection", ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_edit_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.acls.acls.Acls.edit_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.acls.acls.Acls.edit_config", ) self.edit_config = self.mock_edit_config.start() self.mock_execute_show_command = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.acls.acls.AclsFacts.get_device_data" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.acls.acls.AclsFacts.get_device_data", ) self.execute_show_command = self.mock_execute_show_command.start() @@ -90,9 +83,7 @@ def test_nxos_acls_merged(self): fragments=True, sequence=20, protocol="tcp", - protocol_options=dict( - tcp=dict(ack=True) - ), + protocol_options=dict(tcp=dict(ack=True)), ), dict( destination=dict( @@ -110,24 +101,22 @@ def test_nxos_acls_merged(self): ), dict( grant="deny", - destination=dict( - prefix="2002:2:2:2::/64" - ), + destination=dict(prefix="2002:2:2:2::/64"), source=dict(prefix="2002:1:1:1::/64"), sequence=30, protocol="icmp", protocol_options=dict( - icmp=dict(echo_request=True) + icmp=dict(echo_request=True), ), ), ], - ) + ), ], ), dict(afi="ipv6", acls=[dict(name="ACL2v6")]), ], state="merged", - ) + ), ) commands = [ "ip access-list ACL2v4", @@ -163,7 +152,7 @@ def test_nxos_acls_merged_idempotent(self): protocol="udp", ), ], - ) + ), ], ), dict( @@ -178,14 +167,14 @@ def test_nxos_acls_merged_idempotent(self): source=dict(any=True), sequence=10, protocol="sctp", - ) + ), ], - ) + ), ], ), ], state="merged", - ) + ), ) self.execute_module(changed=False, commands=[]) @@ -207,18 +196,16 @@ def test_nxos_acls_replaced(self): sequence=50, protocol="icmp", protocol_options=dict( - icmp=dict( - administratively_prohibited=True - ) + icmp=dict(administratively_prohibited=True), ), - ) + ), ], - ) + ), ], - ) + ), ], state="replaced", - ) + ), ) commands = [ "ip access-list ACL1v4", @@ -253,7 +240,7 @@ def test_nxos_acls_replaced_idempotent(self): protocol="udp", ), ], - ) + ), ], ), dict( @@ -268,14 +255,14 @@ def test_nxos_acls_replaced_idempotent(self): source=dict(any=True), sequence=10, protocol="sctp", - ) + ), ], - ) + ), ], ), ], state="replaced", - ) + ), ) self.execute_module(changed=False, commands=[]) @@ -297,19 +284,17 @@ def test_nxos_acls_overridden(self): sequence=50, protocol="icmp", protocol_options=dict( - icmp=dict( - administratively_prohibited=True - ) + icmp=dict(administratively_prohibited=True), ), ), dict(remark="Overridden ACL"), ], - ) + ), ], - ) + ), ], state="overridden", - ) + ), ) commands = [ "no ip access-list ACL1v4", @@ -345,7 +330,7 @@ def test_nxos_acls_overridden_idempotent(self): protocol="udp", ), ], - ) + ), ], ), dict( @@ -360,14 +345,14 @@ def test_nxos_acls_overridden_idempotent(self): source=dict(any=True), sequence=10, protocol="sctp", - ) + ), ], - ) + ), ], ), ], state="overridden", - ) + ), ) self.execute_module(changed=False, commands=[]) @@ -406,7 +391,7 @@ def test_nxos_acls_rendered(self): protocol="udp", ), ], - ) + ), ], ), dict( @@ -421,14 +406,14 @@ def test_nxos_acls_rendered(self): source=dict(any=True), sequence=10, protocol="sctp", - ) + ), ], - ) + ), ], ), ], state="rendered", - ) + ), ) commands = [ "ip access-list ACL1v4", @@ -439,7 +424,9 @@ def test_nxos_acls_rendered(self): ] result = self.execute_module(changed=False) self.assertEqual( - sorted(result["rendered"]), sorted(commands), result["rendered"] + sorted(result["rendered"]), + sorted(commands), + result["rendered"], ) def test_nxos_acls_parsed(self): @@ -451,10 +438,10 @@ def test_nxos_acls_parsed(self): statistics per-entry 10 permit ip any any 20 deny udp any any dscp AF23 precedence critical - """ + """, ), state="parsed", - ) + ), ) result = self.execute_module(changed=False) compare_list = [ @@ -481,9 +468,9 @@ def test_nxos_acls_parsed(self): "precedence": "critical", }, ], - } + }, ], - } + }, ] self.assertEqual(result["parsed"], compare_list, result["parsed"]) @@ -501,10 +488,10 @@ def test_nxos_acls_gathered(self): "protocol": "sctp", "source": {"any": True}, "grant": "permit", - } + }, ], "name": "ACL1v6", - } + }, ], "afi": "ipv6", }, @@ -528,7 +515,7 @@ def test_nxos_acls_gathered(self): }, ], "name": "ACL1v4", - } + }, ], "afi": "ipv4", }, @@ -545,7 +532,7 @@ def test_nxos_acls_replaced_2(self): 40 remark TEST-COMMENT-2 50 permit ip 198.51.100.6/32 any 60 permit ip 198.51.100.7/32 any - """ + """, ) set_module_args( dict( @@ -585,12 +572,12 @@ def test_nxos_acls_replaced_2(self): protocol="ip", ), ], - ) + ), ], - ) + ), ], state="replaced", - ) + ), ) commands = [ @@ -614,7 +601,7 @@ def test_nxos_acls_merged_failure(self): """\ ip access-list 99 10 remark TEST-COMMENT-1 - """ + """, ) set_module_args( dict( @@ -631,14 +618,14 @@ def test_nxos_acls_merged_failure(self): source=dict(host="192.0.2.1"), sequence=10, protocol="ip", - ) + ), ], - ) + ), ], - ) + ), ], state="merged", - ) + ), ) result = self.execute_module(failed=True) @@ -650,13 +637,22 @@ def test_nxos_acls_parse_remark(self): """\ ip access-list TEST_RESEQUENCE 10 permit ip 10.0.0.0/24 any - 20 deny udp any any eq domain + 11 permit tcp 1.1.1.1/32 range 7111 9111 192.168.0.0/24 established + 20 deny tcp any eq ftp-data any eq domain + 25 permit icmp any any echo-reply + 27 permit icmp any any port-unreachable 30 remark for resetting to default run resequence ip access-list TEST_RESEQUENCE 2 3 ipv6 access-list TEST_RESEQUENCE_ipv6 10 permit udp any any 20 deny tcp any any 30 remark for resetting to default run resequence ip access-list TEST_RESEQUENCE_ipv6 2 3 - """ + ipv6 access-list TEST_PREFIX_HOST + 10 permit ipv6 fd00:976a::/32 any + 20 permit ipv6 2001:db8:85a3::8a2e:370:7334/128 any + ipv6 access-list TEST_ICMPv6 + 10 permit icmp any any nd-na + 20 deny icmp any any nd-ns telemetry_path + """, ) set_module_args(dict(state="gathered")) @@ -685,7 +681,56 @@ def test_nxos_acls_parse_remark(self): "remark": "for resetting to default run resequence ip access-list TEST_RESEQUENCE_ipv6 2 3", }, ], - } + }, + { + "name": "TEST_PREFIX_HOST", + "aces": [ + { + "sequence": 10, + "grant": "permit", + "protocol": "ipv6", + "source": {"prefix": "fd00:976a::/32"}, + "destination": {"any": True}, + }, + { + "sequence": 20, + "grant": "permit", + "protocol": "ipv6", + "source": {"host": "2001:db8:85a3::8a2e:370:7334"}, + "destination": {"any": True}, + }, + ], + }, + { + "name": "TEST_ICMPv6", + "aces": [ + { + "sequence": 10, + "grant": "permit", + "protocol": "icmpv6", + "protocol_options": { + "icmpv6": { + "nd_na": True, + }, + }, + "source": {"any": True}, + "destination": {"any": True}, + }, + { + "sequence": 20, + "grant": "deny", + "protocol": "icmpv6", + "protocol_options": { + "icmpv6": { + "nd_ns": True, + "telemetry_path": True, + }, + }, + "source": {"any": True}, + "destination": {"any": True}, + }, + ], + }, ], "afi": "ipv6", }, @@ -701,22 +746,214 @@ def test_nxos_acls_parse_remark(self): "source": {"prefix": "10.0.0.0/24"}, "destination": {"any": True}, }, + { + "sequence": 11, + "grant": "permit", + "protocol": "tcp", + "protocol_options": {"tcp": {"established": True}}, + "source": { + "host": "1.1.1.1", + "port_protocol": { + "range": {"end": "9111", "start": "7111"}, + }, + }, + "destination": {"prefix": "192.168.0.0/24"}, + }, { "sequence": 20, "grant": "deny", - "protocol": "udp", - "source": {"any": True}, + "protocol": "tcp", + "source": { + "any": True, + "port_protocol": {"eq": "ftp-data"}, + }, "destination": { "any": True, "port_protocol": {"eq": "domain"}, }, }, + { + "sequence": 25, + "grant": "permit", + "protocol": "icmp", + "protocol_options": { + "icmp": { + "echo_reply": True, + }, + }, + "source": { + "any": True, + }, + "destination": { + "any": True, + }, + }, + { + "sequence": 27, + "grant": "permit", + "protocol": "icmp", + "protocol_options": { + "icmp": { + "port_unreachable": True, + }, + }, + "source": { + "any": True, + }, + "destination": { + "any": True, + }, + }, { "sequence": 30, "remark": "for resetting to default run resequence ip access-list TEST_RESEQUENCE 2 3", }, ], - } + }, + ], + "afi": "ipv4", + }, + ] + result = self.execute_module(changed=False) + self.assertEqual(result["gathered"], gathered) + + def test_nxos_acls_icmpv6_1(self): + self.execute_show_command.return_value = dedent( + """\ + ipv6 access-list TEST_ICMPv6 + 20 deny icmp any any nd-ns telemetry_path + """, + ) + set_module_args( + dict( + config=[ + dict( + afi="ipv6", + acls=[ + dict( + name="TEST_ICMPv6", + aces=[ + dict( + grant="permit", + destination=dict(any=True), + source=dict(host="192.0.2.1"), + sequence=10, + protocol="icmpv6", + protocol_options=dict( + icmpv6=dict( + nd_na=True, + ), + ), + ), + dict( + grant="deny", + destination=dict(any=True), + source=dict(any=True), + sequence=20, + protocol="icmpv6", + protocol_options=dict( + icmpv6=dict( + nd_ns=True, + telemetry_path=True, + ), + ), + ), + ], + ), + ], + ), + ], + state="merged", + ), + ) + + commands = [ + "ipv6 access-list TEST_ICMPv6", + "10 permit icmp host 192.0.2.1 any nd-na", + ] + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], commands) + + def test_nxos_acls_ranges(self): + self.execute_show_command.return_value = dedent( + """\ + ip access-list acl1 + 10 permit tcp any any range ftp-data ftp + 20 permit tcp any range ftp-data ftp any range telnet time + 30 permit tcp any range ftp-data ftp any + """, + ) + set_module_args( + dict( + state="gathered", + ), + ) + + gathered = [ + { + "acls": [ + { + "name": "acl1", + "aces": [ + { + "sequence": 10, + "grant": "permit", + "protocol": "tcp", + "source": { + "any": True, + }, + "destination": { + "any": True, + "port_protocol": { + "range": { + "start": "ftp-data", + "end": "ftp", + }, + }, + }, + }, + { + "sequence": 20, + "grant": "permit", + "protocol": "tcp", + "source": { + "any": True, + "port_protocol": { + "range": { + "start": "ftp-data", + "end": "ftp", + }, + }, + }, + "destination": { + "any": True, + "port_protocol": { + "range": { + "start": "telnet", + "end": "time", + }, + }, + }, + }, + { + "sequence": 30, + "grant": "permit", + "protocol": "tcp", + "source": { + "any": True, + "port_protocol": { + "range": { + "start": "ftp-data", + "end": "ftp", + }, + }, + }, + "destination": { + "any": True, + }, + }, + ], + }, ], "afi": "ipv4", }, diff --git a/tests/unit/modules/network/nxos/test_nxos_banner.py b/tests/unit/modules/network/nxos/test_nxos_banner.py index a4784d58b..c9d564ddb 100644 --- a/tests/unit/modules/network/nxos/test_nxos_banner.py +++ b/tests/unit/modules/network/nxos/test_nxos_banner.py @@ -17,26 +17,27 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from ansible_collections.cisco.nxos.plugins.modules import nxos_banner +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from .nxos_module import TestNxosModule, set_module_args class TestNxosBannerModule(TestNxosModule): - module = nxos_banner def setUp(self): super(TestNxosBannerModule, self).setUp() self.mock_run_commands = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_banner.run_commands" + "ansible_collections.cisco.nxos.plugins.modules.nxos_banner.run_commands", ) self.run_commands = self.mock_run_commands.start() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_banner.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_banner.load_config", ) self.load_config = self.mock_load_config.start() @@ -99,3 +100,17 @@ def test_nxos_banner_with_preserved_spaces(self): commands = ["banner motd @\n foo \n\n@"] self.run_commands.return_value = commands self.execute_module(changed=True, commands=commands) + + def test_nxos_banner_multiline_delimiter(self): + set_module_args( + dict( + banner="exec", + text="this is my exec banner\nthat contains my email address email@address.com \nand it's a multiline string\n", + multiline_delimiter="*", + ), + ) + commands = [ + "banner exec *\nthis is my exec banner\nthat contains my email address email@address.com \nand it's a multiline string\n\n*", + ] + self.run_commands.return_value = commands + self.execute_module(changed=True, commands=commands) diff --git a/tests/unit/modules/network/nxos/test_nxos_bfd_global.py b/tests/unit/modules/network/nxos/test_nxos_bfd_global.py index ad4cd1a10..e0e48ac7a 100644 --- a/tests/unit/modules/network/nxos/test_nxos_bfd_global.py +++ b/tests/unit/modules/network/nxos/test_nxos_bfd_global.py @@ -19,45 +19,44 @@ from __future__ import absolute_import, division, print_function -__metaclass__ = type -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.plugins.modules import nxos_bfd_global -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - NxosCmdRef, -) -from .nxos_module import TestNxosModule, load_fixture, set_module_args +__metaclass__ = type # TBD: These imports / import checks are only needed as a workaround for # shippable, which fails this test due to import yaml & import ordereddict. import pytest + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( nxosCmdRef_import_check, ) +from ansible_collections.cisco.nxos.plugins.modules import nxos_bfd_global +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + +from .nxos_module import TestNxosModule, load_fixture, set_module_args + msg = nxosCmdRef_import_check() @pytest.mark.skipif(len(msg), reason=msg) class TestNxosBfdGlobalModule(TestNxosModule): - module = nxos_bfd_global def setUp(self): super(TestNxosBfdGlobalModule, self).setUp() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_bfd_global.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_bfd_global.load_config", ) self.load_config = self.mock_load_config.start() self.mock_execute_show_command = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos.NxosCmdRef.execute_show_command" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos.NxosCmdRef.execute_show_command", ) self.execute_show_command = self.mock_execute_show_command.start() self.mock_get_platform_shortname = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos.NxosCmdRef.get_platform_shortname" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos.NxosCmdRef.get_platform_shortname", ) self.get_platform_shortname = self.mock_get_platform_shortname.start() @@ -87,7 +86,7 @@ def test_bfd_defaults_n9k(self): ipv6_echo_rx_interval=50, ipv6_interval={"tx": 50, "min_rx": 50, "multiplier": 3}, ipv6_slow_timer=2000, - ) + ), ) self.execute_module(changed=False) @@ -110,7 +109,7 @@ def test_bfd_non_defaults_n9k(self): ipv6_echo_rx_interval=51, ipv6_interval={"tx": 51, "min_rx": 51, "multiplier": 4}, ipv6_slow_timer=2001, - ) + ), ) self.execute_module( changed=True, @@ -146,7 +145,7 @@ def test_bfd_defaults_n3k(self): ipv6_echo_rx_interval=250, ipv6_interval={"tx": 250, "min_rx": 250, "multiplier": 3}, ipv6_slow_timer=2000, - ) + ), ) self.execute_module(changed=False) @@ -164,7 +163,7 @@ def test_bfd_defaults_n35(self): ipv4_echo_rx_interval=50, ipv4_interval={"tx": 50, "min_rx": 50, "multiplier": 3}, ipv4_slow_timer=2000, - ) + ), ) self.execute_module(changed=False) @@ -180,7 +179,7 @@ def test_bfd_defaults_n6k(self): fabricpath_interval={"tx": 50, "min_rx": 50, "multiplier": 3}, fabricpath_slow_timer=2000, fabricpath_vlan=1, - ) + ), ) self.execute_module(changed=False) @@ -203,15 +202,13 @@ def test_bfd_defaults_n7k(self): fabricpath_interval={"tx": 50, "min_rx": 50, "multiplier": 3}, fabricpath_slow_timer=2000, fabricpath_vlan=1, - ) + ), ) self.execute_module(changed=False) def test_bfd_existing_n9k(self): module_name = self.module.__name__.rsplit(".", 1)[1] - self.execute_show_command.return_value = load_fixture( - module_name, "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture(module_name, "N9K.cfg") self.get_platform_shortname.return_value = "N9K" set_module_args( dict( @@ -226,7 +223,7 @@ def test_bfd_existing_n9k(self): ipv6_echo_rx_interval=50, ipv6_interval={"tx": 51, "min_rx": 51, "multiplier": 3}, ipv6_slow_timer=2000, - ) + ), ) self.execute_module( changed=True, @@ -247,9 +244,7 @@ def test_bfd_existing_n9k(self): def test_bfd_idempotence_n9k(self): module_name = self.module.__name__.rsplit(".", 1)[1] - self.execute_show_command.return_value = load_fixture( - module_name, "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture(module_name, "N9K.cfg") self.get_platform_shortname.return_value = "N9K" set_module_args( dict( @@ -264,15 +259,13 @@ def test_bfd_idempotence_n9k(self): ipv6_echo_rx_interval=56, ipv6_interval={"tx": 56, "min_rx": 56, "multiplier": 6}, ipv6_slow_timer=2006, - ) + ), ) self.execute_module(changed=False) def test_bfd_existing_n7k(self): module_name = self.module.__name__.rsplit(".", 1)[1] - self.execute_show_command.return_value = load_fixture( - module_name, "N7K.cfg" - ) + self.execute_show_command.return_value = load_fixture(module_name, "N7K.cfg") self.get_platform_shortname.return_value = "N7K" set_module_args( dict( @@ -289,7 +282,7 @@ def test_bfd_existing_n7k(self): fabricpath_interval={"tx": 51, "min_rx": 51, "multiplier": 3}, fabricpath_slow_timer=2003, fabricpath_vlan=3, - ) + ), ) self.execute_module( changed=True, @@ -312,9 +305,7 @@ def test_bfd_existing_n7k(self): def test_bfd_idempotence_n7k(self): module_name = self.module.__name__.rsplit(".", 1)[1] - self.execute_show_command.return_value = load_fixture( - module_name, "N7K.cfg" - ) + self.execute_show_command.return_value = load_fixture(module_name, "N7K.cfg") self.get_platform_shortname.return_value = "N7K" set_module_args( dict( @@ -331,6 +322,6 @@ def test_bfd_idempotence_n7k(self): fabricpath_interval={"tx": 58, "min_rx": 58, "multiplier": 8}, fabricpath_slow_timer=2008, fabricpath_vlan=2, - ) + ), ) self.execute_module(changed=False) diff --git a/tests/unit/modules/network/nxos/test_nxos_bfd_interfaces.py b/tests/unit/modules/network/nxos/test_nxos_bfd_interfaces.py index 8e5dc2712..e40f5fc2e 100644 --- a/tests/unit/modules/network/nxos/test_nxos_bfd_interfaces.py +++ b/tests/unit/modules/network/nxos/test_nxos_bfd_interfaces.py @@ -19,50 +19,43 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type from textwrap import dedent -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - AnsibleFailJson, -) + from ansible_collections.cisco.nxos.plugins.modules import nxos_bfd_interfaces -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.bfd_interfaces.bfd_interfaces import ( - Bfd_interfaces, -) -from .nxos_module import TestNxosModule, load_fixture, set_module_args +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + +from .nxos_module import TestNxosModule, set_module_args + ignore_provider_arg = True class TestNxosBfdInterfacesModule(TestNxosModule): - module = nxos_bfd_interfaces def setUp(self): super(TestNxosBfdInterfacesModule, self).setUp() self.mock_FACT_LEGACY_SUBSETS = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts.FACT_LEGACY_SUBSETS" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts.FACT_LEGACY_SUBSETS", ) self.FACT_LEGACY_SUBSETS = self.mock_FACT_LEGACY_SUBSETS.start() self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection" - ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection", ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" - ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection", ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_edit_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.bfd_interfaces.bfd_interfaces.Bfd_interfaces.edit_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.bfd_interfaces.bfd_interfaces.Bfd_interfaces.edit_config", ) self.edit_config = self.mock_edit_config.start() @@ -104,16 +97,14 @@ def test_1(self): interface Ethernet1/1 interface Ethernet1/2 interface Ethernet1/3 - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} playbook = dict( config=[ dict(name="Ethernet1/1", bfd="disable", echo="disable"), dict(name="Ethernet1/2", bfd="disable"), - ] + ], ) # Expected result commands for each 'state' merged = [ @@ -155,18 +146,16 @@ def test_2(self): interface Ethernet1/3 no bfd no bfd echo - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} playbook = dict( config=[ dict(name="Ethernet1/1", bfd="enable", echo="disable"), dict(name="Ethernet1/2"), # Eth1/3 not present! Thus overridden should set Eth1/3 to defaults; # replaced should ignore Eth1/3. - ] + ], ) # Expected result commands for each 'state' merged = ["interface Ethernet1/1", "bfd", "no bfd echo"] @@ -222,11 +211,9 @@ def test_3(self): interface Ethernet1/3 no bfd no bfd echo - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} playbook = dict(config=[dict(name="Ethernet1/1")]) # Expected result commands for each 'state' merged = [] @@ -265,14 +252,10 @@ def test_4(self): feature bfd interface Ethernet1/1 no bfd - """ - ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } - playbook = dict( - config=[dict(name="Ethernet1/1.42", bfd="enable", echo="disable")] + """, ) + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} + playbook = dict(config=[dict(name="Ethernet1/1.42", bfd="enable", echo="disable")]) # Expected result commands for each 'state' merged = ["interface Ethernet1/1.42", "bfd", "no bfd echo"] deleted = [] @@ -310,16 +293,14 @@ def test_5(self): no bfd no bfd echo interface Ethernet1/2 - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} playbook = dict( config=[ dict(name="Ethernet1/1", bfd="disable", echo="disable"), dict(name="Ethernet1/2", bfd="enable", echo="enable"), - ] + ], ) # Expected result commands for each 'state' merged = [] diff --git a/tests/unit/modules/network/nxos/test_nxos_bgp.py b/tests/unit/modules/network/nxos/test_nxos_bgp.py deleted file mode 100644 index 71edccf0c..000000000 --- a/tests/unit/modules/network/nxos/test_nxos_bgp.py +++ /dev/null @@ -1,162 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# Make coding more python3-ish - -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.plugins.modules import nxos_bgp -from .nxos_module import TestNxosModule, load_fixture, set_module_args - - -class TestNxosBgpModule(TestNxosModule): - - module = nxos_bgp - - def setUp(self): - super(TestNxosBgpModule, self).setUp() - - self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_bgp.load_config" - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_bgp.get_config" - ) - self.get_config = self.mock_get_config.start() - - def tearDown(self): - super(TestNxosBgpModule, self).tearDown() - self.mock_load_config.stop() - self.mock_get_config.stop() - - def load_fixtures(self, commands=None, device=""): - self.get_config.return_value = load_fixture("nxos_bgp", "config.cfg") - self.load_config.return_value = [] - - def test_nxos_bgp(self): - set_module_args(dict(asn=65535, router_id="192.0.2.1")) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], ["router bgp 65535", "router-id 192.0.2.1"] - ) - - def test_nxos_bgp_change_nothing(self): - set_module_args(dict(asn=65535, router_id="192.168.1.1")) - self.execute_module(changed=False) - - def test_nxos_bgp_wrong_asn(self): - set_module_args(dict(asn=10, router_id="192.168.1.1")) - result = self.execute_module(failed=True) - self.assertEqual(result["msg"], "Another BGP ASN already exists.") - - def test_nxos_bgp_remove(self): - set_module_args(dict(asn=65535, state="absent")) - self.execute_module(changed=True, commands=["no router bgp 65535"]) - - def test_nxos_bgp_remove_vrf(self): - set_module_args(dict(asn=65535, vrf="test2", state="absent")) - self.execute_module( - changed=True, commands=["router bgp 65535", "no vrf test2"] - ) - - def test_nxos_bgp_remove_nonexistant_vrf(self): - set_module_args(dict(asn=65535, vrf="foo", state="absent")) - self.execute_module(changed=False) - - def test_nxos_bgp_remove_wrong_asn(self): - set_module_args(dict(asn=10, state="absent")) - self.execute_module(changed=False) - - def test_nxos_bgp_vrf(self): - set_module_args(dict(asn=65535, vrf="test", router_id="192.0.2.1")) - result = self.execute_module( - changed=True, - commands=["router bgp 65535", "vrf test", "router-id 192.0.2.1"], - ) - self.assertEqual(result["warnings"], ["VRF test doesn't exist."]) - - def test_nxos_bgp_global_param(self): - set_module_args(dict(asn=65535, shutdown=True)) - self.execute_module( - changed=True, commands=["router bgp 65535", "shutdown"] - ) - - def test_nxos_bgp_global_param_outside_default(self): - set_module_args(dict(asn=65535, vrf="test", shutdown=True)) - result = self.execute_module(failed=True) - self.assertEqual( - result["msg"], - 'Global params can be modified only under "default" VRF.', - ) - - def test_nxos_bgp_default_value(self): - set_module_args( - dict(asn=65535, graceful_restart_timers_restart="default") - ) - self.execute_module( - changed=True, - commands=["router bgp 65535", "graceful-restart restart-time 120"], - ) - - -class TestNxosBgp32BitsAS(TestNxosModule): - - module = nxos_bgp - - def setUp(self): - super(TestNxosBgp32BitsAS, self).setUp() - - self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_bgp.load_config" - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_bgp.get_config" - ) - self.get_config = self.mock_get_config.start() - - def tearDown(self): - super(TestNxosBgp32BitsAS, self).tearDown() - self.mock_load_config.stop() - self.mock_get_config.stop() - - def load_fixtures(self, commands=None, device=""): - self.get_config.return_value = load_fixture( - "nxos_bgp", "config_32_bits_as.cfg" - ) - self.load_config.return_value = [] - - def test_nxos_bgp_change_nothing(self): - set_module_args(dict(asn="65535.65535", router_id="192.168.1.1")) - self.execute_module(changed=False) - - def test_nxos_bgp_wrong_asn(self): - set_module_args(dict(asn="65535.10", router_id="192.168.1.1")) - result = self.execute_module(failed=True) - self.assertEqual(result["msg"], "Another BGP ASN already exists.") - - def test_nxos_bgp_remove(self): - set_module_args(dict(asn="65535.65535", state="absent")) - self.execute_module( - changed=True, commands=["no router bgp 65535.65535"] - ) diff --git a/tests/unit/modules/network/nxos/test_nxos_bgp_address_family.py b/tests/unit/modules/network/nxos/test_nxos_bgp_address_family.py index 45ecf350f..d9c6c2357 100644 --- a/tests/unit/modules/network/nxos/test_nxos_bgp_address_family.py +++ b/tests/unit/modules/network/nxos/test_nxos_bgp_address_family.py @@ -19,24 +19,21 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type from textwrap import dedent + +from ansible_collections.cisco.nxos.plugins.modules import nxos_bgp_address_family from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - AnsibleFailJson, -) -from ansible_collections.cisco.nxos.plugins.modules import ( - nxos_bgp_address_family, -) -from .nxos_module import TestNxosModule, load_fixture, set_module_args +from .nxos_module import TestNxosModule, set_module_args + ignore_provider_arg = True class TestNxosBGPAddressFamilyModule(TestNxosModule): - # Testing strategy # ------------------ # (a) The unit tests cover `merged` and `replaced` for every attribute. @@ -54,14 +51,12 @@ def setUp(self): super(TestNxosBGPAddressFamilyModule, self).setUp() self.mock_get_resource_connection = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" - ) - self.get_resource_connection = ( - self.mock_get_resource_connection.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", ) + self.get_resource_connection = self.mock_get_resource_connection.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.bgp_address_family.bgp_address_family.Bgp_address_familyFacts.get_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.bgp_address_family.bgp_address_family.Bgp_address_familyFacts.get_config", ) self.get_config = self.mock_get_config.start() @@ -79,7 +74,7 @@ def test_nxos_bgp_additional_paths_merged(self): address-family ipv4 unicast additional-paths install backup additional-paths send - """ + """, ) set_module_args( dict( @@ -146,7 +141,7 @@ def test_nxos_bgp_additional_paths_replaced(self): vrf site-2 address-family ipv6 multicast additional-paths receive - """ + """, ) set_module_args( dict( @@ -156,9 +151,7 @@ def test_nxos_bgp_additional_paths_replaced(self): dict( afi="ipv4", safi="multicast", - additional_paths=dict( - selection=dict(route_map="rmap1") - ), + additional_paths=dict(selection=dict(route_map="rmap1")), ), dict( vrf="site-1", @@ -193,7 +186,7 @@ def test_nxos_bgp_l2vpn_keys_merged(self): router bgp 65563 address-family l2vpn evpn advertise-pip - """ + """, ) set_module_args( dict( @@ -206,7 +199,7 @@ def test_nxos_bgp_l2vpn_keys_merged(self): advertise_pip=False, advertise_system_mac=True, allow_vni_in_ethertag=True, - ) + ), ], ), state="merged", @@ -231,15 +224,13 @@ def test_nxos_bgp_l2vpn_keys_replaced(self): address-family l2vpn evpn advertise-system-mac allow-vni-in-ethertag - """ + """, ) set_module_args( dict( config=dict( as_number="65563", - address_family=[ - dict(afi="l2vpn", safi="evpn", advertise_pip=True) - ], + address_family=[dict(afi="l2vpn", safi="evpn", advertise_pip=True)], ), state="replaced", ), @@ -263,7 +254,7 @@ def test_nxos_bgp_client_to_client_merged(self): vrf site-1 address-family ipv4 unicast no client-to-client reflection - """ + """, ) set_module_args( dict( @@ -309,7 +300,7 @@ def test_nxos_bgp_client_to_client_replaced(self): vrf site-1 address-family ipv4 unicast no client-to-client reflection - """ + """, ) set_module_args( dict( @@ -349,7 +340,7 @@ def test_nxos_bgp_aggregate_address_merged(self): vrf site-1 address-family ipv4 unicast aggregate-address 192.168.1.0/24 as-set - """ + """, ) set_module_args( dict( @@ -360,9 +351,7 @@ def test_nxos_bgp_aggregate_address_merged(self): afi="ipv4", safi="multicast", aggregate_address=[ - dict( - prefix="192.168.1.0/24", summary_only=True - ), + dict(prefix="192.168.1.0/24", summary_only=True), dict( prefix="192.168.2.0/24", advertise_map="rmap1", @@ -424,7 +413,7 @@ def test_nxos_bgp_aggregate_address_replaced(self): address-family ipv4 unicast aggregate-address 10.0.0.0/8 summary-only aggregate-address 11.0.0.0/8 advertise-map rmap1 as-set attribute-map rmap2 - """ + """, ) set_module_args( dict( @@ -440,7 +429,7 @@ def test_nxos_bgp_aggregate_address_replaced(self): advertise_map="rmap1", as_set=True, attribute_map="rmap2", - ) + ), ], ), dict( @@ -486,16 +475,14 @@ def test_nxos_bgp_dampen_igp_metric_merged(self): vrf site-1 address-family ipv4 unicast dampen-igp-metric 1200 - """ + """, ) set_module_args( dict( config=dict( as_number="65563", address_family=[ - dict( - afi="ipv4", safi="multicast", dampen_igp_metric=300 - ), + dict(afi="ipv4", safi="multicast", dampen_igp_metric=300), dict( vrf="site-1", afi="ipv4", @@ -531,7 +518,7 @@ def test_nxos_bgp_dampen_igp_metric_replaced(self): dampen-igp-metric 1800 address-family ipv6 unicast dampen-igp-metric 1200 - """ + """, ) set_module_args( dict( @@ -569,7 +556,7 @@ def test_nxos_bgp_dampening_merged(self): vrf site-1 address-family ipv4 unicast dampening 3 22 23 23 - """ + """, ) set_module_args( dict( @@ -633,7 +620,7 @@ def test_nxos_bgp_dampening_replaced(self): vrf site-1 address-family ipv4 unicast dampening 3 22 23 23 - """ + """, ) set_module_args( dict( @@ -674,7 +661,7 @@ def test_nxos_bgp_dampening_route_map_merged(self): vrf site-1 address-family ipv4 unicast dampening route-map rmap1 - """ + """, ) set_module_args( dict( @@ -719,7 +706,7 @@ def test_nxos_bgp_dampening_route_map_replaced(self): vrf site-1 address-family ipv4 unicast dampening route-map rmap1 - """ + """, ) set_module_args( dict( @@ -755,7 +742,7 @@ def test_nxos_bgp_default_information_merged(self): vrf site-1 address-family ipv4 unicast default-information originate - """ + """, ) set_module_args( dict( @@ -800,7 +787,7 @@ def test_nxos_bgp_default_information_replaced(self): vrf site-1 address-family ipv4 unicast default-information originate - """ + """, ) set_module_args( dict( @@ -836,16 +823,14 @@ def test_nxos_bgp_default_metric_merged(self): vrf site-1 address-family ipv4 unicast default-metric 6400 - """ + """, ) set_module_args( dict( config=dict( as_number="65563", address_family=[ - dict( - afi="ipv4", safi="multicast", default_metric=7200 - ), + dict(afi="ipv4", safi="multicast", default_metric=7200), dict( vrf="site-1", afi="ipv4", @@ -881,7 +866,7 @@ def test_nxos_bgp_default_metric_replaced(self): vrf site-1 address-family ipv4 unicast default-metric 6400 - """ + """, ) set_module_args( dict( @@ -917,7 +902,7 @@ def test_nxos_bgp_distance_merged(self): vrf site-1 address-family ipv4 unicast distance 20 18 2 - """ + """, ) set_module_args( dict( @@ -927,17 +912,13 @@ def test_nxos_bgp_distance_merged(self): dict( afi="ipv4", safi="multicast", - distance=dict( - ebgp_routes=25, ibgp_routes=12, local_routes=4 - ), + distance=dict(ebgp_routes=25, ibgp_routes=12, local_routes=4), ), dict( vrf="site-1", afi="ipv4", safi="unicast", - distance=dict( - ebgp_routes=20, ibgp_routes=18, local_routes=3 - ), + distance=dict(ebgp_routes=20, ibgp_routes=18, local_routes=3), ), ], ), @@ -968,7 +949,7 @@ def test_nxos_bgp_distance_replaced(self): vrf site-1 address-family ipv4 unicast distance 20 18 2 - """ + """, ) set_module_args( dict( @@ -980,9 +961,7 @@ def test_nxos_bgp_distance_replaced(self): vrf="site-1", afi="ipv4", safi="unicast", - distance=dict( - ebgp_routes=20, ibgp_routes=18, local_routes=2 - ), + distance=dict(ebgp_routes=20, ibgp_routes=18, local_routes=2), ), ], ), @@ -1009,7 +988,7 @@ def test_nxos_bgp_export_gateway_ip_merged(self): vrf site-2 address-family ipv4 unicast export-gateway-ip - """ + """, ) set_module_args( dict( @@ -1067,7 +1046,7 @@ def test_nxos_bgp_export_gateway_ip_replaced(self): vrf site-2 address-family ipv4 unicast export-gateway-ip - """ + """, ) set_module_args( dict( @@ -1112,7 +1091,7 @@ def test_nxos_bgp_inject_map_merged(self): vrf site-1 address-family ipv4 unicast inject-map rmap1 exist-map rmap2 - """ + """, ) set_module_args( dict( @@ -1140,7 +1119,7 @@ def test_nxos_bgp_inject_map_merged(self): route_map="rmap3", exist_map="rmap4", copy_attributes=True, - ) + ), ], ), ], @@ -1172,7 +1151,7 @@ def test_nxos_bgp_inject_map_replaced(self): vrf site-1 address-family ipv4 unicast inject-map rmap3 exist-map rmap4 copy-attributes - """ + """, ) set_module_args( dict( @@ -1182,9 +1161,7 @@ def test_nxos_bgp_inject_map_replaced(self): dict( afi="ipv4", safi="multicast", - inject_map=[ - dict(route_map="rmap1", exist_map="rmap3") - ], + inject_map=[dict(route_map="rmap1", exist_map="rmap3")], ), dict( vrf="site-1", @@ -1195,7 +1172,7 @@ def test_nxos_bgp_inject_map_replaced(self): route_map="rmap3", exist_map="rmap4", copy_attributes=True, - ) + ), ], ), ], @@ -1223,7 +1200,7 @@ def test_nxos_bgp_maximum_paths_merged(self): address-family ipv4 unicast maximum-paths 14 maximum-paths eibgp 64 - """ + """, ) set_module_args( dict( @@ -1233,9 +1210,7 @@ def test_nxos_bgp_maximum_paths_merged(self): dict( afi="ipv4", safi="multicast", - maximum_paths=dict( - parallel_paths=15, ibgp=dict(parallel_paths=64) - ), + maximum_paths=dict(parallel_paths=15, ibgp=dict(parallel_paths=64)), ), dict( vrf="site-1", @@ -1288,7 +1263,7 @@ def test_nxos_bgp_maximum_paths_replaced(self): maximum-paths local 30 address-family ipv4 multicast maximum-paths mixed 40 - """ + """, ) set_module_args( dict( @@ -1298,9 +1273,7 @@ def test_nxos_bgp_maximum_paths_replaced(self): dict( afi="ipv4", safi="multicast", - maximum_paths=dict( - parallel_paths=15, ibgp=dict(parallel_paths=64) - ), + maximum_paths=dict(parallel_paths=15, ibgp=dict(parallel_paths=64)), ), dict( vrf="site-1", @@ -1334,7 +1307,7 @@ def test_nxos_bgp_network_merged(self): vrf site-1 address-family ipv4 unicast network 192.168.1.0/24 route-map rmap1 - """ + """, ) set_module_args( dict( @@ -1345,13 +1318,9 @@ def test_nxos_bgp_network_merged(self): afi="ipv4", safi="multicast", networks=[ - dict( - prefix="192.168.1.0/24", route_map="rmap2" - ), + dict(prefix="192.168.1.0/24", route_map="rmap2"), dict(prefix="192.168.2.0/24"), - dict( - prefix="192.168.3.0/24", route_map="rmap3" - ), + dict(prefix="192.168.3.0/24", route_map="rmap3"), ], ), dict( @@ -1397,7 +1366,7 @@ def test_nxos_bgp_network_replaced(self): network 10.0.0.0/8 network 11.0.0.0/8 route-map rmap2 network 192.168.1.0/24 route-map rmap1 - """ + """, ) set_module_args( dict( @@ -1407,19 +1376,13 @@ def test_nxos_bgp_network_replaced(self): dict( afi="ipv4", safi="multicast", - networks=[ - dict( - prefix="192.168.3.0/24", route_map="rmap4" - ) - ], + networks=[dict(prefix="192.168.3.0/24", route_map="rmap4")], ), dict( vrf="site-1", afi="ipv4", safi="unicast", - networks=[ - dict(prefix="11.0.0.0/8", route_map="rmap2") - ], + networks=[dict(prefix="11.0.0.0/8", route_map="rmap2")], ), ], ), @@ -1449,7 +1412,7 @@ def test_nxos_bgp_nexthop_merged(self): vrf site-1 address-family ipv4 unicast nexthop route-map rmap2 - """ + """, ) set_module_args( dict( @@ -1461,9 +1424,7 @@ def test_nxos_bgp_nexthop_merged(self): safi="multicast", nexthop=dict( route_map="rmap1", - trigger_delay=dict( - critical_delay=120, non_critical_delay=180 - ), + trigger_delay=dict(critical_delay=120, non_critical_delay=180), ), ), dict( @@ -1471,9 +1432,7 @@ def test_nxos_bgp_nexthop_merged(self): afi="ipv4", safi="unicast", nexthop=dict( - trigger_delay=dict( - critical_delay=110, non_critical_delay=170 - ) + trigger_delay=dict(critical_delay=110, non_critical_delay=170), ), ), ], @@ -1506,7 +1465,7 @@ def test_nxos_bgp_nexthop_replaced(self): address-family ipv4 unicast nexthop route-map rmap2 nexthop trigger-delay critical 110 non-critical 170 - """ + """, ) set_module_args( dict( @@ -1523,9 +1482,7 @@ def test_nxos_bgp_nexthop_replaced(self): afi="ipv4", safi="unicast", nexthop=dict( - trigger_delay=dict( - critical_delay=110, non_critical_delay=170 - ) + trigger_delay=dict(critical_delay=110, non_critical_delay=170), ), ), ], @@ -1553,7 +1510,7 @@ def test_nxos_bgp_redistribute_merged(self): vrf site-1 address-family ipv4 unicast redistribute eigrp 100 route-map test-17 - """ + """, ) set_module_args( dict( @@ -1630,7 +1587,7 @@ def test_nxos_bgp_redistribute_replaced(self): address-family ipv4 unicast redistribute eigrp 100 route-map test-18 redistribute ospf 101 route-map test-2 - """ + """, ) set_module_args( dict( @@ -1659,7 +1616,7 @@ def test_nxos_bgp_redistribute_replaced(self): protocol="ospf", id="101", route_map="test-2", - ) + ), ], ), ], @@ -1688,7 +1645,7 @@ def test_nxos_bgp_retain_merged(self): vrf site-1 address-family ipv4 unicast retain route-target all - """ + """, ) set_module_args( dict( @@ -1733,7 +1690,7 @@ def test_nxos_bgp_retain_replaced(self): vrf site-1 address-family ipv4 unicast retain route-target route-map rmap1 - """ + """, ) set_module_args( dict( @@ -1769,7 +1726,7 @@ def test_nxos_bgp_suppress_inactive_merged(self): vrf site-1 address-family ipv4 unicast suppress-inactive - """ + """, ) set_module_args( dict( @@ -1814,7 +1771,7 @@ def test_nxos_bgp_suppress_inactive_replaced(self): vrf site-1 address-family ipv4 unicast suppress-inactive - """ + """, ) set_module_args( dict( @@ -1850,7 +1807,7 @@ def test_nxos_bgp_table_map_merged(self): vrf site-1 address-family ipv4 unicast table-map rmap1 filter - """ + """, ) set_module_args( dict( @@ -1890,7 +1847,7 @@ def test_nxos_bgp_table_map_replaced(self): vrf site-1 address-family ipv4 unicast table-map rmap1 filter - """ + """, ) set_module_args( dict( @@ -1928,7 +1885,7 @@ def test_nxos_bgp_timers_merged(self): vrf site-1 address-family ipv4 unicast timers bestpath-defer 100 maximum 350 - """ + """, ) set_module_args( dict( @@ -1939,9 +1896,7 @@ def test_nxos_bgp_timers_merged(self): afi="ipv4", safi="multicast", timers=dict( - bestpath_defer=dict( - defer_time=120, maximum_defer_time=380 - ) + bestpath_defer=dict(defer_time=120, maximum_defer_time=380), ), ), dict( @@ -1949,9 +1904,7 @@ def test_nxos_bgp_timers_merged(self): afi="ipv4", safi="unicast", timers=dict( - bestpath_defer=dict( - defer_time=110, maximum_defer_time=350 - ) + bestpath_defer=dict(defer_time=110, maximum_defer_time=350), ), ), ], @@ -1981,7 +1934,7 @@ def test_nxos_bgp_timers_replaced(self): vrf site-1 address-family ipv4 unicast timers bestpath-defer 100 maximum 350 - """ + """, ) set_module_args( dict( @@ -1992,9 +1945,7 @@ def test_nxos_bgp_timers_replaced(self): afi="ipv4", safi="multicast", timers=dict( - bestpath_defer=dict( - defer_time=120, maximum_defer_time=380 - ) + bestpath_defer=dict(defer_time=120, maximum_defer_time=380), ), ), dict(vrf="site-1", afi="ipv4", safi="unicast"), @@ -2021,7 +1972,7 @@ def test_nxos_bgp_wait_igp_convergence_merged(self): vrf site-1 address-family ipv4 unicast wait-igp-convergence - """ + """, ) set_module_args( dict( @@ -2066,7 +2017,7 @@ def test_nxos_bgp_wait_igp_convergence_replaced(self): vrf site-1 address-family ipv4 unicast wait-igp-convergence - """ + """, ) set_module_args( dict( @@ -2111,7 +2062,7 @@ def test_nxos_bgp_af_parsed(self): vrf site-1 address-family ipv4 unicast timers bestpath-defer 100 maximum 350 - """ + """, ), state="parsed", ), @@ -2125,11 +2076,7 @@ def test_nxos_bgp_af_parsed(self): vrf="site-1", afi="ipv4", safi="unicast", - timers=dict( - bestpath_defer=dict( - defer_time=100, maximum_defer_time=350 - ) - ), + timers=dict(bestpath_defer=dict(defer_time=100, maximum_defer_time=350)), ), ], ) @@ -2152,7 +2099,7 @@ def test_nxos_bgp_af_gathered(self): timers bestpath-defer 100 maximum 350 neighbor 192.168.3.0 address-family ipv6 multicast - """ + """, ) set_module_args(dict(state="gathered"), ignore_provider_arg) @@ -2164,11 +2111,7 @@ def test_nxos_bgp_af_gathered(self): vrf="site-1", afi="ipv4", safi="unicast", - timers=dict( - bestpath_defer=dict( - defer_time=100, maximum_defer_time=350 - ) - ), + timers=dict(bestpath_defer=dict(defer_time=100, maximum_defer_time=350)), ), ], ) @@ -2179,7 +2122,7 @@ def test_nxos_bgp_af_gathered_empty(self): # test gathered self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args(dict(state="gathered"), ignore_provider_arg) @@ -2190,7 +2133,7 @@ def test_nxos_bgp_af_rendered(self): # test gathered self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args( @@ -2219,7 +2162,7 @@ def test_nxos_bgp_af_rendered(self): protocol="ospf", id="101", route_map="test-2", - ) + ), ], ), ], @@ -2259,7 +2202,7 @@ def test_nxos_bgp_af_delete(self): address-family ipv6 multicast vrf site-2 address-family ipv6 unicast - """ + """, ) set_module_args( @@ -2297,7 +2240,7 @@ def test_nxos_bgp_af_idempotent(self): router bgp 65563 address-family ipv4 multicast wait-igp-convergence - """ + """, ) set_module_args( @@ -2309,7 +2252,7 @@ def test_nxos_bgp_af_idempotent(self): afi="ipv4", safi="multicast", wait_igp_convergence=True, - ) + ), ], ), state="merged", @@ -2337,7 +2280,7 @@ def test_nxos_bgp_af_overridden(self): address-family ipv6 multicast vrf site-2 address-family ipv6 unicast - """ + """, ) set_module_args( @@ -2349,7 +2292,7 @@ def test_nxos_bgp_af_overridden(self): afi="ipv4", safi="multicast", wait_igp_convergence=False, - ) + ), ], ), state="overridden", @@ -2391,7 +2334,7 @@ def test_nxos_bgp_af_delete(self): address-family ipv6 multicast vrf site-2 address-family ipv6 unicast - """ + """, ) set_module_args(dict(state="deleted"), ignore_provider_arg) @@ -2419,7 +2362,7 @@ def test_nxos_bgp_vrf_af_advertise_l2vpn_evpn(self): vrf site-2 address-family ipv4 unicast advertise l2vpn evpn - """ + """, ) set_module_args( dict( @@ -2466,7 +2409,7 @@ def test_nxos_bgp_vrf_af_advertise_l2vpn_evpn_replaced(self): vrf site-2 address-family ipv4 unicast advertise l2vpn evpn - """ + """, ) set_module_args( dict( diff --git a/tests/unit/modules/network/nxos/test_nxos_bgp_af.py b/tests/unit/modules/network/nxos/test_nxos_bgp_af.py deleted file mode 100644 index b4fc5de33..000000000 --- a/tests/unit/modules/network/nxos/test_nxos_bgp_af.py +++ /dev/null @@ -1,192 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# Make coding more python3-ish - -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.plugins.modules import nxos_bgp_af -from .nxos_module import TestNxosModule, load_fixture, set_module_args - - -class TestNxosBgpAfModule(TestNxosModule): - - module = nxos_bgp_af - - def setUp(self): - super(TestNxosBgpAfModule, self).setUp() - - self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_bgp_af.load_config" - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_bgp_af.get_config" - ) - self.get_config = self.mock_get_config.start() - - def tearDown(self): - super(TestNxosBgpAfModule, self).tearDown() - self.mock_load_config.stop() - self.mock_get_config.stop() - - def load_fixtures(self, commands=None, device=""): - self.get_config.return_value = load_fixture("nxos_bgp", "config.cfg") - self.load_config.return_value = None - - def test_nxos_bgp_af(self): - set_module_args(dict(asn=65535, afi="ipv4", safi="unicast")) - self.execute_module( - changed=True, - sort=False, - commands=["router bgp 65535", "address-family ipv4 unicast"], - ) - - def test_nxos_bgp_af_vrf(self): - set_module_args( - dict(asn=65535, vrf="test", afi="ipv4", safi="unicast") - ) - self.execute_module( - changed=True, - sort=False, - commands=[ - "router bgp 65535", - "vrf test", - "address-family ipv4 unicast", - ], - ) - - def test_nxos_bgp_af_vrf_exists(self): - set_module_args( - dict(asn=65535, vrf="test2", afi="ipv4", safi="unicast") - ) - self.execute_module(changed=False, commands=[]) - - def test_nxos_bgp_af_dampening_routemap(self): - set_module_args( - dict( - asn=65535, - afi="ipv4", - safi="unicast", - dampening_routemap="route-map-a", - ) - ) - self.execute_module( - changed=True, - commands=[ - "router bgp 65535", - "address-family ipv4 unicast", - "dampening route-map route-map-a", - ], - ) - - def test_nxos_bgp_af_dampening_manual(self): - set_module_args( - dict( - asn=65535, - afi="ipv4", - safi="unicast", - dampening_half_time=5, - dampening_suppress_time=2000, - dampening_reuse_time=1900, - dampening_max_suppress_time=10, - ) - ) - self.execute_module( - changed=True, - commands=[ - "router bgp 65535", - "address-family ipv4 unicast", - "dampening 5 1900 2000 10", - ], - ) - - def test_nxos_bgp_af_dampening_mix(self): - set_module_args( - dict( - asn=65535, - afi="ipv4", - safi="unicast", - dampening_routemap="route-map-a", - dampening_half_time=5, - dampening_suppress_time=2000, - dampening_reuse_time=1900, - dampening_max_suppress_time=10, - ) - ) - result = self.execute_module(failed=True) - self.assertEqual( - result["msg"], - "parameters are mutually exclusive: dampening_routemap|dampening_half_time, " - "dampening_routemap|dampening_suppress_time, dampening_routemap|dampening_reuse_time, " - "dampening_routemap|dampening_max_suppress_time", - ) - - def test_nxos_bgp_af_client(self): - set_module_args( - dict(asn=65535, afi="ipv4", safi="unicast", client_to_client=False) - ) - self.execute_module( - changed=True, - commands=[ - "router bgp 65535", - "address-family ipv4 unicast", - "no client-to-client reflection", - ], - ) - - def test_nxos_bgp_af_retain_route_target(self): - set_module_args( - dict( - asn=65535, afi="l2vpn", safi="evpn", retain_route_target="abc" - ) - ) - self.execute_module( - changed=True, - commands=[ - "router bgp 65535", - "address-family l2vpn evpn", - "retain route-target route-map abc", - ], - ) - - def test_nxos_bgp_af_retain_route_target_all(self): - set_module_args( - dict( - asn=65535, afi="l2vpn", safi="evpn", retain_route_target="all" - ) - ) - self.execute_module( - changed=True, - commands=[ - "router bgp 65535", - "address-family l2vpn evpn", - "retain route-target all", - ], - ) - - def test_nxos_bgp_af_retain_route_target_exists(self): - set_module_args( - dict( - asn=65535, afi="l2vpn", safi="evpn", retain_route_target="xyz" - ) - ) - self.execute_module(changed=False, commands=[]) diff --git a/tests/unit/modules/network/nxos/test_nxos_bgp_global.py b/tests/unit/modules/network/nxos/test_nxos_bgp_global.py index d7b343db1..22c9378eb 100644 --- a/tests/unit/modules/network/nxos/test_nxos_bgp_global.py +++ b/tests/unit/modules/network/nxos/test_nxos_bgp_global.py @@ -19,41 +19,38 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type from textwrap import dedent -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - AnsibleFailJson, -) + from ansible_collections.cisco.nxos.plugins.modules import nxos_bgp_global +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + +from .nxos_module import TestNxosModule, set_module_args -from .nxos_module import TestNxosModule, load_fixture, set_module_args ignore_provider_arg = True class TestNxosBgpGlobalModule(TestNxosModule): - module = nxos_bgp_global def setUp(self): super(TestNxosBgpGlobalModule, self).setUp() self.mock_get_resource_connection = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" - ) - self.get_resource_connection = ( - self.mock_get_resource_connection.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", ) + self.get_resource_connection = self.mock_get_resource_connection.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.bgp_global.bgp_global.Bgp_globalFacts.get_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.bgp_global.bgp_global.Bgp_globalFacts.get_config", ) self.get_config = self.mock_get_config.start() self.mock_cfg_get_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.bgp_global.bgp_global.Bgp_global._get_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.bgp_global.bgp_global.Bgp_global._get_config", ) self.cfg_get_config = self.mock_cfg_get_config.start() @@ -90,9 +87,12 @@ def test_nxos_bgp_global_merged(self): dict( neighbor_address="198.51.100.21", remote_as="65537", - password=dict( - encryption=7, key="12090404011C03162E" - ), + password=dict(encryption=7, key="12090404011C03162E"), + ), + dict( + neighbor_address="2001:4000:4000:fff1::/64", + remote_as_route_map="rmap1", + description="TEST_NBR", ), ], vrfs=[ @@ -111,7 +111,12 @@ def test_nxos_bgp_global_merged(self): encryption=3, key="13D4D3549493D2877B1DC116EE27A6BE", ), - ) + ), + dict( + neighbor_address="2001:4000:5000:fff1::/64", + remote_as_route_map="rmap2", + description="TEST_NBR_2", + ), ], ), dict( @@ -139,6 +144,8 @@ def test_nxos_bgp_global_merged(self): "neighbor 198.51.100.21", "remote-as 65537", "password 7 12090404011C03162E", + "neighbor 2001:4000:4000:fff1::/64 remote-as route-map rmap1", + "description TEST_NBR", "vrf site-1", "local-as 200", "log-neighbor-changes", @@ -148,6 +155,8 @@ def test_nxos_bgp_global_merged(self): "description site-1-nbr-1", "password 3 13D4D3549493D2877B1DC116EE27A6BE", "timers 5 15", + "neighbor 2001:4000:5000:fff1::/64 remote-as route-map rmap2", + "description TEST_NBR_2", "vrf site-2", "local-as 300", "log-neighbor-changes", @@ -171,7 +180,7 @@ def test_nxos_bgp_global_bfd(self): tx_interval=300, min_rx_interval=258, multiplier=12, - ) + ), ), ), ), @@ -185,7 +194,7 @@ def test_nxos_bgp_global_bfd(self): min_rx_interval=260, multiplier=15, ), - ) + ), ), ), dict( @@ -240,7 +249,7 @@ def test_nxos_bgp_global_bfd(self): bfd multihop neighbor 198.51.100.24 bfd - """ + """, ) self.get_config.return_value = run_cfg self.cfg_get_config.return_value = run_cfg @@ -259,7 +268,7 @@ def test_nxos_bgp_global_bfd(self): tx_interval=300, min_rx_interval=258, multiplier=12, - ) + ), ), ), ), @@ -273,7 +282,7 @@ def test_nxos_bgp_global_bfd(self): min_rx_interval=260, multiplier=15, ), - ) + ), ), ), dict( @@ -313,6 +322,8 @@ def test_nxos_bgp_global_merged_idempotent(self): neighbor 198.51.100.21 remote-as 65537 password 7 12090404011C03162E + neighbor 2001:4000:4000:fff1::/64 remote-as route-map rmap1 + description TEST_NBR vrf site-1 local-as 200 log-neighbor-changes @@ -325,7 +336,7 @@ def test_nxos_bgp_global_merged_idempotent(self): local-as 300 log-neighbor-changes neighbor-down fib-accelerate - """ + """, ) self.get_config.return_value = run_cfg @@ -347,9 +358,12 @@ def test_nxos_bgp_global_merged_idempotent(self): dict( neighbor_address="198.51.100.21", remote_as="65537", - password=dict( - encryption=7, key="12090404011C03162E" - ), + password=dict(encryption=7, key="12090404011C03162E"), + ), + dict( + neighbor_address="2001:4000:4000:fff1::/64", + remote_as_route_map="rmap1", + description="TEST_NBR", ), ], vrfs=[ @@ -367,7 +381,7 @@ def test_nxos_bgp_global_merged_idempotent(self): encryption=3, key="13D4D3549493D2877B1DC116EE27A6BE", ), - ) + ), ], ), dict( @@ -413,7 +427,7 @@ def test_nxos_bgp_global_replaced(self): local-as 300 log-neighbor-changes neighbor-down fib-accelerate - """ + """, ) self.get_config.return_value = run_cfg self.cfg_get_config.return_value = run_cfg @@ -432,7 +446,7 @@ def test_nxos_bgp_global_replaced(self): remote_as="65537", description="NBR-1", low_memory=dict(exempt=True), - ) + ), ], vrfs=[ dict( @@ -449,9 +463,9 @@ def test_nxos_bgp_global_replaced(self): encryption=3, key="13D4D3549493D2877B1DC116EE27A6BE", ), - ) + ), ], - ) + ), ], ), state="replaced", @@ -472,6 +486,93 @@ def test_nxos_bgp_global_replaced(self): result = self.execute_module(changed=True) self.assertEqual(set(result["commands"]), set(commands)) + def test_nxos_bgp_global_overridden(self): + run_cfg = dedent( + """\ + router bgp 65536 + log-neighbor-changes + maxas-limit 20 + router-id 198.51.100.2 + neighbor 198.51.100.20 + remote-as 65537 + affinity-group 161 + description NBR-1 + shutdown + low-memory exempt + neighbor 198.51.100.21 + remote-as 65537 + password 7 12090404011C03162E + vrf site-1 + local-as 200 + log-neighbor-changes + neighbor 192.0.2.10 + affinity-group 170 + remote-as 65538 + description site-1-nbr-1 + password 3 13D4D3549493D2877B1DC116EE27A6BE + vrf site-2 + local-as 300 + log-neighbor-changes + neighbor-down fib-accelerate + """, + ) + self.get_config.return_value = run_cfg + self.cfg_get_config.return_value = run_cfg + + set_module_args( + dict( + config=dict( + as_number="65536", + router_id="198.51.100.212", + log_neighbor_changes=True, + maxas_limit=20, + neighbors=[ + dict( + neighbor_address="198.51.100.20", + neighbor_affinity_group=dict(group_id=161), + remote_as="65537", + description="NBR-1", + low_memory=dict(exempt=True), + ), + ], + vrfs=[ + dict( + vrf="site-1", + local_as="200", + log_neighbor_changes=True, + neighbors=[ + dict( + neighbor_address="192.0.2.10", + neighbor_affinity_group=dict(group_id=190), + remote_as="65538", + description="site-1-nbr-1", + password=dict( + encryption=3, + key="13D4D3549493D2877B1DC116EE27A6BE", + ), + ), + ], + ), + ], + ), + state="overridden", + ), + ignore_provider_arg, + ) + commands = [ + "router bgp 65536", + "router-id 198.51.100.212", + "neighbor 198.51.100.20", + "no shutdown", + "no neighbor 198.51.100.21", + "vrf site-1", + "neighbor 192.0.2.10", + "affinity-group 190", + "no vrf site-2", + ] + result = self.execute_module(changed=True) + self.assertEqual(set(result["commands"]), set(commands)) + def test_nxos_bgp_global_replaced_idempotent(self): run_cfg = dedent( """\ @@ -492,7 +593,7 @@ def test_nxos_bgp_global_replaced_idempotent(self): remote-as 65538 description site-1-nbr-1 password 3 13D4D3549493D2877B1DC116EE27A6BE - """ + """, ) self.get_config.return_value = run_cfg self.cfg_get_config.return_value = run_cfg @@ -511,7 +612,7 @@ def test_nxos_bgp_global_replaced_idempotent(self): remote_as="65537", description="NBR-1", low_memory=dict(exempt=True), - ) + ), ], vrfs=[ dict( @@ -528,9 +629,9 @@ def test_nxos_bgp_global_replaced_idempotent(self): encryption=3, key="13D4D3549493D2877B1DC116EE27A6BE", ), - ) + ), ], - ) + ), ], ), state="replaced", @@ -568,7 +669,7 @@ def test_nxos_bgp_global_replaced_failed_1(self): local-as 300 log-neighbor-changes neighbor-down fib-accelerate - """ + """, ) self.get_config.return_value = run_cfg self.cfg_get_config.return_value = run_cfg @@ -587,7 +688,7 @@ def test_nxos_bgp_global_replaced_failed_1(self): remote_as="65537", description="NBR-1", low_memory=dict(exempt=True), - ) + ), ], vrfs=[ dict( @@ -604,9 +705,9 @@ def test_nxos_bgp_global_replaced_failed_1(self): encryption=3, key="13D4D3549493D2877B1DC116EE27A6BE", ), - ) + ), ], - ) + ), ], ), state="replaced", @@ -643,7 +744,7 @@ def test_nxos_bgp_global_replaced_failed_2(self): local-as 300 log-neighbor-changes neighbor-down fib-accelerate - """ + """, ) self.get_config.return_value = run_cfg self.cfg_get_config.return_value = run_cfg @@ -666,9 +767,7 @@ def test_nxos_bgp_global_replaced_failed_2(self): dict( neighbor_address="198.51.100.21", remote_as="65537", - password=dict( - encryption=7, key="12090404011C03162E" - ), + password=dict(encryption=7, key="12090404011C03162E"), ), ], vrfs=[ @@ -677,7 +776,7 @@ def test_nxos_bgp_global_replaced_failed_2(self): local_as="300", log_neighbor_changes=True, neighbor_down=dict(fib_accelerate=True), - ) + ), ], ), state="replaced", @@ -714,7 +813,7 @@ def test_nxos_bgp_global_replaced_failed_3(self): local-as 300 log-neighbor-changes neighbor-down fib-accelerate - """ + """, ) self.get_config.return_value = run_cfg self.cfg_get_config.return_value = run_cfg @@ -737,9 +836,7 @@ def test_nxos_bgp_global_replaced_failed_3(self): dict( neighbor_address="198.51.100.21", remote_as="65537", - password=dict( - encryption=7, key="12090404011C03162E" - ), + password=dict(encryption=7, key="12090404011C03162E"), ), ], vrfs=[ @@ -789,7 +886,7 @@ def test_nxos_bgp_global_deleted(self): local-as 300 log-neighbor-changes neighbor-down fib-accelerate - """ + """, ) self.get_config.return_value = run_cfg self.cfg_get_config.return_value = run_cfg @@ -812,7 +909,7 @@ def test_nxos_bgp_global_deleted(self): def test_nxos_bgp_global_deleted_idempotent_1(self): run_cfg = dedent( """\ - """ + """, ) self.get_config.return_value = run_cfg self.cfg_get_config.return_value = run_cfg @@ -849,7 +946,7 @@ def test_nxos_bgp_global_deleted_idempotent_2(self): local-as 300 log-neighbor-changes neighbor-down fib-accelerate - """ + """, ) self.get_config.return_value = run_cfg self.cfg_get_config.return_value = run_cfg @@ -890,7 +987,7 @@ def test_nxos_bgp_global_deleted_failed(self): local-as 300 log-neighbor-changes neighbor-down fib-accelerate - """ + """, ) self.get_config.return_value = run_cfg self.cfg_get_config.return_value = run_cfg @@ -925,7 +1022,7 @@ def test_nxos_bgp_global_purged(self): local-as 300 log-neighbor-changes neighbor-down fib-accelerate - """ + """, ) self.get_config.return_value = run_cfg self.cfg_get_config.return_value = run_cfg @@ -939,7 +1036,7 @@ def test_nxos_bgp_global_purged(self): def test_nxos_bgp_global_purged_idempotent(self): run_cfg = dedent( """\ - """ + """, ) self.get_config.return_value = run_cfg self.cfg_get_config.return_value = run_cfg @@ -953,7 +1050,7 @@ def test_nxos_bgp_global_purged(self): run_cfg = dedent( """\ router bgp 65001 - """ + """, ) self.get_config.return_value = run_cfg self.cfg_get_config.return_value = run_cfg @@ -967,7 +1064,7 @@ def test_nxos_bgp_global_purged(self): neighbor_address="10.239.0.13", peer_type="fabric-external", remote_as="65002", - ) + ), ], ), state="merged", @@ -983,3 +1080,36 @@ def test_nxos_bgp_global_purged(self): result = self.execute_module(changed=True) self.assertEqual(set(result["commands"]), set(commands)) + + def test_nxos_bgp_global_neighbor_3K(self): + run_cfg = dedent( + """\ + router bgp 65535 + neighbor 192.168.20.2 remote-as 56789 + address-family ipv4 unicast + soft-reconfiguration inbound always + """, + ) + self.get_config.return_value = "" + self.cfg_get_config.return_value = "" + + set_module_args( + dict( + running_config=run_cfg, + state="parsed", + ), + ignore_provider_arg, + ) + + parsed = { + "as_number": "65535", + "neighbors": [ + { + "neighbor_address": "192.168.20.2", + "remote_as": "56789", + }, + ], + } + + result = self.execute_module(changed=False) + self.assertEqual(result["parsed"], parsed) diff --git a/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor.py b/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor.py deleted file mode 100644 index ebaa38529..000000000 --- a/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor.py +++ /dev/null @@ -1,155 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# Make coding more python3-ish - -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.plugins.modules import nxos_bgp_neighbor -from .nxos_module import TestNxosModule, load_fixture, set_module_args - - -class TestNxosBgpNeighborModule(TestNxosModule): - - module = nxos_bgp_neighbor - - def setUp(self): - super(TestNxosBgpNeighborModule, self).setUp() - - self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_bgp_neighbor.load_config" - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_bgp_neighbor.get_config" - ) - self.get_config = self.mock_get_config.start() - - def tearDown(self): - super(TestNxosBgpNeighborModule, self).tearDown() - self.mock_load_config.stop() - self.mock_get_config.stop() - - def load_fixtures(self, commands=None, device=""): - self.get_config.return_value = load_fixture("nxos_bgp", "config.cfg") - self.load_config.return_value = [] - - def test_nxos_bgp_neighbor_bfd_1(self): - # None (disable) -> enable - set_module_args(dict(asn=65535, neighbor="1.1.1.1", bfd="enable")) - self.execute_module( - changed=True, - commands=["router bgp 65535", "neighbor 1.1.1.1", "bfd"], - ) - - # enable -> enable (idempotence) - set_module_args(dict(asn=65535, neighbor="1.1.1.2", bfd="enable")) - self.execute_module(changed=False) - - def test_nxos_bgp_neighbor_bfd_2(self): - # enable -> None (disable) - set_module_args(dict(asn=65535, neighbor="1.1.1.2", bfd="disable")) - self.execute_module( - changed=True, - commands=["router bgp 65535", "neighbor 1.1.1.2", "no bfd"], - ) - - # None (disable) -> disable (idempotence) - set_module_args(dict(asn=65535, neighbor="1.1.1.1", bfd="disable")) - self.execute_module(changed=False) - - def test_nxos_bgp_neighbor(self): - set_module_args( - dict(asn=65535, neighbor="192.0.2.3", description="some words") - ) - self.execute_module( - changed=True, - commands=[ - "router bgp 65535", - "neighbor 192.0.2.3", - "description some words", - ], - ) - - def test_nxos_bgp_neighbor_absent(self): - set_module_args(dict(asn=65535, neighbor="1.1.1.1", state="absent")) - self.execute_module( - changed=True, commands=["router bgp 65535", "no neighbor 1.1.1.1"] - ) - - def test_nxos_bgp_neighbor_remove_private_as(self): - set_module_args( - dict(asn=65535, neighbor="3.3.3.4", remove_private_as="all") - ) - self.execute_module(changed=False, commands=[]) - - def test_nxos_bgp_neighbor_remove_private_as_changed(self): - set_module_args( - dict(asn=65535, neighbor="3.3.3.4", remove_private_as="replace-as") - ) - self.execute_module( - changed=True, - commands=[ - "router bgp 65535", - "neighbor 3.3.3.4", - "remove-private-as replace-as", - ], - ) - - def test_nxos_bgp_neighbor_peertype_border_leaf(self): - set_module_args( - dict( - asn=65535, neighbor="192.0.2.3", peer_type="fabric_border_leaf" - ) - ) - self.execute_module( - changed=True, - commands=[ - "router bgp 65535", - "neighbor 192.0.2.3", - "peer-type fabric-border-leaf", - ], - ) - - def test_nxos_bgp_neighbor_peertype_external(self): - set_module_args( - dict(asn=65535, neighbor="192.0.2.3", peer_type="fabric_external") - ) - self.execute_module( - changed=True, - commands=[ - "router bgp 65535", - "neighbor 192.0.2.3", - "peer-type fabric-external", - ], - ) - - def test_nxos_bgp_neighbor_peertype_border_leaf_exists(self): - set_module_args( - dict(asn=65535, neighbor="5.5.5.5", peer_type="fabric_border_leaf") - ) - self.execute_module(changed=False) - - def test_nxos_bgp_neighbor_peertype_external_exists(self): - set_module_args( - dict(asn=65535, neighbor="6.6.6.6", peer_type="fabric_external") - ) - self.execute_module(changed=False) diff --git a/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor_address_family.py b/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor_address_family.py index 172b0695b..b3943f370 100644 --- a/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor_address_family.py +++ b/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor_address_family.py @@ -19,24 +19,21 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type from textwrap import dedent + +from ansible_collections.cisco.nxos.plugins.modules import nxos_bgp_neighbor_address_family from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - AnsibleFailJson, -) -from ansible_collections.cisco.nxos.plugins.modules import ( - nxos_bgp_neighbor_address_family, -) -from .nxos_module import TestNxosModule, load_fixture, set_module_args +from .nxos_module import TestNxosModule, set_module_args + ignore_provider_arg = True class TestNxosBGPNeighborAddressFamilyModule(TestNxosModule): - # Testing strategy # ------------------ # (a) The unit tests cover `merged` and `replaced` for every attribute. @@ -54,15 +51,13 @@ def setUp(self): super(TestNxosBGPNeighborAddressFamilyModule, self).setUp() self.mock_get_resource_connection = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" - ) - self.get_resource_connection = ( - self.mock_get_resource_connection.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", ) + self.get_resource_connection = self.mock_get_resource_connection.start() self.mock_get_config = patch( "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.bgp_neighbor_address_family." - "bgp_neighbor_address_family.Bgp_neighbor_address_familyFacts.get_config" + "bgp_neighbor_address_family.Bgp_neighbor_address_familyFacts.get_config", ) self.get_config = self.mock_get_config.start() @@ -82,7 +77,7 @@ def test_nxos_bgp_nbr_af_advertise_map_merged(self): advertise-map rmap2 exist-map rmap3 address-family ipv4 multicast advertise-map rmap1 non-exist-map rmap5 - """ + """, ) set_module_args( dict( @@ -95,12 +90,10 @@ def test_nxos_bgp_nbr_af_advertise_map_merged(self): dict( afi="ipv4", safi="multicast", - advertise_map=dict( - route_map="rmap1", exist_map="rmap2" - ), - ) + advertise_map=dict(route_map="rmap1", exist_map="rmap2"), + ), ], - ) + ), ], vrfs=[ dict( @@ -126,9 +119,9 @@ def test_nxos_bgp_nbr_af_advertise_map_merged(self): ), ), ], - ) + ), ], - ) + ), ], ), state="merged", @@ -162,7 +155,7 @@ def test_nxos_bgp_nbr_af_advertise_map_replaced(self): advertise-map rmap2 exist-map rmap3 address-family ipv4 multicast advertise-map rmap1 non-exist-map rmap5 - """ + """, ) set_module_args( dict( @@ -175,12 +168,10 @@ def test_nxos_bgp_nbr_af_advertise_map_replaced(self): dict( afi="ipv4", safi="multicast", - advertise_map=dict( - route_map="rmap1", exist_map="rmap3" - ), - ) + advertise_map=dict(route_map="rmap1", exist_map="rmap3"), + ), ], - ) + ), ], vrfs=[ dict( @@ -199,9 +190,9 @@ def test_nxos_bgp_nbr_af_advertise_map_replaced(self): ), dict(afi="ipv4", safi="multicast"), ], - ) + ), ], - ) + ), ], ), state="replaced", @@ -230,7 +221,7 @@ def test_nxos_bgp_nbr_af_advertisement_interval_merged(self): neighbor 192.168.1.1 address-family ipv4 unicast advertisement-interval 300 - """ + """, ) set_module_args( dict( @@ -244,9 +235,9 @@ def test_nxos_bgp_nbr_af_advertisement_interval_merged(self): afi="ipv4", safi="multicast", advertisement_interval=350, - ) + ), ], - ) + ), ], vrfs=[ dict( @@ -266,9 +257,9 @@ def test_nxos_bgp_nbr_af_advertisement_interval_merged(self): advertisement_interval=400, ), ], - ) + ), ], - ) + ), ], ), state="merged", @@ -304,7 +295,7 @@ def test_nxos_bgp_nbr_af_advertisement_interval_replaced(self): advertisement-interval 300 address-family ipv4 multicast advertisement-interval 400 - """ + """, ) set_module_args( dict( @@ -321,7 +312,7 @@ def test_nxos_bgp_nbr_af_advertisement_interval_replaced(self): advertisement_interval=350, ), ], - ) + ), ], vrfs=[ dict( @@ -337,9 +328,9 @@ def test_nxos_bgp_nbr_af_advertisement_interval_replaced(self): ), dict(afi="ipv4", safi="multicast"), ], - ) + ), ], - ) + ), ], ), state="replaced", @@ -370,7 +361,7 @@ def test_nxos_bgp_nbr_af_allowas_in_merged(self): allowas-in 3 address-family ipv4 multicast allowas-in 3 - """ + """, ) set_module_args( dict( @@ -384,9 +375,9 @@ def test_nxos_bgp_nbr_af_allowas_in_merged(self): afi="ipv4", safi="multicast", allowas_in=dict(max_occurences=8), - ) + ), ], - ) + ), ], vrfs=[ dict( @@ -406,9 +397,9 @@ def test_nxos_bgp_nbr_af_allowas_in_merged(self): allowas_in=dict(max_occurences=3), ), ], - ) + ), ], - ) + ), ], ), state="merged", @@ -442,7 +433,7 @@ def test_nxos_bgp_nbr_af_allowas_in_replaced(self): allowas-in 5 address-family ipv4 multicast allowas-in 3 - """ + """, ) set_module_args( dict( @@ -456,9 +447,9 @@ def test_nxos_bgp_nbr_af_allowas_in_replaced(self): afi="ipv4", safi="multicast", allowas_in=dict(max_occurences=9), - ) + ), ], - ) + ), ], vrfs=[ dict( @@ -474,9 +465,9 @@ def test_nxos_bgp_nbr_af_allowas_in_replaced(self): ), dict(afi="ipv4", safi="multicast"), ], - ) + ), ], - ) + ), ], ), state="replaced", @@ -510,7 +501,7 @@ def test_nxos_bgp_nbr_af_as_override_merged(self): as-override address-family ipv4 multicast as-override - """ + """, ) set_module_args( dict( @@ -524,9 +515,9 @@ def test_nxos_bgp_nbr_af_as_override_merged(self): afi="ipv4", safi="multicast", as_override=True, - ) + ), ], - ) + ), ], vrfs=[ dict( @@ -546,9 +537,9 @@ def test_nxos_bgp_nbr_af_as_override_merged(self): as_override=False, ), ], - ) + ), ], - ) + ), ], ), state="merged", @@ -584,7 +575,7 @@ def test_nxos_bgp_nbr_af_as_override_replaced(self): as-override address-family ipv4 multicast as-override - """ + """, ) set_module_args( dict( @@ -593,10 +584,8 @@ def test_nxos_bgp_nbr_af_as_override_replaced(self): neighbors=[ dict( neighbor_address="10.0.0.2", - address_family=[ - dict(afi="ipv4", safi="multicast") - ], - ) + address_family=[dict(afi="ipv4", safi="multicast")], + ), ], vrfs=[ dict( @@ -612,9 +601,9 @@ def test_nxos_bgp_nbr_af_as_override_replaced(self): ), dict(afi="ipv4", safi="multicast"), ], - ) + ), ], - ) + ), ], ), state="replaced", @@ -647,7 +636,7 @@ def test_nxos_bgp_nbr_af_capability_merged(self): address-family ipv4 multicast capability additional-paths receive disable capability additional-paths send - """ + """, ) set_module_args( dict( @@ -661,13 +650,11 @@ def test_nxos_bgp_nbr_af_capability_merged(self): afi="ipv4", safi="multicast", capability=dict( - additional_paths=dict( - receive="enable", send="enable" - ) + additional_paths=dict(receive="enable", send="enable"), ), - ) + ), ], - ) + ), ], vrfs=[ dict( @@ -683,7 +670,7 @@ def test_nxos_bgp_nbr_af_capability_merged(self): additional_paths=dict( receive="disable", send="enable", - ) + ), ), ), dict( @@ -693,13 +680,13 @@ def test_nxos_bgp_nbr_af_capability_merged(self): additional_paths=dict( receive="enable", send="disable", - ) + ), ), ), ], - ) + ), ], - ) + ), ], ), state="merged", @@ -741,7 +728,7 @@ def test_nxos_bgp_nbr_af_capability_replaced(self): address-family ipv4 multicast capability additional-paths receive capability additional-paths send disable - """ + """, ) set_module_args( dict( @@ -754,12 +741,10 @@ def test_nxos_bgp_nbr_af_capability_replaced(self): dict( afi="ipv4", safi="multicast", - capability=dict( - additional_paths=dict(send="enable") - ), - ) + capability=dict(additional_paths=dict(send="enable")), + ), ], - ) + ), ], vrfs=[ dict( @@ -775,14 +760,14 @@ def test_nxos_bgp_nbr_af_capability_replaced(self): additional_paths=dict( receive="disable", send="enable", - ) + ), ), ), dict(afi="ipv4", safi="multicast"), ], - ) + ), ], - ) + ), ], ), state="replaced", @@ -815,7 +800,7 @@ def test_nxos_bgp_nbr_af_originate_peer_as_merged(self): disable-peer-as-check address-family ipv4 multicast default-originate route-map rmap1 - """ + """, ) set_module_args( dict( @@ -837,7 +822,7 @@ def test_nxos_bgp_nbr_af_originate_peer_as_merged(self): default_originate=dict(route_map="rmap1"), ), ], - ) + ), ], vrfs=[ dict( @@ -855,14 +840,12 @@ def test_nxos_bgp_nbr_af_originate_peer_as_merged(self): dict( afi="ipv4", safi="multicast", - default_originate=dict( - route_map="rmap2" - ), + default_originate=dict(route_map="rmap2"), ), ], - ) + ), ], - ) + ), ], ), state="merged", @@ -903,7 +886,7 @@ def test_nxos_bgp_nbr_af_originate_peer_as_merged(self): disable-peer-as-check address-family ipv4 multicast default-originate route-map rmap1 - """ + """, ) set_module_args( dict( @@ -920,7 +903,7 @@ def test_nxos_bgp_nbr_af_originate_peer_as_merged(self): default_originate=dict(route_map="rmap1"), ), ], - ) + ), ], vrfs=[ dict( @@ -937,9 +920,9 @@ def test_nxos_bgp_nbr_af_originate_peer_as_merged(self): ), dict(afi="ipv4", safi="multicast"), ], - ) + ), ], - ) + ), ], ), state="replaced", @@ -975,7 +958,7 @@ def test_nxos_bgp_nbr_af_filter_list_inherit_merged(self): address-family ipv4 multicast filter-list rmap1 out inherit peer-policy template-1 300 - """ + """, ) set_module_args( dict( @@ -988,15 +971,11 @@ def test_nxos_bgp_nbr_af_filter_list_inherit_merged(self): dict( afi="ipv4", safi="multicast", - filter_list=dict( - inbound="rmap3", outbound="rmap4" - ), - inherit=dict( - template="template-2", sequence=200 - ), - ) + filter_list=dict(inbound="rmap3", outbound="rmap4"), + inherit=dict(template="template-2", sequence=200), + ), ], - ) + ), ], vrfs=[ dict( @@ -1027,9 +1006,9 @@ def test_nxos_bgp_nbr_af_filter_list_inherit_merged(self): ), ), ], - ) + ), ], - ) + ), ], ), state="merged", @@ -1072,7 +1051,7 @@ def test_nxos_bgp_nbr_af_filter_list_inherit_replaced(self): filter-list rmap1 out filter-list rmap2 in inherit peer-policy template-1 300 - """ + """, ) set_module_args( dict( @@ -1086,12 +1065,10 @@ def test_nxos_bgp_nbr_af_filter_list_inherit_replaced(self): afi="ipv4", safi="multicast", filter_list=dict(inbound="rmap3"), - inherit=dict( - template="template-2", sequence=200 - ), - ) + inherit=dict(template="template-2", sequence=200), + ), ], - ) + ), ], vrfs=[ dict( @@ -1114,9 +1091,9 @@ def test_nxos_bgp_nbr_af_filter_list_inherit_replaced(self): ), dict(afi="ipv4", safi="multicast"), ], - ) + ), ], - ) + ), ], ), state="replaced", @@ -1153,7 +1130,7 @@ def test_nxos_bgp_nbr_af_maximum_prefix_merged(self): maximum-prefix 12 85 warning-only address-family ipv6 unicast maximum-prefix 12 85 restart 1200 - """ + """, ) set_module_args( dict( @@ -1195,7 +1172,7 @@ def test_nxos_bgp_nbr_af_maximum_prefix_merged(self): ), ), ], - ) + ), ], vrfs=[ dict( @@ -1207,9 +1184,7 @@ def test_nxos_bgp_nbr_af_maximum_prefix_merged(self): dict( afi="ipv4", safi="multicast", - maximum_prefix=dict( - max_prefix_limit=28 - ), + maximum_prefix=dict(max_prefix_limit=28), ), dict( afi="ipv4", @@ -1238,9 +1213,9 @@ def test_nxos_bgp_nbr_af_maximum_prefix_merged(self): ), ), ], - ) + ), ], - ) + ), ], ), state="merged", @@ -1286,7 +1261,7 @@ def test_nxos_bgp_nbr_af_maximum_prefix_replaced(self): maximum-prefix 12 85 warning-only address-family ipv6 unicast maximum-prefix 12 85 restart 1200 - """ + """, ) set_module_args( dict( @@ -1303,7 +1278,7 @@ def test_nxos_bgp_nbr_af_maximum_prefix_replaced(self): maximum_prefix=dict(max_prefix_limit=28), ), ], - ) + ), ], vrfs=[ dict( @@ -1315,9 +1290,7 @@ def test_nxos_bgp_nbr_af_maximum_prefix_replaced(self): dict( afi="ipv4", safi="multicast", - maximum_prefix=dict( - max_prefix_limit=28 - ), + maximum_prefix=dict(max_prefix_limit=28), ), dict( afi="ipv4", @@ -1330,9 +1303,9 @@ def test_nxos_bgp_nbr_af_maximum_prefix_replaced(self): dict(afi="ipv6", safi="multicast"), dict(afi="ipv6", safi="unicast"), ], - ) + ), ], - ) + ), ], ), state="replaced", @@ -1370,7 +1343,7 @@ def test_nxos_bgp_nbr_af_next_hop_merged(self): no next-hop-third-party address-family ipv4 multicast next-hop-self all - """ + """, ) set_module_args( dict( @@ -1391,7 +1364,7 @@ def test_nxos_bgp_nbr_af_next_hop_merged(self): next_hop_self=dict(all_routes=True), ), ], - ) + ), ], vrfs=[ dict( @@ -1409,21 +1382,17 @@ def test_nxos_bgp_nbr_af_next_hop_merged(self): dict( afi="ipv4", safi="multicast", - next_hop_self=dict( - all_routes=True - ), + next_hop_self=dict(all_routes=True), ), dict( afi="ipv6", safi="multicast", - next_hop_self=dict( - all_routes=True - ), + next_hop_self=dict(all_routes=True), ), ], - ) + ), ], - ) + ), ], ), state="merged", @@ -1464,7 +1433,7 @@ def test_nxos_bgp_nbr_af_next_hop_replaced(self): no next-hop-third-party address-family ipv4 multicast next-hop-self all - """ + """, ) set_module_args( dict( @@ -1481,7 +1450,7 @@ def test_nxos_bgp_nbr_af_next_hop_replaced(self): next_hop_self=dict(all_routes=True), ), ], - ) + ), ], vrfs=[ dict( @@ -1498,14 +1467,12 @@ def test_nxos_bgp_nbr_af_next_hop_replaced(self): dict( afi="ipv4", safi="multicast", - next_hop_self=dict( - all_routes=True - ), + next_hop_self=dict(all_routes=True), ), ], - ) + ), ], - ) + ), ], ), state="replaced", @@ -1538,7 +1505,7 @@ def test_nxos_bgp_nbr_af_prefix_list_merged(self): prefix-list rmap2 out address-family ipv4 multicast prefix-list rmap1 out - """ + """, ) set_module_args( dict( @@ -1551,12 +1518,10 @@ def test_nxos_bgp_nbr_af_prefix_list_merged(self): dict( afi="ipv4", safi="multicast", - prefix_list=dict( - inbound="rmap3", outbound="rmap4" - ), - ) + prefix_list=dict(inbound="rmap3", outbound="rmap4"), + ), ], - ) + ), ], vrfs=[ dict( @@ -1579,9 +1544,9 @@ def test_nxos_bgp_nbr_af_prefix_list_merged(self): prefix_list=dict(inbound="rmap2"), ), ], - ) + ), ], - ) + ), ], ), state="merged", @@ -1619,7 +1584,7 @@ def test_nxos_bgp_nbr_af_prefix_list_replaced(self): address-family ipv4 multicast prefix-list rmap1 out prefix-list rmap2 in - """ + """, ) set_module_args( dict( @@ -1633,9 +1598,9 @@ def test_nxos_bgp_nbr_af_prefix_list_replaced(self): afi="ipv4", safi="multicast", prefix_list=dict(inbound="rmap3"), - ) + ), ], - ) + ), ], vrfs=[ dict( @@ -1654,9 +1619,9 @@ def test_nxos_bgp_nbr_af_prefix_list_replaced(self): ), dict(afi="ipv4", safi="multicast"), ], - ) + ), ], - ) + ), ], ), state="replaced", @@ -1691,7 +1656,7 @@ def test_nxos_bgp_nbr_af_rewrite_evpn_route_map_merged(self): address-family ipv4 multicast route-map rmap1 out rewrite-evpn-rt-asn - """ + """, ) set_module_args( dict( @@ -1704,13 +1669,11 @@ def test_nxos_bgp_nbr_af_rewrite_evpn_route_map_merged(self): dict( afi="ipv4", safi="multicast", - route_map=dict( - inbound="rmap3", outbound="rmap4" - ), + route_map=dict(inbound="rmap3", outbound="rmap4"), rewrite_evpn_rt_asn=True, - ) + ), ], - ) + ), ], vrfs=[ dict( @@ -1735,9 +1698,9 @@ def test_nxos_bgp_nbr_af_rewrite_evpn_route_map_merged(self): rewrite_evpn_rt_asn=True, ), ], - ) + ), ], - ) + ), ], ), state="merged", @@ -1780,7 +1743,7 @@ def test_nxos_bgp_nbr_af_rewrite_evpn_route_map_replaced(self): route-map rmap1 out route-map rmap2 in rewrite-evpn-rt-asn - """ + """, ) set_module_args( dict( @@ -1795,9 +1758,9 @@ def test_nxos_bgp_nbr_af_rewrite_evpn_route_map_replaced(self): safi="multicast", route_map=dict(inbound="rmap3"), rewrite_evpn_rt_asn=True, - ) + ), ], - ) + ), ], vrfs=[ dict( @@ -1817,9 +1780,9 @@ def test_nxos_bgp_nbr_af_rewrite_evpn_route_map_replaced(self): ), dict(afi="ipv4", safi="multicast"), ], - ) + ), ], - ) + ), ], ), state="replaced", @@ -1851,7 +1814,7 @@ def test_nxos_bgp_route_reflector_client_send_community_merged(self): address-family ipv4 unicast route-reflector-client send-community - """ + """, ) set_module_args( dict( @@ -1866,9 +1829,9 @@ def test_nxos_bgp_route_reflector_client_send_community_merged(self): safi="multicast", route_reflector_client=True, send_community=dict(extended=True), - ) + ), ], - ) + ), ], vrfs=[ dict( @@ -1889,9 +1852,9 @@ def test_nxos_bgp_route_reflector_client_send_community_merged(self): send_community=dict(set=True), ), ], - ) + ), ], - ) + ), ], ), state="merged", @@ -1928,7 +1891,7 @@ def test_nxos_bgp_route_reflector_client_send_community_replaced(self): send-community address-family ipv4 multicast send-community - """ + """, ) set_module_args( dict( @@ -1942,9 +1905,9 @@ def test_nxos_bgp_route_reflector_client_send_community_replaced(self): afi="ipv4", safi="multicast", send_community=dict(extended=True), - ) + ), ], - ) + ), ], vrfs=[ dict( @@ -1961,9 +1924,9 @@ def test_nxos_bgp_route_reflector_client_send_community_replaced(self): ), dict(afi="ipv4", safi="multicast"), ], - ) + ), ], - ) + ), ], ), state="replaced", @@ -1993,7 +1956,7 @@ def test_nxos_bgp_nbr_af_soft_reconfiguration_soo_merged(self): address-family ipv4 unicast soft-reconfiguration inbound always soo 65:28 - """ + """, ) set_module_args( dict( @@ -2006,13 +1969,11 @@ def test_nxos_bgp_nbr_af_soft_reconfiguration_soo_merged(self): dict( afi="ipv4", safi="multicast", - soft_reconfiguration_inbound=dict( - set=True - ), + soft_reconfiguration_inbound=dict(set=True), soo="73:43", - ) + ), ], - ) + ), ], vrfs=[ dict( @@ -2024,22 +1985,18 @@ def test_nxos_bgp_nbr_af_soft_reconfiguration_soo_merged(self): dict( afi="ipv4", safi="unicast", - soft_reconfiguration_inbound=dict( - always=True - ), + soft_reconfiguration_inbound=dict(always=True), soo="65:28", ), dict( afi="ipv4", safi="multicast", - soft_reconfiguration_inbound=dict( - always=True - ), + soft_reconfiguration_inbound=dict(always=True), ), ], - ) + ), ], - ) + ), ], ), state="merged", @@ -2076,7 +2033,7 @@ def test_nxos_bgp_nbr_af_soft_reconfiguration_soo_replaced(self): soo 65:28 address-family ipv4 multicast soft-reconfiguration inbound always - """ + """, ) set_module_args( dict( @@ -2089,12 +2046,10 @@ def test_nxos_bgp_nbr_af_soft_reconfiguration_soo_replaced(self): dict( afi="ipv4", safi="multicast", - soft_reconfiguration_inbound=dict( - set=True - ), - ) + soft_reconfiguration_inbound=dict(set=True), + ), ], - ) + ), ], vrfs=[ dict( @@ -2106,16 +2061,14 @@ def test_nxos_bgp_nbr_af_soft_reconfiguration_soo_replaced(self): dict( afi="ipv4", safi="unicast", - soft_reconfiguration_inbound=dict( - always=True - ), + soft_reconfiguration_inbound=dict(always=True), soo="65:28", ), dict(afi="ipv4", safi="multicast"), ], - ) + ), ], - ) + ), ], ), state="replaced", @@ -2147,7 +2100,7 @@ def test_nxos_bgp_nbr_af_suppress_inactive_unsuppress_merged(self): unsuppress-map rmap1 address-family ipv4 multicast weight 10 - """ + """, ) set_module_args( dict( @@ -2163,9 +2116,9 @@ def test_nxos_bgp_nbr_af_suppress_inactive_unsuppress_merged(self): suppress_inactive=True, unsuppress_map="rmap2", weight=20, - ) + ), ], - ) + ), ], vrfs=[ dict( @@ -2188,9 +2141,9 @@ def test_nxos_bgp_nbr_af_suppress_inactive_unsuppress_merged(self): unsuppress_map="rmap4", ), ], - ) + ), ], - ) + ), ], ), state="merged", @@ -2235,7 +2188,7 @@ def test_nxos_bgp_nbr_af_suppress_inactive_unsuppress_replaced(self): suppress-inactive unsuppress-map rmap4 weight 10 - """ + """, ) set_module_args( dict( @@ -2244,10 +2197,8 @@ def test_nxos_bgp_nbr_af_suppress_inactive_unsuppress_replaced(self): neighbors=[ dict( neighbor_address="10.0.0.2", - address_family=[ - dict(afi="ipv4", safi="multicast") - ], - ) + address_family=[dict(afi="ipv4", safi="multicast")], + ), ], vrfs=[ dict( @@ -2265,9 +2216,9 @@ def test_nxos_bgp_nbr_af_suppress_inactive_unsuppress_replaced(self): ), dict(afi="ipv4", safi="multicast"), ], - ) + ), ], - ) + ), ], ), state="replaced", @@ -2307,7 +2258,7 @@ def test_nxos_bgp_nbr_af_deleted(self): address-family ipv4 unicast address-family ipv4 multicast address-family ipv6 unicast - """ + """, ) set_module_args( dict( @@ -2320,7 +2271,7 @@ def test_nxos_bgp_nbr_af_deleted(self): dict(afi="ipv4", safi="multicast"), dict(afi="link-state"), ], - ) + ), ], vrfs=[ dict( @@ -2332,9 +2283,9 @@ def test_nxos_bgp_nbr_af_deleted(self): dict(afi="ipv4", safi="unicast"), dict(afi="ipv4", safi="multicast"), ], - ) + ), ], - ) + ), ], ), state="deleted", @@ -2370,7 +2321,7 @@ def test_nxos_bgp_nbr_af_deleted_all(self): address-family ipv4 unicast address-family ipv4 multicast address-family ipv6 unicast - """ + """, ) set_module_args(dict(state="deleted"), ignore_provider_arg) commands = [ @@ -2406,7 +2357,7 @@ def test_nxos_bgp_nbr_af_overridden(self): address-family ipv4 unicast address-family ipv4 multicast address-family ipv6 unicast - """ + """, ) set_module_args( dict( @@ -2422,7 +2373,7 @@ def test_nxos_bgp_nbr_af_overridden(self): route_reflector_client=True, ), ], - ) + ), ], vrfs=[ dict( @@ -2430,12 +2381,10 @@ def test_nxos_bgp_nbr_af_overridden(self): neighbors=[ dict( neighbor_address="192.168.1.1", - address_family=[ - dict(afi="ipv4", safi="multicast") - ], - ) + address_family=[dict(afi="ipv4", safi="multicast")], + ), ], - ) + ), ], ), state="overridden", @@ -2470,7 +2419,7 @@ def test_nxos_bgp_nbr_af_gathered(self): vrf site-1 neighbor 192.168.1.1 address-family ipv4 multicast - """ + """, ) set_module_args(dict(state="gathered"), ignore_provider_arg) gathered = dict( @@ -2482,7 +2431,7 @@ def test_nxos_bgp_nbr_af_gathered(self): dict(afi="ipv4", safi="unicast"), dict(afi="link-state"), ], - ) + ), ], vrfs=[ dict( @@ -2490,12 +2439,10 @@ def test_nxos_bgp_nbr_af_gathered(self): neighbors=[ dict( neighbor_address="192.168.1.1", - address_family=[ - dict(afi="ipv4", safi="multicast") - ], - ) + address_family=[dict(afi="ipv4", safi="multicast")], + ), ], - ) + ), ], ) result = self.execute_module(changed=False) @@ -2514,7 +2461,7 @@ def test_nxos_bgp_nbr_af_parsed(self): vrf site-1 neighbor 192.168.1.1 address-family ipv4 multicast - """ + """, ), state="parsed", ), @@ -2529,7 +2476,7 @@ def test_nxos_bgp_nbr_af_parsed(self): dict(afi="ipv4", safi="unicast"), dict(afi="link-state"), ], - ) + ), ], vrfs=[ dict( @@ -2537,12 +2484,10 @@ def test_nxos_bgp_nbr_af_parsed(self): neighbors=[ dict( neighbor_address="192.168.1.1", - address_family=[ - dict(afi="ipv4", safi="multicast") - ], - ) + address_family=[dict(afi="ipv4", safi="multicast")], + ), ], - ) + ), ], ) result = self.execute_module(changed=False) @@ -2564,9 +2509,9 @@ def test_nxos_bgp_nbr_af_rendered(self): suppress_inactive=True, unsuppress_map="rmap2", weight=20, - ) + ), ], - ) + ), ], vrfs=[ dict( @@ -2589,9 +2534,9 @@ def test_nxos_bgp_nbr_af_rendered(self): unsuppress_map="rmap4", ), ], - ) + ), ], - ) + ), ], ), state="rendered", @@ -2622,7 +2567,7 @@ def test_nxos_bgp_nbr_af_gathered_empty(self): # test gathered self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args(dict(state="gathered"), ignore_provider_arg) gathered = dict() @@ -2634,7 +2579,7 @@ def test_nxos_bgp_nbr_af_gathered_only_asn(self): self.get_config.return_value = dedent( """\ router bgp 65563 - """ + """, ) set_module_args(dict(state="gathered"), ignore_provider_arg) gathered = dict(as_number="65563") @@ -2648,7 +2593,7 @@ def test_nxos_bgp_nbr_af_no_cmd(self): router bgp 65536 neighbor 10.0.0.2 address-family ipv4 multicast - """ + """, ) set_module_args( dict( @@ -2657,10 +2602,8 @@ def test_nxos_bgp_nbr_af_no_cmd(self): neighbors=[ dict( neighbor_address="10.0.0.2", - address_family=[ - dict(afi="ipv4", safi="multicast") - ], - ) + address_family=[dict(afi="ipv4", safi="multicast")], + ), ], ), state="merged", @@ -2681,7 +2624,7 @@ def test_nxos_bgp_af_send_community(self): address-family l2vpn evpn send-community send-community extended - """ + """, ) set_module_args( dict( @@ -2695,7 +2638,7 @@ def test_nxos_bgp_af_send_community(self): afi="l2vpn", safi="evpn", send_community=dict(both=True), - ) + ), ], ), dict( @@ -2705,7 +2648,7 @@ def test_nxos_bgp_af_send_community(self): afi="l2vpn", safi="evpn", send_community=dict(both=True), - ) + ), ], ), dict( @@ -2715,7 +2658,7 @@ def test_nxos_bgp_af_send_community(self): afi="l2vpn", safi="evpn", send_community=dict(set=True), - ) + ), ], ), ], @@ -2736,3 +2679,98 @@ def test_nxos_bgp_af_send_community(self): ] result = self.execute_module(changed=True) self.assertEqual(set(result["commands"]), set(commands)) + + def test_nxos_bgp_nbr_parsed_3K(self): + # test parsed for neighbor remote-as 3K config + set_module_args( + dict( + running_config=dedent( + """\ + router bgp 65535 + neighbor 192.168.20.2 remote-as 56789 + address-family ipv4 unicast + soft-reconfiguration inbound always + """, + ), + state="parsed", + ), + ignore_provider_arg, + ) + parsed = dict( + as_number="65535", + neighbors=[ + dict( + neighbor_address="192.168.20.2", + address_family=[ + dict( + afi="ipv4", + safi="unicast", + soft_reconfiguration_inbound=dict(always=True), + ), + ], + ), + ], + ) + result = self.execute_module(changed=False) + self.assertEqual(result["parsed"], parsed) + + def test_nxos_bgp_nbr_af_rewrite_rt_asn(self): + # test merged for rewrite_rt_asn + self.get_config.return_value = dedent( + """\ + router bgp 65536 + neighbor 192.168.1.1 + vrf site-1 + neighbor 10.0.0.100 + """, + ) + set_module_args( + dict( + config=dict( + as_number="65536", + neighbors=[ + dict( + neighbor_address="192.168.1.1", + address_family=[ + dict( + afi="ipv4", + safi="mvpn", + rewrite_rt_asn=True, + ), + ], + ), + ], + vrfs=[ + dict( + vrf="site-1", + neighbors=[ + dict( + neighbor_address="10.0.0.100", + address_family=[ + dict( + afi="ipv4", + safi="mvpn", + rewrite_rt_asn=True, + ), + ], + ), + ], + ), + ], + ), + state="merged", + ), + ignore_provider_arg, + ) + commands = [ + "router bgp 65536", + "neighbor 192.168.1.1", + "address-family ipv4 mvpn", + "rewrite-rt-asn", + "vrf site-1", + "neighbor 10.0.0.100", + "address-family ipv4 mvpn", + "rewrite-rt-asn", + ] + result = self.execute_module(changed=True) + self.assertEqual(set(result["commands"]), set(commands)) diff --git a/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor_af.py b/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor_af.py deleted file mode 100644 index daeea18ef..000000000 --- a/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor_af.py +++ /dev/null @@ -1,260 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# Make coding more python3-ish - -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.plugins.modules import nxos_bgp_neighbor_af -from .nxos_module import TestNxosModule, load_fixture, set_module_args - - -class TestNxosBgpNeighborAfModule(TestNxosModule): - - module = nxos_bgp_neighbor_af - - def setUp(self): - super(TestNxosBgpNeighborAfModule, self).setUp() - - self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_bgp_neighbor_af.load_config" - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_bgp_neighbor_af.get_config" - ) - self.get_config = self.mock_get_config.start() - - def tearDown(self): - super(TestNxosBgpNeighborAfModule, self).tearDown() - self.mock_load_config.stop() - self.mock_get_config.stop() - - def load_fixtures(self, commands=None, device=""): - self.get_config.return_value = load_fixture("nxos_bgp", "config.cfg") - self.load_config.return_value = [] - - def test_nxos_bgp_neighbor_af(self): - set_module_args( - dict( - asn=65535, - neighbor="192.0.2.3", - afi="ipv4", - safi="unicast", - route_reflector_client=True, - ) - ) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], - [ - "router bgp 65535", - "neighbor 192.0.2.3", - "address-family ipv4 unicast", - "route-reflector-client", - ], - ) - - def test_nxos_bgp_neighbor_af_exists(self): - set_module_args( - dict(asn=65535, neighbor="3.3.3.5", afi="ipv4", safi="unicast") - ) - self.execute_module(changed=False, commands=[]) - - def test_nxos_bgp_neighbor_af_absent(self): - set_module_args( - dict( - asn=65535, - neighbor="3.3.3.5", - afi="ipv4", - safi="unicast", - state="absent", - ) - ) - self.execute_module( - changed=True, - sort=False, - commands=[ - "router bgp 65535", - "neighbor 3.3.3.5", - "no address-family ipv4 unicast", - ], - ) - - def test_nxos_bgp_neighbor_af_advertise_map(self): - set_module_args( - dict( - asn=65535, - neighbor="3.3.3.5", - afi="ipv4", - safi="unicast", - advertise_map_exist=["my_advertise_map", "my_exist_map"], - ) - ) - self.execute_module( - changed=True, - sort=False, - commands=[ - "router bgp 65535", - "neighbor 3.3.3.5", - "address-family ipv4 unicast", - "advertise-map my_advertise_map exist-map my_exist_map", - ], - ) - - def test_nxos_bgp_neighbor_af_advertise_map_non_exist(self): - set_module_args( - dict( - asn=65535, - neighbor="3.3.3.5", - afi="ipv4", - safi="unicast", - advertise_map_non_exist=[ - "my_advertise_map", - "my_non_exist_map", - ], - ) - ) - self.execute_module( - changed=True, - sort=False, - commands=[ - "router bgp 65535", - "neighbor 3.3.3.5", - "address-family ipv4 unicast", - "advertise-map my_advertise_map non-exist-map my_non_exist_map", - ], - ) - - def test_nxos_bgp_neighbor_af_max_prefix_limit_default(self): - set_module_args( - dict( - asn=65535, - neighbor="3.3.3.5", - afi="ipv4", - safi="unicast", - max_prefix_limit="default", - ) - ) - self.execute_module( - changed=True, - sort=False, - commands=[ - "router bgp 65535", - "neighbor 3.3.3.5", - "address-family ipv4 unicast", - "no maximum-prefix", - ], - ) - - def test_nxos_bgp_neighbor_af_max_prefix(self): - set_module_args( - dict( - asn=65535, - neighbor="3.3.3.5", - afi="ipv4", - safi="unicast", - max_prefix_threshold=20, - max_prefix_limit=20, - ) - ) - self.execute_module( - changed=True, - sort=False, - commands=[ - "router bgp 65535", - "neighbor 3.3.3.5", - "address-family ipv4 unicast", - "maximum-prefix 20 20", - ], - ) - - def test_nxos_bgp_neighbor_af_disable_peer_as_check(self): - set_module_args( - dict( - asn=65535, - neighbor="3.3.3.5", - afi="ipv4", - safi="unicast", - disable_peer_as_check=True, - ) - ) - self.execute_module( - changed=True, - commands=[ - "router bgp 65535", - "neighbor 3.3.3.5", - "address-family ipv4 unicast", - "disable-peer-as-check", - ], - ) - - def test_nxos_bgp_neighbor_af_rewrite_evpn(self): - set_module_args( - dict( - asn=65535, - neighbor="30.30.30.5", - afi="l2vpn", - safi="evpn", - rewrite_evpn_rt_asn=True, - ) - ) - self.execute_module( - changed=True, - commands=[ - "router bgp 65535", - "neighbor 30.30.30.5", - "address-family l2vpn evpn", - "rewrite-evpn-rt-asn", - ], - ) - - def test_nxos_bgp_neighbor_af_rewrite_evpn_disable(self): - set_module_args( - dict( - asn=65535, - neighbor="30.30.30.5", - afi="l2vpn", - safi="evpn", - rewrite_evpn_rt_asn=False, - ) - ) - self.execute_module( - changed=True, - commands=[ - "router bgp 65535", - "neighbor 30.30.30.5", - "address-family l2vpn evpn", - "no rewrite-evpn-rt-asn", - ], - ) - - def test_nxos_bgp_neighbor_af_rewrite_evpn_exists(self): - set_module_args( - dict( - asn=65535, - neighbor="7.7.7.7", - afi="l2vpn", - safi="evpn", - rewrite_evpn_rt_asn=True, - ) - ) - self.execute_module(changed=False, commands=[]) diff --git a/tests/unit/modules/network/nxos/test_nxos_bgp_templates.py b/tests/unit/modules/network/nxos/test_nxos_bgp_templates.py new file mode 100644 index 000000000..8d2fd74b5 --- /dev/null +++ b/tests/unit/modules/network/nxos/test_nxos_bgp_templates.py @@ -0,0 +1,865 @@ +# (c) 2021 Red Hat Inc. +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +# Make coding more python3-ish + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from textwrap import dedent + +from ansible_collections.cisco.nxos.plugins.modules import nxos_bgp_templates +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + +from .nxos_module import TestNxosModule, set_module_args + + +ignore_provider_arg = True + + +class TestNxosBgpTemplatesModule(TestNxosModule): + module = nxos_bgp_templates + + def setUp(self): + super(TestNxosBgpTemplatesModule, self).setUp() + + self.mock_get_resource_connection = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", + ) + self.get_resource_connection = self.mock_get_resource_connection.start() + + self.mock_get_config = patch( + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.bgp_templates.bgp_templates.Bgp_templatesFacts.get_config", + ) + self.get_config = self.mock_get_config.start() + + def tearDown(self): + super(TestNxosBgpTemplatesModule, self).tearDown() + self.get_resource_connection.stop() + self.get_config.stop() + + def test_nxos_bgp_templates_merged(self): + set_module_args( + dict( + config=dict( + as_number="65536", + neighbor=[ + dict( + name="tmplt_1", + description="test-neighbor-template", + bfd=dict( + singlehop=True, + multihop=dict( + interval=dict( + tx_interval=300, + min_rx_interval=258, + multiplier=12, + ), + ), + ), + bmp_activate_server=12, + capability=dict( + suppress_4_byte_as=True, + ), + disable_connected_check=True, + dont_capability_negotiate=True, + dscp="cs1", + dynamic_capability=True, + ebgp_multihop=5, + graceful_shutdown=dict( + activate=dict( + route_map="rmap1", + ), + ), + inherit=dict(peer_session="peer_sess_1"), + local_as="65535", + log_neighbor_changes=dict( + disable=True, + ), + low_memory=dict( + exempt=True, + ), + password=dict( + encryption=7, + key="095C4F1A0A1218000F", + ), + path_attribute=[ + dict( + action="discard", + type=10, + ), + dict( + action="treat-as-withdraw", + range=dict( + start=10, + end=15, + ), + ), + ], + ), + dict( + name="tmplt_2", + bfd=dict( + set=True, + ), + remote_as="65534", + remove_private_as=dict( + replace_as=True, + ), + shutdown=True, + timers=dict( + keepalive=200, + holdtime=300, + ), + transport=dict(connection_mode=dict(passive=True)), + ttl_security=dict( + hops=10, + ), + update_source="Ethernet1/1", + ), + dict( + name="tmplt_3", + bfd=dict( + multihop=dict( + set=True, + ), + ), + address_family=[ + dict( + afi="l2vpn", + safi="evpn", + send_community="both", + ), + ], + ), + ], + ), + state="merged", + ), + ignore_provider_arg, + ) + commands = [ + "router bgp 65536", + "template peer tmplt_1", + "bfd singlehop", + "bfd multihop interval 300 min_rx 258 multiplier 12", + "bmp-activate-server 12", + "capability suppress 4-byte-as", + "description test-neighbor-template", + "disable-connected-check", + "dont-capability-negotiate", + "dscp cs1", + "dynamic-capability", + "ebgp-multihop 5", + "graceful-shutdown activate route-map rmap1", + "inherit peer-session peer_sess_1", + "local-as 65535", + "log-neighbor-changes disable", + "low-memory exempt", + "password 7 095C4F1A0A1218000F", + "path-attribute discard 10 in", + "path-attribute treat-as-withdraw range 10 15 in", + "template peer tmplt_2", + "bfd", + "remote-as 65534", + "remove-private-as replace-as", + "shutdown", + "timers 200 300", + "transport connection-mode passive", + "ttl-security hops 10", + "update-source Ethernet1/1", + "template peer tmplt_3", + "bfd multihop", + "address-family l2vpn evpn", + "send-community", + "send-community extended", + ] + result = self.execute_module(changed=True) + self.assertEqual(set(result["commands"]), set(commands)) + + def test_nxos_bgp_templates_merged_idempotent(self): + self.get_config.return_value = dedent( + """\ + router bgp 65536 + template peer tmplt_1 + bfd singlehop + bfd multihop interval 300 min_rx 258 multiplier 12 + bmp-activate-server 12 + capability suppress 4-byte-as + description test-neighbor-template + disable-connected-check + dont-capability-negotiate + dscp cs1 + dynamic-capability + ebgp-multihop 5 + graceful-shutdown activate route-map rmap1 + inherit peer-session peer_sess_1 + local-as 65535 + log-neighbor-changes disable + low-memory exempt + password 7 095C4F1A0A1218000F + path-attribute discard 10 in + path-attribute treat-as-withdraw range 10 15 in + template peer tmplt_2 + bfd + remote-as 65534 + remove-private-as replace-as + shutdown + timers 200 300 + transport connection-mode passive + ttl-security hops 10 + update-source Ethernet1/1 + template peer tmplt_3 + bfd multihop + """, + ) + set_module_args( + dict( + config=dict( + as_number="65536", + neighbor=[ + dict( + name="tmplt_1", + description="test-neighbor-template", + bfd=dict( + singlehop=True, + multihop=dict( + interval=dict( + tx_interval=300, + min_rx_interval=258, + multiplier=12, + ), + ), + ), + bmp_activate_server=12, + capability=dict( + suppress_4_byte_as=True, + ), + disable_connected_check=True, + dont_capability_negotiate=True, + dscp="cs1", + dynamic_capability=True, + ebgp_multihop=5, + graceful_shutdown=dict( + activate=dict( + route_map="rmap1", + ), + ), + inherit=dict(peer_session="peer_sess_1"), + local_as="65535", + log_neighbor_changes=dict( + disable=True, + ), + low_memory=dict( + exempt=True, + ), + password=dict( + encryption=7, + key="095C4F1A0A1218000F", + ), + path_attribute=[ + dict( + action="discard", + type=10, + ), + dict( + action="treat-as-withdraw", + range=dict( + start=10, + end=15, + ), + ), + ], + ), + dict( + name="tmplt_2", + bfd=dict( + set=True, + ), + remote_as="65534", + remove_private_as=dict( + replace_as=True, + ), + shutdown=True, + timers=dict( + keepalive=200, + holdtime=300, + ), + transport=dict(connection_mode=dict(passive=True)), + ttl_security=dict( + hops=10, + ), + update_source="Ethernet1/1", + ), + dict( + name="tmplt_3", + bfd=dict( + multihop=dict( + set=True, + ), + ), + ), + ], + ), + state="merged", + ), + ignore_provider_arg, + ) + result = self.execute_module(changed=False) + self.assertEqual(result["commands"], []) + + def test_nxos_bgp_templates_deleted_single(self): + self.get_config.return_value = dedent( + """\ + router bgp 65536 + template peer tmplt_1 + bfd singlehop + bfd multihop interval 300 min_rx 258 multiplier 12 + bmp-activate-server 12 + template peer tmplt_2 + bfd + remote-as 65534 + remove-private-as replace-as + """, + ) + set_module_args( + dict( + config=dict(as_number="65536", neighbor=[dict(name="tmplt_1")]), + state="deleted", + ), + ignore_provider_arg, + ) + commands = [ + "router bgp 65536", + "no template peer tmplt_1", + ] + result = self.execute_module(changed=True) + self.assertEqual(set(result["commands"]), set(commands)) + + def test_nxos_bgp_templates_deleted_all(self): + self.get_config.return_value = dedent( + """\ + router bgp 65536 + template peer tmplt_1 + bfd singlehop + bfd multihop interval 300 min_rx 258 multiplier 12 + bmp-activate-server 12 + template peer tmplt_2 + bfd + remote-as 65534 + remove-private-as replace-as + """, + ) + set_module_args( + dict( + state="deleted", + ), + ignore_provider_arg, + ) + commands = ["router bgp 65536", "no template peer tmplt_1", "no template peer tmplt_2"] + result = self.execute_module(changed=True) + self.assertEqual(set(result["commands"]), set(commands)) + + def test_nxos_bgp_templates_overridden(self): + self.get_config.return_value = dedent( + """\ + router bgp 65536 + template peer tmplt_1 + bfd singlehop + bfd multihop interval 300 min_rx 258 multiplier 12 + template peer tmplt_2 + bfd + remote-as 65534 + remove-private-as replace-as + path-attribute discard 10 in + path-attribute treat-as-withdraw range 10 15 in + template peer tmplt_3 + remote-as 65533 + """, + ) + set_module_args( + dict( + config=dict( + as_number="65536", + neighbor=[ + dict( + name="tmplt_1", + bfd=dict( + singlehop=True, + multihop=dict( + interval=dict( + tx_interval=300, + min_rx_interval=258, + multiplier=12, + ), + ), + ), + ), + dict( + name="tmplt_2", + remote_as="65534", + path_attribute=[ + dict( + action="discard", + type=10, + ), + ], + ), + ], + ), + state="overridden", + ), + ignore_provider_arg, + ) + commands = [ + "router bgp 65536", + "no template peer tmplt_3", + "template peer tmplt_2", + "no bfd", + "no remove-private-as replace-as", + "no path-attribute treat-as-withdraw range 10 15 in", + ] + result = self.execute_module(changed=True) + self.assertEqual(set(result["commands"]), set(commands)) + + def test_nxos_bgp_templates_gathered(self): + self.get_config.return_value = dedent( + """\ + router bgp 65536 + template peer tmplt_1 + bfd singlehop + bfd multihop interval 300 min_rx 258 multiplier 12 + template peer tmplt_2 + bfd + remote-as 65534 + remove-private-as replace-as + path-attribute discard 10 in + """, + ) + set_module_args( + dict( + state="gathered", + ), + ignore_provider_arg, + ) + gathered = dict( + as_number="65536", + neighbor=[ + dict( + name="tmplt_1", + bfd=dict( + singlehop=True, + multihop=dict( + interval=dict( + tx_interval=300, + min_rx_interval=258, + multiplier=12, + ), + ), + ), + ), + dict( + name="tmplt_2", + bfd=dict( + set=True, + ), + remote_as="65534", + path_attribute=[ + dict( + action="discard", + type=10, + ), + ], + remove_private_as=dict( + replace_as=True, + ), + ), + ], + ) + result = self.execute_module(changed=False) + self.assertEqual(result["gathered"], gathered) + + def test_nxos_bgp_templates_parsed(self): + run_cfg = dedent( + """\ + router bgp 65536 + template peer tmplt_1 + bfd singlehop + bfd multihop interval 300 min_rx 258 multiplier 12 + template peer tmplt_2 + bfd + remote-as 65534 + remove-private-as replace-as + path-attribute discard 10 in + """, + ) + set_module_args( + dict( + running_config=run_cfg, + state="parsed", + ), + ignore_provider_arg, + ) + parsed = dict( + as_number="65536", + neighbor=[ + dict( + name="tmplt_1", + bfd=dict( + singlehop=True, + multihop=dict( + interval=dict( + tx_interval=300, + min_rx_interval=258, + multiplier=12, + ), + ), + ), + ), + dict( + name="tmplt_2", + bfd=dict( + set=True, + ), + remote_as="65534", + path_attribute=[ + dict( + action="discard", + type=10, + ), + ], + remove_private_as=dict( + replace_as=True, + ), + ), + ], + ) + result = self.execute_module(changed=False) + self.assertEqual(result["parsed"], parsed) + + def test_nxos_bgp_templates_af(self): + self.get_config.return_value = dedent( + """\ + """, + ) + set_module_args( + dict( + config=dict( + as_number="65536", + neighbor=[ + dict( + name="tmplt_1", + description="test-neighbor-template", + address_family=[ + dict( + afi="ipv4", + safi="unicast", + advertise_map=dict( + route_map="rmap1", + exist_map="rmap2", + ), + advertisement_interval=100, + allowas_in=dict( + max_occurences=10, + ), + as_override=True, + capability=dict( + additional_paths=dict( + receive="disable", + send="disable", + ), + ), + default_originate=dict( + route_map="rmap1", + ), + disable_peer_as_check=True, + filter_list=dict( + inbound="flist1", + outbound="flist2", + ), + inherit=dict( + peer_policy="tmplt_policy_1", + ), + ), + dict( + afi="ipv4", + safi="multicast", + maximum_prefix=dict( + max_prefix_limit=10, + generate_warning_threshold=80, + restart_interval=60, + warning_only=True, + ), + next_hop_self=dict( + all_routes=True, + ), + next_hop_third_party=True, + prefix_list=dict( + inbound="plist1", + outbound="plist2", + ), + ), + ], + ), + dict( + name="tmplt_2", + description="test-neighbor-template-2", + address_family=[ + dict( + afi="ipv4", + safi="unicast", + route_map=dict( + inbound="rmap1", + outbound="rmap2", + ), + route_reflector_client=True, + soft_reconfiguration_inbound=dict( + always=True, + ), + soo="test", + suppress_inactive=True, + unsuppress_map="rmap1", + weight=2, + ), + ], + ), + ], + ), + state="merged", + ), + ignore_provider_arg, + ) + commands = [ + "router bgp 65536", + "template peer tmplt_1", + "description test-neighbor-template", + "address-family ipv4 unicast", + "advertise-map rmap1 exist-map rmap2", + "advertisement-interval 100", + "allowas-in 10", + "as-override", + "capability additional-paths receive disable", + "capability additional-paths send disable", + "default-originate route-map rmap1", + "disable-peer-as-check", + "filter-list flist1 in", + "filter-list flist2 out", + "inherit peer-policy tmplt_policy_1", + "address-family ipv4 multicast", + "maximum-prefix 10 80 restart 60 warning-only", + "next-hop-self all", + "next-hop-third-party", + "prefix-list plist1 in", + "prefix-list plist2 out", + "template peer tmplt_2", + "description test-neighbor-template-2", + "address-family ipv4 unicast", + "route-map rmap1 in", + "route-map rmap2 out", + "route-reflector-client", + "soft-reconfiguration inbound always", + "soo test", + "suppress-inactive", + "unsuppress-map rmap1", + "weight 2", + ] + result = self.execute_module(changed=True) + self.assertEqual(set(result["commands"]), set(commands)) + + def test_nxos_bgp_templates_af_idempotent(self): + self.get_config.return_value = dedent( + """\ + router bgp 65536 + template peer tmplt_1 + description test-neighbor-template + address-family ipv4 unicast + advertise-map rmap1 exist-map rmap2 + advertisement-interval 100 + allowas-in 10 + as-override + capability additional-paths receive disable + capability additional-paths send disable + default-originate route-map rmap1 + disable-peer-as-check + filter-list flist1 in + filter-list flist2 out + inherit peer-policy tmplt_policy_1 + address-family ipv4 multicast + maximum-prefix 10 80 restart 60 warning-only + next-hop-self all + no next-hop-third-party + prefix-list plist1 in + prefix-list plist2 out + template peer tmplt_2 + description test-neighbor-template-2 + address-family ipv4 unicast + route-map rmap1 in + route-map rmap2 out + route-reflector-client + soft-reconfiguration inbound always + soo test + suppress-inactive + unsuppress-map rmap1 + weight 2 + """, + ) + set_module_args( + dict( + config=dict( + as_number="65536", + neighbor=[ + dict( + name="tmplt_1", + description="test-neighbor-template", + address_family=[ + dict( + afi="ipv4", + safi="unicast", + advertise_map=dict( + route_map="rmap1", + exist_map="rmap2", + ), + advertisement_interval=100, + allowas_in=dict( + max_occurences=10, + ), + as_override=True, + capability=dict( + additional_paths=dict( + receive="disable", + send="disable", + ), + ), + default_originate=dict( + route_map="rmap1", + ), + disable_peer_as_check=True, + filter_list=dict( + inbound="flist1", + outbound="flist2", + ), + inherit=dict( + peer_policy="tmplt_policy_1", + ), + ), + dict( + afi="ipv4", + safi="multicast", + maximum_prefix=dict( + max_prefix_limit=10, + generate_warning_threshold=80, + restart_interval=60, + warning_only=True, + ), + next_hop_self=dict( + all_routes=True, + ), + next_hop_third_party=False, + prefix_list=dict( + inbound="plist1", + outbound="plist2", + ), + ), + ], + ), + dict( + name="tmplt_2", + description="test-neighbor-template-2", + address_family=[ + dict( + afi="ipv4", + safi="unicast", + route_map=dict( + inbound="rmap1", + outbound="rmap2", + ), + route_reflector_client=True, + soft_reconfiguration_inbound=dict( + always=True, + ), + soo="test", + suppress_inactive=True, + unsuppress_map="rmap1", + weight=2, + ), + ], + ), + ], + ), + state="merged", + ), + ignore_provider_arg, + ) + + result = self.execute_module(changed=False) + self.assertEqual(result["commands"], []) + + def test_nxos_bgp_templates_send_comm(self): + self.get_config.return_value = dedent( + """\ + router bgp 65536 + template peer tmplt_1 + address-family ipv4 unicast + send-community + send-community extended + template peer tmplt_2 + address-family l2vpn evpn + send-community extended + """, + ) + set_module_args( + dict( + config=dict( + as_number="65536", + neighbor=[ + dict( + name="tmplt_1", + address_family=[ + dict( + afi="ipv4", + safi="unicast", + send_community="both", + ), + ], + ), + dict( + name="tmplt_2", + address_family=[ + dict( + afi="l2vpn", + safi="evpn", + send_community="standard", + ), + ], + ), + ], + ), + state="merged", + ), + ignore_provider_arg, + ) + commands = [ + "router bgp 65536", + "template peer tmplt_2", + "address-family l2vpn evpn", + "no send-community extended", + "send-community", + ] + result = self.execute_module(changed=True) + self.assertEqual(set(result["commands"]), set(commands)) diff --git a/tests/unit/modules/network/nxos/test_nxos_command.py b/tests/unit/modules/network/nxos/test_nxos_command.py index af27c64d3..cb7c40ba9 100644 --- a/tests/unit/modules/network/nxos/test_nxos_command.py +++ b/tests/unit/modules/network/nxos/test_nxos_command.py @@ -19,24 +19,25 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type import json -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from ansible_collections.cisco.nxos.plugins.modules import nxos_command +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from .nxos_module import TestNxosModule, load_fixture, set_module_args class TestNxosCommandModule(TestNxosModule): - module = nxos_command def setUp(self): super(TestNxosCommandModule, self).setUp() self.mock_run_commands = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_command.run_commands" + "ansible_collections.cisco.nxos.plugins.modules.nxos_command.run_commands", ) self.run_commands = self.mock_run_commands.start() @@ -86,20 +87,21 @@ def test_nxos_command_wait_for_fails(self): def test_nxos_command_retries(self): wait_for = 'result[0] contains "test string"' - set_module_args( - dict(commands=["show version"], wait_for=wait_for, retries=2) - ) + set_module_args(dict(commands=["show version"], wait_for=wait_for, retries=2)) self.execute_module(failed=True) - self.assertEqual(self.run_commands.call_count, 2) + self.assertEqual(self.run_commands.call_count, 3) + + def test_nxos_command_retries_0(self): + set_module_args(dict(commands=["show version"], retries=0)) + self.execute_module(failed=False) + self.assertEqual(self.run_commands.call_count, 1) def test_nxos_command_match_any(self): wait_for = [ 'result[0] contains "Cisco"', 'result[0] contains "test string"', ] - set_module_args( - dict(commands=["show version"], wait_for=wait_for, match="any") - ) + set_module_args(dict(commands=["show version"], wait_for=wait_for, match="any")) self.execute_module() def test_nxos_command_match_all(self): @@ -107,9 +109,7 @@ def test_nxos_command_match_all(self): 'result[0] contains "Cisco"', 'result[0] contains "image file"', ] - set_module_args( - dict(commands=["show version"], wait_for=wait_for, match="all") - ) + set_module_args(dict(commands=["show version"], wait_for=wait_for, match="all")) self.execute_module() def test_nxos_command_match_all_failure(self): @@ -118,7 +118,5 @@ def test_nxos_command_match_all_failure(self): 'result[0] contains "test string"', ] commands = ["show version", "show version"] - set_module_args( - dict(commands=commands, wait_for=wait_for, match="all") - ) + set_module_args(dict(commands=commands, wait_for=wait_for, match="all")) self.execute_module(failed=True) diff --git a/tests/unit/modules/network/nxos/test_nxos_config.py b/tests/unit/modules/network/nxos/test_nxos_config.py index ec51d19f5..ce5c987c7 100644 --- a/tests/unit/modules/network/nxos/test_nxos_config.py +++ b/tests/unit/modules/network/nxos/test_nxos_config.py @@ -19,41 +19,39 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from ansible_collections.cisco.nxos.tests.unit.compat.mock import ( - patch, - MagicMock, -) -from ansible_collections.cisco.nxos.plugins.modules import nxos_config from ansible_collections.cisco.nxos.plugins.cliconf.nxos import Cliconf +from ansible_collections.cisco.nxos.plugins.modules import nxos_config +from ansible_collections.cisco.nxos.tests.unit.compat.mock import MagicMock, patch + from .nxos_module import TestNxosModule, load_fixture, set_module_args class TestNxosConfigModule(TestNxosModule): - module = nxos_config def setUp(self): super(TestNxosConfigModule, self).setUp() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_config.get_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_config.get_config", ) self.get_config = self.mock_get_config.start() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_config.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_config.load_config", ) self.load_config = self.mock_load_config.start() self.mock_save_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_config.save_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_config.save_config", ) self.save_config = self.mock_save_config.start() self.mock_get_connection = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_config.get_connection" + "ansible_collections.cisco.nxos.plugins.modules.nxos_config.get_connection", ) self.get_connection = self.mock_get_connection.start() @@ -61,7 +59,7 @@ def setUp(self): self.conn.edit_config = MagicMock() self.mock_run_commands = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_config.run_commands" + "ansible_collections.cisco.nxos.plugins.modules.nxos_config.run_commands", ) self.run_commands = self.mock_run_commands.start() @@ -76,18 +74,14 @@ def tearDown(self): self.mock_get_connection.stop() def load_fixtures(self, commands=None, device=""): - self.get_config.return_value = load_fixture( - "nxos_config", "config.cfg" - ) + self.get_config.return_value = load_fixture("nxos_config", "config.cfg") self.load_config.return_value = None def test_nxos_config_no_change(self): lines = ["hostname localhost"] args = dict(lines=lines) self.conn.get_diff = MagicMock( - return_value=self.cliconf_obj.get_diff( - "\n".join(lines), self.running_config - ) + return_value=self.cliconf_obj.get_diff("\n".join(lines), self.running_config), ) set_module_args(args) result = self.execute_module() @@ -96,7 +90,7 @@ def test_nxos_config_src(self): src = load_fixture("nxos_config", "candidate.cfg") args = dict(src=src) self.conn.get_diff = MagicMock( - return_value=self.cliconf_obj.get_diff(src, self.running_config) + return_value=self.cliconf_obj.get_diff(src, self.running_config), ) set_module_args(args) @@ -109,55 +103,45 @@ def test_nxos_config_src(self): "ip routing", ] - self.assertEqual( - sorted(config), sorted(result["commands"]), result["commands"] - ) + self.assertEqual(sorted(config), sorted(result["commands"]), result["commands"]) def test_nxos_config_replace_src(self): set_module_args(dict(replace_src="bootflash:config", replace="config")) self.conn.get_diff = MagicMock( return_value=self.cliconf_obj.get_diff( - self.running_config, self.running_config, diff_replace="config" - ) + self.running_config, + self.running_config, + diff_replace="config", + ), ) result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], ["config replace bootflash:config"] - ) + self.assertEqual(result["commands"], ["config replace bootflash:config"]) def test_nxos_config_lines(self): lines = ["hostname switch01", "ip domain-name eng.ansible.com"] args = dict(lines=lines) self.conn.get_diff = MagicMock( - return_value=self.cliconf_obj.get_diff( - "\n".join(lines), self.running_config - ) + return_value=self.cliconf_obj.get_diff("\n".join(lines), self.running_config), ) set_module_args(args) result = self.execute_module(changed=True) config = ["hostname switch01"] - self.assertEqual( - sorted(config), sorted(result["commands"]), result["commands"] - ) + self.assertEqual(sorted(config), sorted(result["commands"]), result["commands"]) def test_nxos_config_before(self): lines = ["hostname switch01", "ip domain-name eng.ansible.com"] args = dict(lines=lines, before=["before command"]) self.conn.get_diff = MagicMock( - return_value=self.cliconf_obj.get_diff( - "\n".join(lines), self.running_config - ) + return_value=self.cliconf_obj.get_diff("\n".join(lines), self.running_config), ) set_module_args(args) result = self.execute_module(changed=True) config = ["before command", "hostname switch01"] - self.assertEqual( - sorted(config), sorted(result["commands"]), result["commands"] - ) + self.assertEqual(sorted(config), sorted(result["commands"]), result["commands"]) self.assertEqual("before command", result["commands"][0]) def test_nxos_config_after(self): @@ -165,18 +149,14 @@ def test_nxos_config_after(self): args = dict(lines=lines, after=["after command"]) self.conn.get_diff = MagicMock( - return_value=self.cliconf_obj.get_diff( - "\n".join(lines), self.running_config - ) + return_value=self.cliconf_obj.get_diff("\n".join(lines), self.running_config), ) set_module_args(args) result = self.execute_module(changed=True) config = ["after command", "hostname switch01"] - self.assertEqual( - sorted(config), sorted(result["commands"]), result["commands"] - ) + self.assertEqual(sorted(config), sorted(result["commands"]), result["commands"]) self.assertEqual("after command", result["commands"][-1]) def test_nxos_config_parents(self): @@ -185,8 +165,51 @@ def test_nxos_config_parents(self): args = dict(lines=lines, parents=parents) self.conn.get_diff = MagicMock( return_value=self.cliconf_obj.get_diff( - "\n".join(parents + lines), self.running_config, path=parents - ) + "\n".join(parents + lines), + self.running_config, + path=parents, + ), + ) + set_module_args(args) + + result = self.execute_module(changed=True) + config = [ + "interface Ethernet10", + "ip address 1.2.3.4/5", + "no shutdown", + ] + + self.assertEqual(config, result["commands"], result["commands"]) + + def test_nxos_replace_block_src(self): + src = load_fixture("nxos_config", "candidate.cfg") + args = dict(src=src, replace="block") + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff(src, self.running_config), + ) + set_module_args(args) + + result = self.execute_module(changed=True) + config = [ + "hostname switch01", + "interface Ethernet1", + "description test interface", + "no shutdown", + "ip routing", + ] + + self.assertEqual(sorted(config), sorted(result["commands"]), result["commands"]) + + def test_nxos_replace_block_lines(self): + lines = ["ip address 1.2.3.4/5", "no shutdown"] + parents = ["interface Ethernet10"] + args = dict(lines=lines, parents=parents, replace="block") + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff( + "\n".join(parents + lines), + self.running_config, + path=parents, + ), ) set_module_args(args) @@ -219,7 +242,7 @@ def test_nxos_config_match_strict_requires_lines(self): set_module_args(args) result = self.execute_module(failed=True) - def test_nxos_config_replace_block_requires_lines(self): + def test_nxos_config_replace_block_requires_lines_or_src(self): args = dict(replace="block") set_module_args(args) result = self.execute_module(failed=True) @@ -279,17 +302,13 @@ def test_nxos_config_defaults_true(self): self.assertEqual(self.get_config.call_args[1], dict(flags=["all"])) def test_nxos_config_defaults_false_backup_true(self): - set_module_args( - dict(lines=["hostname localhost"], defaults=False, backup=True) - ) + set_module_args(dict(lines=["hostname localhost"], defaults=False, backup=True)) result = self.execute_module(changed=True) self.assertEqual(self.get_config.call_count, 1) self.assertEqual(self.get_config.call_args[1], dict(flags=[])) def test_nxos_config_defaults_true_backup_true(self): - set_module_args( - dict(lines=["hostname localhost"], defaults=True, backup=True) - ) + set_module_args(dict(lines=["hostname localhost"], defaults=True, backup=True)) result = self.execute_module(changed=True) self.assertEqual(self.get_config.call_count, 1) self.assertEqual(self.get_config.call_args[1], dict(flags=["all"])) diff --git a/tests/unit/modules/network/nxos/storage/test_nxos_devicealias.py b/tests/unit/modules/network/nxos/test_nxos_devicealias.py similarity index 73% rename from tests/unit/modules/network/nxos/storage/test_nxos_devicealias.py rename to tests/unit/modules/network/nxos/test_nxos_devicealias.py index 227221fa2..640bcd150 100644 --- a/tests/unit/modules/network/nxos/storage/test_nxos_devicealias.py +++ b/tests/unit/modules/network/nxos/test_nxos_devicealias.py @@ -4,23 +4,16 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type import pytest +from ansible_collections.cisco.nxos.plugins.modules import nxos_devicealias from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - AnsibleFailJson, -) -from ansible_collections.cisco.nxos.plugins.modules.storage import ( - nxos_devicealias, -) -from ansible_collections.cisco.nxos.plugins.modules.storage.nxos_devicealias import ( - showDeviceAliasStatus, - showDeviceAliasDatabase, -) +from ansible_collections.cisco.nxos.tests.unit.modules.utils import AnsibleFailJson -from ..nxos_module import TestNxosModule, load_fixture, set_module_args +from .nxos_module import TestNxosModule, load_fixture, set_module_args class TestNxosDeviceAliasModule(TestNxosModule): @@ -28,18 +21,16 @@ class TestNxosDeviceAliasModule(TestNxosModule): def setUp(self): super(TestNxosDeviceAliasModule, self).setUp() - module_path = "ansible_collections.cisco.nxos.plugins.modules.storage.nxos_devicealias." + module_path = "ansible_collections.cisco.nxos.plugins.modules.nxos_devicealias." self.mock_run_commands = patch(module_path + "run_commands") self.run_commands = self.mock_run_commands.start() - self.mock_execute_show_cmd = patch( - module_path + "showDeviceAliasStatus.execute_show_cmd" - ) + self.mock_execute_show_cmd = patch(module_path + "showDeviceAliasStatus.execute_show_cmd") self.execute_show_cmd = self.mock_execute_show_cmd.start() self.mock_execute_show_cmd_1 = patch( - module_path + "showDeviceAliasDatabase.execute_show_cmd" + module_path + "showDeviceAliasDatabase.execute_show_cmd", ) self.execute_show_cmd_1 = self.mock_execute_show_cmd_1.start() @@ -60,9 +51,7 @@ def test_da_mode_1(self): # Playbook mode is basic # Switch has mode as enahnced set_module_args(dict(mode="basic"), True) - self.execute_show_cmd.return_value = load_fixture( - "nxos_devicealias", "shdastatus.cfg" - ) + self.execute_show_cmd.return_value = load_fixture("nxos_devicealias", "shdastatus.cfg") result = self.execute_module(changed=True) self.assertEqual( result["commands"], @@ -78,9 +67,7 @@ def test_da_mode_2(self): # Playbook mode is enhanced # Switch has mode as enahnced set_module_args(dict(mode="enhanced"), True) - self.execute_show_cmd.return_value = load_fixture( - "nxos_devicealias", "shdastatus.cfg" - ) + self.execute_show_cmd.return_value = load_fixture("nxos_devicealias", "shdastatus.cfg") result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) @@ -88,9 +75,7 @@ def test_da_distribute_1(self): # Playbook mode is enhanced , distrbute = True # Switch has mode as enahnced, distrbute = True set_module_args(dict(distribute=True, mode="enhanced"), True) - self.execute_show_cmd.return_value = load_fixture( - "nxos_devicealias", "shdastatus.cfg" - ) + self.execute_show_cmd.return_value = load_fixture("nxos_devicealias", "shdastatus.cfg") result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) @@ -98,9 +83,7 @@ def test_da_distribute_2(self): # Playbook mode is enhanced , distrbute = False # Switch has mode as enhanced, distrbute = True set_module_args(dict(distribute=False, mode="enhanced"), True) - self.execute_show_cmd.return_value = load_fixture( - "nxos_devicealias", "shdastatus.cfg" - ) + self.execute_show_cmd.return_value = load_fixture("nxos_devicealias", "shdastatus.cfg") result = self.execute_module(changed=True) self.assertEqual(result["commands"], ["no device-alias distribute"]) @@ -108,9 +91,7 @@ def test_da_distribute_3(self): # Playbook mode is basic , distrbute = False # Switch has mode as enahnced, distrbute = True set_module_args(dict(distribute=False, mode="basic"), True) - self.execute_show_cmd.return_value = load_fixture( - "nxos_devicealias", "shdastatus.cfg" - ) + self.execute_show_cmd.return_value = load_fixture("nxos_devicealias", "shdastatus.cfg") result = self.execute_module(changed=True) self.assertEqual( result["commands"], @@ -131,12 +112,8 @@ def test_da_add_1(self): ), True, ) - self.execute_show_cmd.return_value = load_fixture( - "nxos_devicealias", "shdastatus.cfg" - ) - self.execute_show_cmd_1.return_value = load_fixture( - "nxos_devicealias", "shdadatabse.cfg" - ) + self.execute_show_cmd.return_value = load_fixture("nxos_devicealias", "shdastatus.cfg") + self.execute_show_cmd_1.return_value = load_fixture("nxos_devicealias", "shdadatabse.cfg") result = self.execute_module(changed=True) self.assertEqual( result["commands"], @@ -161,12 +138,8 @@ def test_da_add_2(self): ), True, ) - self.execute_show_cmd.return_value = load_fixture( - "nxos_devicealias", "shdastatus.cfg" - ) - self.execute_show_cmd_1.return_value = load_fixture( - "nxos_devicealias", "shdadatabse.cfg" - ) + self.execute_show_cmd.return_value = load_fixture("nxos_devicealias", "shdastatus.cfg") + self.execute_show_cmd_1.return_value = load_fixture("nxos_devicealias", "shdadatabse.cfg") result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) @@ -181,12 +154,8 @@ def test_da_add_3(self): ), True, ) - self.execute_show_cmd.return_value = load_fixture( - "nxos_devicealias", "shdastatus.cfg" - ) - self.execute_show_cmd_1.return_value = load_fixture( - "nxos_devicealias", "shdadatabse.cfg" - ) + self.execute_show_cmd.return_value = load_fixture("nxos_devicealias", "shdastatus.cfg") + self.execute_show_cmd_1.return_value = load_fixture("nxos_devicealias", "shdadatabse.cfg") result = self.execute_module(changed=False, failed=True) def test_da_add_4(self): @@ -200,12 +169,8 @@ def test_da_add_4(self): ), True, ) - self.execute_show_cmd.return_value = load_fixture( - "nxos_devicealias", "shdastatus.cfg" - ) - self.execute_show_cmd_1.return_value = load_fixture( - "nxos_devicealias", "shdadatabse.cfg" - ) + self.execute_show_cmd.return_value = load_fixture("nxos_devicealias", "shdastatus.cfg") + self.execute_show_cmd_1.return_value = load_fixture("nxos_devicealias", "shdadatabse.cfg") result = self.execute_module(changed=False, failed=True) def test_da_remove_1(self): @@ -220,17 +185,13 @@ def test_da_remove_1(self): name="tieHost-2", pwwn="10:00:00:00:89:a1:01:02", remove=True, - ) + ), ], ), True, ) - self.execute_show_cmd.return_value = load_fixture( - "nxos_devicealias", "shdastatus.cfg" - ) - self.execute_show_cmd_1.return_value = load_fixture( - "nxos_devicealias", "shdadatabse.cfg" - ) + self.execute_show_cmd.return_value = load_fixture("nxos_devicealias", "shdastatus.cfg") + self.execute_show_cmd_1.return_value = load_fixture("nxos_devicealias", "shdadatabse.cfg") result = self.execute_module(changed=True) self.assertEqual( result["commands"], @@ -255,17 +216,13 @@ def test_da_remove_2(self): name="somename", pwwn="10:00:00:00:89:a1:01:02", remove=True, - ) + ), ], ), True, ) - self.execute_show_cmd.return_value = load_fixture( - "nxos_devicealias", "shdastatus.cfg" - ) - self.execute_show_cmd_1.return_value = load_fixture( - "nxos_devicealias", "shdadatabse.cfg" - ) + self.execute_show_cmd.return_value = load_fixture("nxos_devicealias", "shdastatus.cfg") + self.execute_show_cmd_1.return_value = load_fixture("nxos_devicealias", "shdadatabse.cfg") result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) @@ -280,14 +237,12 @@ def test_da_lock(self): name="somename", pwwn="10:00:00:00:89:a1:01:02", remove=True, - ) + ), ], ), True, ) - self.execute_show_cmd.return_value = load_fixture( - "nxos_devicealias", "shdastatuslock.cfg" - ) + self.execute_show_cmd.return_value = load_fixture("nxos_devicealias", "shdastatuslock.cfg") self.execute_module(failed=True) def test_da_paramete_not_supported(self): @@ -302,17 +257,13 @@ def test_da_paramete_not_supported(self): name="somename", pwwn="10:00:00:00:89:a1:01:02", remove=True, - ) + ), ], ), True, ) - self.execute_show_cmd.return_value = load_fixture( - "nxos_devicealias", "shdastatus.cfg" - ) - self.execute_show_cmd_1.return_value = load_fixture( - "nxos_devicealias", "shdadatabse.cfg" - ) + self.execute_show_cmd.return_value = load_fixture("nxos_devicealias", "shdastatus.cfg") + self.execute_show_cmd_1.return_value = load_fixture("nxos_devicealias", "shdadatabse.cfg") with pytest.raises(AnsibleFailJson) as errinfo: self.execute_module() testdata = errinfo.value.args[0] @@ -329,12 +280,8 @@ def test_da_name_parameter_missing(self): ), True, ) - self.execute_show_cmd.return_value = load_fixture( - "nxos_devicealias", "shdastatus.cfg" - ) - self.execute_show_cmd_1.return_value = load_fixture( - "nxos_devicealias", "shdadatabse.cfg" - ) + self.execute_show_cmd.return_value = load_fixture("nxos_devicealias", "shdastatus.cfg") + self.execute_show_cmd_1.return_value = load_fixture("nxos_devicealias", "shdadatabse.cfg") with pytest.raises(AnsibleFailJson) as errinfo: self.execute_module() testdata = errinfo.value.args[0] @@ -348,16 +295,12 @@ def test_da_rename_1(self): rename=[ dict(old_name="test1_add", new_name="test234"), dict(old_name="tieHost-1", new_name="tieTarget-1"), - ] + ], ), True, ) - self.execute_show_cmd.return_value = load_fixture( - "nxos_devicealias", "shdastatus.cfg" - ) - self.execute_show_cmd_1.return_value = load_fixture( - "nxos_devicealias", "shdadatabse.cfg" - ) + self.execute_show_cmd.return_value = load_fixture("nxos_devicealias", "shdastatus.cfg") + self.execute_show_cmd_1.return_value = load_fixture("nxos_devicealias", "shdadatabse.cfg") result = self.execute_module(changed=True) self.assertEqual( result["commands"], @@ -378,27 +321,22 @@ def test_da_rename_2(self): rename=[ dict(old_name="test1", new_name="test234"), dict(old_name="tie", new_name="tieTarget-1"), - ] + ], ), True, ) - self.execute_show_cmd.return_value = load_fixture( - "nxos_devicealias", "shdastatus.cfg" - ) - self.execute_show_cmd_1.return_value = load_fixture( - "nxos_devicealias", "shdadatabse.cfg" - ) + self.execute_show_cmd.return_value = load_fixture("nxos_devicealias", "shdastatus.cfg") + self.execute_show_cmd_1.return_value = load_fixture("nxos_devicealias", "shdadatabse.cfg") result = self.execute_module(changed=False, failed=True) self.assertEqual(result["commands"], []) def test_da_mansi(self): set_module_args({"distribute": True, "mode": "enhanced"}, True) self.execute_show_cmd.return_value = load_fixture( - "nxos_devicealias", "shdastatus_mansi.cfg" - ) - self.execute_show_cmd_1.return_value = load_fixture( - "nxos_devicealias", "shdadatabse.cfg" + "nxos_devicealias", + "shdastatus_mansi.cfg", ) + self.execute_show_cmd_1.return_value = load_fixture("nxos_devicealias", "shdadatabse.cfg") result = self.execute_module(changed=True) self.assertEqual( result["commands"], @@ -422,12 +360,8 @@ def test_da_add_bad(self): ), True, ) - self.execute_show_cmd.return_value = load_fixture( - "nxos_devicealias", "shdastatus.cfg" - ) - self.execute_show_cmd_1.return_value = load_fixture( - "nxos_devicealias", "shdadatabse.cfg" - ) + self.execute_show_cmd.return_value = load_fixture("nxos_devicealias", "shdastatus.cfg") + self.execute_show_cmd_1.return_value = load_fixture("nxos_devicealias", "shdadatabse.cfg") result = self.execute_module(changed=False, failed=True) assert "it must start with a letter" in str(result["msg"]) @@ -443,12 +377,8 @@ def test_da_add_bad_1(self): ), True, ) - self.execute_show_cmd.return_value = load_fixture( - "nxos_devicealias", "shdastatus.cfg" - ) - self.execute_show_cmd_1.return_value = load_fixture( - "nxos_devicealias", "shdadatabse.cfg" - ) + self.execute_show_cmd.return_value = load_fixture("nxos_devicealias", "shdastatus.cfg") + self.execute_show_cmd_1.return_value = load_fixture("nxos_devicealias", "shdadatabse.cfg") result = self.execute_module(changed=False, failed=True) assert "and can only contain these characters" in str(result["msg"]) diff --git a/tests/unit/modules/network/nxos/test_nxos_evpn_global.py b/tests/unit/modules/network/nxos/test_nxos_evpn_global.py index 2f926f6f0..c9fa7911e 100644 --- a/tests/unit/modules/network/nxos/test_nxos_evpn_global.py +++ b/tests/unit/modules/network/nxos/test_nxos_evpn_global.py @@ -20,31 +20,32 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from ansible_collections.cisco.nxos.plugins.modules import nxos_evpn_global +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from .nxos_module import TestNxosModule, load_fixture, set_module_args class TestNxosEvpnGlobalModule(TestNxosModule): - module = nxos_evpn_global def setUp(self): super(TestNxosEvpnGlobalModule, self).setUp() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_evpn_global.get_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_evpn_global.get_config", ) self.get_config = self.mock_get_config.start() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_evpn_global.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_evpn_global.load_config", ) self.load_config = self.mock_load_config.start() self.mock_get_capabilities = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_evpn_global.get_capabilities" + "ansible_collections.cisco.nxos.plugins.modules.nxos_evpn_global.get_capabilities", ) self.get_capabilities = self.mock_get_capabilities.start() self.get_capabilities.return_value = {"network_api": "cliconf"} @@ -59,15 +60,11 @@ def load_fixtures(self, commands=None, device=""): self.load_config.return_value = None def start_configured(self, *args, **kwargs): - self.get_config.return_value = load_fixture( - "nxos_evpn_global", "configured.cfg" - ) + self.get_config.return_value = load_fixture("nxos_evpn_global", "configured.cfg") return self.execute_module(*args, **kwargs) def start_unconfigured(self, *args, **kwargs): - self.get_config.return_value = load_fixture( - "nxos_evpn_global", "unconfigured.cfg" - ) + self.get_config.return_value = load_fixture("nxos_evpn_global", "unconfigured.cfg") return self.execute_module(*args, **kwargs) def test_nxos_evpn_global_enable(self): diff --git a/tests/unit/modules/network/nxos/test_nxos_evpn_vni.py b/tests/unit/modules/network/nxos/test_nxos_evpn_vni.py index 53e23d48c..0211a5a31 100644 --- a/tests/unit/modules/network/nxos/test_nxos_evpn_vni.py +++ b/tests/unit/modules/network/nxos/test_nxos_evpn_vni.py @@ -19,27 +19,28 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from ansible_collections.cisco.nxos.plugins.modules import nxos_evpn_vni +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from .nxos_module import TestNxosModule, load_fixture, set_module_args class TestNxosEvpnVniModule(TestNxosModule): - module = nxos_evpn_vni def setUp(self): super(TestNxosEvpnVniModule, self).setUp() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_evpn_vni.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_evpn_vni.load_config", ) self.load_config = self.mock_load_config.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_evpn_vni.get_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_evpn_vni.get_config", ) self.get_config = self.mock_get_config.start() @@ -49,15 +50,11 @@ def tearDown(self): self.mock_get_config.stop() def load_fixtures(self, commands=None, device=""): - self.get_config.return_value = load_fixture( - "", "nxos_evpn_vni_config.cfg" - ) + self.get_config.return_value = load_fixture("", "nxos_evpn_vni_config.cfg") self.load_config.return_value = None def test_nxos_evpn_vni_present(self): - set_module_args( - dict(vni="6000", route_target_import="5000:10", state="present") - ) + set_module_args(dict(vni="6000", route_target_import="5000:10", state="present")) result = self.execute_module(changed=True) self.assertEqual( result["commands"], diff --git a/tests/unit/modules/network/nxos/test_nxos_fc_interfaces.py b/tests/unit/modules/network/nxos/test_nxos_fc_interfaces.py new file mode 100644 index 000000000..098a5b7ff --- /dev/null +++ b/tests/unit/modules/network/nxos/test_nxos_fc_interfaces.py @@ -0,0 +1,1744 @@ +# (c) 2023 Red Hat Inc. +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +# Make coding more python3-ish + + +# remove purge +# add non fc interfaces to the sh run +# check else statements in config file + + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from textwrap import dedent + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.fc_interfaces import ( + allowed_port_modes, + allowed_speed_values, +) +from ansible_collections.cisco.nxos.plugins.modules import nxos_fc_interfaces +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + +from .nxos_module import TestNxosModule, set_module_args + + +ignore_provider_arg = True + +sh_run = """ +interface mgmt0 + ip address 10.126.94.175 255.255.255.0 + no switchport description + switchport speed auto + switchport duplex auto + snmp trap link-status + no shutdown + lldp transmit + lldp receive + cdp enable + spanning-tree port-priority 128 + spanning-tree cost auto + spanning-tree link-type auto + no spanning-tree bpduguard + no spanning-tree bpdufilter + +interface vsan1 + no shutdown + ip address 111.111.111.175 255.255.255.0 + spanning-tree port-priority 128 + spanning-tree cost auto + spanning-tree link-type auto + no spanning-tree bpduguard + no spanning-tree bpdufilter + + +interface fc1/1 + no out-of-service force + switchport speed auto + no transceiver-frequency ethernet + switchport rate-mode default + switchport fcrxbbcredit default + switchport mode auto + switchport description This is a sample line + switchport vl-credit default + switchport trunk mode on + no switchport beacon + switchport fcbbscn + link-state-trap + switchport fcrxbufsize 2112 + no switchport owner + switchport encap default + switchport fcrxbbcredit performance-buffers default + no switchport ignore bit-errors + no switchport ignore interrupt-thresholds + switchport fill-pattern ARBFF speed 8000 + switchport logical-type auto + switchport max-npiv-limit 0 + switchport trunk-max-npiv-limit 0 + no switchport link-diag + no shutdown + +interface fc1/2 + no out-of-service force + switchport speed 1000 + no transceiver-frequency ethernet + switchport rate-mode default + switchport fcrxbbcredit default + switchport mode E + no switchport description + switchport vl-credit default + switchport trunk mode off + no switchport beacon + switchport fcbbscn + link-state-trap + switchport fcrxbufsize 2112 + no port-license + no errdisable detect cause link-down + no errdisable detect cause trustsec-violation + no errdisable detect cause bit-errors + no errdisable detect cause signal-loss + no errdisable detect cause sync-loss + no errdisable detect cause link-reset + no errdisable detect cause credit-loss + no switchport owner + switchport encap default + switchport fcrxbbcredit performance-buffers default + no switchport ignore bit-errors + no switchport ignore interrupt-thresholds + switchport fill-pattern ARBFF speed 8000 + switchport logical-type auto + switchport max-npiv-limit 0 + switchport trunk-max-npiv-limit 0 + no switchport link-diag + no shutdown + +interface fc1/3 + no out-of-service force + switchport speed 2000 + no transceiver-frequency ethernet + switchport rate-mode default + switchport fcrxbbcredit default + switchport mode F + no switchport description + switchport vl-credit default + switchport trunk mode on + no switchport beacon + switchport fcbbscn + link-state-trap + switchport fcrxbufsize 2112 + no switchport owner + switchport encap default + switchport fcrxbbcredit performance-buffers default + no switchport ignore bit-errors + no switchport ignore interrupt-thresholds + switchport fill-pattern ARBFF speed 8000 + switchport logical-type auto + switchport max-npiv-limit 0 + switchport trunk-max-npiv-limit 0 + no switchport link-diag + no shutdown + +interface fc18/1 + no out-of-service force + switchport speed 4000 + no transceiver-frequency ethernet + switchport rate-mode default + switchport fcrxbbcredit default + switchport mode Fx + no switchport description + switchport vl-credit default + switchport trunk mode auto + no switchport beacon + switchport fcbbscn + link-state-trap + switchport fcrxbufsize 2112 + no port-license + no switchport owner + switchport encap default + switchport fcrxbbcredit performance-buffers default + no switchport ignore bit-errors + no switchport ignore interrupt-thresholds + switchport fill-pattern ARBFF speed 8000 + switchport logical-type auto + switchport max-npiv-limit 0 + switchport trunk-max-npiv-limit 0 + no switchport link-diag + no shutdown + +interface fc18/2 + no out-of-service force + switchport speed 8000 + no transceiver-frequency ethernet + switchport rate-mode default + switchport fcrxbbcredit default + switchport mode NP + no switchport description + switchport vl-credit default + switchport trunk mode on + no switchport beacon + switchport fcbbscn + link-state-trap + switchport fcrxbufsize 2112 + no port-license + no switchport owner + switchport encap default + switchport fcrxbbcredit performance-buffers default + no switchport ignore bit-errors + no switchport ignore interrupt-thresholds + switchport fill-pattern ARBFF speed 8000 + switchport logical-type auto + switchport max-npiv-limit 0 + switchport trunk-max-npiv-limit 0 + no switchport link-diag + no shutdown +interface fc18/3 + no out-of-service force + switchport speed 10000 + no transceiver-frequency ethernet + switchport rate-mode default + switchport fcrxbbcredit default + switchport mode SD + no switchport description + switchport vl-credit default + switchport trunk mode on + no switchport beacon + switchport fcbbscn + link-state-trap + switchport fcrxbufsize 2112 + no port-license + no switchport owner + switchport encap default + switchport fcrxbbcredit performance-buffers default + no switchport ignore bit-errors + no switchport ignore interrupt-thresholds + switchport fill-pattern ARBFF speed 8000 + switchport logical-type auto + switchport max-npiv-limit 0 + switchport trunk-max-npiv-limit 0 + no switchport link-diag + no shutdown + +interface fc18/4 + no out-of-service force + switchport speed 16000 + no transceiver-frequency ethernet + switchport rate-mode default + switchport fcrxbbcredit default + switchport mode auto + no switchport description + switchport vl-credit default + switchport trunk mode on + no switchport beacon + switchport fcbbscn + link-state-trap + switchport fcrxbufsize 2112 + no port-license + no switchport owner + switchport encap default + switchport fcrxbbcredit performance-buffers default + no switchport ignore bit-errors + no switchport ignore interrupt-thresholds + switchport fill-pattern ARBFF speed 8000 + switchport logical-type auto + switchport max-npiv-limit 0 + switchport trunk-max-npiv-limit 0 + no switchport link-diag + no shutdown +interface fc18/5 + no out-of-service force + switchport speed 32000 + no transceiver-frequency ethernet + switchport rate-mode default + switchport fcrxbbcredit default + switchport mode auto + no switchport description + switchport vl-credit default + switchport trunk mode on + no switchport beacon + switchport fcbbscn + link-state-trap + switchport fcrxbufsize 2112 + no port-license + no switchport owner + switchport encap default + switchport fcrxbbcredit performance-buffers default + no switchport ignore bit-errors + no switchport ignore interrupt-thresholds + switchport fill-pattern ARBFF speed 8000 + switchport logical-type auto + switchport max-npiv-limit 0 + switchport trunk-max-npiv-limit 0 + no switchport link-diag + no shutdown + +interface fc18/6 + no out-of-service force + switchport speed 64000 + no transceiver-frequency ethernet + switchport rate-mode default + switchport fcrxbbcredit default + switchport mode auto + no switchport description + switchport vl-credit default + switchport trunk mode on + no switchport beacon + switchport fcbbscn + link-state-trap + switchport fcrxbufsize 2112 + no port-license + no switchport owner + switchport encap default + switchport fcrxbbcredit performance-buffers default + no switchport ignore bit-errors + no switchport ignore interrupt-thresholds + switchport fill-pattern ARBFF speed 8000 + switchport logical-type auto + switchport max-npiv-limit 0 + switchport trunk-max-npiv-limit 0 + no switchport link-diag + no shutdown +interface fc18/7 + no out-of-service force + switchport speed auto max 2000 + no transceiver-frequency ethernet + switchport rate-mode default + switchport fcrxbbcredit default + switchport mode auto + no switchport description + switchport vl-credit default + switchport trunk mode on + no switchport beacon + switchport fcbbscn + link-state-trap + switchport fcrxbufsize 2112 + no port-license + no switchport owner + switchport encap default + switchport fcrxbbcredit performance-buffers default + no switchport ignore bit-errors + no switchport ignore interrupt-thresholds + switchport fill-pattern ARBFF speed 8000 + switchport logical-type auto + switchport max-npiv-limit 0 + switchport trunk-max-npiv-limit 0 + no switchport link-diag + no shutdown + +interface fc18/8 + no out-of-service force + switchport speed auto max 4000 + no transceiver-frequency ethernet + switchport rate-mode default + switchport fcrxbbcredit default + switchport mode auto + no switchport description + switchport vl-credit default + switchport trunk mode on + no switchport beacon + switchport fcbbscn + link-state-trap + switchport fcrxbufsize 2112 + no port-license + no switchport owner + switchport encap default + switchport fcrxbbcredit performance-buffers default + no switchport ignore bit-errors + no switchport ignore interrupt-thresholds + switchport fill-pattern ARBFF speed 8000 + switchport logical-type auto + switchport max-npiv-limit 0 + switchport trunk-max-npiv-limit 0 + no switchport link-diag + no shutdown +interface fc18/9 + no out-of-service force + switchport speed auto max 8000 + no transceiver-frequency ethernet + switchport rate-mode default + switchport fcrxbbcredit default + switchport mode auto + switchport description sample description + switchport vl-credit default + switchport trunk mode on + no switchport beacon + switchport fcbbscn + link-state-trap + switchport fcrxbufsize 2112 + no port-license + no switchport owner + switchport encap default + switchport fcrxbbcredit performance-buffers default + no switchport ignore bit-errors + no switchport ignore interrupt-thresholds + switchport fill-pattern ARBFF speed 8000 + switchport logical-type auto + switchport max-npiv-limit 0 + switchport trunk-max-npiv-limit 0 + no switchport link-diag + no shutdown + +interface fc18/10 + no out-of-service force + analytics type fc-nvme + switchport speed auto max 16000 + no transceiver-frequency ethernet + switchport rate-mode default + switchport fcrxbbcredit default + switchport mode auto + switchport description $ + switchport vl-credit default + switchport trunk mode on + no switchport beacon + switchport fcbbscn + link-state-trap + switchport fcrxbufsize 2112 + no port-license + no switchport owner + switchport encap default + switchport fcrxbbcredit performance-buffers default + no switchport ignore bit-errors + no switchport ignore interrupt-thresholds + switchport fill-pattern ARBFF speed 8000 + switchport logical-type auto + switchport max-npiv-limit 0 + switchport trunk-max-npiv-limit 0 + no switchport link-diag + shutdown + +interface fc18/11 + no out-of-service force + analytics type fc-scsi + switchport speed auto max 32000 + no transceiver-frequency ethernet + switchport rate-mode default + switchport fcrxbbcredit default + switchport mode auto + switchport description a + switchport vl-credit default + switchport trunk mode on + no switchport beacon + switchport fcbbscn + link-state-trap + switchport fcrxbufsize 2112 + no port-license + no switchport owner + switchport encap default + switchport fcrxbbcredit performance-buffers default + no switchport ignore bit-errors + no switchport ignore interrupt-thresholds + switchport fill-pattern ARBFF speed 8000 + switchport logical-type auto + switchport max-npiv-limit 0 + switchport trunk-max-npiv-limit 0 + no switchport link-diag + shutdown + +interface fc18/12 + no out-of-service force + analytics type fc-scsi + analytics type fc-nvme + switchport speed auto max 64000 + no transceiver-frequency ethernet + switchport rate-mode default + switchport fcrxbbcredit default + switchport mode auto + switchport description 1 + switchport vl-credit default + switchport trunk mode on + no switchport beacon + switchport fcbbscn + link-state-trap + switchport fcrxbufsize 2112 + no port-license + no switchport owner + switchport encap default + switchport fcrxbbcredit performance-buffers default + no switchport ignore bit-errors + no switchport ignore interrupt-thresholds + switchport fill-pattern ARBFF speed 8000 + switchport logical-type auto + switchport max-npiv-limit 0 + switchport trunk-max-npiv-limit 0 + no switchport link-diag + no shutdown + +interface fc18/13 + no out-of-service force + analytics type fc-scsi + analytics type fc-nvme + switchport speed auto max 64000 + no transceiver-frequency ethernet + switchport rate-mode default + switchport fcrxbbcredit default + switchport mode auto + switchport description 1 + switchport vl-credit default + switchport trunk mode on + no switchport beacon + switchport fcbbscn + link-state-trap + switchport fcrxbufsize 2112 + no port-license + no switchport owner + switchport encap default + switchport fcrxbbcredit performance-buffers default + no switchport ignore bit-errors + no switchport ignore interrupt-thresholds + switchport fill-pattern ARBFF speed 8000 + switchport logical-type auto + switchport max-npiv-limit 0 + switchport trunk-max-npiv-limit 0 + no switchport link-diag + no shutdown + """ + +gath_val = [ + { + "name": "fc1/1", + "speed": "auto", + "mode": "auto", + "trunk_mode": "on", + "enabled": True, + "description": "This is a sample line", + }, + { + "name": "fc1/2", + "speed": "1000", + "mode": "E", + "trunk_mode": "off", + "enabled": True, + }, + { + "name": "fc1/3", + "speed": "2000", + "mode": "F", + "trunk_mode": "on", + "enabled": True, + }, + { + "name": "fc18/1", + "speed": "4000", + "mode": "Fx", + "trunk_mode": "auto", + "enabled": True, + }, + { + "name": "fc18/2", + "speed": "8000", + "mode": "NP", + "trunk_mode": "on", + "enabled": True, + }, + { + "name": "fc18/3", + "speed": "10000", + "mode": "SD", + "trunk_mode": "on", + "enabled": True, + }, + { + "name": "fc18/4", + "speed": "16000", + "mode": "auto", + "trunk_mode": "on", + "enabled": True, + }, + { + "name": "fc18/5", + "speed": "32000", + "mode": "auto", + "trunk_mode": "on", + "enabled": True, + }, + { + "name": "fc18/6", + "speed": "64000", + "mode": "auto", + "trunk_mode": "on", + "enabled": True, + }, + { + "name": "fc18/7", + "speed": "auto max 2000", + "mode": "auto", + "trunk_mode": "on", + "enabled": True, + }, + { + "name": "fc18/8", + "speed": "auto max 4000", + "mode": "auto", + "trunk_mode": "on", + "enabled": True, + }, + { + "name": "fc18/9", + "speed": "auto max 8000", + "mode": "auto", + "trunk_mode": "on", + "enabled": True, + "description": "sample description", + }, + { + "name": "fc18/10", + "speed": "auto max 16000", + "mode": "auto", + "trunk_mode": "on", + "enabled": False, + "description": "$", + "analytics": "fc-nvme", + }, + { + "name": "fc18/11", + "speed": "auto max 32000", + "mode": "auto", + "trunk_mode": "on", + "enabled": False, + "description": "a", + "analytics": "fc-scsi", + }, + { + "name": "fc18/12", + "speed": "auto max 64000", + "mode": "auto", + "trunk_mode": "on", + "enabled": True, + "description": "1", + "analytics": "fc-all", + }, + { + "name": "fc18/13", + "speed": "auto max 64000", + "mode": "auto", + "trunk_mode": "on", + "enabled": True, + "description": "1", + "analytics": "fc-all", + }, +] + + +class TestNxosFcInterfacesModule(TestNxosModule): + module = nxos_fc_interfaces + + def setUp(self): + super(TestNxosFcInterfacesModule, self).setUp() + + self.mock_get_resource_connection = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", + ) + self.get_resource_connection = self.mock_get_resource_connection.start() + + self.mock_get_config = patch( + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.fc_interfaces.fc_interfaces.Fc_interfacesFacts.get_interfaces_data", + ) + self.get_config = self.mock_get_config.start() + self.get_config.return_value = dedent(sh_run) + + self.maxDiff = None + + def tearDown(self): + super(TestNxosFcInterfacesModule, self).tearDown() + self.get_resource_connection.stop() + self.get_config.stop() + + def test_analytics_no_to_all_3_types(self): + args = dict( + config=[ + { + "name": "fc1/1", + "analytics": "fc-scsi", + "mode": "E", + }, + { + "name": "fc1/2", + "analytics": "fc-nvme", + }, + { + "name": "fc1/3", + "analytics": "fc-all", + }, + { + "name": "fc18/12", + "analytics": "fc-scsi", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + [ + "interface fc1/1", + "switchport mode E", + "analytics type fc-scsi", + "interface fc1/2", + "analytics type fc-nvme", + "interface fc1/3", + "analytics type fc-all", + ], + ) + + def test_gathered(self): + # test gathered for config + set_module_args(dict(state="gathered"), ignore_provider_arg) + result = self.execute_module(changed=False) + self.assertEqual(result["gathered"], gath_val) + + def test_parsed(self): + # test parsed for config + set_module_args(dict(state="parsed", running_config=sh_run), ignore_provider_arg) + result = self.execute_module(changed=False) + self.assertEqual(result["parsed"], gath_val) + + def test_idempotency(self): + args = dict( + config=gath_val, + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=False) + self.assertEqual(result["commands"], []) + + def test_analytics_all_to_scsi(self): + args = dict( + config=[ + { + "name": "fc18/12", + "speed": "auto max 64000", + "mode": "auto", + "trunk_mode": "on", + "enabled": True, + "description": "1", + "analytics": "fc-scsi", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=False) + self.assertEqual( + result["commands"], + [], + ) + + def test_analytics_all_to_scsi_replaced(self): + args = dict( + config=[ + { + "name": "fc18/12", + "speed": "auto max 64000", + "mode": "auto", + "trunk_mode": "on", + "enabled": True, + "description": "1", + "analytics": "fc-scsi", + }, + ], + state="replaced", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + ["interface fc18/12", "no analytics type fc-all", "analytics type fc-scsi"], + ) + + def test_analytics_all_to_nvme(self): + args = dict( + config=[ + { + "name": "fc18/12", + "speed": "auto max 64000", + "mode": "auto", + "trunk_mode": "on", + "enabled": True, + "description": "1", + "analytics": "fc-nvme", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=False) + self.assertEqual( + result["commands"], + [], + ) + + def test_analytics_all_to_nvme_replaced(self): + args = dict( + config=[ + { + "name": "fc18/12", + "speed": "auto max 64000", + "mode": "auto", + "trunk_mode": "on", + "enabled": True, + "description": "1", + "analytics": "fc-nvme", + }, + ], + state="replaced", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + ["interface fc18/12", "no analytics type fc-all", "analytics type fc-nvme"], + ) + + def test_analytics_all_to_none_checkthis(self): + args = dict( + config=[ + { + "name": "fc18/12", + "speed": "auto max 64000", + "mode": "auto", + "trunk_mode": "on", + "enabled": True, + "description": "1", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=False) + self.assertEqual(result["commands"], []) + + def test_analytics_all_to_none_desc_change(self): + args = dict( + config=[ + { + "name": "fc18/12", + "speed": "auto max 64000", + "mode": "auto", + "trunk_mode": "on", + "enabled": True, + "description": "2", + "analytics": "fc-all", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], ["interface fc18/12", "switchport description 2"]) + + def test_analytics_scsi_to_nvme(self): + args = dict( + config=[ + { + "name": "fc18/11", + "speed": "auto max 32000", + "mode": "auto", + "trunk_mode": "on", + "enabled": False, + "description": "a", + "analytics": "fc-nvme", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + ["interface fc18/11", "analytics type fc-nvme"], + ) + + def test_analytics_scsi_to_nvme_replaced(self): + args = dict( + config=[ + { + "name": "fc18/11", + "speed": "auto max 32000", + "mode": "auto", + "trunk_mode": "on", + "enabled": False, + "description": "a", + "analytics": "fc-nvme", + }, + ], + state="replaced", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + ["interface fc18/11", "no analytics type fc-all", "analytics type fc-nvme"], + ) + + def test_analytics_scsi_to_all(self): + args = dict( + config=[ + { + "name": "fc18/11", + "speed": "auto max 32000", + "mode": "auto", + "trunk_mode": "on", + "enabled": False, + "description": "a", + "analytics": "fc-all", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], ["interface fc18/11", "analytics type fc-all"]) + + def test_analytics_scsi_to_all_replaced(self): + args = dict( + config=[ + { + "name": "fc18/11", + "speed": "auto max 32000", + "mode": "auto", + "trunk_mode": "on", + "enabled": False, + "description": "a", + "analytics": "fc-all", + }, + ], + state="replaced", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + ["interface fc18/11", "analytics type fc-all"], + ) + + def test_analytics_scsi_to_none_checkthis(self): + args = dict( + config=[ + { + "name": "fc18/11", + "speed": "auto max 32000", + "mode": "auto", + "trunk_mode": "on", + "enabled": False, + "description": "a", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=False) + self.assertEqual(result["commands"], []) + + def test_analytics_nvme_to_scsi(self): + args = dict( + config=[ + { + "name": "fc18/10", + "analytics": "fc-scsi", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + ["interface fc18/10", "analytics type fc-scsi"], + ) + + def test_analytics_nvme_to_scsi_replaced(self): + args = dict( + config=[ + { + "name": "fc18/10", + "analytics": "fc-scsi", + }, + ], + state="replaced", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + [ + "interface fc18/10", + "no switchport description", + "no switchport speed auto max 16000", + "no switchport mode auto", + "switchport trunk mode on", + "shutdown", + "no analytics type fc-all", + "analytics type fc-scsi", + ], + ) + + def test_analytics_nvme_to_all(self): + args = dict( + config=[ + { + "name": "fc18/10", + "analytics": "fc-all", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + ["interface fc18/10", "analytics type fc-all"], + ) + + def test_analytics_nvme_to_all_replaced(self): + args = dict( + config=[ + { + "name": "fc18/10", + "analytics": "fc-all", + }, + ], + state="replaced", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + [ + "interface fc18/10", + "no switchport description", + "no switchport speed auto max 16000", + "no switchport mode auto", + "switchport trunk mode on", + "shutdown", + "analytics type fc-all", + ], + ) + + def test_analytics_none_to_scsi(self): + args = dict( + config=[ + { + "name": "fc1/1", + "analytics": "fc-scsi", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], ["interface fc1/1", "analytics type fc-scsi"]) + + def test_analytics_none_to_scsi_replaced(self): + args = dict( + config=[ + { + "name": "fc1/1", + "analytics": "fc-scsi", + }, + ], + state="replaced", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + [ + "interface fc1/1", + "no switchport description", + "no switchport speed auto", + "no switchport mode auto", + "switchport trunk mode on", + "shutdown", + "analytics type fc-scsi", + ], + ) + + def test_analytics_none_to_nvme(self): + args = dict( + config=[ + { + "name": "fc1/1", + "analytics": "fc-nvme", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], ["interface fc1/1", "analytics type fc-nvme"]) + + def test_analytics_none_to_nvme_replaced(self): + args = dict( + config=[ + { + "name": "fc1/1", + "analytics": "fc-nvme", + }, + ], + state="replaced", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + [ + "interface fc1/1", + "no switchport description", + "no switchport speed auto", + "no switchport mode auto", + "switchport trunk mode on", + "shutdown", + "analytics type fc-nvme", + ], + ) + + def test_analytics_none_to_nvme_overridden(self): + args = dict( + config=[ + { + "name": "fc1/1", + "analytics": "fc-nvme", + }, + ], + state="overridden", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + [ + "interface fc1/2", + "no switchport speed 1000", + "no switchport mode E", + "switchport trunk mode on", + "shutdown", + "interface fc1/3", + "no switchport speed 2000", + "no switchport mode F", + "switchport trunk mode on", + "shutdown", + "interface fc18/1", + "no switchport speed 4000", + "no switchport mode Fx", + "switchport trunk mode on", + "shutdown", + "interface fc18/2", + "no switchport speed 8000", + "no switchport mode NP", + "switchport trunk mode on", + "shutdown", + "interface fc18/3", + "no switchport speed 10000", + "no switchport mode SD", + "switchport trunk mode on", + "shutdown", + "interface fc18/4", + "no switchport speed 16000", + "no switchport mode auto", + "switchport trunk mode on", + "shutdown", + "interface fc18/5", + "no switchport speed 32000", + "no switchport mode auto", + "switchport trunk mode on", + "shutdown", + "interface fc18/6", + "no switchport speed 64000", + "no switchport mode auto", + "switchport trunk mode on", + "shutdown", + "interface fc18/7", + "no switchport speed auto max 2000", + "no switchport mode auto", + "switchport trunk mode on", + "shutdown", + "interface fc18/8", + "no switchport speed auto max 4000", + "no switchport mode auto", + "switchport trunk mode on", + "shutdown", + "interface fc18/9", + "no switchport description", + "no switchport speed auto max 8000", + "no switchport mode auto", + "switchport trunk mode on", + "shutdown", + "interface fc18/10", + "no switchport description", + "no switchport speed auto max 16000", + "no switchport mode auto", + "switchport trunk mode on", + "no analytics type fc-all", + "interface fc18/11", + "no switchport description", + "no switchport speed auto max 32000", + "no switchport mode auto", + "switchport trunk mode on", + "no analytics type fc-all", + "interface fc18/12", + "no switchport description", + "no switchport speed auto max 64000", + "no switchport mode auto", + "switchport trunk mode on", + "shutdown", + "no analytics type fc-all", + "interface fc18/13", + "no switchport description", + "no switchport speed auto max 64000", + "no switchport mode auto", + "switchport trunk mode on", + "shutdown", + "no analytics type fc-all", + "interface fc1/1", + "no switchport description", + "no switchport speed auto", + "no switchport mode auto", + "switchport trunk mode on", + "shutdown", + "analytics type fc-nvme", + ], + ) + + def test_analytics_none_to_all(self): + args = dict( + config=[ + { + "name": "fc1/1", + "analytics": "fc-all", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], ["interface fc1/1", "analytics type fc-all"]) + + def test_analytics_none_to_all_replaced(self): + args = dict( + config=[ + { + "name": "fc1/1", + "analytics": "fc-all", + }, + ], + state="replaced", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + [ + "interface fc1/1", + "no switchport description", + "no switchport speed auto", + "no switchport mode auto", + "switchport trunk mode on", + "shutdown", + "analytics type fc-all", + ], + ) + + def test_analytics_nvme_to_none_checkthis(self): + args = dict( + config=[ + { + "name": "fc18/10", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=False) + self.assertEqual(result["commands"], []) + + def test_description_change_from_one_to_another(self): + args = dict( + config=[ + { + "name": "fc18/9", + "description": "changed from sample description to new description", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + [ + "interface fc18/9", + "switchport description changed from sample description to new description", + ], + ) + + def test_description_change_from_none_to_new(self): + args = dict( + config=[ + { + "name": "fc18/8", + "description": "new sample description", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + [ + "interface fc18/8", + "switchport description new sample description", + ], + ) + + def test_shut_to_noshut(self): + args = dict( + config=[ + { + "name": "fc18/10", + "enabled": True, + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + [ + "interface fc18/10", + "no shutdown", + ], + ) + + def test_noshut_to_shut(self): + args = dict( + config=[ + { + "name": "fc18/6", + "enabled": False, + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + ["interface fc18/6", "shutdown"], + ) + + def test_trunkmode_auto_to_off(self): + args = dict( + config=[ + { + "name": "fc18/1", + "trunk_mode": "off", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + ["interface fc18/1", "switchport trunk mode off"], + ) + + def test_trunkmode_auto_to_on(self): + args = dict( + config=[ + { + "name": "fc18/1", + "trunk_mode": "on", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + ["interface fc18/1", "switchport trunk mode on"], + ) + + def test_trunkmode_on_to_off(self): + args = dict( + config=[ + { + "name": "fc1/1", + "trunk_mode": "off", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + ["interface fc1/1", "switchport trunk mode off"], + ) + + def test_trunkmode_on_to_auto(self): + args = dict( + config=[ + { + "name": "fc1/1", + "trunk_mode": "auto", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + ["interface fc1/1", "switchport trunk mode auto"], + ) + + def test_trunkmode_off_to_on(self): + args = dict( + config=[ + { + "name": "fc1/2", + "trunk_mode": "on", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + ["interface fc1/2", "switchport trunk mode on"], + ) + + def test_trunkmode_off_to_auto(self): + args = dict( + config=[ + { + "name": "fc1/2", + "trunk_mode": "auto", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + ["interface fc1/2", "switchport trunk mode auto"], + ) + + def test_speed_combinations(self): + port_speed = "auto" + port_name = "fc1/1" + for each_speed in allowed_speed_values: + args = dict( + config=[ + { + "name": port_name, + "speed": each_speed, + }, + ], + state="merged", + ) + if each_speed == port_speed: + changed = False + cmds = [] + else: + changed = True + cmds = [f"interface {port_name}", f"switchport speed {each_speed}"] + + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=changed) + self.assertEqual( + result["commands"], + cmds, + ) + + def test_port_mode_combinations(self): + port_mode = "auto" + port_name = "fc1/1" + for each_mode in allowed_port_modes: + args = dict( + config=[ + { + "name": port_name, + "mode": each_mode, + }, + ], + state="merged", + ) + if each_mode == port_mode: + changed = False + cmds = [] + else: + changed = True + cmds = [f"interface {port_name}", f"switchport mode {each_mode}"] + + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=changed) + self.assertEqual( + result["commands"], + cmds, + ) + + def test_deleted_1(self): + # before- trunk mode on + args = dict( + config=[ + { + "name": "fc1/2", + }, + ], + state="deleted", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + [ + "interface fc1/2", + "no switchport speed 1000", + "no switchport mode E", + "switchport trunk mode on", + "shutdown", + ], + ) + + def test_deleted_2(self): + # before- trunk mode off + args = dict( + config=[ + { + "name": "fc1/3", + }, + ], + state="deleted", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + [ + "interface fc1/3", + "no switchport speed 2000", + "no switchport mode F", + "switchport trunk mode on", + "shutdown", + ], + ) + + def test_deleted_3(self): + # before- port shut and with description and analytics config + args = dict( + config=[ + { + "name": "fc18/10", + }, + ], + state="deleted", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + [ + "interface fc18/10", + "no switchport description", + "no switchport speed auto max 16000", + "no switchport mode auto", + "switchport trunk mode on", + "no analytics type fc-all", + ], + ) + + def test_replaced_move_to_def(self): + args = dict( + config=[ + { + "name": "fc18/10", + }, + ], + state="replaced", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + [ + "interface fc18/10", + "no switchport description", + "no switchport speed auto max 16000", + "no switchport mode auto", + "switchport trunk mode on", + "shutdown", + "no analytics type fc-all", + ], + ) + + def test_deleted_combined(self): + args = dict( + config=[ + { + "name": "fc1/2", + }, + { + "name": "fc1/3", + }, + { + "name": "fc18/10", + }, + ], + state="deleted", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + [ + "interface fc1/2", + "no switchport speed 1000", + "no switchport mode E", + "switchport trunk mode on", + "shutdown", + "interface fc1/3", + "no switchport speed 2000", + "no switchport mode F", + "switchport trunk mode on", + "shutdown", + "interface fc18/10", + "no switchport description", + "no switchport speed auto max 16000", + "no switchport mode auto", + "switchport trunk mode on", + "no analytics type fc-all", + ], + ) + + def test_most_of_them_combined(self): + args = dict( + config=[ + { + "name": "fc18/13", + "speed": "auto max 64000", + "mode": "auto", + "trunk_mode": "on", + "enabled": True, + "description": "1", + "analytics": "fc-all", + }, + { + "name": "fc18/12", + "speed": "auto max 64000", + "mode": "auto", + "trunk_mode": "on", + "enabled": True, + "description": "1", + "analytics": "fc-scsi", + }, + { + "name": "fc18/11", + "speed": "auto max 32000", + "mode": "auto", + "trunk_mode": "on", + "enabled": False, + "description": "a", + "analytics": "fc-all", + }, + { + "name": "fc18/10", + "analytics": "fc-scsi", + "enabled": True, + }, + { + "name": "fc18/9", + "description": "changed from sample description to new description", + }, + { + "name": "fc18/8", + "description": "new sample description", + }, + { + "name": "fc18/6", + "enabled": False, + }, + { + "name": "fc18/1", + "trunk_mode": "off", + }, + { + "name": "fc1/1", + "trunk_mode": "auto", + "analytics": "fc-all", + }, + { + "name": "fc1/2", + "trunk_mode": "on", + }, + ], + state="merged", + ) + set_module_args(args, ignore_provider_arg) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + [ + "interface fc1/1", + "switchport trunk mode auto", + "analytics type fc-all", + ] + + [ + "interface fc1/2", + "switchport trunk mode on", + ] + + [ + "interface fc18/1", + "switchport trunk mode off", + ] + + [ + "interface fc18/6", + "shutdown", + ] + + [ + "interface fc18/8", + "switchport description new sample description", + ] + + [ + "interface fc18/9", + "switchport description changed from sample description to new description", + ] + + [ + "interface fc18/10", + "no shutdown", + # "no analytics type fc-all", + "analytics type fc-scsi", + ] + + [ + "interface fc18/11", + "analytics type fc-all", + ], + # + [ + # "interface fc18/12", + # # "no analytics type fc-all", + # "analytics type fc-scsi", + # ], + ) diff --git a/tests/unit/modules/network/nxos/test_nxos_feature.py b/tests/unit/modules/network/nxos/test_nxos_feature.py index cd80ece51..1c79537f1 100644 --- a/tests/unit/modules/network/nxos/test_nxos_feature.py +++ b/tests/unit/modules/network/nxos/test_nxos_feature.py @@ -19,38 +19,39 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type import json -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from ansible_collections.cisco.nxos.plugins.modules import nxos_feature +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from .nxos_module import TestNxosModule, load_fixture, set_module_args class TestNxosFeatureModule(TestNxosModule): - module = nxos_feature def setUp(self): super(TestNxosFeatureModule, self).setUp() self.mock_run_commands = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_feature.run_commands" + "ansible_collections.cisco.nxos.plugins.modules.nxos_feature.run_commands", ) self.run_commands = self.mock_run_commands.start() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_feature.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_feature.load_config", ) self.load_config = self.mock_load_config.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_feature.get_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_feature.get_config", ) self.get_config = self.mock_get_config.start() self.mock_get_capabilities = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_feature.get_capabilities" + "ansible_collections.cisco.nxos.plugins.modules.nxos_feature.get_capabilities", ) self.get_capabilities = self.mock_get_capabilities.start() self.get_capabilities.return_value = {"network_api": "cliconf"} @@ -84,41 +85,36 @@ def load_from_file(*args, **kwargs): def test_nxos_feature_enable(self): set_module_args(dict(feature="nve", state="enabled")) result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], ["terminal dont-ask", "feature nv overlay"] - ) + self.assertEqual(result["commands"], ["terminal dont-ask", "feature nv overlay"]) def test_nxos_feature_disable(self): set_module_args(dict(feature="ospf", state="disabled")) result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], ["terminal dont-ask", "no feature ospf"] - ) + self.assertEqual(result["commands"], ["terminal dont-ask", "no feature ospf"]) class TestNxosFeatureModuleMDS(TestNxosModule): - module = nxos_feature def setUp(self): super(TestNxosFeatureModuleMDS, self).setUp() self.mock_run_commands = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_feature.run_commands" + "ansible_collections.cisco.nxos.plugins.modules.nxos_feature.run_commands", ) self.run_commands = self.mock_run_commands.start() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_feature.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_feature.load_config", ) self.load_config = self.mock_load_config.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_feature.get_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_feature.get_config", ) self.get_config = self.mock_get_config.start() self.mock_get_capabilities = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_feature.get_capabilities" + "ansible_collections.cisco.nxos.plugins.modules.nxos_feature.get_capabilities", ) self.get_capabilities = self.mock_get_capabilities.start() self.get_capabilities.return_value = { @@ -158,16 +154,12 @@ def load_from_file(*args, **kwargs): def test_nxos_feature_enable(self): set_module_args(dict(feature="fcrxbbcredit", state="enabled")) result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], ["terminal dont-ask", "feature fcrxbbcredit"] - ) + self.assertEqual(result["commands"], ["terminal dont-ask", "feature fcrxbbcredit"]) def test_nxos_feature_disable(self): set_module_args(dict(feature="port-track", state="disabled")) result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], ["terminal dont-ask", "no feature port-track"] - ) + self.assertEqual(result["commands"], ["terminal dont-ask", "no feature port-track"]) def test_nxos_feature_enable_already_enabled(self): set_module_args(dict(feature="analytics", state="enabled")) diff --git a/tests/unit/modules/network/nxos/test_nxos_hostname.py b/tests/unit/modules/network/nxos/test_nxos_hostname.py index e5810d7af..732f59e7a 100644 --- a/tests/unit/modules/network/nxos/test_nxos_hostname.py +++ b/tests/unit/modules/network/nxos/test_nxos_hostname.py @@ -18,35 +18,34 @@ # Make coding more python3-ish from __future__ import absolute_import, division, print_function -from typing import Sequence + __metaclass__ = type from textwrap import dedent -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from ansible_collections.cisco.nxos.plugins.modules import nxos_hostname +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from .nxos_module import TestNxosModule, set_module_args + ignore_provider_arg = True class TestNxosHostnameModule(TestNxosModule): - module = nxos_hostname def setUp(self): super(TestNxosHostnameModule, self).setUp() self.mock_get_resource_connection = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" - ) - self.get_resource_connection = ( - self.mock_get_resource_connection.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", ) + self.get_resource_connection = self.mock_get_resource_connection.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.hostname.hostname.HostnameFacts.get_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.hostname.hostname.HostnameFacts.get_config", ) self.get_config = self.mock_get_config.start() @@ -59,7 +58,7 @@ def test_nxos_hostname_merged(self): # test merged for linear attributes self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args( dict(config=dict(hostname="NXOSv-9k"), state="merged"), @@ -74,7 +73,7 @@ def test_nxos_hostname_linear_merged_idempotent(self): self.get_config.return_value = dedent( """\ hostname NXOSv-9k - """ + """, ) set_module_args( dict(config=dict(hostname="NXOSv-9k"), state="merged"), @@ -88,7 +87,7 @@ def test_nxos_hostname_linear_merged_2(self): self.get_config.return_value = dedent( """\ hostname NXOSv-9k - """ + """, ) set_module_args( dict(config=dict(hostname="NXOSv"), state="merged"), @@ -103,7 +102,7 @@ def test_nxos_hostname_linear_replaced(self): self.get_config.return_value = dedent( """\ hostname NXOSv-9k - """ + """, ) set_module_args( dict(config=dict(hostname="NXOSv"), state="replaced"), @@ -118,7 +117,7 @@ def test_nxos_hostname_linear_overridden(self): self.get_config.return_value = dedent( """\ hostname NXOSv-9k - """ + """, ) set_module_args( dict(config=dict(hostname="NXOSv"), state="overridden"), @@ -132,7 +131,7 @@ def test_nxos_hostname_deleted(self): self.get_config.return_value = dedent( """\ hostname NXOSv-9k - """ + """, ) set_module_args(dict(state="deleted"), ignore_provider_arg) commands = ["no hostname NXOSv-9k"] @@ -153,11 +152,9 @@ def test_nxos_hostname_parsed(self): cfg = dedent( """\ hostname NXOSv-9k - """ - ) - set_module_args( - dict(running_config=cfg, state="parsed"), ignore_provider_arg + """, ) + set_module_args(dict(running_config=cfg, state="parsed"), ignore_provider_arg) parsed = {"hostname": "NXOSv-9k"} result = self.execute_module(changed=False) self.assertEqual(result["parsed"], parsed) @@ -167,7 +164,7 @@ def test_nxos_hostname_gathered(self): self.get_config.return_value = dedent( """\ hostname NXOSv-9k - """ + """, ) set_module_args(dict(state="gathered"), ignore_provider_arg) gathered = {"hostname": "NXOSv-9k"} diff --git a/tests/unit/modules/network/nxos/test_nxos_hsrp.py b/tests/unit/modules/network/nxos/test_nxos_hsrp.py index 3c125c857..4ffcc43f3 100644 --- a/tests/unit/modules/network/nxos/test_nxos_hsrp.py +++ b/tests/unit/modules/network/nxos/test_nxos_hsrp.py @@ -19,31 +19,32 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from ansible_collections.cisco.nxos.plugins.modules import nxos_hsrp +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from .nxos_module import TestNxosModule, set_module_args class TestNxosHsrpModule(TestNxosModule): - module = nxos_hsrp def setUp(self): super(TestNxosHsrpModule, self).setUp() self.mock_run_commands = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_hsrp.run_commands" + "ansible_collections.cisco.nxos.plugins.modules.nxos_hsrp.run_commands", ) self.run_commands = self.mock_run_commands.start() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_hsrp.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_hsrp.load_config", ) self.load_config = self.mock_load_config.start() self.mock_get_capabilities = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_hsrp.get_capabilities" + "ansible_collections.cisco.nxos.plugins.modules.nxos_hsrp.get_capabilities", ) self.get_capabilities = self.mock_get_capabilities.start() self.get_capabilities.return_value = {"network_api": "cliconf"} @@ -65,7 +66,7 @@ def test_nxos_hsrp(self): priority="150", interface="Ethernet1/2", preempt="enabled", - ) + ), ) result = self.execute_module(changed=True) self.assertEqual( @@ -79,6 +80,6 @@ def test_nxos_hsrp(self): "priority 150", "ip 192.0.2.2/8", "preempt", - ] + ], ), ) diff --git a/tests/unit/modules/network/nxos/test_nxos_hsrp_interfaces.py b/tests/unit/modules/network/nxos/test_nxos_hsrp_interfaces.py index 2af403c68..e4f21a825 100644 --- a/tests/unit/modules/network/nxos/test_nxos_hsrp_interfaces.py +++ b/tests/unit/modules/network/nxos/test_nxos_hsrp_interfaces.py @@ -19,50 +19,43 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type from textwrap import dedent -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - AnsibleFailJson, -) + from ansible_collections.cisco.nxos.plugins.modules import nxos_hsrp_interfaces -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.hsrp_interfaces.hsrp_interfaces import ( - Hsrp_interfaces, -) -from .nxos_module import TestNxosModule, load_fixture, set_module_args +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + +from .nxos_module import TestNxosModule, set_module_args + ignore_provider_arg = True class TestNxosHsrpInterfacesModule(TestNxosModule): - module = nxos_hsrp_interfaces def setUp(self): super(TestNxosHsrpInterfacesModule, self).setUp() self.mock_FACT_LEGACY_SUBSETS = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts.FACT_LEGACY_SUBSETS" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts.FACT_LEGACY_SUBSETS", ) self.FACT_LEGACY_SUBSETS = self.mock_FACT_LEGACY_SUBSETS.start() self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection" - ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection", ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" - ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection", ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_edit_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.hsrp_interfaces.hsrp_interfaces.Hsrp_interfaces.edit_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.hsrp_interfaces.hsrp_interfaces.Hsrp_interfaces.edit_config", ) self.edit_config = self.mock_edit_config.start() @@ -102,16 +95,14 @@ def test_1(self): interface Ethernet1/1 interface Ethernet1/2 interface Ethernet1/3 - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} playbook = dict( config=[ dict(name="Ethernet1/1", bfd="enable"), dict(name="Ethernet1/2", bfd="disable"), - ] + ], ) # Expected result commands for each 'state' merged = ["interface Ethernet1/1", "hsrp bfd"] @@ -145,18 +136,16 @@ def test_2(self): hsrp bfd interface Ethernet1/3 hsrp bfd - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} playbook = dict( config=[ dict(name="Ethernet1/1", bfd="disable"), dict(name="Ethernet1/2"), # Eth1/3 not present! Thus overridden should set Eth1/3 to defaults; # replaced should ignore Eth1/3. - ] + ], ) # Expected result commands for each 'state' merged = ["interface Ethernet1/1", "no hsrp bfd"] @@ -207,14 +196,10 @@ def test_3(self): hsrp bfd interface Ethernet1/3 hsrp bfd - """ - ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } - playbook = dict( - config=[dict(name="Ethernet1/1"), dict(name="Ethernet1/2")] + """, ) + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} + playbook = dict(config=[dict(name="Ethernet1/1"), dict(name="Ethernet1/2")]) # Expected result commands for each 'state' merged = [] deleted = [ @@ -262,11 +247,9 @@ def test_4(self): hsrp bfd interface Ethernet1/2 hsrp bfd - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} playbook = dict(config=[dict(name="Ethernet1/1.42", bfd="enable")]) # Expected result commands for each 'state' merged = ["interface Ethernet1/1.42", "hsrp bfd"] @@ -304,16 +287,14 @@ def test_5(self): interface Ethernet1/1 hsrp bfd interface Ethernet1/2 - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} playbook = dict( config=[ dict(name="Ethernet1/1", bfd="enable"), dict(name="Ethernet1/2", bfd="disable"), - ] + ], ) # Expected result commands for each 'state' merged = [] diff --git a/tests/unit/modules/network/nxos/test_nxos_interface.py b/tests/unit/modules/network/nxos/test_nxos_interface.py deleted file mode 100644 index d1b83a3c1..000000000 --- a/tests/unit/modules/network/nxos/test_nxos_interface.py +++ /dev/null @@ -1,116 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# Make coding more python3-ish - -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.plugins.modules import nxos_interface -from .nxos_module import TestNxosModule, load_fixture, set_module_args - - -class TestNxosInterfaceModule(TestNxosModule): - - module = nxos_interface - - def setUp(self): - super(TestNxosInterfaceModule, self).setUp() - self.mock_run_commands = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_interface.run_commands" - ) - self.run_commands = self.mock_run_commands.start() - - self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_interface.load_config" - ) - self.load_config = self.mock_load_config.start() - - def tearDown(self): - super(TestNxosInterfaceModule, self).tearDown() - self.mock_run_commands.stop() - self.mock_load_config.stop() - - def load_fixtures(self, commands=None, device=""): - module_name = self.module.__name__.rsplit(".", 1)[1] - - def load_from_file(*args, **kwargs): - module, commands = args - output = list() - - for command in commands: - if type(command) == dict: - command = command["command"] - filename = ( - str(command) - .split(" | ", 1)[0] - .replace(" ", "_") - .replace("/", "_") - ) - print(filename) - output.append(load_fixture(module_name, filename)) - return output - - self.load_config.return_value = None - self.run_commands.side_effect = load_from_file - - def test_nxos_interface_up(self): - set_module_args(dict(interface="loopback0")) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], ["interface loopback0", "no shutdown"] - ) - - def test_nxos_interface_down(self): - set_module_args(dict(interface="loopback0", admin_state="down")) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], ["interface loopback0", "shutdown"] - ) - - def test_nxos_interface_delete(self): - set_module_args(dict(interface="loopback0", state="absent")) - result = self.execute_module(changed=False) - self.assertEqual(result["commands"], []) - - def test_nxos_interface_type(self): - set_module_args(dict(interface_type="loopback", state="absent")) - result = self.execute_module(changed=True) - self.assertEqual(result["commands"], ["no interface loopback0"]) - - def test_nxos_interface_mtu(self): - set_module_args( - dict(interface="Ethernet2/1", mode="layer2", mtu="1800") - ) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], - [ - "interface Ethernet2/1", - "switchport", - "mtu 1800", - "interface Ethernet2/1", - "no shutdown", - ], - ) - - def test_nxos_interface_speed_idempotence(self): - set_module_args(dict(interface="Ethernet2/1", speed="1000")) - result = self.execute_module(changed=False) - self.assertEqual(result["commands"], []) diff --git a/tests/unit/modules/network/nxos/test_nxos_interface_ospf.py b/tests/unit/modules/network/nxos/test_nxos_interface_ospf.py deleted file mode 100644 index b1fa11572..000000000 --- a/tests/unit/modules/network/nxos/test_nxos_interface_ospf.py +++ /dev/null @@ -1,296 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# Make coding more python3-ish - -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.plugins.modules import nxos_interface_ospf -from .nxos_module import TestNxosModule, load_fixture, set_module_args - - -class TestNxosInterfaceOspfModule(TestNxosModule): - - module = nxos_interface_ospf - - def setUp(self): - super(TestNxosInterfaceOspfModule, self).setUp() - - self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_interface_ospf.get_config" - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_interface_ospf.load_config" - ) - self.load_config = self.mock_load_config.start() - - def tearDown(self): - super(TestNxosInterfaceOspfModule, self).tearDown() - self.mock_get_config.stop() - self.mock_load_config.stop() - - def load_fixtures(self, commands=None, device=""): - module_name = self.module.__name__.rsplit(".", 1)[1] - self.get_config.return_value = load_fixture(module_name, "config.cfg") - self.load_config.return_value = None - - def test_nxos_interface_ospf(self): - set_module_args(dict(interface="ethernet1/32", ospf=1, area=1)) - self.execute_module( - changed=True, - commands=[ - "interface Ethernet1/32", - "ip router ospf 1 area 0.0.0.1", - ], - ) - - def test_bfd_1(self): - # default -> enable - set_module_args( - dict(interface="ethernet1/33", ospf=1, area=1, bfd="enable") - ) - self.execute_module( - changed=True, - commands=[ - "interface Ethernet1/33", - "ip router ospf 1 area 0.0.0.1", - "ip ospf bfd", - ], - ) - - # default -> disable - set_module_args( - dict(interface="ethernet1/33", ospf=1, area=1, bfd="disable") - ) - self.execute_module( - changed=True, - commands=[ - "interface Ethernet1/33", - "ip router ospf 1 area 0.0.0.1", - "ip ospf bfd disable", - ], - ) - - def test_bfd_2(self): - # default -> default - set_module_args( - dict(interface="ethernet1/33.101", ospf=1, area=1, bfd="default") - ) - self.execute_module(changed=False) - - # enable -> default - set_module_args( - dict(interface="ethernet1/36", ospf=1, area=1, bfd="default") - ) - self.execute_module( - changed=True, commands=["interface Ethernet1/36", "no ip ospf bfd"] - ) - - # disable -> default - set_module_args( - dict(interface="ethernet1/37", ospf=1, area=1, bfd="default") - ) - self.execute_module( - changed=True, commands=["interface Ethernet1/37", "no ip ospf bfd"] - ) - - def test_bfd_3(self): - # enable -> idempotence - set_module_args( - dict(interface="ethernet1/36", ospf=1, area=1, bfd="enable") - ) - self.execute_module(changed=False) - - # disable -> idempotence - set_module_args( - dict(interface="ethernet1/37", ospf=1, area=1, bfd="disable") - ) - self.execute_module(changed=False) - - def test_bfd_4(self): - # None -> absent - set_module_args( - dict(interface="ethernet1/33.101", ospf=1, area=1, state="absent") - ) - self.execute_module( - changed=True, - commands=[ - "interface Ethernet1/33.101", - "no ip router ospf 1 area 0.0.0.1", - ], - ) - - # enable -> absent - set_module_args( - dict( - interface="ethernet1/36", - ospf=1, - area=1, - bfd="enable", - state="absent", - ) - ) - self.execute_module( - changed=True, - commands=[ - "interface Ethernet1/36", - "no ip router ospf 1 area 0.0.0.1", - "no ip ospf bfd", - ], - ) - - # disable -> absent - set_module_args( - dict( - interface="ethernet1/37", - ospf=1, - area=1, - bfd="disable", - state="absent", - ) - ) - self.execute_module( - changed=True, - commands=[ - "interface Ethernet1/37", - "no ip router ospf 1 area 0.0.0.1", - "no ip ospf bfd", - ], - ) - - def test_absent_1(self): - # area only -> absent - set_module_args( - dict(interface="ethernet1/33.101", ospf=1, area=1, state="absent") - ) - self.execute_module( - changed=True, - commands=[ - "interface Ethernet1/33.101", - "no ip router ospf 1 area 0.0.0.1", - ], - ) - - # None -> absent - set_module_args( - dict(interface="ethernet1/33", ospf=1, area=1, state="absent") - ) - self.execute_module(changed=False) - - def test_loopback_interface_failed(self): - set_module_args( - dict(interface="loopback0", ospf=1, area=0, passive_interface=True) - ) - self.execute_module(failed=True, changed=False) - set_module_args( - dict(interface="loopback0", ospf=1, area=0, network="broadcast") - ) - self.execute_module(failed=True, changed=False) - - def test_nxos_interface_ospf_passive(self): - # default -> True - set_module_args( - dict( - interface="ethernet1/33", - ospf=1, - area=1, - passive_interface=True, - ) - ) - self.execute_module( - changed=True, - commands=[ - "interface Ethernet1/33", - "ip router ospf 1 area 0.0.0.1", - "ip ospf passive-interface", - ], - ) - # default -> False - set_module_args( - dict( - interface="ethernet1/33", - ospf=1, - area=1, - passive_interface=False, - ) - ) - self.execute_module( - changed=True, - commands=[ - "interface Ethernet1/33", - "ip router ospf 1 area 0.0.0.1", - "no ip ospf passive-interface", - ], - ) - # True -> False - set_module_args( - dict( - interface="ethernet1/34", - ospf=1, - area=1, - passive_interface=False, - ) - ) - self.execute_module( - changed=True, - commands=[ - "interface Ethernet1/34", - "no ip ospf passive-interface", - ], - ) - # True -> default (absent) - set_module_args( - dict(interface="ethernet1/34", ospf=1, area=1, state="absent") - ) - self.execute_module( - changed=True, - commands=[ - "interface Ethernet1/34", - "no ip router ospf 1 area 0.0.0.1", - "default ip ospf passive-interface", - ], - ) - # False -> True - set_module_args( - dict( - interface="ethernet1/35", - ospf=1, - area=1, - passive_interface=True, - ) - ) - self.execute_module( - changed=True, - commands=["interface Ethernet1/35", "ip ospf passive-interface"], - ) - # False -> default (absent) - set_module_args( - dict(interface="ethernet1/35", ospf=1, area=1, state="absent") - ) - self.execute_module( - changed=True, - commands=[ - "interface Ethernet1/35", - "no ip router ospf 1 area 0.0.0.1", - "default ip ospf passive-interface", - ], - ) diff --git a/tests/unit/modules/network/nxos/test_nxos_interfaces.py b/tests/unit/modules/network/nxos/test_nxos_interfaces.py index 08b49e955..a1d491af1 100644 --- a/tests/unit/modules/network/nxos/test_nxos_interfaces.py +++ b/tests/unit/modules/network/nxos/test_nxos_interfaces.py @@ -19,63 +19,53 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type from textwrap import dedent -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - AnsibleFailJson, -) + from ansible_collections.cisco.nxos.plugins.modules import nxos_interfaces -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.interfaces.interfaces import ( - Interfaces, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.interfaces.interfaces import ( - InterfacesFacts, -) -from .nxos_module import TestNxosModule, load_fixture, set_module_args +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + +from .nxos_module import TestNxosModule, set_module_args + ignore_provider_arg = True class TestNxosInterfacesModule(TestNxosModule): - module = nxos_interfaces def setUp(self): super(TestNxosInterfacesModule, self).setUp() self.mock_FACT_LEGACY_SUBSETS = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts.FACT_LEGACY_SUBSETS" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts.FACT_LEGACY_SUBSETS", ) self.FACT_LEGACY_SUBSETS = self.mock_FACT_LEGACY_SUBSETS.start() self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection" - ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection", ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" - ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection", ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_edit_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.interfaces.interfaces.Interfaces.edit_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.interfaces.interfaces.Interfaces.edit_config", ) self.edit_config = self.mock_edit_config.start() self.mock_get_system_defaults = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.interfaces.interfaces.Interfaces.get_system_defaults" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.interfaces.interfaces.Interfaces.get_system_defaults", ) self.get_system_defaults = self.mock_get_system_defaults.start() self.mock_get_platform = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.interfaces.interfaces.Interfaces.get_platform" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.interfaces.interfaces.Interfaces.get_platform", ) self.get_platform = self.mock_get_platform.start() @@ -94,7 +84,7 @@ def load_fixtures(self, commands=None, device=""): self.edit_config.return_value = None if device == "legacy": # call execute_module() with device='legacy' to use this codepath - self.get_platform.return_value = "N3K-Cxxx" + self.get_platform.return_value = "N5K-Cxxx" else: self.get_platform.return_value = "N9K-Cxxx" @@ -109,7 +99,7 @@ def test_1(self): ! no system default switchport no system default switchport shutdown - """ + """, ) intf = dedent( """\ @@ -131,11 +121,9 @@ def test_1(self): no shutdown interface loopback0 description test-loopback - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_RUN_INTF: intf - } + self.get_resource_connection_facts.return_value = {self.SHOW_RUN_INTF: intf} self.get_system_defaults.return_value = sysdefs playbook = dict( @@ -158,7 +146,7 @@ def test_1(self): dict(name="Ethernet1/4", mode="layer2"), dict(name="Ethernet1/5"), dict(name="loopback1", description="test-loopback"), - ] + ], ) merged = [ # Update existing device states with any differences in the playbook. @@ -270,7 +258,7 @@ def test_2(self): ! no system default switchport no system default switchport shutdown - """ + """, ) intf = dedent( """\ @@ -291,11 +279,9 @@ def test_2(self): interface port-channel2 interface port-channel3 shutdown - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_RUN_INTF: intf - } + self.get_resource_connection_facts.return_value = {self.SHOW_RUN_INTF: intf} self.get_system_defaults.return_value = sysdefs playbook = dict( @@ -310,11 +296,10 @@ def test_2(self): dict(name="Ethernet1/3", enabled=True), dict(name="loopback3", enabled=True), dict(name="port-channel3", enabled=True), - # Set default state on non-existent objs; no state changes but need to create intf dict(name="loopback4", enabled=True), dict(name="port-channel4", enabled=True), dict(name="Ethernet1/4.101"), - ] + ], ) # Testing with newer code version merged = [ @@ -329,7 +314,9 @@ def test_2(self): "interface port-channel3", "no shutdown", "interface loopback4", + "no shutdown", "interface port-channel4", + "no shutdown", "interface Ethernet1/4.101", ] playbook["state"] = "merged" @@ -367,7 +354,9 @@ def test_2(self): "interface port-channel3", "no shutdown", "interface loopback4", + "no shutdown", "interface port-channel4", + "no shutdown", "interface Ethernet1/4.101", ] playbook["state"] = "replaced" @@ -392,7 +381,9 @@ def test_2(self): "interface loopback1", "shutdown", "interface loopback4", + "no shutdown", "interface port-channel4", + "no shutdown", "interface Ethernet1/4.101", ] playbook["state"] = "overridden" @@ -409,7 +400,7 @@ def test_3(self): ! system default switchport system default switchport shutdown - """ + """, ) intf = dedent( """\ @@ -430,11 +421,9 @@ def test_3(self): interface port-channel2 interface port-channel3 shutdown - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_RUN_INTF: intf - } + self.get_resource_connection_facts.return_value = {self.SHOW_RUN_INTF: intf} self.get_system_defaults.return_value = sysdefs playbook = dict( @@ -453,7 +442,7 @@ def test_3(self): dict(name="loopback4", enabled=True), dict(name="port-channel4", enabled=True), dict(name="Ethernet1/4.101"), - ] + ], ) merged = [ "interface Ethernet1/1", @@ -468,7 +457,9 @@ def test_3(self): "interface port-channel3", "no shutdown", "interface loopback4", + "no shutdown", "interface port-channel4", + "no shutdown", "interface Ethernet1/4.101", ] playbook["state"] = "merged" @@ -490,12 +481,12 @@ def test_3(self): "interface port-channel3", "no shutdown", "interface loopback4", + "no shutdown", "interface port-channel4", + "no shutdown", "interface Ethernet1/4.101", ] - self.execute_module( - changed=True, commands=merged_legacy, device="legacy" - ) + self.execute_module(changed=True, commands=merged_legacy, device="legacy") deleted = [ "interface Ethernet1/2", @@ -528,13 +519,35 @@ def test_3(self): "interface port-channel3", "no shutdown", "interface loopback4", + "no shutdown", "interface port-channel4", + "no shutdown", "interface Ethernet1/4.101", ] playbook["state"] = "replaced" set_module_args(playbook, ignore_provider_arg) self.execute_module(changed=True, commands=replaced) + playbook = dict( + config=[ + # Set non-default states on existing objs + dict(name="Ethernet1/1", mode="layer3", enabled=True), + dict(name="loopback1", enabled=False), + # Set default states on existing objs + dict(name="Ethernet1/2", enabled=False), + dict(name="loopback2", enabled=True), + # Set explicit default state on existing objs (no chg) + dict(name="Ethernet1/3", enabled=False), + dict(name="loopback3", enabled=True), + dict(name="port-channel3", enabled=True), + # Set default state on non-existent objs; no state changes but need to create intf + dict(name="loopback4", enabled=True), + dict(name="port-channel4", enabled=True), + dict(name="Ethernet1/4.101", enabled=False), + dict(name="Ethernet1/4.102", enabled=True), + ], + ) + overridden = [ "interface Ethernet1/2", "switchport", @@ -553,8 +566,12 @@ def test_3(self): "interface loopback1", "shutdown", "interface loopback4", + "no shutdown", "interface port-channel4", + "no shutdown", "interface Ethernet1/4.101", + "interface Ethernet1/4.102", + "no shutdown", ] playbook["state"] = "overridden" set_module_args(playbook, ignore_provider_arg) @@ -569,7 +586,7 @@ def test_4(self): ! no system default switchport no system default switchport shutdown - """ + """, ) intf = dedent( """\ @@ -578,18 +595,16 @@ def test_4(self): switchport speed 1000 shutdown - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_RUN_INTF: intf - } + self.get_resource_connection_facts.return_value = {self.SHOW_RUN_INTF: intf} self.get_system_defaults.return_value = sysdefs playbook = dict( config=[ dict(name="Ethernet1/1", mode="layer3"), dict(name="Ethernet1/2", mode="layer2", enabled=False), - ] + ], ) merged = [] playbook["state"] = "merged" @@ -605,7 +620,7 @@ def test_5(self): ! no system default switchport no system default switchport shutdown - """ + """, ) intf = dedent( """\ @@ -614,11 +629,9 @@ def test_5(self): interface Ethernet1/2 speed 1000 no shutdown - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_RUN_INTF: intf - } + self.get_resource_connection_facts.return_value = {self.SHOW_RUN_INTF: intf} self.get_system_defaults.return_value = sysdefs playbook = dict() @@ -642,7 +655,7 @@ def test_6_gathered(self): ! no system default switchport no system default switchport shutdown - """ + """, ) intf = dedent( """\ @@ -656,11 +669,9 @@ def test_6_gathered(self): speed 1000 no shutdown interface loopback1 - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_RUN_INTF: intf - } + self.get_resource_connection_facts.return_value = {self.SHOW_RUN_INTF: intf} self.get_system_defaults.return_value = sysdefs playbook = dict() @@ -686,7 +697,7 @@ def test_7_purged(self): """\ no system default switchport no system default switchport shutdown - """ + """, ) intf = dedent( """\ @@ -699,11 +710,9 @@ def test_7_purged(self): interface Ethernet1/2 interface Ethernet1/2.100 description sub-intf - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_RUN_INTF: intf - } + self.get_resource_connection_facts.return_value = {self.SHOW_RUN_INTF: intf} self.get_system_defaults.return_value = sysdefs playbook = dict( @@ -711,7 +720,7 @@ def test_7_purged(self): dict(name="Vlan42"), dict(name="port-channel10"), dict(name="Ethernet1/2.100"), - ] + ], ) playbook["state"] = "purged" @@ -724,3 +733,88 @@ def test_7_purged(self): set_module_args(playbook, ignore_provider_arg) result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_vlan_enabled(self): + sysdefs = dedent( + """\ + ! + ! Interfaces default to L3 !! + ! + no system default switchport + no system default switchport shutdown + """, + ) + intf = dedent( + """\ + interface Vlan9 + no shutdown + interface Vlan10 + """, + ) + self.get_resource_connection_facts.return_value = {self.SHOW_RUN_INTF: intf} + self.get_system_defaults.return_value = sysdefs + + playbook = dict( + config=[ + dict(name="Vlan9", enabled=False), + dict(name="Vlan10", enabled=True), + dict(name="Vlan11", enabled=True), + ], + ) + merged = [ + "interface Vlan9", + "shutdown", + "interface Vlan10", + "no shutdown", + "interface Vlan11", + "no shutdown", + ] + playbook["state"] = "merged" + set_module_args(playbook, ignore_provider_arg) + self.execute_module(changed=True, commands=merged) + + def test_mode_mtu(self): + # test mode change with MTU + sysdefs = dedent( + """\ + ! + ! Interfaces default to L3 !! + ! + no system default switchport + """, + ) + intf = dedent( + """\ + interface Ethernet1/28 + description Auto_Cable_Testing + mtu 9216 + """, + ) + self.get_resource_connection_facts.return_value = {self.SHOW_RUN_INTF: intf} + self.get_system_defaults.return_value = sysdefs + + playbook = dict( + config=[ + dict( + name="Ethernet1/28", + description="Ansible Port Turn Up1", + mode="layer2", + mtu="9216", + speed="1000", + duplex="full", + enabled=True, + ), + ], + ) + replaced = [ + "interface Ethernet1/28", + "description Ansible Port Turn Up1", + "switchport", + "mtu 9216", + "speed 1000", + "duplex full", + "no shutdown", + ] + playbook["state"] = "replaced" + set_module_args(playbook, ignore_provider_arg) + self.execute_module(changed=True, commands=replaced) diff --git a/tests/unit/modules/network/nxos/test_nxos_l3_interface.py b/tests/unit/modules/network/nxos/test_nxos_l3_interface.py deleted file mode 100644 index f30ad8ff1..000000000 --- a/tests/unit/modules/network/nxos/test_nxos_l3_interface.py +++ /dev/null @@ -1,395 +0,0 @@ -# Copyright: (c) 2019, Olivier Blin -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -# Make coding more python3-ish - -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.plugins.modules import nxos_l3_interface -from .nxos_module import TestNxosModule, load_fixture, set_module_args - - -class TestNxosL3InterfaceModule(TestNxosModule): - - module = nxos_l3_interface - - def setUp(self): - super(TestNxosL3InterfaceModule, self).setUp() - - self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_l3_interface.load_config" - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_l3_interface.get_config" - ) - self.get_config = self.mock_get_config.start() - - def tearDown(self): - super(TestNxosL3InterfaceModule, self).tearDown() - self.mock_load_config.stop() - self.mock_get_config.stop() - - def load_fixtures(self, commands=None, device=""): - self.load_config.return_value = None - self.get_config.return_value = load_fixture( - "nxos_l3_interface", self.mode - ) - - def test_nxos_l3_interface_unknonw_ethernet(self): - self.mode = "ethernet_noshut" - set_module_args(dict(name="Ethernet1/2", ipv4="192.168.0.1/24")) - result = self.execute_module(changed=False) - - # Add when missing - def test_nxos_l3_interface_add_missing_ipv4(self): - self.mode = "ethernet_noshut" - set_module_args(dict(name="Ethernet1/1", ipv4="192.168.0.1/24")) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], - ["interface Ethernet1/1", "ip address 192.168.0.1/24", "exit"], - ) - - def test_nxos_l3_interface_add_missing_ipv4_on_e11(self): - self.mode = "ethernet_noshut" - set_module_args(dict(name="et1/1", ipv4="192.168.0.1/24")) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], - ["interface Ethernet1/1", "ip address 192.168.0.1/24", "exit"], - ) - - def test_nxos_l3_interface_add_missing_ipv6(self): - self.mode = "ethernet_noshut" - set_module_args(dict(name="Ethernet1/1", ipv6="2001:db8::1/124")) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], - ["interface Ethernet1/1", "ipv6 address 2001:db8::1/124", "exit"], - ) - - def test_nxos_l3_interface_add_missing_ipv4_and_ipv6(self): - self.mode = "ethernet_noshut" - set_module_args( - dict( - name="Ethernet1/1", - ipv4="192.168.0.1/24", - ipv6="2001:db8::1/124", - ) - ) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], - [ - "interface Ethernet1/1", - "ip address 192.168.0.1/24", - "ipv6 address 2001:db8::1/124", - "exit", - ], - ) - - # Add when existing - def test_nxos_l3_interface_add_existing_ipv4(self): - self.mode = "ethernet_noshut_ipv4_ipv6" - set_module_args(dict(name="Ethernet1/1", ipv4="192.168.0.1/24")) - result = self.execute_module() - - def test_nxos_l3_interface_add_existing_ipv4_on_e11(self): - self.mode = "ethernet_noshut_ipv4_ipv6" - set_module_args(dict(name="et1/1", ipv4="192.168.0.1/24")) - result = self.execute_module() - - def test_nxos_l3_interface_add_existing_ipv6(self): - self.mode = "ethernet_noshut_ipv4_ipv6" - set_module_args(dict(name="Ethernet1/1", ipv6="2001:db8::1/124")) - result = self.execute_module() - - def test_nxos_l3_interface_add_existing_ipv4_and_ipv6(self): - self.mode = "ethernet_noshut_ipv4_ipv6" - set_module_args( - dict( - name="Ethernet1/1", - ipv4="192.168.0.1/24", - ipv6="2001:db8::1/124", - ) - ) - result = self.execute_module() - - def test_nxos_l3_interface_new_ipv4_and_ipv6(self): - self.mode = "ethernet_noshut_ipv4_ipv6" - set_module_args( - dict( - name="Ethernet1/1", - ipv4="192.168.0.2/24", - ipv6="2001:db8::2/124", - ) - ) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], - [ - "interface Ethernet1/1", - "ip address 192.168.0.2/24", - "ipv6 address 2001:db8::2/124", - "exit", - ], - ) - - # Add when existing with multiple IPv6 - def test_nxos_l3_interface_multiple_ipv6_add_first(self): - self.mode = "ethernet_noshut_multiple_ipv6" - set_module_args(dict(name="Ethernet1/1", ipv6="2001:db8::1/124")) - result = self.execute_module() - - def test_nxos_l3_interface_multiple_ipv6_add_last(self): - self.mode = "ethernet_noshut_multiple_ipv6" - set_module_args(dict(name="Ethernet1/1", ipv6="2001:db8:2::1/124")) - result = self.execute_module() - - # Add aggregate - def test_nxos_l3_interface_add_missing_with_empty_aggregate(self): - self.mode = "ethernet_noshut" - set_module_args(dict(aggregate=[])) - result = self.execute_module() - - def test_nxos_l3_interface_add_missing_with_aggregate(self): - self.mode = "ethernet_noshut" - set_module_args( - dict( - aggregate=[ - dict( - name="Ethernet1/1", - ipv4="192.168.0.2/24", - ipv6="2001:db8::2/124", - ), - dict(name="Ethernet1/1", ipv6="2001:db8:1::2/124"), - dict(name="Ethernet1/1", ipv6="2001:db8:2::2/124"), - ] - ) - ) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], - [ - "interface Ethernet1/1", - "ip address 192.168.0.2/24", - "ipv6 address 2001:db8::2/124", - "exit", - "interface Ethernet1/1", - "ipv6 address 2001:db8:1::2/124", - "exit", - "interface Ethernet1/1", - "ipv6 address 2001:db8:2::2/124", - "exit", - ], - ) - - # Rem when missing - def test_nxos_l3_interface_rem_missing_ipv4(self): - self.mode = "ethernet_noshut" - set_module_args( - dict(name="Ethernet1/1", ipv4="192.168.0.1/24", state="absent") - ) - result = self.execute_module() - - def test_nxos_l3_interface_rem_missing_ipv4_on_e11(self): - self.mode = "ethernet_noshut" - set_module_args( - dict(name="et1/1", ipv4="192.168.0.1/24", state="absent") - ) - result = self.execute_module() - - def test_nxos_l3_interface_rem_missing_ipv6(self): - self.mode = "ethernet_noshut" - set_module_args( - dict(name="Ethernet1/1", ipv6="2001:db8::1/124", state="absent") - ) - result = self.execute_module() - - def test_nxos_l3_interface_rem_missing_ipv4_and_ipv6(self): - self.mode = "ethernet_noshut" - set_module_args( - dict( - name="Ethernet1/1", - ipv4="192.168.0.1/24", - ipv6="2001:db8::1/124", - state="absent", - ) - ) - result = self.execute_module() - - # Rem when existing - def test_nxos_l3_interface_rem_existing_ipv4(self): - self.mode = "ethernet_noshut_ipv4_ipv6" - set_module_args( - dict(name="Ethernet1/1", ipv4="192.168.0.1/24", state="absent") - ) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], - ["interface Ethernet1/1", "no ip address 192.168.0.1/24", "exit"], - ) - - def test_nxos_l3_interface_rem_existing_ipv4_on_e11(self): - self.mode = "ethernet_noshut_ipv4_ipv6" - set_module_args( - dict(name="et1/1", ipv4="192.168.0.1/24", state="absent") - ) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], - ["interface Ethernet1/1", "no ip address 192.168.0.1/24", "exit"], - ) - - def test_nxos_l3_interface_rem_existing_ipv6(self): - self.mode = "ethernet_noshut_ipv4_ipv6" - set_module_args( - dict(name="Ethernet1/1", ipv6="2001:db8::1/124", state="absent") - ) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], - [ - "interface Ethernet1/1", - "no ipv6 address 2001:db8::1/124", - "exit", - ], - ) - - def test_nxos_l3_interface_rem_existing_ipv4_and_ipv6(self): - self.mode = "ethernet_noshut_ipv4_ipv6" - set_module_args( - dict( - name="Ethernet1/1", - ipv4="192.168.0.1/24", - ipv6="2001:db8::1/124", - state="absent", - ) - ) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], - [ - "interface Ethernet1/1", - "no ip address 192.168.0.1/24", - "no ipv6 address 2001:db8::1/124", - "exit", - ], - ) - - # Rem when existing with multiple IPv6 - def test_nxos_l3_interface_multiple_ipv6_rem_first(self): - self.mode = "ethernet_noshut_multiple_ipv6" - set_module_args( - dict(name="Ethernet1/1", ipv6="2001:db8::1/124", state="absent") - ) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], - [ - "interface Ethernet1/1", - "no ipv6 address 2001:db8::1/124", - "exit", - ], - ) - - def test_nxos_l3_interface_multiple_ipv6_rem_last(self): - self.mode = "ethernet_noshut_multiple_ipv6" - set_module_args( - dict(name="Ethernet1/1", ipv6="2001:db8:2::1/124", state="absent") - ) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], - [ - "interface Ethernet1/1", - "no ipv6 address 2001:db8:2::1/124", - "exit", - ], - ) - - # Rem when missing with aggregate - def test_nxos_l3_interface_rem_with_empty_aggregate(self): - self.mode = "ethernet_noshut_multiple_ipv6" - set_module_args(dict(aggregate=[], state="absent")) - result = self.execute_module() - - def test_nxos_l3_interface_rem_missing_with_aggregate(self): - self.mode = "ethernet_noshut_multiple_ipv6" - set_module_args( - dict( - state="absent", - aggregate=[ - dict( - name="Ethernet1/1", - ipv4="192.168.0.2/24", - ipv6="2001:db8::2/124", - ), - dict(name="Ethernet1/1", ipv6="2001:db8:1::2/124"), - dict(name="Ethernet1/1", ipv6="2001:db8:2::2/124"), - ], - ) - ) - result = self.execute_module() - - # Rem when existing with aggregate - def test_nxos_l3_interface_rem_existing_with_aggregate(self): - self.mode = "ethernet_noshut_multiple_ipv6" - set_module_args( - dict( - state="absent", - aggregate=[ - dict( - name="Ethernet1/1", - ipv4="192.168.0.1/24", - ipv6="2001:db8::1/124", - ), - dict(name="Ethernet1/1", ipv6="2001:db8:1::1/124"), - dict(name="Ethernet1/1", ipv6="2001:db8:2::1/124"), - ], - ) - ) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], - [ - "interface Ethernet1/1", - "no ip address 192.168.0.1/24", - "no ipv6 address 2001:db8::1/124", - "exit", - "interface Ethernet1/1", - "no ipv6 address 2001:db8:1::1/124", - "exit", - "interface Ethernet1/1", - "no ipv6 address 2001:db8:2::1/124", - "exit", - ], - ) - - # Add itf only - def test_nxos_l3_interface_add_on_itf_only(self): - self.mode = "ethernet_noshut" - set_module_args(dict(name="Ethernet1/1")) - result = self.execute_module(changed=True) - self.assertEqual(result["commands"], ["interface Ethernet1/1"]) - - # Add unknown interface - def test_nxos_l3_interface_add_on_unknown_itf(self): - self.mode = "ethernet_noshut" - set_module_args(dict(name="Ethernet1/2", ipv4="192.168.0.1/24")) - result = self.execute_module() - self.assertEqual(result["warnings"], ["Unknown interface Ethernet1/2"]) - - # Rem unknown interface - def test_nxos_l3_interface_rem_on_unknown_itf(self): - self.mode = "ethernet_noshut" - set_module_args( - dict(name="Ethernet1/2", ipv4="192.168.0.1/24", state="absent") - ) - result = self.execute_module() - self.assertEqual(result["warnings"], ["Unknown interface Ethernet1/2"]) diff --git a/tests/unit/modules/network/nxos/test_nxos_l3_interfaces.py b/tests/unit/modules/network/nxos/test_nxos_l3_interfaces.py index bacc0d4c4..289c36ffd 100644 --- a/tests/unit/modules/network/nxos/test_nxos_l3_interfaces.py +++ b/tests/unit/modules/network/nxos/test_nxos_l3_interfaces.py @@ -19,53 +19,46 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type from textwrap import dedent -from ansible_collections.cisco.nxos.tests.unit.compat.mock import ( - patch, - PropertyMock, -) -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - AnsibleFailJson, -) -from ansible_collections.cisco.nxos.plugins.modules import nxos_l3_interfaces + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.l3_interfaces.l3_interfaces import ( L3_interfaces, ) -from .nxos_module import TestNxosModule, load_fixture, set_module_args +from ansible_collections.cisco.nxos.plugins.modules import nxos_l3_interfaces +from ansible_collections.cisco.nxos.tests.unit.compat.mock import PropertyMock, patch + +from .nxos_module import TestNxosModule, set_module_args + ignore_provider_arg = True class TestNxosL3InterfacesModule(TestNxosModule): - module = nxos_l3_interfaces def setUp(self): super(TestNxosL3InterfacesModule, self).setUp() self.mock_FACT_LEGACY_SUBSETS = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts.FACT_LEGACY_SUBSETS" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts.FACT_LEGACY_SUBSETS", ) self.FACT_LEGACY_SUBSETS = self.mock_FACT_LEGACY_SUBSETS.start() self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection" - ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection", ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" - ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection", ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_edit_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.l3_interfaces.l3_interfaces.L3_interfaces.edit_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.l3_interfaces.l3_interfaces.L3_interfaces.edit_config", ) self.edit_config = self.mock_edit_config.start() @@ -111,22 +104,33 @@ def test_2(self): ip address 10.1.2.1/24 interface Ethernet1/3 ip address 10.1.3.1/24 - """ + interface port-channel336 + interface port-channel337 + no ipv6 redirects + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} playbook = dict( config=[ dict(name="mgmt0", ipv4=[{"address": "10.0.0.254/24"}]), dict(name="Ethernet1/1", ipv4=[{"address": "192.168.1.1/24"}]), dict(name="Ethernet1/2"), + dict(name="port-channel355", ipv6_redirects=False), + dict(name="port-channel336", ipv6_redirects=False, ipv6=[{"address": "10::5/128"}]), # Eth1/3 not present! Thus overridden should set Eth1/3 to defaults; # replaced should ignore Eth1/3. - ] + ], ) # Expected result commands for each 'state' - merged = ["interface Ethernet1/1", "ip address 192.168.1.1/24"] + merged = [ + "interface Ethernet1/1", + "ip address 192.168.1.1/24", + "interface port-channel355", + "no ipv6 redirects", + "interface port-channel336", + "ipv6 address 10::5/128", + "no ipv6 redirects", + ] deleted = [ "interface mgmt0", "no ip address", @@ -140,6 +144,11 @@ def test_2(self): "ip address 192.168.1.1/24", "interface Ethernet1/2", "no ip address", + "interface port-channel355", + "no ipv6 redirects", + "interface port-channel336", + "ipv6 address 10::5/128", + "no ipv6 redirects", ] overridden = [ "interface Ethernet1/1", @@ -148,6 +157,13 @@ def test_2(self): "no ip address", "interface Ethernet1/3", "no ip address", + "interface port-channel355", + "no ipv6 redirects", + "interface port-channel336", + "ipv6 address 10::5/128", + "no ipv6 redirects", + "interface port-channel337", + "ipv6 redirects", ] playbook["state"] = "merged" @@ -183,11 +199,9 @@ def test_3(self): encapsulation dot1q 45 ip address 10.5.5.5/24 ipv6 address 10::5/128 - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} playbook = dict( config=[ dict(name="mgmt0", ipv4=[{"address": "10.0.0.254/24"}]), @@ -203,7 +217,7 @@ def test_3(self): ipv6=[{"address": "10::2/128"}], ), dict(name="Ethernet1/1.44"), - ] + ], ) # Expected result commands for each 'state' merged = [ @@ -290,11 +304,9 @@ def test_4(self): no ip redirects ip address 10.15.15.15/24 ip address 10.25.25.25/24 secondary - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} playbook = dict( config=[ dict(name="mgmt0", ipv4=[{"address": "10.0.0.254/24"}]), @@ -336,7 +348,7 @@ def test_4(self): ], ), dict(name="Ethernet1/5"), - ] + ], ) # Expected result commands for each 'state' merged = [ @@ -432,11 +444,9 @@ def test_5(self): ipv6 address 10::12/128 interface Ethernet1/3 ipv6 address 10::13/128 - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} playbook = dict( config=[ dict( @@ -450,7 +460,7 @@ def test_5(self): ], ), # new addr+tag dict(name="Ethernet1/2"), - ] + ], ) # Expected result commands for each 'state' merged = [ @@ -519,11 +529,9 @@ def test_6(self): interface Ethernet1/4 interface Ethernet1/5 no ip redirects - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} playbook = dict( config=[ dict( @@ -533,11 +541,9 @@ def test_6(self): ipv4=[{"address": "192.168.1.1/24"}], ), dict(name="Ethernet1/2"), - dict( - name="Ethernet1/3", redirects=True, unreachables=False - ), # defaults + dict(name="Ethernet1/3", redirects=True, unreachables=False), # defaults dict(name="Ethernet1/4", redirects=False, unreachables=True), - ] + ], ) merged = [ "interface Ethernet1/1", @@ -605,11 +611,9 @@ def test_7(self): no ip redirects ip unreachables interface Ethernet1/2 - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} playbook = dict( config=[ dict( @@ -636,7 +640,7 @@ def test_7(self): ], ), dict(name="Ethernet1/2"), - ] + ], ) playbook["state"] = "merged" set_module_args(playbook, ignore_provider_arg) @@ -655,11 +659,9 @@ def test_7(self): """\ interface Ethernet1/1 interface Ethernet1/2 - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} playbook["state"] = "deleted" set_module_args(playbook, ignore_provider_arg) self.execute_module(changed=False) @@ -670,11 +672,9 @@ def test_8(self): """\ interface Ethernet1/1 ip address 10.1.1.1/24 - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} playbook = dict() for i in ["merged", "replaced", "overridden"]: @@ -698,14 +698,10 @@ def test_9(self): no ip redirects ip address 10.15.15.15/24 ip address 10.25.25.25/24 secondary - """ - ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } - playbook = dict( - config=[dict(name="Ethernet1/3"), dict(name="Ethernet1/5")] + """, ) + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} + playbook = dict(config=[dict(name="Ethernet1/3"), dict(name="Ethernet1/5")]) # Expected result commands for each 'state' deleted = [ "interface Ethernet1/3", @@ -760,11 +756,9 @@ def test_10(self): interface Ethernet1/3 ip address 10.1.3.1/24 evpn multisite dci-tracking - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} playbook = dict( config=[ dict(name="mgmt0", ipv4=[{"address": "10.0.0.254/24"}]), @@ -772,7 +766,7 @@ def test_10(self): dict(name="Ethernet1/2"), # Eth1/3 not present! Thus overridden should set Eth1/3 to defaults; # replaced should ignore Eth1/3. - ] + ], ) # Expected result commands for each 'state' merged = ["interface Ethernet1/1", "ip address 192.168.1.1/24"] @@ -842,11 +836,9 @@ def test_11(self): ip address 10.15.15.15/24 ip address 10.25.25.25/24 secondary evpn multisite fabric-tracking - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} playbook = dict( config=[ dict(name="mgmt0", ipv4=[{"address": "10.0.0.254/24"}]), @@ -889,7 +881,7 @@ def test_11(self): evpn_multisite_tracking="dci-tracking", ), dict(name="Ethernet1/5"), - ] + ], ) # Expected result commands for each 'state' merged = [ @@ -987,19 +979,15 @@ def test_12(self): interface Vlan99 no shutdown ip address 192.168.1.1/24 - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} playbook = dict( config=[ dict( name="Vlan99", - ipv4=[ - {"address": "192.168.1.1/24", "tag": 500} - ], # adding a tag - ) + ipv4=[{"address": "192.168.1.1/24", "tag": 500}], # adding a tag + ), ], state="replaced", ) @@ -1020,11 +1008,9 @@ def test_12_gathered(self): interface Ethernet1/2 ip address 192.168.2.1/24 interface loopback1 - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} playbook = dict(state="gathered") gathered_facts = [ {"name": "nve1"}, @@ -1035,3 +1021,26 @@ def test_12_gathered(self): set_module_args(playbook, ignore_provider_arg) result = self.execute_module(changed=False) self.assertEqual(result["gathered"], gathered_facts) + + def test_replaced_tag(self): + existing = dedent( + """\ + interface Vlan10 + ip address 192.168.1.10/24 tag 20 + """, + ) + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} + playbook = dict( + config=[ + dict( + name="Vlan10", + ipv4=[{"address": "192.168.1.11/24", "tag": 20}], + ), + ], + state="replaced", + ) + + commands = ["interface Vlan10", "ip address 192.168.1.11/24 tag 20"] + playbook["state"] = "replaced" + set_module_args(playbook, ignore_provider_arg) + self.execute_module(changed=True, commands=commands) diff --git a/tests/unit/modules/network/nxos/test_nxos_lacp_interfaces.py b/tests/unit/modules/network/nxos/test_nxos_lacp_interfaces.py index b9f699488..e6850278a 100644 --- a/tests/unit/modules/network/nxos/test_nxos_lacp_interfaces.py +++ b/tests/unit/modules/network/nxos/test_nxos_lacp_interfaces.py @@ -19,47 +19,43 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type from textwrap import dedent -from ansible_collections.cisco.nxos.tests.unit.compat.mock import ( - patch, - PropertyMock, -) + from ansible_collections.cisco.nxos.plugins.modules import nxos_lacp_interfaces +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from .nxos_module import TestNxosModule, set_module_args + ignore_provider_arg = True class TestNxosLacpInterfacesModule(TestNxosModule): - module = nxos_lacp_interfaces def setUp(self): super(TestNxosLacpInterfacesModule, self).setUp() self.mock_FACT_LEGACY_SUBSETS = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts.FACT_LEGACY_SUBSETS" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts.FACT_LEGACY_SUBSETS", ) self.FACT_LEGACY_SUBSETS = self.mock_FACT_LEGACY_SUBSETS.start() self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection" - ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection", ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" - ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection", ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_edit_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.l3_interfaces.l3_interfaces.L3_interfaces.edit_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.l3_interfaces.l3_interfaces.L3_interfaces.edit_config", ) self.edit_config = self.mock_edit_config.start() @@ -86,11 +82,9 @@ def test_lacp_mode_parse(self): switchport trunk native vlan 5 switchport trunk allowed vlan 10 no lacp graceful-convergence - """ + """, ) - self.get_resource_connection_facts.return_value = { - self.SHOW_CMD: existing - } + self.get_resource_connection_facts.return_value = {self.SHOW_CMD: existing} playbook = dict( config=[ dict( @@ -98,8 +92,8 @@ def test_lacp_mode_parse(self): convergence={"graceful": False}, suspend_individual=True, mode="delay", - ) - ] + ), + ], ) # Expected result commands for each 'state' merged = [ diff --git a/tests/unit/modules/network/nxos/test_nxos_lldp_interfaces.py b/tests/unit/modules/network/nxos/test_nxos_lldp_interfaces.py index 843a766c4..c2acfcc49 100644 --- a/tests/unit/modules/network/nxos/test_nxos_lldp_interfaces.py +++ b/tests/unit/modules/network/nxos/test_nxos_lldp_interfaces.py @@ -5,57 +5,49 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type from ansible_collections.cisco.nxos.plugins.modules import nxos_lldp_interfaces -from ansible_collections.cisco.nxos.tests.unit.compat.mock import ( - patch, - MagicMock, -) -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - set_module_args, -) -from .nxos_module import TestNxosModule, load_fixture +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch +from ansible_collections.cisco.nxos.tests.unit.modules.utils import set_module_args +from .nxos_module import TestNxosModule -class TestNxosLldpInterfacesModule(TestNxosModule): +class TestNxosLldpInterfacesModule(TestNxosModule): module = nxos_lldp_interfaces def setUp(self): super(TestNxosLldpInterfacesModule, self).setUp() self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config" + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", ) self.get_config = self.mock_get_config.start() self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config" + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", ) self.load_config = self.mock_load_config.start() self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection" - ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection", ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" - ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection", ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_edit_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.lldp_interfaces.lldp_interfaces.Lldp_interfaces.edit_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.lldp_interfaces.lldp_interfaces.Lldp_interfaces.edit_config", ) self.edit_config = self.mock_edit_config.start() self.mock_execute_show_command = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.lldp_interfaces.lldp_interfaces.Lldp_interfacesFacts.get_device_data" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.lldp_interfaces.lldp_interfaces.Lldp_interfacesFacts.get_device_data", ) self.execute_show_command = self.mock_execute_show_command.start() @@ -88,10 +80,10 @@ def test_nxos_lldp_interfaces_merged(self): name="Ethernet1/3", receive=False, tlv_set=dict(vlan=123), - ) + ), ], state="merged", - ) + ), ) commands = [ "interface Ethernet1/3", @@ -112,7 +104,7 @@ def test_nxos_lldp_interfaces_merged_idempotent(self): dict(name="Ethernet1/1", receive=True, transmit=False), ], state="merged", - ) + ), ) self.execute_module(changed=False, commands=[]) @@ -125,10 +117,10 @@ def test_nxos_lldp_interfaces_replaced(self): receive=True, transmit=False, tlv_set=dict(management_address="192.0.2.123"), - ) + ), ], state="replaced", - ) + ), ) commands = [ "interface Ethernet1/2", @@ -151,18 +143,16 @@ def test_nxos_lldp_interfaces_replaced_idempotent(self): dict(name="Ethernet1/1", receive=True, transmit=False), ], state="replaced", - ) + ), ) self.execute_module(changed=False, commands=[]) def test_nxos_lldp_interfaces_overridden(self): set_module_args( dict( - config=[ - dict(name="Ethernet1/4", receive=True, transmit=False) - ], + config=[dict(name="Ethernet1/4", receive=True, transmit=False)], state="overridden", - ) + ), ) commands = [ "interface Ethernet1/4", @@ -189,14 +179,12 @@ def test_nxos_lldp_interfaces_overridden_idempotent(self): dict(name="Ethernet1/1", receive=True, transmit=False), ], state="overridden", - ) + ), ) self.execute_module(changed=False, commands=[]) def test_nxos_lldp_interfaces_deleted_intf(self): - set_module_args( - dict(config=[dict(name="Ethernet1/2")], state="deleted") - ) + set_module_args(dict(config=[dict(name="Ethernet1/2")], state="deleted")) commands = [ "interface Ethernet1/2", "lldp receive", @@ -228,7 +216,7 @@ def test_nxos_lldp_interfaces_rendered(self): dict(name="Ethernet1/1", receive=True, transmit=False), ], state="rendered", - ) + ), ) commands = [ "interface Ethernet1/1", @@ -239,9 +227,7 @@ def test_nxos_lldp_interfaces_rendered(self): "lldp tlv-set vlan 12", ] result = self.execute_module(changed=False) - self.assertEqual( - sorted(result["rendered"]), sorted(commands), result["rendered"] - ) + self.assertEqual(sorted(result["rendered"]), sorted(commands), result["rendered"]) def test_nxos_lldp_interfaces_parsed(self): set_module_args( @@ -253,7 +239,7 @@ def test_nxos_lldp_interfaces_parsed(self): no lldp receive lldp tlv-set vlan 12""", state="parsed", - ) + ), ) result = self.execute_module(changed=False) compare_list = [ diff --git a/tests/unit/modules/network/nxos/test_nxos_logging_global.py b/tests/unit/modules/network/nxos/test_nxos_logging_global.py index 1300a936b..aea13fc94 100644 --- a/tests/unit/modules/network/nxos/test_nxos_logging_global.py +++ b/tests/unit/modules/network/nxos/test_nxos_logging_global.py @@ -18,38 +18,34 @@ # Make coding more python3-ish from __future__ import absolute_import, division, print_function -from typing import Sequence + __metaclass__ = type from textwrap import dedent -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - AnsibleFailJson, -) + from ansible_collections.cisco.nxos.plugins.modules import nxos_logging_global +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from .nxos_module import TestNxosModule, set_module_args + ignore_provider_arg = True class TestNxosLoggingGlobalModule(TestNxosModule): - module = nxos_logging_global def setUp(self): super(TestNxosLoggingGlobalModule, self).setUp() self.mock_get_resource_connection = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" - ) - self.get_resource_connection = ( - self.mock_get_resource_connection.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", ) + self.get_resource_connection = self.mock_get_resource_connection.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.logging_global.logging_global.Logging_globalFacts.get_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.logging_global.logging_global.Logging_globalFacts.get_config", ) self.get_config = self.mock_get_config.start() @@ -62,7 +58,7 @@ def test_nxos_logging_global_linear_merged(self): # test merged for linear attributes self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args( dict( @@ -104,7 +100,7 @@ def test_nxos_logging_global_linear_merged_idempotent(self): no logging rate-limit logging rfc-strict 5424 logging origin-id string nodeA - """ + """, ) set_module_args( dict( @@ -134,7 +130,7 @@ def test_nxos_logging_global_linear_merged_2(self): logging history 6 logging history size 4096 no logging rate-limit - """ + """, ) set_module_args( dict( @@ -170,7 +166,7 @@ def test_nxos_logging_global_linear_replaced(self): no logging rate-limit logging rfc-strict 5424 logging origin-id string nodeA - """ + """, ) set_module_args( dict( @@ -205,7 +201,7 @@ def test_nxos_logging_global_linear_replaced(self): logging history size 4096 no logging rate-limit logging rfc-strict 5424 - """ + """, ) set_module_args( dict( @@ -232,7 +228,7 @@ def test_nxos_logging_global_linear_merged_3(self): # test merged for linear attributes - 3 self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args( dict( @@ -240,12 +236,10 @@ def test_nxos_logging_global_linear_merged_3(self): origin_id=dict(hostname=True), ip=dict( access_list=dict( - cache=dict( - entries=16384, interval=200, threshold=80 - ), + cache=dict(entries=16384, interval=200, threshold=80), detailed=True, include=dict(sgt=True), - ) + ), ), source_interface="Ethernet1/100", timestamp="milliseconds", @@ -279,7 +273,7 @@ def test_nxos_logging_global_linear_merged_3_idempotent(self): logging ip access-list include sgt logging source-interface Ethernet1/100 logging timestamp milliseconds - """ + """, ) set_module_args( dict( @@ -287,12 +281,10 @@ def test_nxos_logging_global_linear_merged_3_idempotent(self): origin_id=dict(hostname=True), ip=dict( access_list=dict( - cache=dict( - entries=16384, interval=200, threshold=80 - ), + cache=dict(entries=16384, interval=200, threshold=80), detailed=True, include=dict(sgt=True), - ) + ), ), source_interface="Ethernet1/100", timestamp="milliseconds", @@ -316,17 +308,13 @@ def test_nxos_logging_global_linear_replaced_3(self): logging ip access-list include sgt logging source-interface Ethernet1/100 logging timestamp milliseconds - """ + """, ) set_module_args( dict( config=dict( origin_id=dict(ip="192.168.1.1"), - ip=dict( - access_list=dict( - cache=dict(entries=16384, interval=210) - ) - ), + ip=dict(access_list=dict(cache=dict(entries=16384, interval=210))), source_interface="Ethernet1/120", ), state="replaced", @@ -350,7 +338,7 @@ def test_nxos_logging_global_complex_merged(self): # test merged for complex attributes self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args( dict( @@ -391,7 +379,7 @@ def test_nxos_logging_global_complex_merged_idempotent(self): logging level ospfv3 2 logging level auth 1 logging level vlan_mgr 5 - """ + """, ) set_module_args( dict( @@ -424,7 +412,7 @@ def test_nxos_logging_global_complex_replaced(self): logging level cron 5 logging level ospfv3 2 logging level auth 1 - """ + """, ) set_module_args( dict( @@ -433,7 +421,7 @@ def test_nxos_logging_global_complex_replaced(self): dict(facility="auth", severity="alert"), dict(facility="ospfv3", severity="critical"), dict(facility="ospf", severity="notification"), - ] + ], ), state="replaced", ), @@ -453,7 +441,7 @@ def test_nxos_logging_global_event_merged(self): # test merged for `event` self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args( dict( @@ -461,7 +449,7 @@ def test_nxos_logging_global_event_merged(self): event=dict( link_status=dict(enable=False, default=False), trunk_status=dict(enable=False, default=True), - ) + ), ), state="merged", ), @@ -484,7 +472,7 @@ def test_nxos_logging_global_event_merged(self): no logging event link-status default no logging event trunk-status enable logging event trunk-status default - """ + """, ) set_module_args( dict( @@ -492,7 +480,7 @@ def test_nxos_logging_global_event_merged(self): event=dict( link_status=dict(enable=False, default=False), trunk_status=dict(enable=False, default=True), - ) + ), ), state="merged", ), @@ -509,7 +497,7 @@ def test_nxos_logging_global_event_replaced(self): no logging event link-status default no logging event trunk-status enable logging event trunk-status default - """ + """, ) set_module_args( dict( @@ -517,7 +505,7 @@ def test_nxos_logging_global_event_replaced(self): event=dict( link_status=dict(default=False), trunk_status=dict(enable=False), - ) + ), ), state="replaced", ), @@ -532,9 +520,7 @@ def test_nxos_logging_global_event_replaced(self): self.assertEqual(set(result["commands"]), set(commands)) def test_nxos_logging_global_gathered_empty(self): - set_module_args( - dict(running_config="", state="gathered"), ignore_provider_arg - ) + set_module_args(dict(running_config="", state="gathered"), ignore_provider_arg) result = self.execute_module(changed=False) self.assertEqual(result["gathered"], {}) @@ -551,7 +537,7 @@ def test_nxos_logging_global_gathered(self): no logging rate-limit logging rfc-strict 5424 logging origin-id string nodeA - """ + """, ) set_module_args(dict(state="gathered"), ignore_provider_arg) gathered = { @@ -562,9 +548,7 @@ def test_nxos_logging_global_gathered(self): "rate_limit": "disabled", "rfc_strict": True, "origin_id": {"string": "nodeA"}, - "facilities": [ - {"facility": "vlan_mgr", "severity": "notification"} - ], + "facilities": [{"facility": "vlan_mgr", "severity": "notification"}], } result = self.execute_module(changed=False) self.assertEqual(result["gathered"], gathered) @@ -581,11 +565,9 @@ def test_nxos_logging_global_parsed(self): no logging rate-limit logging rfc-strict 5424 logging origin-id string nodeA - """ - ) - set_module_args( - dict(running_config=cfg, state="parsed"), ignore_provider_arg + """, ) + set_module_args(dict(running_config=cfg, state="parsed"), ignore_provider_arg) parsed = { "console": {"severity": "alert"}, "module": {"severity": "notification"}, @@ -602,7 +584,7 @@ def test_nxos_logging_global_hosts_merged(self): # test merged for `hosts` self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args( dict( @@ -614,13 +596,11 @@ def test_nxos_logging_global_hosts_merged(self): facility="auth", port=5891, use_vrf="default", - secure=dict( - trustpoint=dict(client_identity="test") - ), + secure=dict(trustpoint=dict(client_identity="test")), ), dict(host="192.168.1.2"), dict(host="192.168.1.3", severity="critical"), - ] + ], ), state="merged", ), @@ -641,7 +621,7 @@ def test_nxos_logging_global_hosts_replaced(self): logging server 192.168.1.1 1 port 5891 secure trustpoint client-identity test facility auth use-vrf default logging server 192.168.1.2 logging server 192.168.1.3 2 - """ + """, ) set_module_args( dict( @@ -653,16 +633,14 @@ def test_nxos_logging_global_hosts_replaced(self): facility="auth", port=5891, use_vrf="default", - secure=dict( - trustpoint=dict(client_identity="test") - ), + secure=dict(trustpoint=dict(client_identity="test")), ), dict( host="192.168.1.3", severity="debugging", use_vrf="management", ), - ] + ], ), state="replaced", ), @@ -684,7 +662,7 @@ def test_nxos_logging_global_linear_negated_merged(self): no logging console no logging module no logging monitor - """ + """, ) set_module_args( dict( @@ -713,7 +691,7 @@ def test_nxos_logging_global_deleted(self): no logging rate-limit logging rfc-strict 5424 logging origin-id string nodeA - """ + """, ) set_module_args(dict(state="deleted"), ignore_provider_arg) commands = [ @@ -737,13 +715,11 @@ def test_nxos_logging_global_event_replaced_2(self): no logging event link-status default no logging event trunk-status enable logging event trunk-status default - """ + """, ) set_module_args( dict( - config=dict( - event=dict(trunk_status=dict(enable=False, default=True)) - ), + config=dict(event=dict(trunk_status=dict(enable=False, default=True))), state="replaced", ), ignore_provider_arg, @@ -763,7 +739,7 @@ def test_nxos_logging_global_event_replaced_2(self): no logging event link-status default no logging event trunk-status enable logging event trunk-status default - """ + """, ) set_module_args( dict( diff --git a/tests/unit/modules/network/nxos/test_nxos_ntp_global.py b/tests/unit/modules/network/nxos/test_nxos_ntp_global.py index d1528db01..7c49d8668 100644 --- a/tests/unit/modules/network/nxos/test_nxos_ntp_global.py +++ b/tests/unit/modules/network/nxos/test_nxos_ntp_global.py @@ -19,36 +19,33 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type from textwrap import dedent -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - AnsibleFailJson, -) + from ansible_collections.cisco.nxos.plugins.modules import nxos_ntp_global +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from .nxos_module import TestNxosModule, set_module_args + ignore_provider_arg = True class TestNxosNtpGlobalModule(TestNxosModule): - module = nxos_ntp_global def setUp(self): super(TestNxosNtpGlobalModule, self).setUp() self.mock_get_resource_connection = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" - ) - self.get_resource_connection = ( - self.mock_get_resource_connection.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", ) + self.get_resource_connection = self.mock_get_resource_connection.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.ntp_global.ntp_global.Ntp_globalFacts.get_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.ntp_global.ntp_global.Ntp_globalFacts.get_config", ) self.get_config = self.mock_get_config.start() @@ -61,7 +58,7 @@ def test_nxos_ntp_global_linear_merged(self): # test merged for linear attributes self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args( dict( @@ -119,7 +116,7 @@ def test_nxos_ntp_global_linear_merged_idempotent(self): ntp access-group serve-only ServeOnlyAcl2 ntp allow control rate-limit 400 ntp allow private - """ + """, ) set_module_args( dict( @@ -165,7 +162,7 @@ def test_nxos_ntp_global_linear_replaced_idempotent(self): ntp access-group serve-only ServeOnlyAcl2 ntp allow control rate-limit 400 ntp allow private - """ + """, ) set_module_args( dict( @@ -203,7 +200,7 @@ def test_nxos_ntp_global_complex_merged(self): # test merged for complex attributes self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args( dict( @@ -248,7 +245,7 @@ def test_nxos_ntp_global_complex_merged_idempotent(self): ntp master 2 ntp passive ntp source 192.168.1.1 - """ + """, ) set_module_args( dict( @@ -283,7 +280,7 @@ def test_nxos_ntp_global_complex_merged_idempotent(self): ntp master 2 ntp passive ntp source 192.168.1.1 - """ + """, ) set_module_args( dict( @@ -314,7 +311,7 @@ def test_nxos_ntp_global_complex_2_merged(self): # test merged for complex attributes - 2 self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args( dict( @@ -329,9 +326,7 @@ def test_nxos_ntp_global_complex_2_merged(self): prefer=True, ), dict(peer="192.168.1.2", key_id=3, use_vrf="siteB"), - dict( - peer="192.168.1.3", maxpoll=10, use_vrf="default" - ), + dict(peer="192.168.1.3", maxpoll=10, use_vrf="default"), ], servers=[ dict( @@ -343,9 +338,7 @@ def test_nxos_ntp_global_complex_2_merged(self): prefer=True, ), dict(server="203.0.113.2", key_id=3, use_vrf="siteB"), - dict( - server="203.0.113.3", maxpoll=10, use_vrf="default" - ), + dict(server="203.0.113.3", maxpoll=10, use_vrf="default"), ], ), state="merged", @@ -373,7 +366,7 @@ def test_nxos_ntp_global_complex_2_merged_idempotent(self): ntp server 203.0.113.1 prefer use-vrf siteA key 2 minpoll 5 maxpoll 15 ntp server 203.0.113.2 use-vrf siteB key 3 ntp server 203.0.113.3 use-vrf default maxpoll 10 - """ + """, ) set_module_args( dict( @@ -420,7 +413,7 @@ def test_nxos_ntp_global_complex_2_replaced(self): ntp server 203.0.113.1 prefer use-vrf siteA key 2 minpoll 5 maxpoll 15 ntp server 203.0.113.2 use-vrf siteB key 3 ntp server 203.0.113.3 use-vrf default maxpoll 10 - """ + """, ) set_module_args( dict( @@ -444,7 +437,7 @@ def test_nxos_ntp_global_complex_2_replaced(self): maxpoll=15, vrf="siteA", prefer=True, - ) + ), ], ), state="replaced", @@ -465,7 +458,7 @@ def test_nxos_ntp_global_complex_3_merged(self): # test merged for complex attributes - 3 self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args( dict( @@ -498,7 +491,7 @@ def test_nxos_ntp_global_complex_3_merged_idempotent(self): ntp trusted-key 1002 ntp trusted-key 1003 ntp source-interface Ethernet1/1 - """ + """, ) set_module_args( dict( @@ -525,7 +518,7 @@ def test_nxos_ntp_global_source_interface_merged_idempotent(self): ntp trusted-key 1002 ntp trusted-key 1003 ntp source-interface Ethernet1/1 - """ + """, ) set_module_args( dict(config=dict(source_interface="Ethernet1/1"), state="merged"), @@ -542,7 +535,7 @@ def test_nxos_ntp_global_complex_3_replaced(self): ntp trusted-key 1002 ntp trusted-key 1003 ntp source-interface 192.168.1.100 - """ + """, ) set_module_args( dict( @@ -567,9 +560,7 @@ def test_nxos_ntp_global_complex_3_replaced(self): self.assertEqual(set(result["commands"]), set(commands)) def test_nxos_ntp_global_gathered_empty(self): - set_module_args( - dict(running_config="", state="gathered"), ignore_provider_arg - ) + set_module_args(dict(running_config="", state="gathered"), ignore_provider_arg) result = self.execute_module(changed=False) self.assertEqual(result["gathered"], {}) @@ -580,7 +571,7 @@ def test_nxos_ntp_global_gathered(self): ntp trusted-key 1002 ntp trusted-key 1003 ntp source-interface 192.168.1.100 - """ + """, ) set_module_args(dict(state="gathered"), ignore_provider_arg) gathered = { @@ -601,11 +592,9 @@ def test_nxos_ntp_global_parsed(self): ntp trusted-key 1002 ntp trusted-key 1003 ntp source-interface 192.168.1.100 - """ - ) - set_module_args( - dict(running_config=cfg, state="parsed"), ignore_provider_arg + """, ) + set_module_args(dict(running_config=cfg, state="parsed"), ignore_provider_arg) parsed = { "trusted_keys": [ {"key_id": 1001}, @@ -630,7 +619,7 @@ def test_nxos_ntp_global_linear_deleted(self): ntp access-group serve-only ServeOnlyAcl2 ntp allow control rate-limit 400 ntp allow private - """ + """, ) set_module_args(dict(state="deleted"), ignore_provider_arg) commands = [ @@ -651,7 +640,7 @@ def test_nxos_ntp_global_linear_deleted(self): def test_nxos_ntp_global_alias(self): self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args( dict( @@ -697,7 +686,7 @@ def test_nxos_ntp_global_alias_idempotent(self): ntp server 1.1.1.3 use-vrf v200 ntp peer 192.168.1.1 use-vrf default ntp peer 192.168.1.2 use-vrf v200 - """ + """, ) set_module_args( dict( diff --git a/tests/unit/modules/network/nxos/test_nxos_nxapi.py b/tests/unit/modules/network/nxos/test_nxos_nxapi.py index 3e40becb9..7eb12a21c 100644 --- a/tests/unit/modules/network/nxos/test_nxos_nxapi.py +++ b/tests/unit/modules/network/nxos/test_nxos_nxapi.py @@ -19,32 +19,33 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from ansible_collections.cisco.nxos.plugins.modules import nxos_nxapi +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from .nxos_module import TestNxosModule, load_fixture, set_module_args class TestNxosNxapiModule(TestNxosModule): - module = nxos_nxapi def setUp(self): super(TestNxosNxapiModule, self).setUp() self.mock_run_commands = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_nxapi.run_commands" + "ansible_collections.cisco.nxos.plugins.modules.nxos_nxapi.run_commands", ) self.run_commands = self.mock_run_commands.start() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_nxapi.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_nxapi.load_config", ) self.load_config = self.mock_load_config.start() self.mock_get_capabilities = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_nxapi.get_capabilities" + "ansible_collections.cisco.nxos.plugins.modules.nxos_nxapi.get_capabilities", ) self.get_capabilities = self.mock_get_capabilities.start() self.get_capabilities.return_value = { @@ -83,18 +84,17 @@ def test_nxos_nxapi_no_change(self): http_port=80, https_port=443, sandbox=False, - ) + ), ) self.execute_module_devices(changed=False, commands=[]) def test_nxos_nxapi_disable(self): set_module_args(dict(state="absent")) - self.execute_module_devices( - changed=True, commands=["no feature nxapi"] - ) + self.execute_module_devices(changed=True, commands=["no feature nxapi"]) def test_nxos_nxapi_no_http(self): set_module_args(dict(https=True, http=False, https_port=8443)) self.execute_module_devices( - changed=True, commands=["no nxapi http", "nxapi https port 8443"] + changed=True, + commands=["no nxapi http", "nxapi https port 8443"], ) diff --git a/tests/unit/modules/network/nxos/test_nxos_ospf.py b/tests/unit/modules/network/nxos/test_nxos_ospf.py deleted file mode 100644 index 5cc4102a7..000000000 --- a/tests/unit/modules/network/nxos/test_nxos_ospf.py +++ /dev/null @@ -1,62 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# Make coding more python3-ish - -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.plugins.modules import nxos_ospf -from .nxos_module import TestNxosModule, set_module_args - - -class TestNxosOspfModule(TestNxosModule): - - module = nxos_ospf - - def setUp(self): - super(TestNxosOspfModule, self).setUp() - - self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_ospf.load_config" - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_ospf.get_config" - ) - self.get_config = self.mock_get_config.start() - - def tearDown(self): - super(TestNxosOspfModule, self).tearDown() - self.mock_load_config.stop() - self.mock_get_config.stop() - - def load_fixtures(self, commands=None, device=""): - self.load_config.return_value = None - - def test_nxos_ospf_present(self): - set_module_args(dict(ospf=1, state="present")) - result = self.execute_module(changed=True) - self.assertEqual(result["commands"], ["router ospf 1"]) - - def test_nxos_ospf_absent(self): - set_module_args(dict(ospf=1, state="absent")) - result = self.execute_module(changed=False) - self.assertEqual(result["commands"], []) diff --git a/tests/unit/modules/network/nxos/test_nxos_ospf_interfaces.py b/tests/unit/modules/network/nxos/test_nxos_ospf_interfaces.py index b16d66c74..f22889574 100644 --- a/tests/unit/modules/network/nxos/test_nxos_ospf_interfaces.py +++ b/tests/unit/modules/network/nxos/test_nxos_ospf_interfaces.py @@ -19,22 +19,21 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type from textwrap import dedent -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - AnsibleFailJson, -) + from ansible_collections.cisco.nxos.plugins.modules import nxos_ospf_interfaces +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + +from .nxos_module import TestNxosModule, set_module_args -from .nxos_module import TestNxosModule, load_fixture, set_module_args ignore_provider_arg = True class TestNxosOspfInterfacesModule(TestNxosModule): - # Testing strategy # ------------------ # (a) The unit tests cover `merged` and `replaced` for every attribute. @@ -49,14 +48,12 @@ def setUp(self): super(TestNxosOspfInterfacesModule, self).setUp() self.mock_get_resource_connection = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" - ) - self.get_resource_connection = ( - self.mock_get_resource_connection.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", ) + self.get_resource_connection = self.mock_get_resource_connection.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.ospf_interfaces.ospf_interfaces.Ospf_interfacesFacts.get_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.ospf_interfaces.ospf_interfaces.Ospf_interfacesFacts.get_config", ) self.get_config = self.mock_get_config.start() @@ -80,7 +77,7 @@ def test_nxos_ospf_interfaces_af_process_area_merged(self): no switchport interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict( @@ -94,7 +91,7 @@ def test_nxos_ospf_interfaces_af_process_area_merged(self): dict( process_id="102", area=dict(area_id="1.1.1.2"), - ) + ), ], ), dict( @@ -103,7 +100,7 @@ def test_nxos_ospf_interfaces_af_process_area_merged(self): dict( process_id="200", area=dict(area_id="2.2.2.8"), - ) + ), ], ), ], @@ -117,9 +114,9 @@ def test_nxos_ospf_interfaces_af_process_area_merged(self): dict( process_id="101", area=dict(area_id="2.2.2.3"), - ) + ), ], - ) + ), ], ), dict( @@ -134,9 +131,9 @@ def test_nxos_ospf_interfaces_af_process_area_merged(self): area_id="2.2.2.3", secondaries="False", ), - ) + ), ], - ) + ), ], ), ], @@ -171,7 +168,7 @@ def test_nxos_ospf_interfaces_af_process_area_replaced(self): no switchport interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict( @@ -185,9 +182,9 @@ def test_nxos_ospf_interfaces_af_process_area_replaced(self): dict( process_id="200", area=dict(area_id="2.2.2.8"), - ) + ), ], - ) + ), ], ), dict( @@ -199,9 +196,9 @@ def test_nxos_ospf_interfaces_af_process_area_replaced(self): dict( process_id="102", area=dict(area_id="1.1.1.2"), - ) + ), ], - ) + ), ], ), ], @@ -238,7 +235,7 @@ def test_nxos_ospf_interfaces_af_process_multiareas_merged(self): no switchport interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict( @@ -258,7 +255,7 @@ def test_nxos_ospf_interfaces_af_process_multiareas_merged(self): multi_areas=["3.3.3.3", "4.4.4.4"], ), ], - ) + ), ], ), dict( @@ -270,9 +267,9 @@ def test_nxos_ospf_interfaces_af_process_multiareas_merged(self): dict( process_id="109", multi_areas=["5.5.5.5", "5.5.5.6"], - ) + ), ], - ) + ), ], ), ], @@ -312,7 +309,7 @@ def test_nxos_ospf_interfaces_af_process_multiareas_replaced(self): no switchport interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict( @@ -336,7 +333,7 @@ def test_nxos_ospf_interfaces_af_process_multiareas_replaced(self): multi_areas=["3.3.3.3", "4.4.4.4"], ), ], - ) + ), ], ), dict( @@ -348,9 +345,9 @@ def test_nxos_ospf_interfaces_af_process_multiareas_replaced(self): dict( process_id="109", multi_areas=["5.5.5.6"], - ) + ), ], - ) + ), ], ), ], @@ -392,7 +389,7 @@ def test_nxos_ospf_interfaces_af_multiareas_merged(self): no switchport interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict( @@ -400,19 +397,13 @@ def test_nxos_ospf_interfaces_af_multiareas_merged(self): dict( name="Ethernet1/1", address_family=[ - dict( - afi="ipv4", multi_areas=["1.1.1.1", "1.1.1.3"] - ), - dict( - afi="ipv6", multi_areas=["3.3.3.3", "4.4.4.4"] - ), + dict(afi="ipv4", multi_areas=["1.1.1.1", "1.1.1.3"]), + dict(afi="ipv6", multi_areas=["3.3.3.3", "4.4.4.4"]), ], ), dict( name="Ethernet1/2", - address_family=[ - dict(afi="ipv6", multi_areas=["5.5.5.6"]) - ], + address_family=[dict(afi="ipv6", multi_areas=["5.5.5.6"])], ), ], state="merged", @@ -447,7 +438,7 @@ def test_nxos_ospf_interfaces_af_multiareas_replaced(self): no switchport interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict( @@ -455,12 +446,8 @@ def test_nxos_ospf_interfaces_af_multiareas_replaced(self): dict( name="Ethernet1/1", address_family=[ - dict( - afi="ipv4", multi_areas=["1.1.1.1", "1.1.1.3"] - ), - dict( - afi="ipv6", multi_areas=["3.3.3.3", "4.4.4.4"] - ), + dict(afi="ipv4", multi_areas=["1.1.1.1", "1.1.1.3"]), + dict(afi="ipv6", multi_areas=["3.3.3.3", "4.4.4.4"]), ], ), dict(name="Ethernet1/2"), @@ -498,7 +485,7 @@ def test_nxos_ospf_interfaces_authentication_merged(self): interface Ethernet1/4 no switchport ip ospf authentication - """ + """, ) set_module_args( dict( @@ -508,31 +495,21 @@ def test_nxos_ospf_interfaces_authentication_merged(self): address_family=[ dict( afi="ipv4", - authentication=dict( - key_chain="test-1", message_digest=True - ), - ) + authentication=dict(key_chain="test-1", message_digest=True), + ), ], ), dict( name="Ethernet1/2", - address_family=[ - dict( - afi="ipv4", authentication=dict(null_auth=True) - ) - ], + address_family=[dict(afi="ipv4", authentication=dict(null_auth=True))], ), dict( name="Ethernet1/3", - address_family=[ - dict(afi="ipv4", authentication=dict(enable=True)) - ], + address_family=[dict(afi="ipv4", authentication=dict(enable=True))], ), dict( name="Ethernet1/4", - address_family=[ - dict(afi="ipv4", authentication=dict(enable=False)) - ], + address_family=[dict(afi="ipv4", authentication=dict(enable=False))], ), ], state="merged", @@ -568,7 +545,7 @@ def test_nxos_ospf_interfaces_authentication_replaced(self): no switchport interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict( @@ -576,17 +553,11 @@ def test_nxos_ospf_interfaces_authentication_replaced(self): dict(name="Ethernet1/1"), dict( name="Ethernet1/2", - address_family=[ - dict( - afi="ipv4", authentication=dict(null_auth=True) - ) - ], + address_family=[dict(afi="ipv4", authentication=dict(null_auth=True))], ), dict( name="Ethernet1/3", - address_family=[ - dict(afi="ipv4", authentication=dict(enable=True)) - ], + address_family=[dict(afi="ipv4", authentication=dict(enable=True))], ), ], state="replaced", @@ -619,7 +590,7 @@ def test_nxos_ospf_interfaces_authentication_key_merged(self): no switchport interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict( @@ -629,10 +600,8 @@ def test_nxos_ospf_interfaces_authentication_key_merged(self): address_family=[ dict( afi="ipv4", - authentication_key=dict( - encryption=3, key="77840f9d4d882176" - ), - ) + authentication_key=dict(encryption=3, key="77840f9d4d882176"), + ), ], ), dict( @@ -640,10 +609,8 @@ def test_nxos_ospf_interfaces_authentication_key_merged(self): address_family=[ dict( afi="ipv4", - authentication_key=dict( - encryption=0, key="password" - ), - ) + authentication_key=dict(encryption=0, key="password"), + ), ], ), dict( @@ -651,10 +618,8 @@ def test_nxos_ospf_interfaces_authentication_key_merged(self): address_family=[ dict( afi="ipv4", - authentication_key=dict( - encryption=7, key="712090404011C031628" - ), - ) + authentication_key=dict(encryption=7, key="712090404011C031628"), + ), ], ), ], @@ -688,7 +653,7 @@ def test_nxos_ospf_interfaces_authentication_key_replaced(self): ip ospf authentication-key 7 712090404011C031628 interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict( @@ -699,10 +664,8 @@ def test_nxos_ospf_interfaces_authentication_key_replaced(self): address_family=[ dict( afi="ipv4", - authentication_key=dict( - encryption=0, key="password" - ), - ) + authentication_key=dict(encryption=0, key="password"), + ), ], ), ], @@ -733,7 +696,7 @@ def test_nxos_ospf_interfaces_message_digest_key_merged(self): no switchport interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict( @@ -748,7 +711,7 @@ def test_nxos_ospf_interfaces_message_digest_key_merged(self): encryption=3, key="abc01d272be25d29", ), - ) + ), ], ), dict( @@ -756,10 +719,8 @@ def test_nxos_ospf_interfaces_message_digest_key_merged(self): address_family=[ dict( afi="ipv4", - message_digest_key=dict( - key_id=1, encryption=0, key="password" - ), - ) + message_digest_key=dict(key_id=1, encryption=0, key="password"), + ), ], ), dict( @@ -772,7 +733,7 @@ def test_nxos_ospf_interfaces_message_digest_key_merged(self): encryption=7, key="712090404011C031628", ), - ) + ), ], ), ], @@ -806,7 +767,7 @@ def test_nxos_ospf_interfaces_message_digest_key_replaced(self): no switchport interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict( @@ -817,10 +778,8 @@ def test_nxos_ospf_interfaces_message_digest_key_replaced(self): address_family=[ dict( afi="ipv4", - message_digest_key=dict( - key_id=1, encryption=0, key="password1" - ), - ) + message_digest_key=dict(key_id=1, encryption=0, key="password1"), + ), ], ), ], @@ -857,7 +816,7 @@ def test_nxos_ospf_interfaces_linear_args_1_merged(self): no switchport interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict( @@ -925,22 +884,18 @@ def test_nxos_ospf_interfaces_linear_args_1_replaced(self): no switchport interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict( config=[ dict( name="Ethernet1/1", - address_family=[ - dict(afi="ipv4", cost=200, hello_interval=9000) - ], + address_family=[dict(afi="ipv4", cost=200, hello_interval=9000)], ), dict( name="Ethernet1/2", - address_family=[ - dict(afi="ipv6", cost=180, dead_interval=3000) - ], + address_family=[dict(afi="ipv6", cost=180, dead_interval=3000)], ), ], state="replaced", @@ -980,7 +935,7 @@ def test_nxos_ospf_interfaces_linear_args_2_merged(self): no switchport interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict( @@ -1038,7 +993,7 @@ def test_nxos_ospf_interfaces_linear_args_2_replaced(self): no switchport interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict( @@ -1090,7 +1045,7 @@ def test_nxos_ospf_interfaces_linear_args_3_merged(self): no switchport interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict( @@ -1113,7 +1068,7 @@ def test_nxos_ospf_interfaces_linear_args_3_merged(self): afi="ipv4", passive_interface=True, retransmit_interval=5000, - ) + ), ], ), dict( @@ -1168,7 +1123,7 @@ def test_nxos_ospf_interfaces_linear_args_3_replaced(self): ospfv3 retransmit-interval 5100 interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict( @@ -1217,7 +1172,7 @@ def test_nxos_ospf_interfaces_linear_args_4_merged(self): no switchport interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict( @@ -1225,9 +1180,7 @@ def test_nxos_ospf_interfaces_linear_args_4_merged(self): dict( name="Ethernet1/1", address_family=[ - dict( - afi="ipv4", shutdown=False, transmit_delay=210 - ), + dict(afi="ipv4", shutdown=False, transmit_delay=210), dict(afi="ipv6", shutdown=True), ], ), @@ -1241,12 +1194,8 @@ def test_nxos_ospf_interfaces_linear_args_4_merged(self): dict( name="Ethernet1/3", address_family=[ - dict( - afi="ipv4", shutdown=True, transmit_delay=430 - ), - dict( - afi="ipv6", shutdown=True, transmit_delay=120 - ), + dict(afi="ipv4", shutdown=True, transmit_delay=430), + dict(afi="ipv6", shutdown=True, transmit_delay=120), ], ), ], @@ -1289,7 +1238,7 @@ def test_nxos_ospf_interfaces_linear_args_4_replaced(self): ip ospf transmit-delay 430 interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict( @@ -1333,7 +1282,7 @@ def test_nxos_ospf_interfaces_parsed(self): no switchport interface Ethernet1/4 no switchport - """ + """, ), state="parsed", ), @@ -1352,7 +1301,7 @@ def test_nxos_ospf_interfaces_parsed(self): "area_id": "1.1.1.2", "secondaries": False, }, - } + }, ], }, { @@ -1361,7 +1310,7 @@ def test_nxos_ospf_interfaces_parsed(self): { "process_id": "200", "area": {"area_id": "2.2.2.8"}, - } + }, ], }, ], @@ -1371,10 +1320,8 @@ def test_nxos_ospf_interfaces_parsed(self): "address_family": [ { "afi": "ipv6", - "processes": [ - {"process_id": "210", "multi_areas": ["3.3.3.3"]} - ], - } + "processes": [{"process_id": "210", "multi_areas": ["3.3.3.3"]}], + }, ], }, {"name": "Ethernet1/3"}, @@ -1398,7 +1345,7 @@ def test_nxos_ospf_interfaces_gathered(self): no switchport interface Ethernet1/4 no switchport - """ + """, ) set_module_args(dict(state="gathered"), ignore_provider_arg) gathered = [ @@ -1414,7 +1361,7 @@ def test_nxos_ospf_interfaces_gathered(self): "area_id": "1.1.1.2", "secondaries": False, }, - } + }, ], }, { @@ -1423,7 +1370,7 @@ def test_nxos_ospf_interfaces_gathered(self): { "process_id": "200", "area": {"area_id": "2.2.2.8"}, - } + }, ], }, ], @@ -1433,10 +1380,8 @@ def test_nxos_ospf_interfaces_gathered(self): "address_family": [ { "afi": "ipv6", - "processes": [ - {"process_id": "210", "multi_areas": ["3.3.3.3"]} - ], - } + "processes": [{"process_id": "210", "multi_areas": ["3.3.3.3"]}], + }, ], }, {"name": "Ethernet1/3"}, @@ -1449,7 +1394,7 @@ def test_nxos_ospf_interfaces_sanity(self): # test gathered self.get_config.return_value = dedent( """ - """ + """, ) set_module_args(dict(state="gathered"), ignore_provider_arg) gathered = [] @@ -1473,7 +1418,7 @@ def test_nxos_ospf_interfaces_overridden(self): ip ospf message-digest-key 101 md5 3 109a86e9d947cc5d interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict( @@ -1481,12 +1426,10 @@ def test_nxos_ospf_interfaces_overridden(self): dict( name="Ethernet1/1", address_family=[ - dict( - afi="ipv4", shutdown=False, transmit_delay=300 - ), + dict(afi="ipv4", shutdown=False, transmit_delay=300), dict(afi="ipv6", shutdown=True), ], - ) + ), ], state="overridden", ), @@ -1524,7 +1467,7 @@ def test_nxos_ospf_interfaces_deleted(self): ip ospf message-digest-key 101 md5 3 109a86e9d947cc5d interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict(config=[dict(name="Ethernet1/1")], state="deleted"), @@ -1555,7 +1498,7 @@ def test_nxos_ospf_interfaces_deleted_all(self): ip ospf message-digest-key 101 md5 3 109a86e9d947cc5d interface Ethernet1/4 no switchport - """ + """, ) set_module_args(dict(state="deleted"), ignore_provider_arg) commands = [ @@ -1585,7 +1528,7 @@ def test_nxos_ospf_interfaces_passive_intf(self): no ospfv3 passive-interface interface Ethernet1/4 no switchport - """ + """, ) set_module_args( dict( @@ -1599,21 +1542,15 @@ def test_nxos_ospf_interfaces_passive_intf(self): ), dict( name="Ethernet1/2", - address_family=[ - dict(afi="ipv4", default_passive_interface=True) - ], + address_family=[dict(afi="ipv4", default_passive_interface=True)], ), dict( name="Ethernet1/3", - address_family=[ - dict(afi="ipv6", default_passive_interface=True) - ], + address_family=[dict(afi="ipv6", default_passive_interface=True)], ), dict( name="Ethernet1/4", - address_family=[ - dict(afi="ipv4", default_passive_interface=True) - ], + address_family=[dict(afi="ipv4", default_passive_interface=True)], ), ], state="merged", diff --git a/tests/unit/modules/network/nxos/test_nxos_ospf_vrf.py b/tests/unit/modules/network/nxos/test_nxos_ospf_vrf.py deleted file mode 100644 index 754453301..000000000 --- a/tests/unit/modules/network/nxos/test_nxos_ospf_vrf.py +++ /dev/null @@ -1,116 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# Make coding more python3-ish - -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.plugins.modules import nxos_ospf_vrf -from .nxos_module import TestNxosModule, set_module_args - - -class TestNxosOspfVrfModule(TestNxosModule): - - module = nxos_ospf_vrf - - def setUp(self): - super(TestNxosOspfVrfModule, self).setUp() - - self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_ospf_vrf.load_config" - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_ospf_vrf.get_config" - ) - self.get_config = self.mock_get_config.start() - - def tearDown(self): - super(TestNxosOspfVrfModule, self).tearDown() - self.mock_load_config.stop() - self.mock_get_config.stop() - - def load_fixtures(self, commands=None, device=""): - self.load_config.return_value = None - - def test_nxos_ospf_vrf_present(self): - set_module_args( - dict( - ospf=1, - vrf="test", - timer_throttle_spf_start=50, - timer_throttle_spf_hold=1000, - timer_throttle_spf_max=2000, - timer_throttle_lsa_start=60, - timer_throttle_lsa_hold=1100, - timer_throttle_lsa_max=3000, - bfd="enable", - state="present", - ) - ) - result = self.execute_module(changed=True) - self.assertEqual( - sorted(result["commands"]), - sorted( - [ - "router ospf 1", - "vrf test", - "timers throttle lsa 60 1100 3000", - "timers throttle spf 50 1000 2000", - "bfd", - ] - ), - ) - - def test_nxos_ospf_vrf_absent(self): - set_module_args(dict(ospf=1, vrf="test", state="absent")) - result = self.execute_module(changed=False) - self.assertEqual(result["commands"], []) - - def test_bfd_1(self): - self.get_config.return_value = "router ospf 1\n bfd\nrouter ospf 2" - # enable -> disable - set_module_args(dict(ospf=1, bfd="disable")) - self.execute_module(changed=True, commands=["router ospf 1", "no bfd"]) - - # disable -> enable - set_module_args(dict(ospf=2, bfd="enable")) - self.execute_module(changed=True, commands=["router ospf 2", "bfd"]) - - def test_bfd_2(self): - # enable idempotence - self.get_config.return_value = "router ospf 1\n bfd\nrouter ospf 2" - set_module_args(dict(ospf=1, bfd="enable")) - self.execute_module(changed=False) - - # disable idempotence - set_module_args(dict(ospf=2, bfd="disable")) - self.execute_module(changed=False) - - def test_bfd_3(self): - # absent tests - self.get_config.return_value = "router ospf 1\n bfd\nrouter ospf 2" - set_module_args(dict(ospf=1, state="absent")) - self.execute_module(changed=True, commands=["router ospf 1", "no bfd"]) - - # absent w/bfd disable - set_module_args(dict(ospf=2, state="absent")) - self.execute_module(changed=False) diff --git a/tests/unit/modules/network/nxos/test_nxos_ospfv2.py b/tests/unit/modules/network/nxos/test_nxos_ospfv2.py index 829b4777f..175570499 100644 --- a/tests/unit/modules/network/nxos/test_nxos_ospfv2.py +++ b/tests/unit/modules/network/nxos/test_nxos_ospfv2.py @@ -19,36 +19,33 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type from textwrap import dedent -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - AnsibleFailJson, -) + from ansible_collections.cisco.nxos.plugins.modules import nxos_ospfv2 +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + +from .nxos_module import TestNxosModule, set_module_args -from .nxos_module import TestNxosModule, load_fixture, set_module_args ignore_provider_arg = True class TestNxosOspfv2Module(TestNxosModule): - module = nxos_ospfv2 def setUp(self): super(TestNxosOspfv2Module, self).setUp() self.mock_get_resource_connection = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" - ) - self.get_resource_connection = ( - self.mock_get_resource_connection.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", ) + self.get_resource_connection = self.mock_get_resource_connection.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.ospfv2.ospfv2.Ospfv2Facts.get_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.ospfv2.ospfv2.Ospfv2Facts.get_config", ) self.get_config = self.mock_get_config.start() @@ -85,12 +82,8 @@ def test_nxos_ospfv2_merged(self): dict( area_id="0.0.0.100", filter_list=[ - dict( - route_map="rmap_1", direction="in" - ), - dict( - route_map="rmap_2", direction="out" - ), + dict(route_map="rmap_1", direction="in"), + dict(route_map="rmap_2", direction="out"), ], ranges=[ dict(prefix="198.51.100.64/27"), @@ -103,7 +96,7 @@ def test_nxos_ospfv2_merged(self): ), ], ), - ] + ], ), state="merged", ), @@ -140,7 +133,7 @@ def test_nxos_ospfv2_merged_idempotent(self): area 0.0.0.100 range 198.51.100.64/27 area 0.0.0.100 range 198.51.100.96/27 area 0.0.0.101 authentication message-digest - """ + """, ) set_module_args( dict( @@ -168,12 +161,8 @@ def test_nxos_ospfv2_merged_idempotent(self): dict( area_id="0.0.0.100", filter_list=[ - dict( - route_map="rmap_1", direction="in" - ), - dict( - route_map="rmap_2", direction="out" - ), + dict(route_map="rmap_1", direction="in"), + dict(route_map="rmap_2", direction="out"), ], ranges=[ dict(prefix="198.51.100.64/27"), @@ -186,7 +175,7 @@ def test_nxos_ospfv2_merged_idempotent(self): ), ], ), - ] + ], ), state="merged", ), @@ -209,7 +198,7 @@ def test_nxos_ospfv2_merged_update(self): area 0.0.0.100 range 198.51.100.64/27 area 0.0.0.100 range 198.51.100.96/27 area 0.0.0.101 authentication message-digest - """ + """, ) set_module_args( dict( @@ -223,16 +212,16 @@ def test_nxos_ospfv2_merged_update(self): protocol="eigrp", id="100", route_map="rmap_2", - ) + ), ], areas=[ dict( area_id="0.0.0.101", stub=dict(no_summary=True), - ) + ), ], - ) - ] + ), + ], ), state="merged", ), @@ -262,7 +251,7 @@ def test_nxos_ospfv2_replaced(self): area 0.0.0.100 range 198.51.100.64/27 area 0.0.0.100 range 198.51.100.96/27 area 0.0.0.101 authentication message-digest - """ + """, ) set_module_args( dict( @@ -275,10 +264,10 @@ def test_nxos_ospfv2_replaced(self): dict( area_id="0.0.0.101", stub=dict(no_summary=True), - ) + ), ], - ) - ] + ), + ], ), state="replaced", ), @@ -307,7 +296,7 @@ def test_nxos_ospfv2_replaced_idempotent(self): area 0.0.0.100 range 198.51.100.64/27 area 0.0.0.100 range 198.51.100.96/27 area 0.0.0.101 authentication message-digest - """ + """, ) set_module_args( dict( @@ -335,12 +324,8 @@ def test_nxos_ospfv2_replaced_idempotent(self): dict( area_id="0.0.0.100", filter_list=[ - dict( - route_map="rmap_1", direction="in" - ), - dict( - route_map="rmap_2", direction="out" - ), + dict(route_map="rmap_1", direction="in"), + dict(route_map="rmap_2", direction="out"), ], ranges=[ dict(prefix="198.51.100.64/27"), @@ -353,7 +338,7 @@ def test_nxos_ospfv2_replaced_idempotent(self): ), ], ), - ] + ], ), state="replaced", ), @@ -376,15 +361,11 @@ def test_nxos_ospfv2_overridden(self): area 0.0.0.100 range 198.51.100.64/27 area 0.0.0.100 range 198.51.100.96/27 area 0.0.0.101 authentication message-digest - """ + """, ) set_module_args( dict( - config=dict( - processes=[ - dict(process_id="300", router_id="203.0.113.20") - ] - ), + config=dict(processes=[dict(process_id="300", router_id="203.0.113.20")]), state="overridden", ), ignore_provider_arg, @@ -412,7 +393,7 @@ def test_nxos_ospfv2_overridden_idempotent(self): area 0.0.0.100 range 198.51.100.64/27 area 0.0.0.100 range 198.51.100.96/27 area 0.0.0.101 authentication message-digest - """ + """, ) set_module_args( dict( @@ -440,12 +421,8 @@ def test_nxos_ospfv2_overridden_idempotent(self): dict( area_id="0.0.0.100", filter_list=[ - dict( - route_map="rmap_1", direction="in" - ), - dict( - route_map="rmap_2", direction="out" - ), + dict(route_map="rmap_1", direction="in"), + dict(route_map="rmap_2", direction="out"), ], ranges=[ dict(prefix="198.51.100.64/27"), @@ -458,7 +435,7 @@ def test_nxos_ospfv2_overridden_idempotent(self): ), ], ), - ] + ], ), state="overridden", ), @@ -483,13 +460,11 @@ def test_nxos_ospfv2_deleted(self): area 0.0.0.101 authentication message-digest router ospf 300 router-id 192.0.168.102 - """ + """, ) set_module_args( dict( - config=dict( - processes=[dict(process_id="100"), dict(process_id="300")] - ), + config=dict(processes=[dict(process_id="100"), dict(process_id="300")]), state="deleted", ), ignore_provider_arg, @@ -515,13 +490,11 @@ def test_nxos_ospfv2_deleted_idempotent(self): area 0.0.0.101 authentication message-digest router ospf 300 router-id 192.0.168.102 - """ + """, ) set_module_args( dict( - config=dict( - processes=[dict(process_id="400"), dict(process_id="500")] - ), + config=dict(processes=[dict(process_id="400"), dict(process_id="500")]), state="deleted", ), ignore_provider_arg, @@ -546,7 +519,7 @@ def test_nxos_ospfv2_deleted_all(self): area 0.0.0.101 authentication message-digest router ospf 300 router-id 192.0.168.102 - """ + """, ) set_module_args(dict(state="deleted"), ignore_provider_arg) @@ -566,7 +539,7 @@ def test_nxos_ospfv2_process_id_word(self): router-id 203.0.113.20 router ospf TEST-1 router-id 198.51.100.1 - """ + """, ) set_module_args( dict( @@ -575,7 +548,7 @@ def test_nxos_ospfv2_process_id_word(self): dict(process_id="100", router_id="203.0.113.20"), dict(process_id="TEST-1", router_id="198.51.100.1"), dict(process_id="TEST-2", router_id="198.52.200.1"), - ] + ], ), state="merged", ), diff --git a/tests/unit/modules/network/nxos/test_nxos_ospfv3.py b/tests/unit/modules/network/nxos/test_nxos_ospfv3.py index aa38f7c40..70a2ae47e 100644 --- a/tests/unit/modules/network/nxos/test_nxos_ospfv3.py +++ b/tests/unit/modules/network/nxos/test_nxos_ospfv3.py @@ -19,22 +19,21 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type from textwrap import dedent -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - AnsibleFailJson, -) + from ansible_collections.cisco.nxos.plugins.modules import nxos_ospfv3 +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + +from .nxos_module import TestNxosModule, set_module_args -from .nxos_module import TestNxosModule, load_fixture, set_module_args ignore_provider_arg = True class TestNxosOspfv3Module(TestNxosModule): - # Testing strategy # ------------------ # (a) The unit tests cover `merged` and `replaced` for every attribute. @@ -52,14 +51,12 @@ def setUp(self): super(TestNxosOspfv3Module, self).setUp() self.mock_get_resource_connection = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" - ) - self.get_resource_connection = ( - self.mock_get_resource_connection.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", ) + self.get_resource_connection = self.mock_get_resource_connection.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.ospfv3.ospfv3.Ospfv3Facts.get_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.ospfv3.ospfv3.Ospfv3Facts.get_config", ) self.get_config = self.mock_get_config.start() @@ -76,7 +73,7 @@ def test_nxos_ospfv3_af_areas_filter_list_merged(self): address-family ipv6 unicast area 1.1.1.1 default-cost 100 area 1.1.1.1 filter-list route-map test-11 in - """ + """, ) set_module_args( dict( @@ -116,8 +113,8 @@ def test_nxos_ospfv3_af_areas_filter_list_merged(self): ), ], ), - ) - ] + ), + ], ), state="merged", ), @@ -142,7 +139,7 @@ def test_nxos_ospfv3_af_areas_filter_list_replaced(self): address-family ipv6 unicast area 1.1.1.4 filter-list route-map test-11 out area 1.1.1.4 filter-list route-map test-12 in - """ + """, ) set_module_args( dict( @@ -182,8 +179,8 @@ def test_nxos_ospfv3_af_areas_filter_list_replaced(self): ), ], ), - ) - ] + ), + ], ), state="replaced", ), @@ -210,7 +207,7 @@ def test_nxos_ospfv3_af_areas_ranges_merged(self): address-family ipv6 unicast area 1.1.1.1 range 2001:db2::/32 area 1.1.1.1 range 2001:db3::/32 cost 10 - """ + """, ) set_module_args( dict( @@ -228,15 +225,13 @@ def test_nxos_ospfv3_af_areas_ranges_merged(self): dict( prefix="2001:db3::/32", cost="20", - ) + ), ], ), dict( area_id="1.1.1.2", ranges=[ - dict( - prefix="2001:db4::/32", cost=11 - ), + dict(prefix="2001:db4::/32", cost=11), dict( prefix="2001:db5::/32", not_advertise=True, @@ -250,8 +245,8 @@ def test_nxos_ospfv3_af_areas_ranges_merged(self): ), ], ), - ) - ] + ), + ], ), state="merged", ), @@ -276,7 +271,7 @@ def test_nxos_ospfv3_af_areas_ranges_replaced(self): address-family ipv6 unicast area 1.1.1.1 range 2001:db2::/32 area 1.1.1.1 range 2001:db3::/32 cost 10 - """ + """, ) set_module_args( dict( @@ -291,9 +286,7 @@ def test_nxos_ospfv3_af_areas_ranges_replaced(self): dict( area_id="1.1.1.2", ranges=[ - dict( - prefix="2001:db4::/32", cost=11 - ), + dict(prefix="2001:db4::/32", cost=11), dict( prefix="2001:db5::/32", not_advertise=True, @@ -304,11 +297,11 @@ def test_nxos_ospfv3_af_areas_ranges_replaced(self): cost=18, ), ], - ) + ), ], ), - ) - ] + ), + ], ), state="replaced", ), @@ -333,7 +326,7 @@ def test_nxos_ospfv3_af_areas_default_cost_merged(self): router ospfv3 100 address-family ipv6 unicast area 1.1.1.1 default-cost 10 - """ + """, ) set_module_args( dict( @@ -349,8 +342,8 @@ def test_nxos_ospfv3_af_areas_default_cost_merged(self): dict(area_id="1.1.1.2", default_cost=200), ], ), - ) - ] + ), + ], ), state="merged", ), @@ -372,7 +365,7 @@ def test_nxos_ospfv3_af_areas_default_cost_replaced(self): router ospfv3 100 address-family ipv6 unicast area 1.1.1.1 default-cost 10 - """ + """, ) set_module_args( dict( @@ -383,12 +376,10 @@ def test_nxos_ospfv3_af_areas_default_cost_replaced(self): address_family=dict( afi="ipv6", safi="unicast", - areas=[ - dict(area_id="1.1.1.2", default_cost=200) - ], + areas=[dict(area_id="1.1.1.2", default_cost=200)], ), - ) - ] + ), + ], ), state="replaced", ), @@ -410,7 +401,7 @@ def test_nxos_ospfv3_af_default_information_merged(self): router ospfv3 100 address-family ipv6 unicast default-information originate - """ + """, ) set_module_args( dict( @@ -422,13 +413,11 @@ def test_nxos_ospfv3_af_default_information_merged(self): afi="ipv6", safi="unicast", default_information=dict( - originate=dict( - always=True, route_map="test-2" - ) + originate=dict(always=True, route_map="test-2"), ), ), - ) - ] + ), + ], ), state="merged", ), @@ -449,7 +438,7 @@ def test_nxos_ospfv3_af_default_information_merged_2(self): router ospfv3 100 address-family ipv6 unicast default-information originate always route-map test-2 - """ + """, ) set_module_args( dict( @@ -460,12 +449,10 @@ def test_nxos_ospfv3_af_default_information_merged_2(self): address_family=dict( afi="ipv6", safi="unicast", - default_information=dict( - originate=dict(set=False) - ), + default_information=dict(originate=dict(set=False)), ), - ) - ] + ), + ], ), state="merged", ), @@ -486,7 +473,7 @@ def test_nxos_ospfv3_af_default_information_replaced(self): router ospfv3 100 address-family ipv6 unicast default-information originate always test-2 - """ + """, ) set_module_args( dict( @@ -497,12 +484,10 @@ def test_nxos_ospfv3_af_default_information_replaced(self): address_family=dict( afi="ipv6", safi="unicast", - default_information=dict( - originate=dict(set=True) - ), + default_information=dict(originate=dict(set=True)), ), - ) - ] + ), + ], ), state="replaced", ), @@ -523,7 +508,7 @@ def test_nxos_ospfv3_af_distance_merged(self): router ospfv3 100 address-family ipv6 unicast distance 20 - """ + """, ) set_module_args( dict( @@ -531,11 +516,9 @@ def test_nxos_ospfv3_af_distance_merged(self): processes=[ dict( process_id="100", - address_family=dict( - afi="ipv6", safi="unicast", distance=35 - ), - ) - ] + address_family=dict(afi="ipv6", safi="unicast", distance=35), + ), + ], ), state="merged", ), @@ -558,7 +541,7 @@ def test_nxos_ospfv3_af_distance_replaced(self): router ospfv3 100 address-family ipv6 unicast distance 20 - """ + """, ) set_module_args( dict( @@ -567,8 +550,8 @@ def test_nxos_ospfv3_af_distance_replaced(self): dict( process_id="100", address_family=dict(afi="ipv6", safi="unicast"), - ) - ] + ), + ], ), state="replaced", ), @@ -589,7 +572,7 @@ def test_nxos_ospfv3_af_maximum_paths_merged(self): router ospfv3 100 address-family ipv6 unicast maximum-paths 18 - """ + """, ) set_module_args( dict( @@ -597,11 +580,9 @@ def test_nxos_ospfv3_af_maximum_paths_merged(self): processes=[ dict( process_id="100", - address_family=dict( - afi="ipv6", safi="unicast", maximum_paths=27 - ), - ) - ] + address_family=dict(afi="ipv6", safi="unicast", maximum_paths=27), + ), + ], ), state="replaced", ), @@ -624,7 +605,7 @@ def test_nxos_ospfv3_af_maximum_paths_replaced(self): router ospfv3 100 address-family ipv6 unicast maximum-paths 18 - """ + """, ) set_module_args( dict( @@ -633,8 +614,8 @@ def test_nxos_ospfv3_af_maximum_paths_replaced(self): dict( process_id="100", address_family=dict(afi="ipv6", safi="unicast"), - ) - ] + ), + ], ), state="replaced", ), @@ -655,7 +636,7 @@ def test_nxos_ospfv3_af_redistribute_merged(self): router ospfv3 100 address-family ipv6 unicast redistribute eigrp 100 route-map test-17 - """ + """, ) set_module_args( dict( @@ -682,13 +663,11 @@ def test_nxos_ospfv3_af_redistribute_merged(self): id="65563", route_map="test-3", ), - dict( - protocol="static", route_map="test-4" - ), + dict(protocol="static", route_map="test-4"), ], ), - ) - ] + ), + ], ), state="merged", ), @@ -712,7 +691,7 @@ def test_nxos_ospfv3_af_redistribute_replaced(self): router ospfv3 100 address-family ipv6 unicast redistribute eigrp 100 route-map test-1 - """ + """, ) set_module_args( dict( @@ -734,13 +713,11 @@ def test_nxos_ospfv3_af_redistribute_replaced(self): id="65563", route_map="test-3", ), - dict( - protocol="static", route_map="test-4" - ), + dict(protocol="static", route_map="test-4"), ], ), - ) - ] + ), + ], ), state="replaced", ), @@ -764,7 +741,7 @@ def test_nxos_ospfv3_af_summary_address_merged(self): router ospfv3 100 address-family ipv6 unicast summary-address 2001:db2::/32 - """ + """, ) set_module_args( dict( @@ -784,8 +761,8 @@ def test_nxos_ospfv3_af_summary_address_merged(self): dict(prefix="2001:db4::/32"), ], ), - ) - ] + ), + ], ), state="merged", ), @@ -808,7 +785,7 @@ def test_nxos_ospfv3_af_summary_address_replaced(self): router ospfv3 100 address-family ipv6 unicast summary-address 2001:db2::/32 tag 19 - """ + """, ) set_module_args( dict( @@ -823,11 +800,11 @@ def test_nxos_ospfv3_af_summary_address_replaced(self): dict( prefix="2001:db3::/32", not_advertise=True, - ) + ), ], ), - ) - ] + ), + ], ), state="replaced", ), @@ -849,7 +826,7 @@ def test_nxos_ospfv3_af_table_map_merged(self): router ospfv3 100 address-family ipv6 unicast summary-address 2001:db2::/32 tag 19 - """ + """, ) set_module_args( dict( @@ -862,8 +839,8 @@ def test_nxos_ospfv3_af_table_map_merged(self): safi="unicast", table_map=dict(name="test-1", filter=True), ), - ) - ] + ), + ], ), state="merged", ), @@ -884,7 +861,7 @@ def test_nxos_ospfv3_af_table_map_replaced(self): router ospfv3 100 address-family ipv6 unicast table-map test-1 filter - """ + """, ) set_module_args( dict( @@ -897,8 +874,8 @@ def test_nxos_ospfv3_af_table_map_replaced(self): safi="unicast", table_map=dict(name="test-2"), ), - ) - ] + ), + ], ), state="replaced", ), @@ -919,7 +896,7 @@ def test_nxos_ospfv3_af_timers_merged(self): router ospfv3 100 address-family ipv6 unicast timers throttle spf 1000 20 2800 - """ + """, ) set_module_args( dict( @@ -935,12 +912,12 @@ def test_nxos_ospfv3_af_timers_merged(self): spf=dict( initial_spf_delay=1100, max_wait_time=2805, - ) - ) + ), + ), ), ), - ) - ] + ), + ], ), state="merged", ), @@ -961,7 +938,7 @@ def test_nxos_ospfv3_af_timers_replaced(self): router ospfv3 100 address-family ipv6 unicast timers throttle spf 1000 20 2800 - """ + """, ) set_module_args( dict( @@ -970,8 +947,8 @@ def test_nxos_ospfv3_af_timers_replaced(self): dict( process_id="100", address_family=dict(afi="ipv6", safi="unicast"), - ) - ] + ), + ], ), state="replaced", ), @@ -991,7 +968,7 @@ def test_nxos_ospfv3_areas_nssa_merged(self): """\ router ospfv3 100 area 1.1.1.1 nssa no-redistribution default-information-originate - """ + """, ) set_module_args( dict( @@ -1012,16 +989,12 @@ def test_nxos_ospfv3_areas_nssa_merged(self): no_summary=True, no_redistribution=True, route_map="test-1", - translate=dict( - type7=dict( - always=True, supress_fa=True - ) - ), + translate=dict(type7=dict(always=True, supress_fa=True)), ), ), ], - ) - ] + ), + ], ), state="merged", ), @@ -1043,7 +1016,7 @@ def test_nxos_ospfv3_areas_nssa_merged_2(self): """\ router ospfv3 100 area 1.1.1.1 nssa no-summary - """ + """, ) set_module_args( dict( @@ -1051,11 +1024,9 @@ def test_nxos_ospfv3_areas_nssa_merged_2(self): processes=[ dict( process_id="100", - areas=[ - dict(area_id="1.1.1.1", nssa=dict(set=False)) - ], - ) - ] + areas=[dict(area_id="1.1.1.1", nssa=dict(set=False))], + ), + ], ), state="merged", ), @@ -1072,7 +1043,7 @@ def test_nxos_ospfv3_areas_nssa_replaced(self): router ospfv3 100 area 1.1.1.1 nssa no-summary no-redistribution default-information-originate area 1.1.1.3 nssa translate type7 always supress-fa - """ + """, ) set_module_args( dict( @@ -1089,10 +1060,10 @@ def test_nxos_ospfv3_areas_nssa_replaced(self): no_redistribution=True, route_map="test-1", ), - ) + ), ], - ) - ] + ), + ], ), state="replaced", ), @@ -1113,7 +1084,7 @@ def test_nxos_ospfv3_areas_stub_merged(self): """\ router ospfv3 100 area 1.1.1.3 stub - """ + """, ) set_module_args( dict( @@ -1125,10 +1096,10 @@ def test_nxos_ospfv3_areas_stub_merged(self): dict( area_id="1.1.1.3", stub=dict(no_summary=True), - ) + ), ], - ) - ] + ), + ], ), state="merged", ), @@ -1144,7 +1115,7 @@ def test_nxos_ospfv3_areas_stub_merged_2(self): """\ router ospfv3 100 area 1.1.1.3 stub - """ + """, ) set_module_args( dict( @@ -1159,8 +1130,8 @@ def test_nxos_ospfv3_areas_stub_merged_2(self): stub=dict(no_summary=True), ), ], - ) - ] + ), + ], ), state="merged", ), @@ -1180,15 +1151,11 @@ def test_nxos_ospfv3_areas_stub_replaced(self): """\ router ospfv3 100 area 1.1.1.3 stub no-summary - """ + """, ) set_module_args( dict( - config=dict( - processes=[ - dict(process_id="100", areas=[dict(area_id="1.1.1.3")]) - ] - ), + config=dict(processes=[dict(process_id="100", areas=[dict(area_id="1.1.1.3")])]), state="replaced", ), ignore_provider_arg, @@ -1203,7 +1170,7 @@ def test_nxos_ospfv3_autocost_flush_route_isolate_merged(self): """\ router ospfv3 100 auto-cost reference-bandwidth 300 Mbps - """ + """, ) set_module_args( dict( @@ -1211,13 +1178,11 @@ def test_nxos_ospfv3_autocost_flush_route_isolate_merged(self): processes=[ dict( process_id="100", - auto_cost=dict( - reference_bandwidth=100, unit="Gbps" - ), + auto_cost=dict(reference_bandwidth=100, unit="Gbps"), flush_routes=True, isolate=True, - ) - ] + ), + ], ), state="merged", ), @@ -1239,7 +1204,7 @@ def test_nxos_ospfv3_autocost_flush_route_isolate_replaced(self): router ospfv3 100 auto-cost reference-bandwidth 300 Mbps flush-routes - """ + """, ) set_module_args( dict( @@ -1265,7 +1230,7 @@ def test_nxos_ospfv3_log_adjacency_changes_name_lookup_passive_interface_merged( """\ router ospfv3 100 log-adjacency-changes - """ + """, ) set_module_args( dict( @@ -1281,7 +1246,7 @@ def test_nxos_ospfv3_log_adjacency_changes_name_lookup_passive_interface_merged( process_id="102", log_adjacency_changes=dict(log=True), ), - ] + ], ), state="merged", ), @@ -1307,7 +1272,7 @@ def test_nxos_ospfv3_log_adjacency_changes_name_lookup_passive_interface_replace router ospfv3 100 log-adjacency-changes detail name-lookup - """ + """, ) set_module_args( dict( @@ -1316,8 +1281,8 @@ def test_nxos_ospfv3_log_adjacency_changes_name_lookup_passive_interface_replace dict( process_id="100", passive_interface=dict(default=True), - ) - ] + ), + ], ), state="replaced", ), @@ -1341,7 +1306,7 @@ def test_nxos_ospfv3_max_lsa_router_id_merged(self): max-lsa 4200 85 ignore-count 10 reset-time 120 router ospfv3 102 max-lsa 4200 85 ignore-time 120 ignore-count 12 reset-time 300 - """ + """, ) set_module_args( dict( @@ -1375,7 +1340,7 @@ def test_nxos_ospfv3_max_lsa_router_id_merged(self): warning_only=True, ), ), - ] + ], ), state="merged", ), @@ -1402,7 +1367,7 @@ def test_nxos_ospfv3_max_lsa_router_id_replaced(self): max-lsa 4200 85 ignore-count 10 reset-time 120 router ospfv3 102 max-lsa 4200 85 ignore-time 120 ignore-count 12 reset-time 300 - """ + """, ) set_module_args( dict( @@ -1415,8 +1380,8 @@ def test_nxos_ospfv3_max_lsa_router_id_replaced(self): threshold=85, warning_only=True, ), - ) - ] + ), + ], ), state="replaced", ), @@ -1438,7 +1403,7 @@ def test_nxos_ospfv3_graceful_restart_merged(self): no graceful-restart router ospfv3 102 no graceful-restart planned-only - """ + """, ) set_module_args( dict( @@ -1446,15 +1411,13 @@ def test_nxos_ospfv3_graceful_restart_merged(self): processes=[ dict( process_id="100", - graceful_restart=dict( - grace_period=50, helper_disable=True - ), + graceful_restart=dict(grace_period=50, helper_disable=True), ), dict( process_id="102", graceful_restart=dict(planned_only=True), ), - ] + ], ), state="merged", ), @@ -1478,7 +1441,7 @@ def test_nxos_ospfv3_graceful_restart_replaced(self): graceful-restart grace-period 50 graceful-restart helper-disable router ospfv3 102 - """ + """, ) set_module_args( dict( @@ -1492,7 +1455,7 @@ def test_nxos_ospfv3_graceful_restart_replaced(self): process_id="102", graceful_restart=dict(helper_disable=True), ), - ] + ], ), state="replaced", ), @@ -1514,7 +1477,7 @@ def test_nxos_ospfv3_max_metric_merged(self): """\ router ospfv3 100 max-metric router-lsa external-lsa 1900 - """ + """, ) set_module_args( dict( @@ -1527,17 +1490,13 @@ def test_nxos_ospfv3_max_metric_merged(self): external_lsa=dict(max_metric_value=2000), stub_prefix_lsa=True, on_startup=dict(set=True), - ) + ), ), ), dict( process_id="102", max_metric=dict( - router_lsa=dict( - inter_area_prefix_lsa=dict( - max_metric_value=1800 - ) - ) + router_lsa=dict(inter_area_prefix_lsa=dict(max_metric_value=1800)), ), ), dict( @@ -1549,10 +1508,10 @@ def test_nxos_ospfv3_max_metric_merged(self): wait_for_bgp_asn=65563, ), inter_area_prefix_lsa=dict(set=True), - ) + ), ), ), - ] + ], ), state="merged", ), @@ -1577,7 +1536,7 @@ def test_nxos_ospfv3_max_metric_merged_2(self): max-metric router-lsa inter-area-prefix-lsa 1800 router ospfv3 103 max-metric router-lsa on-startup 1200 wait-for bgp 65563 inter-area-prefix-lsa - """ + """, ) set_module_args( dict( @@ -1586,8 +1545,8 @@ def test_nxos_ospfv3_max_metric_merged_2(self): dict( process_id="100", max_metric=dict(router_lsa=dict(set=False)), - ) - ] + ), + ], ), state="merged", ), @@ -1606,7 +1565,7 @@ def test_nxos_ospfv3_max_metric_replaced(self): max-metric router-lsa inter-area-prefix-lsa 1800 router ospfv3 103 max-metric router-lsa on-startup 1200 wait-for bgp 65563 inter-area-prefix-lsa - """ + """, ) set_module_args( dict( @@ -1619,12 +1578,12 @@ def test_nxos_ospfv3_max_metric_replaced(self): external_lsa=dict(max_metric_value=2000), stub_prefix_lsa=True, on_startup=dict(set=True), - ) + ), ), ), dict(process_id="102"), dict(process_id="103"), - ] + ], ), state="replaced", ), @@ -1648,7 +1607,7 @@ def test_nxos_ospfv3_timers_shutdown_merged(self): router ospfv3 100 timers lsa-group-pacing 190 shutdown - """ + """, ) set_module_args( dict( @@ -1664,12 +1623,12 @@ def test_nxos_ospfv3_timers_shutdown_merged(self): start_interval=100, hold_interval=70, max_interval=1500, - ) + ), ), ), shutdown=False, - ) - ] + ), + ], ), state="merged", ), @@ -1693,7 +1652,7 @@ def test_nxos_ospfv3_timers_shutdown_replaced(self): timers lsa-arrival 800 timers lsa-group-pacing 210 timers throttle lsa 100 70 1500 - """ + """, ) set_module_args( dict( @@ -1703,8 +1662,8 @@ def test_nxos_ospfv3_timers_shutdown_replaced(self): process_id="100", timers=dict(lsa_arrival=1200), shutdown=True, - ) - ] + ), + ], ), state="replaced", ), @@ -1727,7 +1686,7 @@ def test_nxos_ospfv3_vrf_merged(self): router ospfv3 100 vrf blue area 1.1.1.1 nssa - """ + """, ) set_module_args( dict( @@ -1763,10 +1722,10 @@ def test_nxos_ospfv3_vrf_merged(self): type7=dict( always=True, supress_fa=True, - ) + ), ), ), - ) + ), ], ), ], @@ -1782,12 +1741,10 @@ def test_nxos_ospfv3_vrf_merged(self): wait_period=1200, wait_for_bgp_asn=65563, ), - inter_area_prefix_lsa=dict( - set=True - ), - ) + inter_area_prefix_lsa=dict(set=True), + ), ), - ) + ), ], ), dict( @@ -1803,14 +1760,14 @@ def test_nxos_ospfv3_vrf_merged(self): start_interval=100, hold_interval=70, max_interval=1500, - ) + ), ), ), shutdown=True, - ) + ), ], ), - ] + ], ), state="merged", ), @@ -1857,7 +1814,7 @@ def test_nxos_ospfv3_vrf_replaced(self): timers lsa-group-pacing 210 timers throttle lsa 100 70 1500 shutdown - """ + """, ) set_module_args( dict( @@ -1877,15 +1834,15 @@ def test_nxos_ospfv3_vrf_replaced(self): type7=dict( always=True, supress_fa=True, - ) + ), ), ), - ) + ), ], - ) + ), ], - ) - ] + ), + ], ), state="replaced", ), @@ -1909,7 +1866,7 @@ def test_nxos_ospfv3_top_spec_af_vrf_merged(self): router ospfv3 100 address-family ipv6 unicast table-map map1 filter - """ + """, ) set_module_args( dict( @@ -1925,7 +1882,7 @@ def test_nxos_ospfv3_top_spec_af_vrf_merged(self): protocol="eigrp", id="100", route_map="rmap1", - ) + ), ], ), vrfs=[ @@ -1936,7 +1893,7 @@ def test_nxos_ospfv3_top_spec_af_vrf_merged(self): dict( area_id="1.1.1.1", nssa=dict(set=True), - ) + ), ], ), ], @@ -1945,7 +1902,7 @@ def test_nxos_ospfv3_top_spec_af_vrf_merged(self): process_id="103", vrfs=[dict(vrf="red", shutdown=True)], ), - ] + ], ), state="merged", ), @@ -1981,7 +1938,7 @@ def test_nxos_ospfv3_top_spec_af_vrf_replaced(self): router ospfv3 103 vrf red shutdown - """ + """, ) set_module_args( dict( @@ -1997,11 +1954,11 @@ def test_nxos_ospfv3_top_spec_af_vrf_replaced(self): protocol="eigrp", id="100", route_map="rmap1", - ) + ), ], ), - ) - ] + ), + ], ), state="replaced", ), @@ -2032,7 +1989,7 @@ def test_nxos_ospfv3_top_spec_af_vrf_overridden(self): router ospfv3 103 vrf red shutdown - """ + """, ) set_module_args( dict( @@ -2048,11 +2005,11 @@ def test_nxos_ospfv3_top_spec_af_vrf_overridden(self): protocol="eigrp", id="100", route_map="rmap2", - ) + ), ], ), - ) - ] + ), + ], ), state="overridden", ), @@ -2085,7 +2042,7 @@ def test_nxos_ospfv3_top_spec_af_vrf_deleted(self): router ospfv3 103 vrf red shutdown - """ + """, ) set_module_args( dict( @@ -2113,7 +2070,7 @@ def test_nxos_ospfv3_top_spec_af_vrf_deleted_all(self): router ospfv3 103 vrf red shutdown - """ + """, ) set_module_args(dict(state="deleted"), ignore_provider_arg) commands = ["no router ospfv3 100", "no router ospfv3 103"] @@ -2137,7 +2094,7 @@ def test_nxos_ospfv3_parsed(self): router ospfv3 103 vrf red shutdown - """ + """, ), state="parsed", ), @@ -2154,7 +2111,7 @@ def test_nxos_ospfv3_parsed(self): "protocol": "eigrp", "id": "100", "route_map": "rmap1", - } + }, ], "afi": "ipv6", "safi": "unicast", @@ -2163,9 +2120,7 @@ def test_nxos_ospfv3_parsed(self): {"vrf": "blue", "router_id": "10.0.0.2"}, { "vrf": "red", - "areas": [ - {"area_id": "1.1.1.1", "nssa": {"set": True}} - ], + "areas": [{"area_id": "1.1.1.1", "nssa": {"set": True}}], }, ], }, @@ -2173,7 +2128,7 @@ def test_nxos_ospfv3_parsed(self): "process_id": "103", "vrfs": [{"vrf": "red", "shutdown": True}], }, - ] + ], } result = self.execute_module(changed=False) self.assertEqual(set(result["parsed"]), set(parsed)) @@ -2193,7 +2148,7 @@ def test_nxos_ospfv3_gathered(self): router ospfv3 103 vrf red shutdown - """ + """, ) set_module_args(dict(state="gathered"), ignore_provider_arg) gathered = { @@ -2207,7 +2162,7 @@ def test_nxos_ospfv3_gathered(self): "protocol": "eigrp", "id": "100", "route_map": "rmap1", - } + }, ], "afi": "ipv6", "safi": "unicast", @@ -2216,9 +2171,7 @@ def test_nxos_ospfv3_gathered(self): {"vrf": "blue", "router_id": "10.0.0.2"}, { "vrf": "red", - "areas": [ - {"area_id": "1.1.1.1", "nssa": {"set": True}} - ], + "areas": [{"area_id": "1.1.1.1", "nssa": {"set": True}}], }, ], }, @@ -2226,7 +2179,7 @@ def test_nxos_ospfv3_gathered(self): "process_id": "103", "vrfs": [{"vrf": "red", "shutdown": True}], }, - ] + ], } result = self.execute_module(changed=False) self.assertEqual(set(result["gathered"]), set(gathered)) @@ -2238,7 +2191,7 @@ def test_nxos_ospfv3_process_id_word(self): router-id 203.0.113.20 router ospfv3 TEST-1 router-id 198.51.100.1 - """ + """, ) set_module_args( dict( @@ -2247,7 +2200,7 @@ def test_nxos_ospfv3_process_id_word(self): dict(process_id="100", router_id="203.0.113.20"), dict(process_id="TEST-1", router_id="198.51.100.1"), dict(process_id="TEST-2", router_id="198.52.200.1"), - ] + ], ), state="merged", ), diff --git a/tests/unit/modules/network/nxos/test_nxos_overlay_global.py b/tests/unit/modules/network/nxos/test_nxos_overlay_global.py index 4ec526924..976aa0964 100644 --- a/tests/unit/modules/network/nxos/test_nxos_overlay_global.py +++ b/tests/unit/modules/network/nxos/test_nxos_overlay_global.py @@ -19,26 +19,27 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from ansible_collections.cisco.nxos.plugins.modules import nxos_overlay_global +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from .nxos_module import TestNxosModule, load_fixture, set_module_args class TestNxosOverlayGlobalModule(TestNxosModule): - module = nxos_overlay_global def setUp(self): super(TestNxosOverlayGlobalModule, self).setUp() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_overlay_global.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_overlay_global.load_config", ) self.load_config = self.mock_load_config.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_overlay_global.get_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_overlay_global.get_config", ) self.get_config = self.mock_get_config.start() @@ -48,9 +49,7 @@ def tearDown(self): self.mock_get_config.stop() def load_fixtures(self, commands=None, device=""): - self.get_config.return_value = load_fixture( - "", "nxos_overlay_global_config.cfg" - ) + self.get_config.return_value = load_fixture("", "nxos_overlay_global_config.cfg") self.load_config.return_value = None def test_nxos_overlay_global_up(self): diff --git a/tests/unit/modules/network/nxos/test_nxos_pim.py b/tests/unit/modules/network/nxos/test_nxos_pim.py index 66fe01628..eea384836 100644 --- a/tests/unit/modules/network/nxos/test_nxos_pim.py +++ b/tests/unit/modules/network/nxos/test_nxos_pim.py @@ -19,27 +19,28 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from ansible_collections.cisco.nxos.plugins.modules import nxos_pim +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from .nxos_module import TestNxosModule, load_fixture, set_module_args class TestNxosPimModule(TestNxosModule): - module = nxos_pim def setUp(self): super(TestNxosPimModule, self).setUp() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_pim.get_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_pim.get_config", ) self.get_config = self.mock_get_config.start() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_pim.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_pim.load_config", ) self.load_config = self.mock_load_config.start() @@ -55,17 +56,13 @@ def test_nxos_pim_1(self): # Add/ Modify self.get_config.return_value = load_fixture("nxos_pim", "config.cfg") set_module_args(dict(ssm_range="233.0.0.0/8")) - self.execute_module( - changed=True, commands=["ip pim ssm range 233.0.0.0/8"] - ) + self.execute_module(changed=True, commands=["ip pim ssm range 233.0.0.0/8"]) def test_nxos_pim_2(self): # Remove existing values self.get_config.return_value = load_fixture("nxos_pim", "config.cfg") set_module_args(dict(bfd="disable", ssm_range="none")) - self.execute_module( - changed=True, commands=["no ip pim bfd", "ip pim ssm range none"] - ) + self.execute_module(changed=True, commands=["no ip pim bfd", "ip pim ssm range none"]) def test_nxos_pim_3(self): # bfd None (disable)-> enable @@ -91,9 +88,7 @@ def test_nxos_pim_5(self): # SSM 'default' self.get_config.return_value = load_fixture("nxos_pim", "config.cfg") set_module_args(dict(ssm_range="default")) - self.execute_module( - changed=True, commands=["no ip pim ssm range none"] - ) + self.execute_module(changed=True, commands=["no ip pim ssm range none"]) # SSM 'default' idempotence self.get_config.return_value = None diff --git a/tests/unit/modules/network/nxos/test_nxos_pim_interface.py b/tests/unit/modules/network/nxos/test_nxos_pim_interface.py index a5ec2ad86..b746b8b46 100644 --- a/tests/unit/modules/network/nxos/test_nxos_pim_interface.py +++ b/tests/unit/modules/network/nxos/test_nxos_pim_interface.py @@ -19,32 +19,33 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from ansible_collections.cisco.nxos.plugins.modules import nxos_pim_interface +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from .nxos_module import TestNxosModule, load_fixture, set_module_args class TestNxosIPInterfaceModule(TestNxosModule): - module = nxos_pim_interface def setUp(self): super(TestNxosIPInterfaceModule, self).setUp() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_pim_interface.get_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_pim_interface.get_config", ) self.get_config = self.mock_get_config.start() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_pim_interface.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_pim_interface.load_config", ) self.load_config = self.mock_load_config.start() self.mock_run_commands = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_pim_interface.run_commands" + "ansible_collections.cisco.nxos.plugins.modules.nxos_pim_interface.run_commands", ) self.run_commands = self.mock_run_commands.start() @@ -62,14 +63,9 @@ def load_from_file(*args, **kwargs): output = list() for command in commands: - if type(command) == dict: + if isinstance(command, dict): command = command["command"] - filename = ( - str(command) - .split(" | ", 1)[0] - .replace(" ", "_") - .replace("/", "_") - ) + filename = str(command).split(" | ", 1)[0].replace(" ", "_").replace("/", "_") output.append(load_fixture(module_name, filename)) return output @@ -85,7 +81,7 @@ def test_nxos_pim_interface_present(self): hello_interval=40, sparse=True, border=False, - ) + ), ) self.execute_module( changed=True, @@ -105,7 +101,7 @@ def test_nxos_pim_interface_jp(self): jp_policy_out="JPOUT", jp_type_in="routemap", jp_type_out="routemap", - ) + ), ) self.execute_module( changed=True, @@ -126,29 +122,28 @@ def test_nxos_pim_interface_ip_absent(self): class TestNxosPimInterfaceBfdModule(TestNxosModule): - module = nxos_pim_interface def setUp(self): super(TestNxosPimInterfaceBfdModule, self).setUp() self.mock_get_interface_mode = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_pim_interface.get_interface_mode" + "ansible_collections.cisco.nxos.plugins.modules.nxos_pim_interface.get_interface_mode", ) self.get_interface_mode = self.mock_get_interface_mode.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_pim_interface.get_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_pim_interface.get_config", ) self.get_config = self.mock_get_config.start() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_pim_interface.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_pim_interface.load_config", ) self.load_config = self.mock_load_config.start() self.mock_run_commands = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_pim_interface.run_commands" + "ansible_collections.cisco.nxos.plugins.modules.nxos_pim_interface.run_commands", ) self.run_commands = self.mock_run_commands.start() @@ -166,9 +161,7 @@ def test_bfd_1(self): # default (None) -> enable self.get_config.return_value = None set_module_args(dict(interface="eth2/1", bfd="enable")) - self.execute_module( - changed=True, commands=["interface eth2/1", "ip pim bfd-instance"] - ) + self.execute_module(changed=True, commands=["interface eth2/1", "ip pim bfd-instance"]) # default (None) -> disable set_module_args(dict(interface="eth2/1", bfd="disable")) @@ -275,7 +268,7 @@ def test_bfd_4(self): interface="Ethernet9/2", hello_interval=1, hello_interval_ms=True, - ) + ), ) self.execute_module( changed=True, @@ -288,7 +281,7 @@ def test_bfd_4(self): interface="Ethernet9/2", hello_interval=1000, hello_interval_ms=True, - ) + ), ) self.execute_module(changed=False, commands=[]) diff --git a/tests/unit/modules/network/nxos/test_nxos_pim_rp_address.py b/tests/unit/modules/network/nxos/test_nxos_pim_rp_address.py index ebff3a47b..f4dbd13ac 100644 --- a/tests/unit/modules/network/nxos/test_nxos_pim_rp_address.py +++ b/tests/unit/modules/network/nxos/test_nxos_pim_rp_address.py @@ -19,27 +19,28 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from ansible_collections.cisco.nxos.plugins.modules import nxos_pim_rp_address +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from .nxos_module import TestNxosModule, load_fixture, set_module_args class TestNxosPimRpAddressModule(TestNxosModule): - module = nxos_pim_rp_address def setUp(self): super(TestNxosPimRpAddressModule, self).setUp() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_pim_rp_address.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_pim_rp_address.load_config", ) self.load_config = self.mock_load_config.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_pim_rp_address.get_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_pim_rp_address.get_config", ) self.get_config = self.mock_get_config.start() @@ -49,16 +50,12 @@ def tearDown(self): self.mock_get_config.stop() def load_fixtures(self, commands=None, device=""): - self.get_config.return_value = load_fixture( - "nxos_pim_rp_address", "config.cfg" - ) + self.get_config.return_value = load_fixture("nxos_pim_rp_address", "config.cfg") self.load_config.return_value = None def test_nxos_pim_rp_address(self): set_module_args(dict(rp_address="5.6.7.8")) - self.execute_module( - changed=True, commands=["ip pim rp-address 5.6.7.8"] - ) + self.execute_module(changed=True, commands=["ip pim rp-address 5.6.7.8"]) def test_nxos_pim_rp_address_no_change(self): set_module_args(dict(rp_address="1.2.3.4")) @@ -66,9 +63,7 @@ def test_nxos_pim_rp_address_no_change(self): def test_nxos_pim_rp_address_absent(self): set_module_args(dict(rp_address="1.2.3.4", state="absent")) - self.execute_module( - changed=True, commands=["no ip pim rp-address 1.2.3.4"] - ) + self.execute_module(changed=True, commands=["no ip pim rp-address 1.2.3.4"]) def test_nxos_pim_rp_address_absent_no_change(self): set_module_args(dict(rp_address="5.6.7.8", state="absent")) diff --git a/tests/unit/modules/network/nxos/test_nxos_ping.py b/tests/unit/modules/network/nxos/test_nxos_ping.py index 8df553c50..bdaabe881 100644 --- a/tests/unit/modules/network/nxos/test_nxos_ping.py +++ b/tests/unit/modules/network/nxos/test_nxos_ping.py @@ -19,29 +19,27 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from textwrap import dedent -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - AnsibleFailJson, -) from ansible_collections.cisco.nxos.plugins.modules import nxos_ping +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + +from .nxos_module import TestNxosModule, set_module_args -from .nxos_module import TestNxosModule, load_fixture, set_module_args ignore_provider_arg = True class TestNxosPingModule(TestNxosModule): - """Class used for Unit Tests agains ios_ping module""" + """Class used for Unit Tests against nxos_ping module""" module = nxos_ping def setUp(self): super(TestNxosPingModule, self).setUp() self.mock_run_commands = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_ping.run_commands" + "ansible_collections.cisco.nxos.plugins.modules.nxos_ping.run_commands", ) self.run_commands = self.mock_run_commands.start() @@ -62,13 +60,11 @@ def test_nxos_ping_expected_success(self): --- 172.28.128.7 ping statistics --- 5 packets transmitted, 5 packets received, 0.00% packet loss round-trip min/avg/max = 1.597/2.32/4.197 ms - """ + """, ] set_module_args(dict(dest="172.28.128.7", vrf="management")) result = self.execute_module() - self.assertEqual( - result["commands"], ["ping 172.28.128.7 count 5 vrf management"] - ) + self.assertEqual(result["commands"], ["ping 172.28.128.7 count 5 vrf management"]) self.assertEqual(result["packet_loss"], "0.00%") self.assertEqual(result["packets_rx"], 5) self.assertEqual(result["packets_tx"], 5) @@ -88,11 +84,9 @@ def test_nxos_ping_expected_failure(self): --- 172.28.128.8 ping statistics --- 5 packets transmitted, 0 packets received, 100.00% packet loss - """ + """, ] - set_module_args( - dict(dest="172.28.128.8", vrf="management", state="absent") - ) + set_module_args(dict(dest="172.28.128.8", vrf="management", state="absent")) self.execute_module(failed=False) def test_nxos_ping_expected_success_but_failed(self): @@ -107,7 +101,7 @@ def test_nxos_ping_expected_success_but_failed(self): --- 172.28.128.8 ping statistics --- 5 packets transmitted, 0 packets received, 100.00% packet loss - """ + """, ] set_module_args(dict(dest="172.28.128.8", vrf="management")) result = self.execute_module(failed=True) @@ -126,11 +120,9 @@ def test_nxos_ping_expected_failure_but_succeeded(self): --- 172.28.128.7 ping statistics --- 5 packets transmitted, 5 packets received, 0.00% packet loss round-trip min/avg/max = 1.597/2.32/4.197 ms - """ + """, ] - set_module_args( - dict(dest="172.28.128.7", vrf="management", state="absent") - ) + set_module_args(dict(dest="172.28.128.7", vrf="management", state="absent")) result = self.execute_module(failed=True) self.assertEqual(result["msg"], "Ping succeeded unexpectedly") @@ -147,7 +139,7 @@ def test_nxos_ping_expected_success_source(self): --- 172.28.128.7 ping statistics --- 5 packets transmitted, 5 packets received, 0.00% packet loss round-trip min/avg/max = 1.597/2.32/4.197 ms - """ + """, ] set_module_args(dict(dest="172.28.128.7", source="192.168.1.10")) result = self.execute_module() @@ -175,13 +167,11 @@ def test_nxos_ping_expected_success_df_bit(self): --- 172.28.128.7 ping statistics --- 5 packets transmitted, 5 packets received, 0.00% packet loss round-trip min/avg/max = 1.597/2.32/4.197 ms - """ + """, ] set_module_args(dict(dest="172.28.128.7", df_bit=True)) result = self.execute_module() - self.assertEqual( - result["commands"], ["ping 172.28.128.7 count 5 df-bit"] - ) + self.assertEqual(result["commands"], ["ping 172.28.128.7 count 5 df-bit"]) def test_nxos_ping_expected_success_size(self): self.run_commands.return_value = [ @@ -196,13 +186,11 @@ def test_nxos_ping_expected_success_size(self): --- 172.28.128.7 ping statistics --- 5 packets transmitted, 5 packets received, 0.00% packet loss round-trip min/avg/max = 1.597/2.32/4.197 ms - """ + """, ] set_module_args(dict(dest="172.28.128.7", size=65468)) result = self.execute_module() - self.assertEqual( - result["commands"], ["ping 172.28.128.7 count 5 packet-size 65468"] - ) + self.assertEqual(result["commands"], ["ping 172.28.128.7 count 5 packet-size 65468"]) def test_nxos_ping_expected_success_all(self): self.run_commands.return_value = [ @@ -217,7 +205,7 @@ def test_nxos_ping_expected_success_all(self): --- 172.28.128.7 ping statistics --- 5 packets transmitted, 5 packets received, 0.00% packet loss round-trip min/avg/max = 1.597/2.32/4.197 ms - """ + """, ] set_module_args( dict( @@ -227,13 +215,13 @@ def test_nxos_ping_expected_success_all(self): df_bit=True, source="192.168.1.1", vrf="management", - ) + ), ) result = self.execute_module() self.assertEqual( result["commands"], [ - "ping 172.28.128.7 count 10 source 192.168.1.1 vrf management packet-size 65468 df-bit" + "ping 172.28.128.7 count 10 source 192.168.1.1 vrf management packet-size 65468 df-bit", ], ) @@ -241,7 +229,7 @@ def test_nxos_ping_failed_cant_bind(self): self.run_commands.return_value = [ """ ping: can't bind to address 192.168.1.10 - """ + """, ] set_module_args( dict( @@ -251,7 +239,7 @@ def test_nxos_ping_failed_cant_bind(self): df_bit=True, source="192.168.1.1", vrf="management", - ) + ), ) result = self.execute_module(failed=True) self.assertEqual(result["msg"], "Can't bind to source address.") @@ -260,7 +248,7 @@ def test_nxos_ping_failed_bad_context(self): self.run_commands.return_value = [ """ ping: bad context site-1 - """ + """, ] set_module_args(dict(dest="172.28.128.7", count=10, vrf="site-1")) result = self.execute_module(failed=True) @@ -271,6 +259,4 @@ def test_nxos_ping_failed_error(self): self.run_commands.return_value = [""""""] set_module_args(dict(dest="172.28.128.7", count=10, vrf="site-1")) result = self.execute_module(failed=True) - self.assertEqual( - result["msg"], "An unexpected error occurred. Check all params." - ) + self.assertEqual(result["msg"], "An unexpected error occurred. Check all params.") diff --git a/tests/unit/modules/network/nxos/test_nxos_prefix_lists.py b/tests/unit/modules/network/nxos/test_nxos_prefix_lists.py index 0ade67b9d..d94f0b3e0 100644 --- a/tests/unit/modules/network/nxos/test_nxos_prefix_lists.py +++ b/tests/unit/modules/network/nxos/test_nxos_prefix_lists.py @@ -18,24 +18,22 @@ # Make coding more python3-ish from __future__ import absolute_import, division, print_function -from typing import Sequence + __metaclass__ = type from textwrap import dedent -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - AnsibleFailJson, -) + from ansible_collections.cisco.nxos.plugins.modules import nxos_prefix_lists +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from .nxos_module import TestNxosModule, set_module_args + ignore_provider_arg = True class TestNxosPrefixListsModule(TestNxosModule): - # Testing strategy # ------------------ # (a) The unit tests cover `merged` and `replaced` for every attribute. @@ -53,14 +51,12 @@ def setUp(self): super(TestNxosPrefixListsModule, self).setUp() self.mock_get_resource_connection = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" - ) - self.get_resource_connection = ( - self.mock_get_resource_connection.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", ) + self.get_resource_connection = self.mock_get_resource_connection.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.prefix_lists.prefix_lists.Prefix_listsFacts.get_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.prefix_lists.prefix_lists.Prefix_listsFacts.get_config", ) self.get_config = self.mock_get_config.start() @@ -73,7 +69,7 @@ def test_nxos_prefix_lists_linear_merged(self): # test merged for linear attributes self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args( dict( @@ -188,7 +184,7 @@ def test_nxos_prefix_lists_linear_merged_idempotent(self): ipv6 prefix-list plist3 seq 20 permit 2001:db8:2000::/36 ipv6 prefix-list plist4 seq 20 permit 2001:db8:3000::/36 ipv6 prefix-list plist4 seq 50 deny 2001:db8:4000::/36 - """ + """, ) set_module_args( dict( @@ -291,7 +287,7 @@ def test_nxos_prefix_lists_merged_update(self): ipv6 prefix-list plist3 seq 20 permit 2001:db8:2000::/36 ipv6 prefix-list plist4 seq 20 permit 2001:db8:3000::/36 ipv6 prefix-list plist4 seq 50 deny 2001:db8:4000::/36 - """ + """, ) set_module_args( dict( @@ -307,11 +303,11 @@ def test_nxos_prefix_lists_merged_update(self): sequence=10, action="permit", prefix="192.168.8.0/24", - ) + ), ], - ) + ), ], - ) + ), ], state="merged", ), @@ -338,7 +334,7 @@ def test_nxos_prefix_lists_replaced_update(self): ipv6 prefix-list plist3 seq 20 permit 2001:db8:2000::/36 ipv6 prefix-list plist4 seq 20 permit 2001:db8:3000::/36 ipv6 prefix-list plist4 seq 50 deny 2001:db8:4000::/36 - """ + """, ) set_module_args( dict( @@ -362,9 +358,9 @@ def test_nxos_prefix_lists_replaced_update(self): mask="255.255.255.0", ), ], - ) + ), ], - ) + ), ], state="replaced", ), @@ -391,7 +387,7 @@ def test_nxos_prefix_lists_replaced(self): ipv6 prefix-list plist3 seq 20 permit 2001:db8:2000::/36 ipv6 prefix-list plist4 seq 20 permit 2001:db8:3000::/36 ipv6 prefix-list plist4 seq 50 deny 2001:db8:4000::/36 - """ + """, ) set_module_args( dict( @@ -406,11 +402,11 @@ def test_nxos_prefix_lists_replaced(self): sequence=10, action="permit", prefix="192.168.8.0/24", - ) + ), ], - ) + ), ], - ) + ), ], state="replaced", ), @@ -439,7 +435,7 @@ def test_nxos_prefix_lists_overridden(self): ipv6 prefix-list plist3 seq 20 permit 2001:db8:2000::/36 ipv6 prefix-list plist4 seq 20 permit 2001:db8:3000::/36 ipv6 prefix-list plist4 seq 50 deny 2001:db8:4000::/36 - """ + """, ) set_module_args( dict( @@ -454,11 +450,11 @@ def test_nxos_prefix_lists_overridden(self): sequence=10, action="permit", prefix="192.168.8.0/24", - ) + ), ], - ) + ), ], - ) + ), ], state="overridden", ), @@ -490,7 +486,7 @@ def test_nxos_prefix_lists_deleted_afi(self): ipv6 prefix-list plist3 seq 20 permit 2001:db8:2000::/36 ipv6 prefix-list plist4 seq 20 permit 2001:db8:3000::/36 ipv6 prefix-list plist4 seq 50 deny 2001:db8:4000::/36 - """ + """, ) set_module_args( dict(config=[dict(afi="ipv4")], state="deleted"), @@ -514,7 +510,7 @@ def test_nxos_prefix_lists_deleted_prefix_list(self): ipv6 prefix-list plist3 seq 20 permit 2001:db8:2000::/36 ipv6 prefix-list plist4 seq 20 permit 2001:db8:3000::/36 ipv6 prefix-list plist4 seq 50 deny 2001:db8:4000::/36 - """ + """, ) set_module_args( dict( @@ -541,7 +537,7 @@ def test_nxos_prefix_lists_deleted_all(self): ipv6 prefix-list plist3 seq 20 permit 2001:db8:2000::/36 ipv6 prefix-list plist4 seq 20 permit 2001:db8:3000::/36 ipv6 prefix-list plist4 seq 50 deny 2001:db8:4000::/36 - """ + """, ) set_module_args(dict(state="deleted"), ignore_provider_arg) commands = [ @@ -559,23 +555,17 @@ def test_nxos_prefix_lists_parsed(self): """\ ip prefix-list plist1 description Test plist1 ipv6 prefix-list plist3 description Test plist3 - """ - ) - set_module_args( - dict(running_config=cfg, state="parsed"), ignore_provider_arg + """, ) + set_module_args(dict(running_config=cfg, state="parsed"), ignore_provider_arg) parsed = [ { "afi": "ipv4", - "prefix_lists": [ - {"name": "plist1", "description": "Test plist1"} - ], + "prefix_lists": [{"name": "plist1", "description": "Test plist1"}], }, { "afi": "ipv6", - "prefix_lists": [ - {"name": "plist3", "description": "Test plist3"} - ], + "prefix_lists": [{"name": "plist3", "description": "Test plist3"}], }, ] result = self.execute_module(changed=False) @@ -589,7 +579,7 @@ def test_nxos_prefix_lists_gathered(self): ip prefix-list plist1 seq 20 deny 192.168.2.0/24 mask 255.255.255.0 ipv6 prefix-list plist3 description Test plist3 ipv6 prefix-list plist3 seq 50 deny 2001:db8:4000::/36 - """ + """, ) set_module_args(dict(state="gathered"), ignore_provider_arg) gathered = [ @@ -605,9 +595,9 @@ def test_nxos_prefix_lists_gathered(self): "action": "deny", "prefix": "192.168.2.0/24", "mask": "255.255.255.0", - } + }, ], - } + }, ], }, { @@ -621,9 +611,9 @@ def test_nxos_prefix_lists_gathered(self): "sequence": 50, "action": "deny", "prefix": "2001:db8:4000::/36", - } + }, ], - } + }, ], }, ] diff --git a/tests/unit/modules/network/nxos/test_nxos_route_maps.py b/tests/unit/modules/network/nxos/test_nxos_route_maps.py index df45051e1..06d76fe38 100644 --- a/tests/unit/modules/network/nxos/test_nxos_route_maps.py +++ b/tests/unit/modules/network/nxos/test_nxos_route_maps.py @@ -19,22 +19,21 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type from textwrap import dedent -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - AnsibleFailJson, -) + from ansible_collections.cisco.nxos.plugins.modules import nxos_route_maps +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + +from .nxos_module import TestNxosModule, set_module_args -from .nxos_module import TestNxosModule, load_fixture, set_module_args ignore_provider_arg = True class TestNxosRouteMapsModule(TestNxosModule): - # Testing strategy # ------------------ # (a) The unit tests cover `merged` and `replaced` for every attribute. @@ -52,14 +51,12 @@ def setUp(self): super(TestNxosRouteMapsModule, self).setUp() self.mock_get_resource_connection = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" - ) - self.get_resource_connection = ( - self.mock_get_resource_connection.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", ) + self.get_resource_connection = self.mock_get_resource_connection.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.route_maps.route_maps.Route_mapsFacts.get_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.route_maps.route_maps.Route_mapsFacts.get_config", ) self.get_config = self.mock_get_config.start() @@ -72,7 +69,7 @@ def test_nxos_route_maps_linear_merged(self): # test merged for linear attributes self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args( dict( @@ -91,9 +88,7 @@ def test_nxos_route_maps_linear_merged(self): sequence=40, description="rmap1-deny-40", set=dict( - as_path=dict( - prepend=dict(last_as=10), tag=True - ), + as_path=dict(prepend=dict(last_as=10), tag=True), comm_list="comm1", dampening=dict( half_life=10, @@ -116,15 +111,11 @@ def test_nxos_route_maps_linear_merged(self): set=dict( null_interface="null0", ip=dict( - address=dict( - prefix_list="prefixlist1" - ), + address=dict(prefix_list="prefixlist1"), precedence="critical", ), ipv6=dict( - address=dict( - prefix_list="prefixlist2" - ), + address=dict(prefix_list="prefixlist2"), precedence="immediate", ), label_index=20, @@ -144,7 +135,7 @@ def test_nxos_route_maps_linear_merged(self): tag=10, weight=40, ), - ) + ), ], ), ], @@ -216,7 +207,7 @@ def test_nxos_route_maps_linear_merged_idempotent(self): set path-selection all advertise set tag 10 set weight 40 - """ + """, ) set_module_args( dict( @@ -235,9 +226,7 @@ def test_nxos_route_maps_linear_merged_idempotent(self): sequence=40, description="rmap1-deny-40", set=dict( - as_path=dict( - prepend=dict(last_as=10), tag=True - ), + as_path=dict(prepend=dict(last_as=10), tag=True), comm_list="comm1", dampening=dict( half_life=10, @@ -260,15 +249,11 @@ def test_nxos_route_maps_linear_merged_idempotent(self): set=dict( null_interface="null0", ip=dict( - address=dict( - prefix_list="prefixlist1" - ), + address=dict(prefix_list="prefixlist1"), precedence="critical", ), ipv6=dict( - address=dict( - prefix_list="prefixlist2" - ), + address=dict(prefix_list="prefixlist2"), precedence="immediate", ), label_index=20, @@ -288,7 +273,7 @@ def test_nxos_route_maps_linear_merged_idempotent(self): tag=10, weight=40, ), - ) + ), ], ), ], @@ -332,7 +317,7 @@ def test_nxos_route_maps_linear_replaced(self): set path-selection all advertise set tag 10 set weight 40 - """ + """, ) set_module_args( dict( @@ -366,13 +351,11 @@ def test_nxos_route_maps_linear_replaced(self): action="deny", set=dict( ip=dict( - address=dict( - prefix_list="prefixlist1" - ), + address=dict(prefix_list="prefixlist1"), precedence="critical", - ) + ), ), - ) + ), ], ), ], @@ -418,7 +401,7 @@ def test_nxos_route_maps_parsed(self): set ip precedence critical set ipv6 address prefix-list prefixlist2 set ipv6 precedence immediate - """ + """, ), state="parsed", ), @@ -439,9 +422,7 @@ def test_nxos_route_maps_parsed(self): action="deny", sequence=40, description="rmap1-deny-40", - set=dict( - as_path=dict(prepend=dict(last_as=10), tag=True) - ), + set=dict(as_path=dict(prepend=dict(last_as=10), tag=True)), ), ], ), @@ -462,7 +443,7 @@ def test_nxos_route_maps_parsed(self): precedence="immediate", ), ), - ) + ), ], ), ] @@ -489,7 +470,7 @@ def test_nxos_route_maps_gathered(self): set ip precedence critical set ipv6 address prefix-list prefixlist2 set ipv6 precedence immediate - """ + """, ) set_module_args(dict(state="gathered"), ignore_provider_arg) @@ -507,9 +488,7 @@ def test_nxos_route_maps_gathered(self): action="deny", sequence=40, description="rmap1-deny-40", - set=dict( - as_path=dict(prepend=dict(last_as=10), tag=True) - ), + set=dict(as_path=dict(prepend=dict(last_as=10), tag=True)), ), ], ), @@ -530,7 +509,7 @@ def test_nxos_route_maps_gathered(self): precedence="immediate", ), ), - ) + ), ], ), ] @@ -572,13 +551,11 @@ def test_nxos_route_maps_rendered(self): action="deny", set=dict( ip=dict( - address=dict( - prefix_list="prefixlist1" - ), + address=dict(prefix_list="prefixlist1"), precedence="critical", - ) + ), ), - ) + ), ], ), ], @@ -621,7 +598,7 @@ def test_nxos_route_maps_overridden(self): description rmap3-permit-21 route-map rmap3 permit 22 description rmap3-permit-21 - """ + """, ) set_module_args( dict( @@ -641,11 +618,9 @@ def test_nxos_route_maps_overridden(self): description="rmap1-deny-40", set=dict( ipv6=dict( - address=dict( - prefix_list="prefixlist2" - ), + address=dict(prefix_list="prefixlist2"), precedence="immediate", - ) + ), ), ), ], @@ -658,7 +633,7 @@ def test_nxos_route_maps_overridden(self): action="permit", description="rmap2-permit-10", set=dict(null_interface="null0"), - ) + ), ], ), ], @@ -699,7 +674,7 @@ def test_nxos_route_maps_deleted_1(self): description rmap3-permit-21 route-map rmap3 permit 22 description rmap3-permit-21 - """ + """, ) set_module_args( dict(config=[dict(route_map="rmap1")], state="deleted"), @@ -732,7 +707,7 @@ def test_nxos_route_maps_deleted_2(self): description rmap3-permit-21 route-map rmap3 permit 22 description rmap3-permit-21 - """ + """, ) set_module_args(dict(state="deleted"), ignore_provider_arg) commands = [ @@ -750,7 +725,7 @@ def test_nxos_route_maps_complex_merged(self): # test merged for complex attributes self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args( dict( @@ -767,15 +742,13 @@ def test_nxos_route_maps_complex_merged(self): as_path_list=["acl1", "acl2"], ), as_path=["65565", "65578", "65590"], - community=dict( - community_list=["comm1", "comm2"] - ), + community=dict(community_list=["comm1", "comm2"]), evpn=dict(route_types=["1", "2-mac-ip"]), extcommunity=dict( extcommunity_list=[ "extcomm1", "extcomm2", - ] + ], ), interfaces=["Ethernet1/1", "Ethernet1/2"], ip=dict( @@ -791,12 +764,8 @@ def test_nxos_route_maps_complex_merged(self): ), source="192.168.1.0/24", ), - next_hop=dict( - prefix_lists=["pl1", "pl2"] - ), - route_source=dict( - prefix_lists=["pl3", "pl4"] - ), + next_hop=dict(prefix_lists=["pl1", "pl2"]), + route_source=dict(prefix_lists=["pl3", "pl4"]), ), mac_list=["mac1", "mac2"], metric=[100, 200], @@ -823,41 +792,29 @@ def test_nxos_route_maps_complex_merged(self): ), source="192.168.1.0/24", ), - next_hop=dict( - prefix_lists=["pl1", "pl2"] - ), - route_source=dict( - prefix_lists=["pl3", "pl4"] - ), - ) + next_hop=dict(prefix_lists=["pl1", "pl2"]), + route_source=dict(prefix_lists=["pl3", "pl4"]), + ), ), ), dict( sequence=40, action="permit", set=dict( - as_path=dict( - prepend=dict( - as_number=["65546", "78878"] - ) - ), + as_path=dict(prepend=dict(as_number=["65546", "78878"])), distance=dict( igp_ebgp_routes=10, internal_routes=20, local_routes=90, ), - evpn=dict( - gateway_ip=dict(ip="192.168.1.1") - ), + evpn=dict(gateway_ip=dict(ip="192.168.1.1")), ), ), dict( sequence=52, action="permit", set=dict( - evpn=dict( - gateway_ip=dict(use_nexthop=True) - ), + evpn=dict(gateway_ip=dict(use_nexthop=True)), community=dict( internet=True, number=["655:10", "655:20"], @@ -870,7 +827,7 @@ def test_nxos_route_maps_complex_merged(self): ), ), ], - ) + ), ], state="merged", ), @@ -917,7 +874,7 @@ def test_nxos_route_maps_complex_merged_2(self): # test merged for complex attributes self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args( dict( @@ -940,7 +897,7 @@ def test_nxos_route_maps_complex_merged_2(self): rp_type="Bidir", ), source="192.168.1.0/24", - ) + ), ), ipv6=dict( multicast=dict( @@ -953,7 +910,7 @@ def test_nxos_route_maps_complex_merged_2(self): rp_type="Bidir", ), source="2001:db8:2000::/36", - ) + ), ), ), set=dict( @@ -962,11 +919,11 @@ def test_nxos_route_maps_complex_merged_2(self): igrp_delay_metric=90, igrp_reliability_metric=80, igrp_effective_bandwidth_metric=100, - ) + ), ), - ) + ), ], - ) + ), ], state="merged", ), @@ -989,7 +946,7 @@ def test_nxos_route_maps_complex_replaced(self): match ip address prefix-list pl1 pl2 pl3 match ip multicast source 192.168.1.0/24 group-range 239.0.0.1 to 239.255.255.255 rp 209.165.201.0/27 rp-type Bidir match ipv6 multicast source 2001:db8:2000::/36 group-range fd00:80:: to fd00:ff:ffff:ffff:: rp fd00:280::/25 rp-type Bidir - """ + """, ) set_module_args( dict( @@ -1023,12 +980,12 @@ def test_nxos_route_maps_complex_replaced(self): rp_type="Bidir", ), source="2001:db8:2000::/36", - ) + ), ), ), - ) + ), ], - ) + ), ], state="replaced", ), @@ -1048,9 +1005,491 @@ def test_nxos_route_maps_gathered_empty(self): # test gathered for empty config self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args(dict(state="gathered"), ignore_provider_arg) result = self.execute_module(changed=False) self.assertEqual(result["gathered"], []) + + def test_nxos_route_maps_next_hop_gathered(self): + # test gathered for empty config + self.get_config.return_value = dedent( + """\ + route-map TEST permit 10 + description *** first stanza *** + set ip next-hop verify-availability 3.3.3.3 track 1 + set ip next-hop verify-availability 5.5.5.5 track 3 + route-map TEST permit 20 + set ip next-hop 2.2.2.2 5.5.5.5 load-share + route-map TEST permit 30 + set ip next-hop peer-address + route-map TEST permit 40 + set ip next-hop unchanged + set ip next-hop redist-unchanged + """, + ) + set_module_args(dict(state="gathered"), ignore_provider_arg) + + gathered = [ + dict( + route_map="TEST", + entries=[ + dict( + action="permit", + sequence=10, + description="*** first stanza ***", + set=dict( + ip=dict( + next_hop=dict( + verify_availability=[ + dict( + address="3.3.3.3", + track=1, + drop_on_fail=False, + force_order=False, + load_share=False, + ), + dict( + address="5.5.5.5", + track=3, + drop_on_fail=False, + force_order=False, + load_share=False, + ), + ], + ), + tag=True, + ), + ), + ), + dict( + action="permit", + sequence=20, + set=dict( + ip=dict( + next_hop=dict( + address="2.2.2.2 5.5.5.5", + drop_on_fail=False, + force_order=False, + load_share=True, + ), + tag=True, + ), + ), + ), + dict( + action="permit", + sequence=30, + set=dict( + ip=dict( + next_hop=dict( + peer_address=True, + ), + tag=True, + ), + ), + ), + dict( + action="permit", + sequence=30, + set=dict( + ip=dict( + next_hop=dict( + unchanged=True, + redist_unchanged=True, + ), + tag=True, + ), + ), + ), + ], + ), + ] + + result = self.execute_module(changed=False) + self.assertEqual(set(result["gathered"][0]), set(gathered[0])) + + def test_nxos_route_maps_next_hop_merged_idempotent(self): + # test merged + self.get_config.return_value = dedent( + """\ + route-map TEST permit 10 + description *** first stanza *** + set ip next-hop verify-availability 3.3.3.3 track 1 + set ip next-hop verify-availability 5.5.5.5 track 3 + route-map TEST permit 20 + set ip next-hop 5.5.5.5 2.2.2.2 load-share drop-on-fail + route-map TEST permit 30 + set ip next-hop peer-address + route-map TEST permit 40 + set ip next-hop unchanged + set ip next-hop redist-unchanged + """, + ) + set_module_args( + dict( + config=[ + dict( + route_map="TEST", + entries=[ + dict( + action="permit", + sequence=10, + description="*** first stanza ***", + set=dict( + ip=dict( + next_hop=dict( + verify_availability=[ + dict( + address="3.3.3.3", + track=1, + drop_on_fail=False, + force_order=False, + load_share=False, + ), + dict( + address="5.5.5.5", + track=3, + drop_on_fail=False, + force_order=False, + load_share=False, + ), + ], + ), + ), + ), + ), + dict( + action="permit", + sequence=20, + set=dict( + ip=dict( + next_hop=dict( + address="5.5.5.5 2.2.2.2", + drop_on_fail=True, + force_order=False, + load_share=True, + ), + ), + ), + ), + dict( + action="permit", + sequence=30, + set=dict( + ip=dict( + next_hop=dict( + peer_address=True, + ), + ), + ), + ), + dict( + action="permit", + sequence=40, + set=dict( + ip=dict( + next_hop=dict( + unchanged=True, + redist_unchanged=True, + ), + ), + ), + ), + ], + ), + ], + state="merged", + ), + ignore_provider_arg, + ) + commands = [] + result = self.execute_module(changed=False) + self.assertEqual(result["commands"], commands) + + def test_nxos_route_maps_next_hop_linear_merged(self): + # test merged for linear attributes + self.get_config.return_value = dedent( + """\ + """, + ) + set_module_args( + dict( + config=[ + dict( + route_map="TEST", + entries=[ + dict( + action="permit", + sequence=10, + description="*** first stanza ***", + set=dict( + ip=dict( + next_hop=dict( + verify_availability=[ + dict( + address="3.3.3.3", + track=1, + drop_on_fail=False, + force_order=False, + load_share=False, + ), + dict( + address="5.5.5.5", + track=3, + drop_on_fail=False, + force_order=False, + load_share=False, + ), + ], + ), + ), + ), + ), + dict( + action="permit", + sequence=20, + set=dict( + ip=dict( + next_hop=dict( + address="5.5.5.5 2.2.2.2", + drop_on_fail=True, + force_order=False, + load_share=True, + ), + ), + ), + ), + dict( + action="permit", + sequence=30, + set=dict( + ip=dict( + next_hop=dict( + peer_address=True, + ), + ), + ), + ), + dict( + action="permit", + sequence=40, + set=dict( + ip=dict( + next_hop=dict( + unchanged=True, + redist_unchanged=True, + ), + ), + ), + ), + ], + ), + ], + state="merged", + ), + ignore_provider_arg, + ) + commands = [ + "route-map TEST permit 10", + "description *** first stanza ***", + "set ip next-hop verify-availability 3.3.3.3 track 1", + "set ip next-hop verify-availability 5.5.5.5 track 3", + "route-map TEST permit 20", + "set ip next-hop 5.5.5.5 2.2.2.2 load-share drop-on-fail", + "route-map TEST permit 30", + "set ip next-hop peer-address", + "route-map TEST permit 40", + "set ip next-hop unchanged", + "set ip next-hop redist-unchanged", + ] + result = self.execute_module(changed=True) + self.assertEqual(set(result["commands"]), set(commands)) + + def test_nxos_route_maps_next_hop_replaced(self): + # test replaced for linear attributes + self.get_config.return_value = dedent( + """\ + route-map TEST permit 10 + set ip next-hop 5.5.5.5 2.2.2.2 load-share drop-on-fail + route-map TEST permit 20 + description *** second stanza *** + set ip next-hop verify-availability 3.3.3.3 track 1 + set ip next-hop verify-availability 5.5.5.5 track 3 + route-map TEST permit 30 + set ip next-hop peer-address + route-map TEST permit 40 + set ip next-hop unchanged + set ip next-hop redist-unchanged + """, + ) + set_module_args( + dict( + config=[ + dict( + route_map="TEST", + entries=[ + dict( + action="permit", + sequence=10, + description="*** first stanza ***", + set=dict( + ip=dict( + next_hop=dict( + verify_availability=[ + dict( + address="3.3.3.3", + track=1, + drop_on_fail=False, + force_order=False, + load_share=False, + ), + dict( + address="5.5.5.5", + track=3, + drop_on_fail=False, + force_order=False, + load_share=False, + ), + ], + ), + ), + ), + ), + dict( + action="permit", + sequence=20, + set=dict( + ip=dict( + next_hop=dict( + address="5.5.5.5 2.2.2.2", + drop_on_fail=True, + force_order=False, + load_share=True, + ), + ), + ), + ), + dict( + action="permit", + sequence=30, + set=dict( + ip=dict( + next_hop=dict( + peer_address=True, + ), + ), + ), + ), + dict( + action="permit", + sequence=40, + set=dict( + ip=dict( + next_hop=dict( + unchanged=True, + redist_unchanged=True, + ), + ), + ), + ), + ], + ), + ], + state="replaced", + ), + ignore_provider_arg, + ) + commands = [ + "route-map TEST permit 10", + "no set ip next-hop verify-availability 3.3.3.3 track 1", + "no set ip next-hop verify-availability 5.5.5.5 track 3", + "no description *** second stanza ***", + "set ip next-hop 5.5.5.5 2.2.2.2 load-share drop-on-fail", + "route-map TEST permit 20", + "no set ip next-hop 5.5.5.5 2.2.2.2 load-share drop-on-fail", + "set ip next-hop verify-availability 3.3.3.3 track 1", + "set ip next-hop verify-availability 5.5.5.5 track 3", + "description *** first stanza ***", + ] + result = self.execute_module(changed=True) + self.assertEqual(set(result["commands"]), set(commands)) + + def test_nxos_route_maps_extcomm_rt(self): + # test for extcommunity.rt + self.get_config.return_value = dedent( + """\ + route-map test-1 permit 10 + set extcommunity rt additive + route-map test-2 permit 11 + set extcommunity rt 65000:516590 65000:516591 65000:516592 additive + """, + ) + set_module_args( + dict( + config=[ + dict( + route_map="test-1", + entries=[ + dict( + action="permit", + sequence=10, + set=dict( + extcommunity=dict( + rt=dict( + extcommunity_numbers=[ + "65000:516586", + ], + additive=True, + ), + ), + ), + ), + ], + ), + ], + state="merged", + ), + ignore_provider_arg, + ) + commands = [ + "route-map test-1 permit 10", + "set extcommunity rt 65000:516586 additive", + ] + result = self.execute_module(changed=True) + self.assertEqual(set(result["commands"]), set(commands)) + + set_module_args( + dict( + config=[ + dict( + route_map="test-2", + entries=[ + dict( + action="permit", + sequence=11, + set=dict( + extcommunity=dict( + rt=dict( + extcommunity_numbers=[ + "65000:516590", + ], + ), + ), + ), + ), + ], + ), + ], + state="replaced", + ), + ignore_provider_arg, + ) + commands = [ + "route-map test-2 permit 11", + "no set extcommunity rt 65000:516590 65000:516591 65000:516592 additive", + "set extcommunity rt 65000:516590", + ] + result = self.execute_module(changed=True) + self.assertEqual(set(result["commands"]), set(commands)) diff --git a/tests/unit/modules/network/nxos/test_nxos_snmp_server.py b/tests/unit/modules/network/nxos/test_nxos_snmp_server.py index dda41cbe8..1b7672775 100644 --- a/tests/unit/modules/network/nxos/test_nxos_snmp_server.py +++ b/tests/unit/modules/network/nxos/test_nxos_snmp_server.py @@ -19,33 +19,33 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type from textwrap import dedent -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from ansible_collections.cisco.nxos.plugins.modules import nxos_snmp_server +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from .nxos_module import TestNxosModule, set_module_args + ignore_provider_arg = True class TestNxosSnmpServerModule(TestNxosModule): - module = nxos_snmp_server def setUp(self): super(TestNxosSnmpServerModule, self).setUp() self.mock_get_resource_connection = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" - ) - self.get_resource_connection = ( - self.mock_get_resource_connection.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", ) + self.get_resource_connection = self.mock_get_resource_connection.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.snmp_server.snmp_server.Snmp_serverFacts.get_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.snmp_server.snmp_server.Snmp_serverFacts.get_config", ) self.get_config = self.mock_get_config.start() @@ -58,7 +58,7 @@ def test_nxos_snmp_server_linear_merged(self): # test merged for linear attributes self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args( dict( @@ -68,25 +68,17 @@ def test_nxos_snmp_server_linear_merged(self): context=dict(name="public", vrf="siteA", instance="test"), counter=dict(cache=dict(timeout=1800)), drop=dict(unknown_engine_id=True, unknown_user=True), - engine_id=dict( - local="'00:00:00:63:00:01:00:10:20:15:10:03'" - ), + engine_id=dict(local="'00:00:00:63:00:01:00:10:20:15:10:03'"), communities=[ dict(name="private", group="network-admin"), dict(community="public", use_ipv4acl="myacl"), ], global_enforce_priv=True, location="lab", - mib=dict( - community_map=dict( - community="public", context="public1" - ) - ), + mib=dict(community_map=dict(community="public", context="public1")), packetsize=484, protocol=dict(enable=True), - source_interface=dict( - informs="Ethernet1/1", traps="Ethernet1/2" - ), + source_interface=dict(informs="Ethernet1/1", traps="Ethernet1/2"), system_shutdown=True, tcp_session=dict(auth=True), ), @@ -137,7 +129,7 @@ def test_nxos_snmp_server_linear_merged_idempotent(self): snmp-server location lab snmp-server mib community-map public context public1 snmp-server source-interface traps Ethernet1/2 - """ + """, ) set_module_args( dict( @@ -147,21 +139,13 @@ def test_nxos_snmp_server_linear_merged_idempotent(self): context=dict(name="public", vrf="siteA"), counter=dict(cache=dict(timeout=1800)), drop=dict(unknown_engine_id=True, unknown_user=True), - engine_id=dict( - local="00:00:00:63:00:01:00:10:20:15:10:03" - ), + engine_id=dict(local="00:00:00:63:00:01:00:10:20:15:10:03"), global_enforce_priv=True, location="lab", - mib=dict( - community_map=dict( - community="public", context="public1" - ) - ), + mib=dict(community_map=dict(community="public", context="public1")), packetsize=484, protocol=dict(enable=True), - source_interface=dict( - informs="Ethernet1/1", traps="Ethernet1/2" - ), + source_interface=dict(informs="Ethernet1/1", traps="Ethernet1/2"), system_shutdown=True, tcp_session=dict(auth=True), ), @@ -192,7 +176,7 @@ def test_nxos_snmp_server_linear_replaced(self): snmp-server location lab snmp-server mib community-map public context public1 snmp-server source-interface traps Ethernet1/2 - """ + """, ) set_module_args( dict( @@ -201,21 +185,13 @@ def test_nxos_snmp_server_linear_replaced(self): contact="testswitch@localhost", context=dict(name="public", vrf="siteA"), counter=dict(cache=dict(timeout=1860)), - engine_id=dict( - local="00:00:00:63:00:01:00:10:20:15:10:03" - ), + engine_id=dict(local="00:00:00:63:00:01:00:10:20:15:10:03"), global_enforce_priv=True, location="lab", - mib=dict( - community_map=dict( - community="public", context="public1" - ) - ), + mib=dict(community_map=dict(community="public", context="public1")), packetsize=484, protocol=dict(enable=True), - source_interface=dict( - informs="Ethernet1/3", traps="Ethernet1/2" - ), + source_interface=dict(informs="Ethernet1/3", traps="Ethernet1/2"), tcp_session=dict(auth=True), ), state="replaced", @@ -253,7 +229,7 @@ def test_nxos_snmp_server_linear_overridden(self): snmp-server location lab snmp-server mib community-map public context public1 snmp-server source-interface traps Ethernet1/2 - """ + """, ) set_module_args( dict( @@ -262,21 +238,13 @@ def test_nxos_snmp_server_linear_overridden(self): contact="testswitch@localhost", context=dict(name="public", vrf="siteA"), counter=dict(cache=dict(timeout=1860)), - engine_id=dict( - local="00:00:00:63:00:01:00:10:20:15:10:03" - ), + engine_id=dict(local="00:00:00:63:00:01:00:10:20:15:10:03"), global_enforce_priv=True, location="lab", - mib=dict( - community_map=dict( - community="public", context="public1" - ) - ), + mib=dict(community_map=dict(community="public", context="public1")), packetsize=484, protocol=dict(enable=True), - source_interface=dict( - informs="Ethernet1/3", traps="Ethernet1/2" - ), + source_interface=dict(informs="Ethernet1/3", traps="Ethernet1/2"), tcp_session=dict(auth=True), ), state="overridden", @@ -300,7 +268,7 @@ def test_nxos_snmp_server_location_spaces(self): """\ snmp-server contact testswitch@localhost snmp-server location lab - """ + """, ) set_module_args( dict( @@ -323,7 +291,7 @@ def test_nxos_snmp_server_traps_merged(self): # test merged for traps self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args( dict( @@ -366,7 +334,7 @@ def test_nxos_snmp_server_traps_merged_idempotent(self): snmp-server enable traps bgp snmp-server enable traps ospf snmp-server enable traps ospfv3 - """ + """, ) set_module_args( dict( @@ -378,7 +346,7 @@ def test_nxos_snmp_server_traps_merged_idempotent(self): bgp=dict(enable=True), ospf=dict(enable=True), ospfv3=dict(enable=True), - ) + ), ), state="merged", ), @@ -397,7 +365,8 @@ def test_nxos_snmp_server_traps_replaced(self): snmp-server enable traps bridge topologychange snmp-server enable traps callhome event-notify snmp-server enable traps callhome smtp-send-fail - """ + snmp-server enable traps link cisco-xcvr-mon-status-chg + """, ) set_module_args( dict( @@ -406,7 +375,8 @@ def test_nxos_snmp_server_traps_replaced(self): aaa=dict(server_state_change=True), bridge=dict(enable=True), cfs=dict(merge_failure=True), - ) + link=dict(cisco_xcvr_mon_status_chg=False), + ), ), state="replaced", ), @@ -416,6 +386,7 @@ def test_nxos_snmp_server_traps_replaced(self): "no snmp-server enable traps callhome event-notify", "no snmp-server enable traps callhome smtp-send-fail", "snmp-server enable traps cfs merge-failure", + "no snmp-server enable traps link cisco-xcvr-mon-status-chg", ] result = self.execute_module(changed=True) self.assertEqual(set(result["commands"]), set(commands)) @@ -429,7 +400,7 @@ def test_nxos_snmp_server_traps_replaced(self): snmp-server enable traps bridge topologychange snmp-server enable traps callhome event-notify snmp-server enable traps callhome smtp-send-fail - """ + """, ) set_module_args( dict( @@ -438,7 +409,7 @@ def test_nxos_snmp_server_traps_replaced(self): aaa=dict(server_state_change=True), bridge=dict(enable=True), cfs=dict(merge_failure=True), - ) + ), ), state="replaced", ), @@ -456,7 +427,7 @@ def test_nxos_snmp_server_hosts_merged(self): # test merged for hosts self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args( dict( @@ -468,9 +439,7 @@ def test_nxos_snmp_server_hosts_merged(self): community="public", traps=True, ), - dict( - host="192.168.1.1", source_interface="Ethernet1/1" - ), + dict(host="192.168.1.1", source_interface="Ethernet1/1"), dict( host="192.168.2.1", version="1", @@ -496,7 +465,7 @@ def test_nxos_snmp_server_hosts_merged(self): priv="private", informs=True, ), - ] + ], ), state="merged", ), @@ -523,7 +492,7 @@ def test_nxos_snmp_server_hosts_merged(self): snmp-server host 192.168.1.1 source-interface Ethernet1/1 snmp-server host 192.168.2.1 traps version 1 private snmp-server host 192.168.3.1 informs version 3 auth private udp-port 65550 - """ + """, ) set_module_args( dict( @@ -535,9 +504,7 @@ def test_nxos_snmp_server_hosts_merged(self): community="public", traps=True, ), - dict( - host="192.168.1.1", source_interface="Ethernet1/1" - ), + dict(host="192.168.1.1", source_interface="Ethernet1/1"), dict( host="192.168.2.1", version="1", @@ -563,7 +530,7 @@ def test_nxos_snmp_server_hosts_merged(self): priv="private", informs=True, ), - ] + ], ), state="merged", ), @@ -582,7 +549,7 @@ def test_nxos_snmp_server_hosts_replaced(self): snmp-server host 192.168.1.1 source-interface Ethernet1/1 snmp-server host 192.168.2.1 traps version 1 private snmp-server host 192.168.3.1 informs version 3 auth private udp-port 65550 - """ + """, ) set_module_args( dict( @@ -594,9 +561,7 @@ def test_nxos_snmp_server_hosts_replaced(self): community="public", traps=True, ), - dict( - host="192.168.1.1", source_interface="Ethernet1/1" - ), + dict(host="192.168.1.1", source_interface="Ethernet1/1"), dict( host="192.168.2.1", version="1", @@ -611,7 +576,7 @@ def test_nxos_snmp_server_hosts_replaced(self): ), dict(host="192.168.2.1", filter_vrf="siteA"), dict(host="192.168.4.1", use_vrf="siteB"), - ] + ], ), state="replaced", ), @@ -630,7 +595,7 @@ def test_nxos_snmp_server_users_merged(self): # test merged for users self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args( dict( @@ -655,9 +620,9 @@ def test_nxos_snmp_server_users_merged(self): password="0x5632724fb8ac3699296af26281e1d0f1", engine_id="2:2:2:2:2", priv=dict( - privacy_password="0x5632724fb8ac3699296af26281e1d0f1" + privacy_password="0x5632724fb8ac3699296af26281e1d0f1", ), - localized_key=True, + localizedv2_key=True, ), ), dict( @@ -674,8 +639,22 @@ def test_nxos_snmp_server_users_merged(self): localized_key=True, ), ), - ] - ) + dict( + user="snmp_user_4", + group="network-admin", + authentication=dict( + algorithm="sha-256", + password="0x5632724fb8ac3699296af26281e1d0f1", + engine_id="4:4:4:4:4", + priv=dict( + privacy_password="0x5632724fb8ac3699296af26281e1d0f1", + aes_128=True, + ), + localized_key=True, + ), + ), + ], + ), ), state="merged", ), @@ -685,9 +664,11 @@ def test_nxos_snmp_server_users_merged(self): "snmp-server user snmp_user_2 network-admin auth md5 0x5632724fb8ac3699296af26281e1d0f1 priv 0x5632724fb8ac3699296af26281e1d0f1" " localizedkey engineID 2:2:2:2:2", "snmp-server user snmp_user_3 network-admin auth md5 0x5632724fb8ac3699296af26281e1d0f1 priv aes-128" - " 0x5632724fb8ac3699296af26281e1d0f1 localizedkey engineID 3:3:3:3:3", + " 0x5632724fb8ac3699296af26281e1d0f1 localizedV2key engineID 3:3:3:3:3", "snmp-server user snmp_user_1 network-admin auth md5 0x5632724fb8ac3699296af26281e1d0f1" " localizedkey engineID 1:1:1:1:1", + "snmp-server user snmp_user_4 network-admin auth sha-256 0x5632724fb8ac3699296af26281e1d0f1 priv aes-128" + " 0x5632724fb8ac3699296af26281e1d0f1 localizedkey engineID 4:4:4:4:4", ] result = self.execute_module(changed=True) self.assertEqual(set(result["commands"]), set(commands)) @@ -696,10 +677,11 @@ def test_nxos_snmp_server_users_merged(self): # test merged for users self.get_config.return_value = dedent( """\ - snmp-server user user2 network-admin auth md5 0x5632724fb8ac3699296af262 priv 0x5632724fb8ac3699296af262 localizedkey engineID 2:2:2:2:2 + snmp-server user user2 network-admin auth md5 0x5632724fb8ac3699296af262 priv 0x5632724fb8ac3699296af262 localizedV2key engineID 2:2:2:2:2 snmp-server user user3 network-admin auth md5 0x5632724fb8ac3699296af262 priv aes-128 0x5632724fb8ac3699296af262 localizedkey engineID 3:3:3:3:3 snmp-server user user1 network-admin auth md5 0x5632724fb8ac3699296af262 localizedkey engineID 1:1:1:1:1 - """ + snmp-server user user4 network-admin auth sha-256 0x5632724fb8ac3699296af262 priv aes-128 0x5632724fb8ac3699296af262 localizedkey engineID 4:4:4:4:4 + """, ) set_module_args( dict( @@ -723,10 +705,8 @@ def test_nxos_snmp_server_users_merged(self): algorithm="md5", password="0x5632724fb8ac3699296af262", engine_id="2:2:2:2:2", - priv=dict( - privacy_password="0x5632724fb8ac3699296af262" - ), - localized_key=True, + priv=dict(privacy_password="0x5632724fb8ac3699296af262"), + localizedv2_key=True, ), ), dict( @@ -743,8 +723,22 @@ def test_nxos_snmp_server_users_merged(self): localized_key=True, ), ), - ] - ) + dict( + user="user4", + group="network-admin", + authentication=dict( + algorithm="sha-256", + password="0x5632724fb8ac3699296af262", + engine_id="4:4:4:4:4", + priv=dict( + privacy_password="0x5632724fb8ac3699296af262", + aes_128=True, + ), + localized_key=True, + ), + ), + ], + ), ), state="merged", ), @@ -760,7 +754,7 @@ def test_nxos_snmp_server_users_replaced(self): snmp-server user user2 network-admin auth md5 0x5632724fb8ac3699296af262 priv 0x5632724fb8ac3699296af262 localizedkey engineID 2:2:2:2:2 snmp-server user user3 network-admin auth md5 0x5632724fb8ac3699296af262 priv aes-128 0x5632724fb8ac3699296af262 localizedkey engineID 3:3:3:3:3 snmp-server user user1 network-admin auth md5 0x5632724fb8ac3699296af262 localizedkey engineID 1:1:1:1:1 - """ + """, ) set_module_args( dict( @@ -791,18 +785,16 @@ def test_nxos_snmp_server_users_replaced(self): localized_key=True, ), ), - ] - ) + ], + ), ), state="replaced", ), ignore_provider_arg, ) commands = [ - "no snmp-server user user2 network-admin auth md5 0x5632724fb8ac3699296af262 priv" - " 0x5632724fb8ac3699296af262 localizedkey engineID 2:2:2:2:2", - "no snmp-server user user3 network-admin auth md5 0x5632724fb8ac3699296af262 priv" - " aes-128 0x5632724fb8ac3699296af262 localizedkey engineID 3:3:3:3:3", + "no snmp-server user user2", + "no snmp-server user user3", "snmp-server user user4 network-admin auth md5 0x5632724fb8ac3699296af262 priv aes-128" " 0x5632724fb8ac3699296af262 localizedkey engineID 3:3:3:3:3", ] @@ -829,7 +821,7 @@ def test_nxos_snmp_server_deleted(self): snmp-server location lab snmp-server mib community-map public context public1 snmp-server source-interface traps Ethernet1/2 - """ + """, ) set_module_args(dict(state="deleted"), ignore_provider_arg) commands = [ @@ -860,7 +852,7 @@ def test_nxos_snmp_server_parsed(self): running_config=dedent( """\ snmp-server community private group network-admin - snmp-server community public use-ipv4acl myacl + snmp-server community public use-ipv4acl myacl use-ipv6acl myaclv6 snmp-server globalEnforcePriv snmp-server tcp-session auth snmp-server counter cache timeout 1800 @@ -879,7 +871,7 @@ def test_nxos_snmp_server_parsed(self): snmp-server source-interface traps Ethernet1/2 snmp-server user 1234 network-admin auth md5 0x7d425fbf09417c44bca69e1d9e9ce889 priv 0x7d425fbf09417c44bca69e1d9e9ce889 localizedkey snmp-server user snmp_user_1 network-operator auth md5 0x5632724fb8ac3699296af26281e1d0f1 localizedkey - """ + """, ), state="parsed", ), @@ -891,7 +883,7 @@ def test_nxos_snmp_server_parsed(self): contact="testswitch@localhost", communities=[ dict(name="private", group="network-admin"), - dict(name="public", use_ipv4acl="myacl"), + dict(name="public", use_ipv4acl="myacl", use_ipv6acl="myaclv6"), ], context=dict(name="public", vrf="siteA"), counter=dict(cache=dict(timeout=1800)), @@ -899,9 +891,7 @@ def test_nxos_snmp_server_parsed(self): engine_id=dict(local="00:00:00:63:00:01:00:10:20:15:10:03"), global_enforce_priv=True, location="lab", - mib=dict( - community_map=dict(community="public", context="public1") - ), + mib=dict(community_map=dict(community="public", context="public1")), packetsize=484, protocol=dict(enable=True), source_interface=dict(informs="Ethernet1/1", traps="Ethernet1/2"), @@ -916,9 +906,7 @@ def test_nxos_snmp_server_parsed(self): algorithm="md5", password="0x7d425fbf09417c44bca69e1d9e9ce889", localized_key=True, - priv=dict( - privacy_password="0x7d425fbf09417c44bca69e1d9e9ce889" - ), + priv=dict(privacy_password="0x7d425fbf09417c44bca69e1d9e9ce889"), ), ), dict( @@ -930,7 +918,7 @@ def test_nxos_snmp_server_parsed(self): localized_key=True, ), ), - ] + ], ), ) result = self.execute_module(changed=False) @@ -945,22 +933,18 @@ def test_nxos_snmp_server_rendered(self): contact="testswitch@localhost", context=dict(name="public", vrf="siteA"), counter=dict(cache=dict(timeout=1800)), + communities=[ + dict(name="private", group="network-admin"), + dict(name="public", use_ipv4acl="myacl", use_ipv6acl="myaclv6"), + ], drop=dict(unknown_engine_id=True, unknown_user=True), - engine_id=dict( - local="'00:00:00:63:00:01:00:10:20:15:10:03'" - ), + engine_id=dict(local="'00:00:00:63:00:01:00:10:20:15:10:03'"), global_enforce_priv=True, location="lab", - mib=dict( - community_map=dict( - community="public", context="public1" - ) - ), + mib=dict(community_map=dict(community="public", context="public1")), packetsize=484, protocol=dict(enable=True), - source_interface=dict( - informs="Ethernet1/1", traps="Ethernet1/2" - ), + source_interface=dict(informs="Ethernet1/1", traps="Ethernet1/2"), system_shutdown=True, tcp_session=dict(auth=True), ), @@ -985,6 +969,8 @@ def test_nxos_snmp_server_rendered(self): "snmp-server location lab", "snmp-server mib community-map public context public1", "snmp-server source-interface traps Ethernet1/2", + "snmp-server community private group network-admin", + "snmp-server community public use-ipv4acl myacl use-ipv6acl myaclv6", ] result = self.execute_module(changed=False) self.assertEqual(set(result["rendered"]), set(rendered)) @@ -1009,7 +995,7 @@ def test_nxos_snmp_server_gathered(self): snmp-server location lab snmp-server mib community-map public context public1 snmp-server source-interface traps Ethernet1/2 - """ + """, ) set_module_args(dict(state="gathered"), ignore_provider_arg) @@ -1022,9 +1008,7 @@ def test_nxos_snmp_server_gathered(self): engine_id=dict(local="00:00:00:63:00:01:00:10:20:15:10:03"), global_enforce_priv=True, location="lab", - mib=dict( - community_map=dict(community="public", context="public1") - ), + mib=dict(community_map=dict(community="public", context="public1")), packetsize=484, protocol=dict(enable=True), source_interface=dict(informs="Ethernet1/1", traps="Ethernet1/2"), @@ -1037,7 +1021,7 @@ def test_nxos_snmp_server_gathered(self): def test_nxos_snmp_server_gathered_empty(self): self.get_config.return_value = dedent( """\ - """ + """, ) set_module_args(dict(state="gathered"), ignore_provider_arg) diff --git a/tests/unit/modules/network/nxos/test_nxos_static_route.py b/tests/unit/modules/network/nxos/test_nxos_static_route.py deleted file mode 100644 index 55cf040d0..000000000 --- a/tests/unit/modules/network/nxos/test_nxos_static_route.py +++ /dev/null @@ -1,126 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# Make coding more python3-ish - -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.plugins.modules import nxos_static_route -from .nxos_module import TestNxosModule, load_fixture, set_module_args - - -class TestNxosStaticRouteModule(TestNxosModule): - - module = nxos_static_route - - def setUp(self): - super(TestNxosStaticRouteModule, self).setUp() - - self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_static_route.load_config" - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_static_route.get_config" - ) - self.get_config = self.mock_get_config.start() - - def tearDown(self): - super(TestNxosStaticRouteModule, self).tearDown() - self.mock_load_config.stop() - self.mock_get_config.stop() - - def load_fixtures(self, commands=None, device=""): - self.get_config.return_value = load_fixture( - "", "nxos_static_route.cfg" - ) - self.load_config.return_value = None - - def test_nxos_static_route_present(self): - set_module_args(dict(prefix="192.168.20.64/24", next_hop="192.0.2.3")) - self.execute_module( - changed=True, commands=["ip route 192.168.20.0/24 192.0.2.3"] - ) - - def test_nxos_static_route_present_no_defaults(self): - set_module_args( - dict( - prefix="192.168.20.64/24", - next_hop="192.0.2.3", - route_name="testing", - pref=100, - ) - ) - self.execute_module( - changed=True, - commands=["ip route 192.168.20.0/24 192.0.2.3 name testing 100"], - ) - - def test_nxos_static_route_present_vrf(self): - set_module_args( - dict(prefix="192.168.20.64/24", next_hop="192.0.2.3", vrf="test") - ) - self.execute_module( - changed=True, - sort=False, - commands=[ - "vrf context test", - "ip route 192.168.20.0/24 192.0.2.3", - ], - ) - - def test_nxos_static_route_no_change(self): - set_module_args(dict(prefix="10.10.30.64/24", next_hop="1.2.4.8")) - self.execute_module(changed=False, commands=[]) - - def test_nxos_static_route_absent(self): - set_module_args( - dict(prefix="10.10.30.12/24", next_hop="1.2.4.8", state="absent") - ) - self.execute_module( - changed=True, commands=["no ip route 10.10.30.0/24 1.2.4.8"] - ) - - def test_nxos_static_route_absent_no_change(self): - set_module_args( - dict( - prefix="192.168.20.6/24", next_hop="192.0.2.3", state="absent" - ) - ) - self.execute_module(changed=False, commands=[]) - - def test_nxos_static_route_absent_vrf(self): - set_module_args( - dict( - prefix="10.11.12.13/14", - next_hop="15.16.17.18", - vrf="test", - state="absent", - ) - ) - self.execute_module( - changed=True, - sort=False, - commands=[ - "vrf context test", - "no ip route 10.8.0.0/14 15.16.17.18", - ], - ) diff --git a/tests/unit/modules/network/nxos/test_nxos_static_routes.py b/tests/unit/modules/network/nxos/test_nxos_static_routes.py index dd2cff02e..76ed4a3a9 100644 --- a/tests/unit/modules/network/nxos/test_nxos_static_routes.py +++ b/tests/unit/modules/network/nxos/test_nxos_static_routes.py @@ -5,368 +5,858 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type +from textwrap import dedent + from ansible_collections.cisco.nxos.plugins.modules import nxos_static_routes -from ansible_collections.cisco.nxos.tests.unit.compat.mock import ( - patch, - MagicMock, -) -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - set_module_args, -) -from .nxos_module import TestNxosModule, load_fixture +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch +from .nxos_module import TestNxosModule, set_module_args -class TestNxosStaticRoutesModule(TestNxosModule): +ignore_provider_arg = True + + +class TestNxosStaticRoutesModule(TestNxosModule): module = nxos_static_routes def setUp(self): super(TestNxosStaticRoutesModule, self).setUp() - self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config" - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config" - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection" - ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() - ) - - self.mock_get_resource_connection_facts = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" + self.mock_get_resource_connection = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() - ) - - self.mock_edit_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.static_routes.static_routes.Static_routes.edit_config" - ) - self.edit_config = self.mock_edit_config.start() + self.get_resource_connection = self.mock_get_resource_connection.start() self.mock_execute_show_command = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.static_routes.static_routes.Static_routesFacts.get_device_data" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.static_routes.static_routes.Static_routesFacts.get_static_routes_data", ) self.execute_show_command = self.mock_execute_show_command.start() def tearDown(self): super(TestNxosStaticRoutesModule, self).tearDown() - self.mock_get_resource_connection_config.stop() - self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() + self.get_resource_connection.stop() self.mock_execute_show_command.stop() - def load_fixtures(self, commands=None, device=""): - def load_from_file(*args, **kwargs): - non_vrf_data = [ - "ip route 192.0.2.16/28 192.0.2.24 name initial_route" - ] - vrf_data = [ - "vrf context test\n ip route 192.0.2.96/28 192.0.2.122 vrf dest_vrf" - "\n ip route static bfd Vlan100 192.168.1.100\n ipv6 route 2001:db8:12::/32 2001:db8::1001 name ipv6_route 3\n" - ] + def test_nxos_static_routes_all_idempotent(self): + self.execute_show_command.return_value = dedent( + """\ + ip route 192.0.2.16/28 192.0.2.23 name replaced_route1 3 + ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2 + ip route 192.0.2.80/28 192.0.2.26 tag 12 + vrf context Test + ip route 192.0.2.48/28 192.0.2.13 + ip route 192.0.2.48/28 192.0.2.14 5 + vrf context management + ip name-server 192.168.255.1 + ip route 0.0.0.0/0 192.168.255.1 + vrf context newvrf + ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11 + ip route 10.0.11.0/25 10.0.11.10 tag 22 11 + ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11 + ip route 192.0.2.48/28 loopback22 192.0.2.13 + ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5 + ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11 + ipv6 route 2200:10::/36 port-channel22 2048:ae12::1 + ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22 + vrf context trial_vrf + ip route 192.0.2.64/28 192.0.2.22 tag 4 + ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 + """, + ) - output = non_vrf_data + vrf_data - return output + config = [ + { + "address_families": [ + { + "afi": "ipv4", + "routes": [ + { + "next_hops": [ + { + "forward_router_address": "192.0.2.23", + "admin_distance": 3, + "route_name": "replaced_route1", + }, + { + "interface": "Ethernet1/2", + "forward_router_address": "192.0.2.45", + "dest_vrf": "destinationVRF", + "route_name": "replaced_route2", + }, + ], + "dest": "192.0.2.16/28", + }, + { + "next_hops": [{"forward_router_address": "192.0.2.26", "tag": 12}], + "dest": "192.0.2.80/28", + }, + ], + }, + ], + }, + { + "vrf": "Test", + "address_families": [ + { + "afi": "ipv4", + "routes": [ + { + "next_hops": [ + {"forward_router_address": "192.0.2.13"}, + { + "forward_router_address": "192.0.2.14", + "admin_distance": 5, + }, + ], + "dest": "192.0.2.48/28", + }, + ], + }, + ], + }, + { + "vrf": "management", + "address_families": [ + { + "afi": "ipv4", + "routes": [ + { + "next_hops": [{"forward_router_address": "192.168.255.1"}], + "dest": "0.0.0.0/0", + }, + ], + }, + ], + }, + { + "vrf": "newvrf", + "address_families": [ + { + "afi": "ipv4", + "routes": [ + { + "next_hops": [ + { + "forward_router_address": "10.0.10.3", + "admin_distance": 11, + "tag": 22323, + "route_name": "test_name", + }, + ], + "dest": "10.0.10.0/25", + }, + { + "next_hops": [ + { + "forward_router_address": "10.0.11.10", + "admin_distance": 11, + "tag": 22, + }, + { + "forward_router_address": "10.0.11.12", + "admin_distance": 11, + "dest_vrf": "Test", + "tag": 22, + }, + ], + "dest": "10.0.11.0/25", + }, + { + "next_hops": [ + { + "interface": "loopback22", + "forward_router_address": "192.0.2.13", + }, + ], + "dest": "192.0.2.48/28", + }, + ], + }, + { + "afi": "ipv6", + "routes": [ + { + "next_hops": [ + { + "forward_router_address": "2048:ae12::1", + "admin_distance": 5, + "dest_vrf": "dest", + }, + { + "interface": "mgmt0", + "forward_router_address": "2048:ae12::1", + "admin_distance": 11, + "tag": 22, + }, + { + "interface": "port-channel22", + "forward_router_address": "2048:ae12::1", + }, + { + "interface": "Ethernet2/1", + "forward_router_address": "2048:ae12::1", + "admin_distance": 22, + "route_name": "test_name2", + }, + ], + "dest": "2200:10::/36", + }, + ], + }, + ], + }, + { + "vrf": "trial_vrf", + "address_families": [ + { + "afi": "ipv4", + "routes": [ + { + "next_hops": [ + {"forward_router_address": "192.0.2.22", "tag": 4}, + { + "forward_router_address": "192.0.2.23", + "admin_distance": 1, + "route_name": "merged_route", + }, + ], + "dest": "192.0.2.64/28", + }, + ], + }, + ], + }, + ] - self.execute_show_command.side_effect = load_from_file + for state in ["merged", "replaced", "overridden"]: + set_module_args({"config": config, "state": state}) + result = self.execute_module(changed=False) + self.assertEqual(result["commands"], []) def test_nxos_static_routes_merged(self): + self.execute_show_command.return_value = dedent( + """\ + ip route 192.0.2.16/28 192.0.2.23 name replaced_route1 3 + """, + ) set_module_args( dict( config=[ - dict( - address_families=[ - dict( - afi="ipv4", - routes=[ - dict( - dest="192.0.2.32/28", - next_hops=[ - dict( - forward_router_address="192.0.2.40", - interface="Ethernet1/2", - admin_distance=5, - ) + { + "address_families": [ + { + "afi": "ipv4", + "routes": [ + { + "next_hops": [ + { + "forward_router_address": "192.0.2.23", + "admin_distance": 3, + "route_name": "replaced_route1", + }, + { + "interface": "Ethernet1/2", + "forward_router_address": "192.0.2.45", + "dest_vrf": "destinationVRF", + "route_name": "replaced_route2", + }, + ], + "dest": "192.0.2.16/28", + }, + { + "next_hops": [ + {"forward_router_address": "192.0.2.26", "tag": 12}, ], - ) + "dest": "192.0.2.80/28", + }, ], - ) - ] - ) - ], - state="merged", - ) - ) - commands = [ - "configure terminal", - "ip route 192.0.2.32/28 Ethernet1/2 192.0.2.40 5", - ] - self.execute_module(changed=True, commands=commands) - - def test_nxos_static_routes_merged_idempotent(self): - set_module_args( - dict( - config=[ - dict( - address_families=[ - dict( - afi="ipv4", - routes=[ - dict( - dest="192.0.2.16/28", - next_hops=[ - dict( - forward_router_address="192.0.2.24", - route_name="initial_route", - ) + }, + ], + }, + { + "vrf": "Test", + "address_families": [ + { + "afi": "ipv4", + "routes": [ + { + "next_hops": [ + {"forward_router_address": "192.0.2.13"}, + { + "forward_router_address": "192.0.2.14", + "admin_distance": 5, + }, ], - ) + "dest": "192.0.2.48/28", + }, ], - ) - ] - ) - ], - state="merged", - ) - ) - self.execute_module(changed=False, commands=[]) - - def test_nxos_static_routes_replaced(self): - set_module_args( - dict( - config=[ - dict( - address_families=[ - dict( - afi="ipv4", - routes=[ - dict( - dest="192.0.2.16/28", - next_hops=[ - dict( - forward_router_address="192.0.2.50", - tag=12, - route_name="replaced_route", - ) + }, + ], + }, + { + "vrf": "management", + "address_families": [ + { + "afi": "ipv4", + "routes": [ + { + "next_hops": [{"forward_router_address": "192.168.255.1"}], + "dest": "0.0.0.0/0", + }, + ], + }, + ], + }, + { + "vrf": "newvrf", + "address_families": [ + { + "afi": "ipv4", + "routes": [ + { + "next_hops": [ + { + "forward_router_address": "10.0.10.3", + "admin_distance": 11, + "tag": 22323, + "route_name": "test_name", + }, + ], + "dest": "10.0.10.0/25", + }, + { + "next_hops": [ + { + "forward_router_address": "10.0.11.10", + "admin_distance": 11, + "tag": 22, + }, + { + "forward_router_address": "10.0.11.12", + "admin_distance": 11, + "dest_vrf": "Test", + "tag": 22, + }, + ], + "dest": "10.0.11.0/25", + }, + { + "next_hops": [ + { + "interface": "loopback22", + "forward_router_address": "192.0.2.13", + }, + ], + "dest": "192.0.2.48/28", + }, + ], + }, + { + "afi": "ipv6", + "routes": [ + { + "next_hops": [ + { + "forward_router_address": "2048:ae12::1", + "admin_distance": 5, + "dest_vrf": "dest", + }, + { + "interface": "mgmt0", + "forward_router_address": "2048:ae12::1", + "admin_distance": 11, + "tag": 22, + }, + { + "interface": "port-channel22", + "forward_router_address": "2048:ae12::1", + }, + { + "interface": "Ethernet2/1", + "forward_router_address": "2048:ae12::1", + "admin_distance": 22, + "route_name": "test_name2", + }, + ], + "dest": "2200:10::/36", + }, + ], + }, + ], + }, + { + "vrf": "trial_vrf", + "address_families": [ + { + "afi": "ipv4", + "routes": [ + { + "next_hops": [ + {"forward_router_address": "192.0.2.22", "tag": 4}, + { + "forward_router_address": "192.0.2.23", + "admin_distance": 1, + "route_name": "merged_route", + }, ], - ) + "dest": "192.0.2.64/28", + }, ], - ) - ] - ) + }, + ], + }, ], - state="replaced", - ) + state="merged", + ), ) commands = [ - "configure terminal", - "no ip route 192.0.2.16/28 192.0.2.24 name initial_route", - "ip route 192.0.2.16/28 192.0.2.50 name replaced_route tag 12", + "ip route 192.0.2.80/28 192.0.2.26 tag 12", + "ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2", + "vrf context newvrf", + "ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11", + "ip route 10.0.11.0/25 10.0.11.10 tag 22 11", + "ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11", + "ip route 192.0.2.48/28 loopback22 192.0.2.13", + "ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5", + "ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11", + "ipv6 route 2200:10::/36 port-channel22 2048:ae12::1", + "ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22", + "vrf context Test", + "ip route 192.0.2.48/28 192.0.2.13", + "ip route 192.0.2.48/28 192.0.2.14 5", + "vrf context trial_vrf", + "ip route 192.0.2.64/28 192.0.2.22 tag 4", + "ip route 192.0.2.64/28 192.0.2.23 name merged_route 1", + "vrf context management", + "ip route 0.0.0.0/0 192.168.255.1", ] self.execute_module(changed=True, commands=commands) - def test_nxos_static_routes_replaced_idempotent(self): + def test_nxos_static_routes_replaced(self): + self.execute_show_command.return_value = dedent( + """\ + ip route 192.0.2.16/28 192.0.2.23 name replaced_route1 3 + ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2 + ip route 192.0.2.80/28 192.0.2.26 tag 12 + vrf context Test + ip route 192.0.2.48/28 192.0.2.13 + ip route 192.0.2.48/28 192.0.2.14 5 + vrf context management + ip name-server 192.168.255.1 + ip route 0.0.0.0/0 192.168.255.1 + vrf context newvrf + ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11 + ip route 10.0.11.0/25 10.0.11.10 tag 22 11 + ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11 + ip route 192.0.2.48/28 loopback22 192.0.2.13 + ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5 + ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11 + ipv6 route 2200:10::/36 port-channel22 2048:ae12::1 + ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22 + vrf context trial_vrf + ip route 192.0.2.64/28 192.0.2.22 tag 4 + ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 + """, + ) set_module_args( dict( config=[ - dict( - address_families=[ - dict( - afi="ipv4", - routes=[ - dict( - dest="192.0.2.16/28", - next_hops=[ - dict( - forward_router_address="192.0.2.24", - route_name="initial_route", - ) + { + "address_families": [ + { + "afi": "ipv4", + "routes": [ + { + "next_hops": [ + { + "forward_router_address": "192.0.2.23", + "admin_distance": 3, + "route_name": "replaced_route1", + }, + { + "interface": "Ethernet1/2", + "forward_router_address": "192.0.2.45", + "dest_vrf": "destinationVRF", + "route_name": "replaced_route2", + }, + ], + "dest": "192.0.2.16/28", + }, + { + "next_hops": [ + {"forward_router_address": "192.0.2.27", "tag": 13}, ], - ) + "dest": "192.0.2.80/28", + }, ], - ) - ] - ) - ], - state="replaced", - ) - ) - self.execute_module(changed=False, commands=[]) - - def test_nxos_static_routes_overridden(self): - set_module_args( - dict( - config=[ - dict( - address_families=[ - dict( - afi="ipv4", - routes=[ - dict( - dest="192.0.2.112/28", - next_hops=[ - dict( - forward_router_address="192.0.2.68", - route_name="overridden_route", - dest_vrf="end_vrf", - ) + }, + ], + }, + { + "vrf": "trial_vrf", + "address_families": [ + { + "afi": "ipv4", + "routes": [ + { + "next_hops": [ + { + "forward_router_address": "192.0.2.23", + "admin_distance": 1, + "route_name": "merged_route", + }, ], - ) + "dest": "192.0.2.0/28", + }, ], - ) - ] - ) + }, + ], + }, ], - state="overridden", - ) + state="replaced", + ), ) commands = [ - "configure terminal", - "no ip route 192.0.2.16/28 192.0.2.24 name initial_route", - "ip route 192.0.2.112/28 192.0.2.68 vrf end_vrf name overridden_route", - "vrf context test", - "no ipv6 route 2001:db8:12::/32 2001:db8::1001 name ipv6_route 3", - "no ip route 192.0.2.96/28 192.0.2.122 vrf dest_vrf", + "ip route 192.0.2.80/28 192.0.2.27 tag 13", + "no ip route 192.0.2.80/28 192.0.2.26 tag 12", + "vrf context trial_vrf", + "ip route 192.0.2.0/28 192.0.2.23 name merged_route 1", + "no ip route 192.0.2.64/28 192.0.2.22 tag 4", + "no ip route 192.0.2.64/28 192.0.2.23 name merged_route 1", ] - self.execute_module(changed=True, commands=commands) + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], commands) - def test_nxos_static_routes_overridden_idempotent(self): + def test_nxos_static_routes_overridden(self): + self.execute_show_command.return_value = dedent( + """\ + ip route 192.0.2.17/28 192.0.2.23 name replaced_route1 3 + ip route 192.0.2.17/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2 + ip route 192.0.2.79/28 192.0.2.26 tag 12 + vrf context Test + ip route 192.0.2.48/28 192.0.2.13 + ip route 192.0.2.48/28 192.0.2.14 5 + vrf context management + ip name-server 192.168.255.1 + ip route 0.0.0.0/0 192.168.255.1 + vrf context newvrf + ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11 + ip route 10.0.11.0/25 10.0.11.10 tag 22 11 + ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11 + ip route 192.0.2.48/28 loopback22 192.0.2.13 + ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5 + ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11 + ipv6 route 2200:10::/36 port-channel22 2048:ae12::1 + ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22 + vrf context trial_vrf + ip route 192.0.2.64/28 192.0.2.22 tag 4 + ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 + """, + ) set_module_args( dict( config=[ - dict( - vrf="test", - address_families=[ - dict( - afi="ipv4", - routes=[ - dict( - dest="192.0.2.96/28", - next_hops=[ - dict( - forward_router_address="192.0.2.122", - dest_vrf="dest_vrf", - ) + { + "address_families": [ + { + "afi": "ipv4", + "routes": [ + { + "next_hops": [ + { + "forward_router_address": "192.0.2.23", + "admin_distance": 3, + "route_name": "replaced_route1", + }, + { + "interface": "Ethernet1/2", + "forward_router_address": "192.0.2.45", + "dest_vrf": "destinationVRF", + "route_name": "replaced_route2", + }, + ], + "dest": "192.0.2.16/28", + }, + { + "next_hops": [ + {"forward_router_address": "192.0.2.27", "tag": 13}, ], - ) + "dest": "192.0.2.80/28", + }, ], - ) + }, ], - ), - dict( - address_families=[ - dict( - afi="ipv4", - routes=[ - dict( - dest="192.0.2.16/28", - next_hops=[ - dict( - forward_router_address="192.0.2.24", - route_name="initial_route", - ) + }, + { + "vrf": "trial_vrf", + "address_families": [ + { + "afi": "ipv4", + "routes": [ + { + "next_hops": [ + { + "forward_router_address": "192.0.2.23", + "admin_distance": 1, + "route_name": "merged_route", + }, ], - ) + "dest": "192.0.2.0/28", + }, ], - ) - ] - ), + }, + ], + }, ], state="overridden", - ) + ), ) - self.execute_module(changed=False, commands=[]) + commands = [ + "ip route 192.0.2.16/28 192.0.2.23 name replaced_route1 3", + "ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2", + "ip route 192.0.2.80/28 192.0.2.27 tag 13", + "no ip route 192.0.2.17/28 192.0.2.23 name replaced_route1 3", + "no ip route 192.0.2.17/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2", + "no ip route 192.0.2.79/28 192.0.2.26 tag 12", + "vrf context trial_vrf", + "ip route 192.0.2.0/28 192.0.2.23 name merged_route 1", + "no ip route 192.0.2.64/28 192.0.2.22 tag 4", + "no ip route 192.0.2.64/28 192.0.2.23 name merged_route 1", + "vrf context Test", + "no ip route 192.0.2.48/28 192.0.2.13", + "no ip route 192.0.2.48/28 192.0.2.14 5", + "vrf context management", + "no ip route 0.0.0.0/0 192.168.255.1", + "vrf context newvrf", + "no ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11", + "no ip route 10.0.11.0/25 10.0.11.10 tag 22 11", + "no ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11", + "no ip route 192.0.2.48/28 loopback22 192.0.2.13", + "no ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5", + "no ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11", + "no ipv6 route 2200:10::/36 port-channel22 2048:ae12::1", + "no ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22", + ] + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], commands) def test_nxos_static_routes_deletedvrf(self): - set_module_args(dict(config=[dict(vrf="test")], state="deleted")) + self.execute_show_command.return_value = dedent( + """\ + ip route 192.0.2.17/28 192.0.2.23 name replaced_route1 3 + ip route 192.0.2.17/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2 + ip route 192.0.2.79/28 192.0.2.26 tag 12 + vrf context Test + ip route 192.0.2.48/28 192.0.2.13 + ip route 192.0.2.48/28 192.0.2.14 5 + vrf context management + ip name-server 192.168.255.1 + ip route 0.0.0.0/0 192.168.255.1 + vrf context newvrf + ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11 + ip route 10.0.11.0/25 10.0.11.10 tag 22 11 + ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11 + ip route 192.0.2.48/28 loopback22 192.0.2.13 + ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5 + ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11 + ipv6 route 2200:10::/36 port-channel22 2048:ae12::1 + ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22 + vrf context trial_vrf + ip route 192.0.2.64/28 192.0.2.22 tag 4 + ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 + """, + ) + set_module_args(dict(config=[dict(vrf="Test")], state="deleted")) commands = [ - "vrf context test", - "no ip route 192.0.2.96/28 192.0.2.122 vrf dest_vrf", - "no ipv6 route 2001:db8:12::/32 2001:db8::1001 name ipv6_route 3", + "vrf context Test", + "no ip route 192.0.2.48/28 192.0.2.13", + "no ip route 192.0.2.48/28 192.0.2.14 5", ] - self.execute_module(changed=True, commands=commands) + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], commands) def test_nxos_static_routes_deletedafi(self): + self.execute_show_command.return_value = dedent( + """\ + ip route 192.0.2.17/28 192.0.2.23 name replaced_route1 3 + ip route 192.0.2.17/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2 + ip route 192.0.2.79/28 192.0.2.26 tag 12 + vrf context Test + ip route 192.0.2.48/28 192.0.2.13 + ip route 192.0.2.48/28 192.0.2.14 5 + vrf context management + ip name-server 192.168.255.1 + ip route 0.0.0.0/0 192.168.255.1 + vrf context newvrf + ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11 + ip route 10.0.11.0/25 10.0.11.10 tag 22 11 + ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11 + ip route 192.0.2.48/28 loopback22 192.0.2.13 + ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5 + ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11 + ipv6 route 2200:10::/36 port-channel22 2048:ae12::1 + ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22 + vrf context trial_vrf + ip route 192.0.2.64/28 192.0.2.22 tag 4 + ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 + """, + ) set_module_args( dict( config=[dict(address_families=[dict(afi="ipv4")])], state="deleted", - ) + ), ) commands = [ - "configure terminal", - "no ip route 192.0.2.16/28 192.0.2.24 name initial_route", + "no ip route 192.0.2.17/28 192.0.2.23 name replaced_route1 3", + "no ip route 192.0.2.17/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2", + "no ip route 192.0.2.79/28 192.0.2.26 tag 12", ] - self.execute_module(changed=True, commands=commands) + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], commands) def test_nxos_static_routes_deleteddest(self): + self.execute_show_command.return_value = dedent( + """\ + ip route 192.0.2.17/28 192.0.2.23 name replaced_route1 3 + ip route 192.0.2.17/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2 + ip route 192.0.2.79/28 192.0.2.26 tag 12 + vrf context Test + ip route 192.0.2.48/28 192.0.2.13 + ip route 192.0.2.48/28 192.0.2.14 5 + vrf context management + ip name-server 192.168.255.1 + ip route 0.0.0.0/0 192.168.255.1 + vrf context newvrf + ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11 + ip route 10.0.11.0/25 10.0.11.10 tag 22 11 + ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11 + ip route 192.0.2.48/28 loopback22 192.0.2.13 + ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5 + ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11 + ipv6 route 2200:10::/36 port-channel22 2048:ae12::1 + ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22 + vrf context trial_vrf + ip route 192.0.2.64/28 192.0.2.22 tag 4 + ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 + """, + ) set_module_args( dict( config=[ dict( - vrf="test", - address_families=[ - dict( - afi="ipv4", routes=[dict(dest="192.0.2.96/28")] - ) - ], - ) + vrf="Test", + address_families=[dict(afi="ipv4", routes=[dict(dest="192.0.2.48/28")])], + ), ], state="deleted", - ) + ), ) commands = [ - "vrf context test", - "no ip route 192.0.2.96/28 192.0.2.122 vrf dest_vrf", + "vrf context Test", + "no ip route 192.0.2.48/28 192.0.2.13", + "no ip route 192.0.2.48/28 192.0.2.14 5", ] - self.execute_module(changed=True, commands=commands) + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], commands) def test_nxos_static_routes_deletedroute(self): + self.execute_show_command.return_value = dedent( + """\ + ip route 192.0.2.17/28 192.0.2.23 name replaced_route1 3 + ip route 192.0.2.17/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2 + ip route 192.0.2.79/28 192.0.2.26 tag 12 + vrf context Test + ip route 192.0.2.48/28 192.0.2.13 + ip route 192.0.2.48/28 192.0.2.14 5 + vrf context management + ip name-server 192.168.255.1 + ip route 0.0.0.0/0 192.168.255.1 + vrf context newvrf + ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11 + ip route 10.0.11.0/25 10.0.11.10 tag 22 11 + ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11 + ip route 192.0.2.48/28 loopback22 192.0.2.13 + ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5 + ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11 + ipv6 route 2200:10::/36 port-channel22 2048:ae12::1 + ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22 + vrf context trial_vrf + ip route 192.0.2.64/28 192.0.2.22 tag 4 + ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 + """, + ) set_module_args( dict( config=[ - dict( - vrf="test", - address_families=[ - dict( - afi="ipv6", - routes=[ - dict( - dest="2001:db8:12::/32", - next_hops=[ - dict( - forward_router_address="2001:db8::1001", - route_name="ipv6_route", - admin_distance=3, - ) + { + "address_families": [ + { + "afi": "ipv4", + "routes": [ + { + "next_hops": [ + { + "forward_router_address": "192.0.2.23", + "admin_distance": 3, + "route_name": "replaced_route1", + }, + { + "interface": "Ethernet1/2", + "forward_router_address": "192.0.2.45", + "dest_vrf": "destinationVRF", + "route_name": "replaced_route2", + }, + ], + "dest": "192.0.2.16/28", + }, + { + "next_hops": [ + {"forward_router_address": "192.0.2.26", "tag": 12}, ], - ) + "dest": "192.0.2.80/28", + }, ], - ) + }, ], - ) + }, + { + "vrf": "Test", + "address_families": [ + { + "afi": "ipv4", + "routes": [ + { + "next_hops": [ + {"forward_router_address": "192.0.2.13"}, + { + "forward_router_address": "192.0.2.14", + "admin_distance": 5, + }, + ], + "dest": "192.0.2.48/28", + }, + ], + }, + ], + }, ], state="deleted", - ) + ), ) commands = [ - "vrf context test", - "no ipv6 route 2001:db8:12::/32 2001:db8::1001 name ipv6_route 3", + "no ip route 192.0.2.17/28 192.0.2.23 name replaced_route1 3", + "no ip route 192.0.2.17/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2", + "no ip route 192.0.2.79/28 192.0.2.26 tag 12", + "vrf context Test", + "no ip route 192.0.2.48/28 192.0.2.13", + "no ip route 192.0.2.48/28 192.0.2.14 5", ] - self.execute_module(changed=True, commands=commands) + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], commands) def test_nxos_static_routes_rendered(self): set_module_args( @@ -383,150 +873,406 @@ def test_nxos_static_routes_rendered(self): next_hops=[ dict( forward_router_address="2048:ae12::/64", - interface="Eth1/4", + interface="Ethernet1/4", admin_distance=5, - ) + ), ], - ) + ), ], - ) + ), ], - ) + ), ], state="rendered", - ) + ), ) commands = [ "vrf context testvrf", "ipv6 route 1200:10::/64 Ethernet1/4 2048:ae12::/64 5", ] result = self.execute_module(changed=False) - self.assertEqual( - sorted(result["rendered"]), sorted(commands), result["rendered"] - ) + self.assertEqual(result["rendered"], commands) def test_nxos_static_routes_parsed(self): set_module_args( dict( - running_config="""ip route 192.0.2.16/28 192.0.2.24 name initial_route - vrf context test - ip route 192.0.2.96/28 192.0.2.122 vrf dest_vrf - ipv6 route 2001:db8:12::/32 2001:db8::1001 name ipv6_route 3""", + running_config=dedent( + """\ + ip route 192.0.2.16/28 192.0.2.23 name replaced_route1 3 + ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2 + ip route 192.0.2.80/28 192.0.2.26 tag 12 + vrf context Test + ip route 192.0.2.48/28 192.0.2.13 + ip route 192.0.2.48/28 192.0.2.14 5 + vrf context management + ip name-server 192.168.255.1 + ip route 0.0.0.0/0 192.168.255.1 + vrf context newvrf + ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11 + ip route 10.0.11.0/25 10.0.11.10 tag 22 11 + ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11 + ip route 192.0.2.48/28 loopback22 192.0.2.13 + ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5 + ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11 + ipv6 route 2200:10::/36 port-channel22 2048:ae12::1 + ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22 + vrf context trial_vrf + ip route 192.0.2.64/28 192.0.2.22 tag 4 + ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 + """, + ), state="parsed", - ) + ), ) result = self.execute_module(changed=False) compare_list = [ { - "vrf": "test", "address_families": [ { + "afi": "ipv4", "routes": [ { - "dest": "192.0.2.96/28", "next_hops": [ { - "dest_vrf": "dest_vrf", - "forward_router_address": "192.0.2.122", - } + "forward_router_address": "192.0.2.23", + "admin_distance": 3, + "route_name": "replaced_route1", + }, + { + "interface": "Ethernet1/2", + "forward_router_address": "192.0.2.45", + "dest_vrf": "destinationVRF", + "route_name": "replaced_route2", + }, + ], + "dest": "192.0.2.16/28", + }, + { + "next_hops": [{"forward_router_address": "192.0.2.26", "tag": 12}], + "dest": "192.0.2.80/28", + }, + ], + }, + ], + }, + { + "vrf": "Test", + "address_families": [ + { + "afi": "ipv4", + "routes": [ + { + "next_hops": [ + {"forward_router_address": "192.0.2.13"}, + {"forward_router_address": "192.0.2.14", "admin_distance": 5}, ], - } + "dest": "192.0.2.48/28", + }, ], + }, + ], + }, + { + "vrf": "management", + "address_families": [ + { "afi": "ipv4", + "routes": [ + { + "next_hops": [{"forward_router_address": "192.168.255.1"}], + "dest": "0.0.0.0/0", + }, + ], }, + ], + }, + { + "vrf": "newvrf", + "address_families": [ { + "afi": "ipv4", "routes": [ { - "dest": "2001:db8:12::/32", "next_hops": [ { - "route_name": "ipv6_route", - "forward_router_address": "2001:db8::1001", - "admin_distance": 3, - } + "forward_router_address": "10.0.10.3", + "admin_distance": 11, + "tag": 22323, + "route_name": "test_name", + }, ], - } + "dest": "10.0.10.0/25", + }, + { + "next_hops": [ + { + "forward_router_address": "10.0.11.10", + "admin_distance": 11, + "tag": 22, + }, + { + "forward_router_address": "10.0.11.12", + "admin_distance": 11, + "dest_vrf": "Test", + "tag": 22, + }, + ], + "dest": "10.0.11.0/25", + }, + { + "next_hops": [ + { + "interface": "loopback22", + "forward_router_address": "192.0.2.13", + }, + ], + "dest": "192.0.2.48/28", + }, ], + }, + { "afi": "ipv6", + "routes": [ + { + "next_hops": [ + { + "forward_router_address": "2048:ae12::1", + "admin_distance": 5, + "dest_vrf": "dest", + }, + { + "interface": "mgmt0", + "forward_router_address": "2048:ae12::1", + "admin_distance": 11, + "tag": 22, + }, + { + "interface": "port-channel22", + "forward_router_address": "2048:ae12::1", + }, + { + "interface": "Ethernet2/1", + "forward_router_address": "2048:ae12::1", + "admin_distance": 22, + "route_name": "test_name2", + }, + ], + "dest": "2200:10::/36", + }, + ], }, ], }, { + "vrf": "trial_vrf", "address_families": [ { + "afi": "ipv4", "routes": [ { - "dest": "192.0.2.16/28", "next_hops": [ + {"forward_router_address": "192.0.2.22", "tag": 4}, { - "route_name": "initial_route", - "forward_router_address": "192.0.2.24", - } + "forward_router_address": "192.0.2.23", + "admin_distance": 1, + "route_name": "merged_route", + }, ], - } + "dest": "192.0.2.64/28", + }, ], - "afi": "ipv4", - } - ] + }, + ], }, ] - self.assertEqual(result["parsed"], compare_list, result["parsed"]) + self.assertEqual(result["parsed"], compare_list) def test_nxos_static_routes_gathered(self): + self.execute_show_command.return_value = dedent( + """\ + ip route 192.0.2.17/28 192.0.2.23 name replaced_route1 3 + ip route 192.0.2.17/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2 + ip route 192.0.2.79/28 192.0.2.26 tag 12 + vrf context Test + ip route 192.0.2.48/28 192.0.2.13 + ip route 192.0.2.48/28 192.0.2.14 5 + vrf context management + ip name-server 192.168.255.1 + ip route 0.0.0.0/0 192.168.255.1 + vrf context newvrf + ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11 + ip route 10.0.11.0/25 10.0.11.10 tag 22 11 + ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11 + ip route 192.0.2.48/28 loopback22 192.0.2.13 + ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5 + ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11 + ipv6 route 2200:10::/36 port-channel22 2048:ae12::1 + ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22 + vrf context trial_vrf + ip route 192.0.2.64/28 192.0.2.22 tag 4 + ip route 192.0.2.64/28 192.0.2.23 name merged_route 1 + """, + ) set_module_args(dict(config=[], state="gathered")) result = self.execute_module(changed=False) compare_list = [ { - "vrf": "test", "address_families": [ { + "afi": "ipv4", "routes": [ { - "dest": "192.0.2.96/28", "next_hops": [ { - "dest_vrf": "dest_vrf", - "forward_router_address": "192.0.2.122", - } + "forward_router_address": "192.0.2.23", + "admin_distance": 3, + "route_name": "replaced_route1", + }, + { + "interface": "Ethernet1/2", + "forward_router_address": "192.0.2.45", + "dest_vrf": "destinationVRF", + "route_name": "replaced_route2", + }, ], - } + "dest": "192.0.2.17/28", + }, + { + "next_hops": [{"forward_router_address": "192.0.2.26", "tag": 12}], + "dest": "192.0.2.79/28", + }, ], + }, + ], + }, + { + "vrf": "Test", + "address_families": [ + { "afi": "ipv4", + "routes": [ + { + "next_hops": [ + {"forward_router_address": "192.0.2.13"}, + {"forward_router_address": "192.0.2.14", "admin_distance": 5}, + ], + "dest": "192.0.2.48/28", + }, + ], }, + ], + }, + { + "vrf": "management", + "address_families": [ { + "afi": "ipv4", + "routes": [ + { + "next_hops": [{"forward_router_address": "192.168.255.1"}], + "dest": "0.0.0.0/0", + }, + ], + }, + ], + }, + { + "vrf": "newvrf", + "address_families": [ + { + "afi": "ipv4", "routes": [ { - "dest": "2001:db8:12::/32", "next_hops": [ { - "route_name": "ipv6_route", - "forward_router_address": "2001:db8::1001", - "admin_distance": 3, - } + "forward_router_address": "10.0.10.3", + "admin_distance": 11, + "tag": 22323, + "route_name": "test_name", + }, ], - } + "dest": "10.0.10.0/25", + }, + { + "next_hops": [ + { + "forward_router_address": "10.0.11.10", + "admin_distance": 11, + "tag": 22, + }, + { + "forward_router_address": "10.0.11.12", + "admin_distance": 11, + "dest_vrf": "Test", + "tag": 22, + }, + ], + "dest": "10.0.11.0/25", + }, + { + "next_hops": [ + { + "interface": "loopback22", + "forward_router_address": "192.0.2.13", + }, + ], + "dest": "192.0.2.48/28", + }, ], + }, + { "afi": "ipv6", + "routes": [ + { + "next_hops": [ + { + "forward_router_address": "2048:ae12::1", + "admin_distance": 5, + "dest_vrf": "dest", + }, + { + "interface": "mgmt0", + "forward_router_address": "2048:ae12::1", + "admin_distance": 11, + "tag": 22, + }, + { + "interface": "port-channel22", + "forward_router_address": "2048:ae12::1", + }, + { + "interface": "Ethernet2/1", + "forward_router_address": "2048:ae12::1", + "admin_distance": 22, + "route_name": "test_name2", + }, + ], + "dest": "2200:10::/36", + }, + ], }, ], }, { + "vrf": "trial_vrf", "address_families": [ { + "afi": "ipv4", "routes": [ { - "dest": "192.0.2.16/28", "next_hops": [ + {"forward_router_address": "192.0.2.22", "tag": 4}, { - "route_name": "initial_route", - "forward_router_address": "192.0.2.24", - } + "forward_router_address": "192.0.2.23", + "admin_distance": 1, + "route_name": "merged_route", + }, ], - } + "dest": "192.0.2.64/28", + }, ], - "afi": "ipv4", - } - ] + }, + ], }, ] self.assertEqual(result["gathered"], compare_list, result["gathered"]) diff --git a/tests/unit/modules/network/nxos/test_nxos_system.py b/tests/unit/modules/network/nxos/test_nxos_system.py index aa6bc1f38..ea7eec95c 100644 --- a/tests/unit/modules/network/nxos/test_nxos_system.py +++ b/tests/unit/modules/network/nxos/test_nxos_system.py @@ -20,27 +20,28 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from ansible_collections.cisco.nxos.plugins.modules import nxos_system +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from .nxos_module import TestNxosModule, load_fixture, set_module_args class TestNxosSystemModule(TestNxosModule): - module = nxos_system def setUp(self): super(TestNxosSystemModule, self).setUp() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_system.get_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_system.get_config", ) self.get_config = self.mock_get_config.start() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_system.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_system.load_config", ) self.load_config = self.mock_load_config.start() @@ -50,9 +51,7 @@ def tearDown(self): self.mock_load_config.stop() def load_fixtures(self, commands=None, device=""): - self.get_config.return_value = load_fixture( - "nxos_system", "config.cfg", device=device - ) + self.get_config.return_value = load_fixture("nxos_system", "config.cfg", device=device) self.load_config.return_value = None def test_nxos_system_hostname_changed(self): @@ -87,13 +86,11 @@ def test_nxos_system_domain_name_vrf_only(self): domain_name=[ {"name": "abc.com", "vrf": "test"}, {"name": "xyz.com", "vrf": "test2"}, - ] - ) + ], + ), ) commands = [] - self.execute_module( - changed=False, commands=commands, device="vrf_only" - ) + self.execute_module(changed=False, commands=commands, device="vrf_only") def test_nxos_system_domain_name_complex(self): domain_name = dict(name="example.net", vrf="management") diff --git a/tests/unit/modules/network/nxos/test_nxos_telemetry.py b/tests/unit/modules/network/nxos/test_nxos_telemetry.py index d197fc1c3..160804c11 100644 --- a/tests/unit/modules/network/nxos/test_nxos_telemetry.py +++ b/tests/unit/modules/network/nxos/test_nxos_telemetry.py @@ -19,28 +19,24 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type from textwrap import dedent -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - AnsibleFailJson, -) -from ansible_collections.cisco.nxos.plugins.modules import nxos_telemetry -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( - NxosCmdRef, -) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.telemetry.telemetry import ( - Telemetry, -) -from .nxos_module import TestNxosModule, load_fixture, set_module_args # TBD: These imports / import checks are only needed as a workaround for # shippable, which fails this test due to import yaml & import ordereddict. import pytest + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import ( nxosCmdRef_import_check, ) +from ansible_collections.cisco.nxos.plugins.modules import nxos_telemetry +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch +from ansible_collections.cisco.nxos.tests.unit.modules.utils import AnsibleFailJson + +from .nxos_module import TestNxosModule, load_fixture, set_module_args + msg = nxosCmdRef_import_check() ignore_provider_arg = True @@ -48,43 +44,38 @@ @pytest.mark.skipif(len(msg), reason=msg) class TestNxosTelemetryModule(TestNxosModule): - module = nxos_telemetry def setUp(self): super(TestNxosTelemetryModule, self).setUp() self.mock_FACT_LEGACY_SUBSETS = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts.FACT_LEGACY_SUBSETS" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts.FACT_LEGACY_SUBSETS", ) self.FACT_LEGACY_SUBSETS = self.mock_FACT_LEGACY_SUBSETS.start() self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection" - ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection", ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" - ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection", ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_edit_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.telemetry.telemetry.Telemetry.edit_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.telemetry.telemetry.Telemetry.edit_config", ) self.edit_config = self.mock_edit_config.start() self.mock_execute_show_command = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos.NxosCmdRef.execute_show_command" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos.NxosCmdRef.execute_show_command", ) self.execute_show_command = self.mock_execute_show_command.start() self.mock_get_platform_shortname = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos.NxosCmdRef.get_platform_shortname" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos.NxosCmdRef.get_platform_shortname", ) self.get_platform_shortname = self.mock_get_platform_shortname.start() @@ -122,7 +113,7 @@ def test_tms_global_merged_n9k(self): compression="gzip", source_interface="Ethernet2/1", vrf="blue", - ) + ), ), ignore_provider_arg, ) @@ -192,9 +183,7 @@ def test_tms_global_merged2_n9k(self): def test_tms_global_idempotent_n9k(self): # Assumes feature telemetry is enabled # TMS global config is present. - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" set_module_args( dict( @@ -206,7 +195,7 @@ def test_tms_global_idempotent_n9k(self): compression="gzip", source_interface="loopback55", vrf="management", - ) + ), ), ignore_provider_arg, ) @@ -216,9 +205,7 @@ def test_tms_global_change_cert_n9k(self): # Assumes feature telemetry is enabled # TMS global config is present # Change certificate - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" set_module_args( dict( @@ -230,7 +217,7 @@ def test_tms_global_change_cert_n9k(self): compression="gzip", source_interface="loopback55", vrf="management", - ) + ), ), ignore_provider_arg, ) @@ -246,9 +233,7 @@ def test_tms_global_change_interface_n9k(self): # Assumes feature telemetry is enabled # TMS global config is present # Change interface - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" set_module_args( dict( @@ -260,7 +245,7 @@ def test_tms_global_change_interface_n9k(self): compression="gzip", source_interface="Ethernet8/1", vrf="management", - ) + ), ), ignore_provider_arg, ) @@ -277,9 +262,7 @@ def test_tms_global_change_several_n9k(self): # Assumes feature telemetry is enabled # TMS global config is present # Change source_interface, vrf and cert - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" set_module_args( dict( @@ -291,7 +274,7 @@ def test_tms_global_change_several_n9k(self): compression="gzip", source_interface="Ethernet8/1", vrf="blue", - ) + ), ), ignore_provider_arg, ) @@ -322,8 +305,8 @@ def test_tms_destgroup_input_validation_1(self): "port": "5001", "protocol": "GRPC", "encoding": "GPB", - } - } + }, + }, ], "destination_groups", ) @@ -331,25 +314,20 @@ def test_tms_destgroup_input_validation_1(self): with pytest.raises(AnsibleFailJson) as errinfo: self.execute_module() testdata = errinfo.value.args[0] - assert "Parameter under is required" in str( - testdata["msg"] - ) + assert "Parameter under is required" in str(testdata["msg"]) assert testdata["failed"] def test_tms_destgroup_input_validation_2(self): # Parameter 'destination' is not a dict. self.execute_show_command.return_value = None self.get_platform_shortname.return_value = "N9K" - args = build_args( - [{"id": "88", "destination": "192.168.1.1"}], "destination_groups" - ) + args = build_args([{"id": "88", "destination": "192.168.1.1"}], "destination_groups") set_module_args(args, ignore_provider_arg) with pytest.raises(AnsibleFailJson) as errinfo: self.execute_module() testdata = errinfo.value.args[0] - assert ( - "Parameter under must be a dict" - in str(testdata["msg"]) + assert "Parameter under must be a dict" in str( + testdata["msg"], ) assert testdata["failed"] @@ -365,9 +343,7 @@ def test_tms_destgroup_input_validation_3(self): with pytest.raises(AnsibleFailJson) as errinfo: self.execute_module() testdata = errinfo.value.args[0] - assert "Playbook entry contains unrecongnized parameters" in str( - testdata["msg"] - ) + assert "Playbook entry contains unrecongnized parameters" in str(testdata["msg"]) assert testdata["failed"] def test_tms_destgroup_merged_n9k(self): @@ -446,7 +422,7 @@ def test_tms_destgroup_checkmode_n9k(self): "protocol": "GRPC", "encoding": "GPB", }, - } + }, ], "destination_groups", state="merged", @@ -484,9 +460,7 @@ def test_tms_destgroup_idempotent_n9k(self): # Assumes feature telemetry is enabled # TMS destgroup config is not present. # Configure only identifier - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" args = build_args( [ @@ -498,7 +472,7 @@ def test_tms_destgroup_idempotent_n9k(self): "protocol": "grpc", "encoding": "gpb", }, - } + }, ], "destination_groups", ) @@ -509,9 +483,7 @@ def test_tms_destgroup_idempotent2_n9k(self): # Assumes feature telemetry is enabled # TMS destgroup config is not present. # Configure only identifier - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" args = build_args([{"id": "2"}], "destination_groups") set_module_args(args, ignore_provider_arg) @@ -520,9 +492,7 @@ def test_tms_destgroup_idempotent2_n9k(self): def test_tms_destgroup_merged_aggregate_idempotent_n9k(self): # Assumes feature telemetry is enabled # TMS destgroup config is present. - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" args = build_args( [ @@ -553,9 +523,7 @@ def test_tms_destgroup_merged_aggregate_idempotent_n9k(self): def test_tms_destgroup_change_n9k(self): # TMS destgroup config is not present. # Change protocol and encoding for dest group 2 - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" args = build_args( [ @@ -594,9 +562,7 @@ def test_tms_destgroup_add_n9k(self): # TMS destgroup config is not present. # Add destinations to destgroup 10 # Add new destgroup 55 and 56 - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" args = build_args( [ @@ -653,12 +619,8 @@ def test_tms_sensorgroup_merged_n9k(self): # TMS sensorgroup config is not present. self.execute_show_command.return_value = None self.get_platform_shortname.return_value = "N9K" - td55_name = ( - "sys/bgp/inst/dom-default/peer-[10.10.10.11]/ent-[10.10.10.11]" - ) - td55_fc = ( - 'or(eq(ethpmPhysIf.operSt,"down"),eq(ethpmPhysIf.operSt,"up"))' - ) + td55_name = "sys/bgp/inst/dom-default/peer-[10.10.10.11]/ent-[10.10.10.11]" + td55_fc = 'or(eq(ethpmPhysIf.operSt,"down"),eq(ethpmPhysIf.operSt,"up"))' args = build_args( [ { @@ -735,7 +697,7 @@ def test_tms_sensorgroup_input_validation_1(self): "query_condition": "query_condition_xyz", "filter_condition": "filter_condition_xyz", }, - } + }, ], "sensor_groups", ) @@ -743,9 +705,7 @@ def test_tms_sensorgroup_input_validation_1(self): with pytest.raises(AnsibleFailJson) as errinfo: self.execute_module() testdata = errinfo.value.args[0] - assert "Parameter under is required" in str( - testdata["msg"] - ) + assert "Parameter under is required" in str(testdata["msg"]) assert testdata["failed"] def test_tms_sensorgroup_input_validation_2(self): @@ -762,7 +722,7 @@ def test_tms_sensorgroup_input_validation_2(self): "query_condition": "query_condition_xyz", "filter_condition": "filter_condition_xyz", }, - } + }, ], "sensor_groups", ) @@ -770,10 +730,7 @@ def test_tms_sensorgroup_input_validation_2(self): with pytest.raises(AnsibleFailJson) as errinfo: self.execute_module() testdata = errinfo.value.args[0] - assert ( - "Parameter under requires key" - in str(testdata["msg"]) - ) + assert "Parameter under requires key" in str(testdata["msg"]) assert testdata["failed"] def test_tms_sensorgroup_resource_key_n9k(self): @@ -819,7 +776,7 @@ def test_tms_sensorgroup_merged_variable_args2_n9k(self): "id": "77", "data_source": "DME", "path": {"name": "sys/bgp", "depth": 0}, - } + }, ], "sensor_groups", ) @@ -850,7 +807,7 @@ def test_tms_sensorgroup_merged_variable_args3_n9k(self): "depth": 0, "query_condition": "query_condition_xyz", }, - } + }, ], "sensor_groups", ) @@ -881,7 +838,7 @@ def test_tms_sensorgroup_merged_variable_args4_n9k(self): "depth": 0, "filter_condition": "filter_condition_xyz", }, - } + }, ], "sensor_groups", ) @@ -900,9 +857,7 @@ def test_tms_sensorgroup_merged_variable_args4_n9k(self): def test_tms_sensorgroup_merged_idempotent_n9k(self): # Assumes feature telemetry is enabled # TMS sensorgroup config is not present. - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" args = build_args( [ @@ -915,7 +870,7 @@ def test_tms_sensorgroup_merged_idempotent_n9k(self): "query_condition": "qc", "filter_condition": "fc", }, - } + }, ], "sensor_groups", ) @@ -925,9 +880,7 @@ def test_tms_sensorgroup_merged_idempotent_n9k(self): def test_tms_sensorgroup_quotes_merged_idempotent_n9k(self): # Assumes feature telemetry is enabled # TMS sensorgroup config is present with quotes in NX-API path. - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K_SGs.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K_SGs.cfg") self.get_platform_shortname.return_value = "N9K" args = build_args( [ @@ -953,9 +906,7 @@ def test_tms_sensorgroup_quotes_merged_idempotent_n9k(self): def test_tms_sensorgroup_vxlan_idempotent_n9k(self): # TMS sensorgroup config present. - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" args = build_args( [{"id": "56", "data_source": "DME", "path": {"name": "vxlan"}}], @@ -966,9 +917,7 @@ def test_tms_sensorgroup_vxlan_idempotent_n9k(self): def test_tms_sensorgroup_idempotent_variable1_n9k(self): # TMS sensorgroup config is present with path key name. - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" args = build_args( [ @@ -976,9 +925,9 @@ def test_tms_sensorgroup_idempotent_variable1_n9k(self): "id": "2", "data_source": "DME", "path": { - "name": "sys/bgp/inst/dom-default/peer-[10.10.10.11]/ent-[10.10.10.11]" + "name": "sys/bgp/inst/dom-default/peer-[10.10.10.11]/ent-[10.10.10.11]", }, - } + }, ], "sensor_groups", ) @@ -987,9 +936,7 @@ def test_tms_sensorgroup_idempotent_variable1_n9k(self): def test_tms_sensorgroup_idempotent_variable2_n9k(self): # TMS sensorgroup config is present with path key name and depth. - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" args = build_args( [ @@ -997,7 +944,7 @@ def test_tms_sensorgroup_idempotent_variable2_n9k(self): "id": "2", "data_source": "DME", "path": {"name": "boo", "depth": 0}, - } + }, ], "sensor_groups", ) @@ -1006,9 +953,7 @@ def test_tms_sensorgroup_idempotent_variable2_n9k(self): def test_tms_sensorgroup_idempotent_resource_key_n9k(self): # TMS sensorgroup config is present resource key only. - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" args = build_args([{"id": "55"}], "sensor_groups") set_module_args(args, ignore_provider_arg) @@ -1025,7 +970,7 @@ def test_tms_sensorgroup_present_path_environment_n9k(self): "id": "77", "data_source": "YANG", "path": {"name": "environment"}, - } + }, ], "sensor_groups", ) @@ -1052,7 +997,7 @@ def test_tms_sensorgroup_present_path_interface_n9k(self): "id": "77", "data_source": "NATIVE", "path": {"name": "interface"}, - } + }, ], "sensor_groups", ) @@ -1079,7 +1024,7 @@ def test_tms_sensorgroup_present_path_interface_n9k(self): "id": "77", "data_source": "NX-API", "path": {"name": "resources"}, - } + }, ], "sensor_groups", ) @@ -1135,9 +1080,7 @@ def test_tms_subscription_merged_n9k(self): def test_tms_subscription_merged_idempotent_n9k(self): # TMS subscription config is not present. - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" args = build_args( [ @@ -1161,9 +1104,7 @@ def test_tms_subscription_merged_idempotent_n9k(self): def test_tms_subscription_merged_change1_n9k(self): # TMS subscription config present. # Change sample interval for sensor group 2 - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" args = build_args( [ @@ -1194,9 +1135,7 @@ def test_tms_subscription_merged_change1_n9k(self): def test_tms_subscription_add_n9k(self): # TMS subscription config present. # Add new destination_group and sensor_group to subscription 5 - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" args = build_args( [ @@ -1383,9 +1322,7 @@ def test_telemetry_full_n9k(self): def test_telemetry_deleted_input_validation_n9k(self): # State is 'deleted' and 'config' key present. - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" set_module_args( dict( @@ -1405,19 +1342,14 @@ def test_telemetry_deleted_input_validation_n9k(self): with pytest.raises(AnsibleFailJson) as errinfo: self.execute_module() testdata = errinfo.value.args[0] - assert ( - "Remove config key from playbook when state is " - in str(testdata["msg"]) - ) + assert "Remove config key from playbook when state is " in str(testdata["msg"]) assert testdata["failed"] def test_telemetry_deleted_n9k(self): # Assumes feature telemetry is enabled # TMS global config is present. # Make absent with all playbook keys provided - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" set_module_args(dict(state="deleted"), ignore_provider_arg) self.execute_module(changed=True, commands=["no telemetry"]) @@ -1434,9 +1366,7 @@ def test_telemetry_deleted_idempotent_n9k(self): def test_tms_replaced1_n9k(self): # Assumes feature telemetry is enabled # Modify global config and remove everything else - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" set_module_args( dict( @@ -1479,9 +1409,7 @@ def test_tms_replaced2_n9k(self): # Modify destination-group 10, add 11 and 99, remove 2 # Modify sensor-group 55, 56 # remove all subscriptions - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" set_module_args( { @@ -1597,9 +1525,7 @@ def test_tms_replaced3_n9k(self): # remove all other destination-groups # Modify sensor-group 55 and delete all others # Modify subscription 7, add 10 and delete all others - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" set_module_args( { @@ -1615,7 +1541,7 @@ def test_tms_replaced3_n9k(self): "protocol": "GRPC", "encoding": "GPB", }, - } + }, ], "sensor_groups": [ { @@ -1627,7 +1553,7 @@ def test_tms_replaced3_n9k(self): "query_condition": "query_condition_xyz", "filter_condition": "filter_condition_xyz", }, - } + }, ], "subscriptions": [ { @@ -1690,9 +1616,7 @@ def test_tms_replaced_idempotent_n9k(self): # remove all other destination-groups # Modify sensor-group 55 and delete all others # Modify subscription 7, add 10 and delete all others - self.execute_show_command.return_value = load_fixture( - "nxos_telemetry", "N9K.cfg" - ) + self.execute_show_command.return_value = load_fixture("nxos_telemetry", "N9K.cfg") self.get_platform_shortname.return_value = "N9K" set_module_args( { @@ -1772,13 +1696,13 @@ def test_tms_replaced_idempotent_n9k(self): { "id": 2, "path": { - "name": "sys/bgp/inst/dom-default/peer-[10.10.10.11]/ent-[10.10.10.11]" + "name": "sys/bgp/inst/dom-default/peer-[10.10.10.11]/ent-[10.10.10.11]", }, }, { "id": 2, "path": { - "name": "sys/bgp/inst/dom-default/peer-[20.20.20.11]/ent-[20.20.20.11]" + "name": "sys/bgp/inst/dom-default/peer-[20.20.20.11]/ent-[20.20.20.11]", }, }, { @@ -1833,7 +1757,7 @@ def test_telemetry_gathered(self): destination-group 2 ip address 192.168.0.1 port 50001 protocol gRPC encoding GPB ip address 192.168.0.2 port 60001 protocol gRPC encoding GPB - """ + """, ) self.get_platform_shortname.return_value = "N9K" set_module_args(dict(state="gathered"), ignore_provider_arg) @@ -1871,6 +1795,123 @@ def test_telemetry_gathered(self): result = self.execute_module(changed=False) self.assertEqual(result["gathered"], gathered) + def test_tms_names(self): + # TMS input with strings + self.execute_show_command.return_value = "" + self.get_platform_shortname.return_value = "N9K" + set_module_args( + dict( + config=dict( + destination_groups=[ + dict( + id="collector", + destination=dict( + ip="192.168.1.100", + port=50051, + protocol="gRPC", + encoding="GPB", + ), + ), + ], + sensor_groups=[ + dict( + id="dme_bgp", + data_source="DME", + path=dict( + name="sys/bd", + depth="unbounded", + ), + ), + ], + subscriptions=[ + dict( + id="collector_sub", + destination_group="collector", + sensor_group=dict( + id="dme_bgp", + sample_interval=1000, + ), + ), + ], + ), + state="merged", + ), + ignore_provider_arg, + ) + self.execute_module( + changed=True, + commands=[ + "feature telemetry", + "telemetry", + "destination-group collector", + "ip address 192.168.1.100 port 50051 protocol grpc encoding gpb", + "sensor-group dme_bgp", + "data-source DME", + "path sys/bd depth unbounded", + "subscription collector_sub", + "dst-grp collector", + "snsr-grp dme_bgp sample-interval 1000", + ], + ) + + def test_tms_names_idempotent(self): + # TMS input with strings + self.execute_show_command.return_value = dedent( + """\ + feature telemetry + telemetry + destination-group collector + ip address 192.168.1.100 port 50051 protocol grpc encoding gpb + sensor-group dme_bgp + data-source DME + path sys/bd depth unbounded + subscription collector_sub + dst-grp collector + snsr-grp dme_bgp sample-interval 1000 + """, + ) + self.get_platform_shortname.return_value = "N9K" + set_module_args( + dict( + config=dict( + destination_groups=[ + dict( + id="collector", + destination=dict( + ip="192.168.1.100", + port=50051, + protocol="gRPC", + encoding="GPB", + ), + ), + ], + sensor_groups=[ + dict( + id="dme_bgp", + data_source="DME", + path=dict( + name="sys/bd", + depth="unbounded", + ), + ), + ], + subscriptions=[ + dict( + id="collector_sub", + destination_group="collector", + sensor_group=dict( + id="dme_bgp", + sample_interval=1000, + ), + ), + ], + ), + state="merged", + ), + ignore_provider_arg, + ) + self.execute_module(changed=False, commands=[]) + def build_args(data, type, state=None, check_mode=None): if state is None: diff --git a/tests/unit/modules/network/nxos/test_nxos_user.py b/tests/unit/modules/network/nxos/test_nxos_user.py index 62620129c..c397c82cb 100644 --- a/tests/unit/modules/network/nxos/test_nxos_user.py +++ b/tests/unit/modules/network/nxos/test_nxos_user.py @@ -19,39 +19,41 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from ansible_collections.cisco.nxos.plugins.modules import nxos_user +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from .nxos_module import TestNxosModule, set_module_args + ignore_provider_arg = True class TestNxosUserModule(TestNxosModule): - module = nxos_user def setUp(self): super(TestNxosUserModule, self).setUp() self.mock_run_commands = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_user.run_commands" + "ansible_collections.cisco.nxos.plugins.modules.nxos_user.run_commands", ) self.run_commands = self.mock_run_commands.start() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_user.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_user.load_config", ) self.load_config = self.mock_load_config.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_user.get_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_user.get_config", ) self.get_config = self.mock_get_config.start() self.mock_get_device_info = patch( - "ansible_collections.cisco.nxos.plugins.cliconf.nxos.Cliconf.get_device_info" + "ansible_collections.cisco.nxos.plugins.cliconf.nxos.Cliconf.get_device_info", ) self.get_device_info = self.mock_get_device_info.start() @@ -71,18 +73,16 @@ def test_mds(self): { "usr_name": "admin", "expire_date": "this user account has no expiry date", - "TABLE_role": { - "ROW_role": {"role": "network-admin"} - }, + "TABLE_role": {"ROW_role": {"role": "network-admin"}}, }, { "usr_name": "ansible-test-1", "expire_date": "this user account has no expiry date", "TABLE_role": {"ROW_role": [{"role": "priv-10"}]}, }, - ] - } - } + ], + }, + }, ] self.get_device_info.return_value = { "network_os": "nxos", @@ -92,9 +92,7 @@ def test_mds(self): "network_os_image": "bootflash:///m9100-s5ek9-mz.8.4.2b.bin", "network_os_platform": "DS-C9710", } - set_module_args( - dict(name="ansible-test-2", configured_password="ansible") - ) + set_module_args(dict(name="ansible-test-2", configured_password="ansible")) self.execute_module( changed=True, commands=[ @@ -102,3 +100,18 @@ def test_mds(self): "username ansible-test-2 password ansible", ], ) + + def test_nxos_hashed_password(self): + set_module_args( + dict( + name="ansible", + hashed_password="$5$JFHICC$u.zXRUgprAkkYLiEns8VrhsNEIOj7FzVrn67tuJdtKB", + ), + ) + self.execute_module( + changed=True, + commands=[ + "username ansible", + "username ansible password 5 $5$JFHICC$u.zXRUgprAkkYLiEns8VrhsNEIOj7FzVrn67tuJdtKB", + ], + ) diff --git a/tests/unit/modules/network/nxos/test_nxos_vlan.py b/tests/unit/modules/network/nxos/test_nxos_vlan.py deleted file mode 100644 index c1a0c8a09..000000000 --- a/tests/unit/modules/network/nxos/test_nxos_vlan.py +++ /dev/null @@ -1,235 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# Make coding more python3-ish - -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - -import json - -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.plugins.modules import nxos_vlan -from .nxos_module import TestNxosModule, load_fixture, set_module_args - - -class TestNxosVlanModule(TestNxosModule): - - module = nxos_vlan - - def setUp(self): - super(TestNxosVlanModule, self).setUp() - - self.mock_run_commands = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_vlan.run_commands" - ) - self.run_commands = self.mock_run_commands.start() - - self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_vlan.load_config" - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_vlan.get_config" - ) - self.get_config = self.mock_get_config.start() - - self.mock_get_capabilities = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_vlan.get_capabilities" - ) - self.get_capabilities = self.mock_get_capabilities.start() - self.get_capabilities.return_value = { - "device_info": {"network_os_platform": "N9K-9000v"}, - "network_api": "cliconf", - } - - def tearDown(self): - super(TestNxosVlanModule, self).tearDown() - self.mock_run_commands.stop() - self.mock_load_config.stop() - self.mock_get_config.stop() - self.mock_get_capabilities.stop() - - def load_fixtures(self, commands=None, device=""): - def load_from_file(*args, **kwargs): - module, commands = args - output = list() - - for item in commands: - try: - obj = json.loads(item) - command = obj["command"] - except ValueError: - command = item - filename = "%s.txt" % str(command).split(" | ", 1)[0].replace( - " ", "_" - ) - output.append(load_fixture("nxos_vlan", filename)) - return output - - def agg_load_from_file(*args, **kwargs): - """Load vlan output for aggregate/purge tests""" - return [load_fixture("nxos_vlan", "agg_show_vlan_brief.txt")] - - if "_agg_" in self._testMethodName: - self.run_commands.side_effect = agg_load_from_file - else: - self.run_commands.side_effect = load_from_file - - self.load_config.return_value = None - self.get_config.return_value = load_fixture("nxos_vlan", "config.cfg") - - def test_nxos_vlan_agg_1(self): - # Aggregate: vlan 4/5 exist -> Add 6 - set_module_args( - dict( - aggregate=[ - {"name": "_5_", "vlan_id": 5}, - {"name": "_6_", "vlan_id": 6}, - ] - ) - ) - self.execute_module( - changed=True, - commands=[ - "vlan 6", - "name _6_", - "state active", - "no shutdown", - "exit", - ], - ) - - def test_nxos_vlan_agg_2(self): - # Aggregate: vlan 4/5 exist -> Add none (idempotence) - set_module_args( - dict( - aggregate=[ - {"name": "_5_", "vlan_id": 5}, - {"name": "_4_", "vlan_id": 4}, - ] - ) - ) - self.execute_module(changed=False) - - def test_nxos_vlan_agg_3(self): - # Aggregate/Purge: vlan 4/5 exist -> Add 6, Purge 4 - set_module_args( - dict( - aggregate=[ - {"name": "_5_", "vlan_id": 5}, - {"name": "_6_", "vlan_id": 6}, - ], - purge=True, - ) - ) - self.execute_module( - changed=True, - commands=[ - "vlan 6", - "name _6_", - "state active", - "no shutdown", - "exit", - "no vlan 4", - ], - ) - - def test_nxos_vlan_agg_4(self): - # Aggregate/Purge: vlan 4/5 exist -> Purge None (idempotence) - set_module_args( - dict( - aggregate=[ - {"name": "_5_", "vlan_id": 5}, - {"name": "_4_", "vlan_id": 4}, - ] - ) - ) - self.execute_module(changed=False) - - def test_nxos_vlan_agg_5(self): - # Purge with Single Vlan: vlan 4/5 exist -> Add 6, Purge 4/5 - set_module_args(dict(vlan_id=6, name="_6_", purge=True)) - self.execute_module( - changed=True, - commands=[ - "vlan 6", - "name _6_", - "state active", - "no shutdown", - "exit", - "no vlan 4", - "no vlan 5", - ], - ) - - def test_nxos_vlan_agg_6(self): - # Purge All: vlan 4/5 exist -> Purge 4/5 - set_module_args(dict(vlan_id=1, purge=True)) - self.execute_module(changed=True, commands=["no vlan 4", "no vlan 5"]) - - def test_nxos_vlan_range(self): - set_module_args(dict(vlan_range="6-10")) - self.execute_module( - changed=True, - commands=["vlan 6", "vlan 7", "vlan 8", "vlan 9", "vlan 10"], - ) - - def test_nxos_vlan_range_absent(self): - set_module_args(dict(vlan_range="1-5", state="absent")) - result = self.execute_module(changed=True) - self.assertEqual(result["commands"], ["no vlan 1"]) - - def test_nxos_vlan_id(self): - set_module_args(dict(vlan_id="15", state="present")) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], - ["vlan 15", "state active", "no shutdown", "exit"], - ) - - def test_nxos_vlan_id_absent(self): - set_module_args(dict(vlan_id="1", state="absent")) - result = self.execute_module(changed=True) - self.assertEqual(result["commands"], ["no vlan 1"]) - - def test_nxos_vlan_named_vlan(self): - set_module_args(dict(vlan_id="15", name="WEB")) - result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], - ["vlan 15", "name WEB", "state active", "no shutdown", "exit"], - ) - - def test_nxos_vlan_shut_down(self): - set_module_args(dict(vlan_id="1", admin_state="down")) - result = self.execute_module(changed=True) - self.assertEqual(result["commands"], ["vlan 1", "shutdown", "exit"]) - - def test_nxos_vlan_no_change(self): - set_module_args( - dict( - vlan_id="1", - name="default", - vlan_state="active", - admin_state="up", - ) - ) - result = self.execute_module(changed=False) - self.assertEqual(result["commands"], []) diff --git a/tests/unit/modules/network/nxos/test_nxos_vlans.py b/tests/unit/modules/network/nxos/test_nxos_vlans.py index 17a8b2e1f..97870e76d 100644 --- a/tests/unit/modules/network/nxos/test_nxos_vlans.py +++ b/tests/unit/modules/network/nxos/test_nxos_vlans.py @@ -19,60 +19,51 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from textwrap import dedent -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - AnsibleFailJson, -) from ansible_collections.cisco.nxos.plugins.modules import nxos_vlans -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.vlans.vlans import ( - Vlans, -) +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from .nxos_module import TestNxosModule, load_fixture, set_module_args + ignore_provider_arg = True class TestNxosVlansModule(TestNxosModule): - module = nxos_vlans def setUp(self): super(TestNxosVlansModule, self).setUp() self.mock_FACT_LEGACY_SUBSETS = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts.FACT_LEGACY_SUBSETS" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts.FACT_LEGACY_SUBSETS", ) self.FACT_LEGACY_SUBSETS = self.mock_FACT_LEGACY_SUBSETS.start() self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection" - ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection", ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" - ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection", ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_edit_config = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.vlans.vlans.Vlans.edit_config" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.vlans.vlans.Vlans.edit_config", ) self.edit_config = self.mock_edit_config.start() self.mock_get_device_data = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.vlans.vlans.VlansFacts.get_device_data" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.vlans.vlans.VlansFacts.get_device_data", ) self.get_device_data = self.mock_get_device_data.start() self.mock_get_platform = patch( - "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.vlans.vlans.Vlans.get_platform" + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.vlans.vlans.Vlans.get_platform", ) self.get_platform = self.mock_get_platform.start() @@ -128,12 +119,10 @@ def test_1(self): config=[ dict(vlan_id=4), dict(vlan_id=5, mapped_vni=555, mode="ce"), - dict( - vlan_id=7, mapped_vni=777, name="test-vlan7", enabled=False - ), - dict(vlan_id="8", state="active", name="test-changeme-not") + dict(vlan_id=7, mapped_vni=777, name="test-vlan7", enabled=False), + dict(vlan_id="8", state="active", name="test-changeme-not"), # vlan 3 is not present in playbook. - ] + ], ) merged = [ @@ -278,7 +267,7 @@ def test_5(self): state="suspend", enabled=False, ), - ] + ], ) playbook["state"] = "merged" diff --git a/tests/unit/modules/network/nxos/test_nxos_vpc.py b/tests/unit/modules/network/nxos/test_nxos_vpc.py index 2aac9c000..a74525e86 100644 --- a/tests/unit/modules/network/nxos/test_nxos_vpc.py +++ b/tests/unit/modules/network/nxos/test_nxos_vpc.py @@ -19,32 +19,33 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from ansible_collections.cisco.nxos.plugins.modules import nxos_vpc +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from .nxos_module import TestNxosModule, load_fixture, set_module_args class TestNxosVpcModule(TestNxosModule): - module = nxos_vpc def setUp(self): super(TestNxosVpcModule, self).setUp() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_vpc.get_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_vpc.get_config", ) self.get_config = self.mock_get_config.start() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_vpc.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_vpc.load_config", ) self.load_config = self.mock_load_config.start() self.mock_run_commands = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_vpc.run_commands" + "ansible_collections.cisco.nxos.plugins.modules.nxos_vpc.run_commands", ) self.run_commands = self.mock_run_commands.start() @@ -69,9 +70,7 @@ def vrf_load_from_file(*args, **kwargs): module, commands = args output = list() for command in commands: - filename = "vrf_test_" + str(command).split(" | ", 1)[ - 0 - ].replace(" ", "_") + filename = "vrf_test_" + str(command).split(" | ", 1)[0].replace(" ", "_") output.append(load_fixture("nxos_vpc", filename)) return output @@ -91,7 +90,7 @@ def test_nxos_vpc_present(self): pkl_src="10.1.100.20", peer_gw=True, auto_recovery=True, - ) + ), ) self.execute_module( changed=True, @@ -114,7 +113,7 @@ def test_nxos_vpc_vrf_1(self): pkl_dest="192.168.1.1", pkl_src="10.1.1.1", pkl_vrf="default", - ) + ), ) self.execute_module( changed=True, @@ -127,16 +126,14 @@ def test_nxos_vpc_vrf_1(self): def test_nxos_vpc_vrf_2(self): # vrf 'my_vrf'-> vrf 'test-vrf' # All pkl commands should be present - self.get_config.return_value = load_fixture( - "nxos_vpc", "vrf_test_vpc_config" - ) + self.get_config.return_value = load_fixture("nxos_vpc", "vrf_test_vpc_config") set_module_args( dict( domain=100, pkl_dest="192.168.1.1", pkl_src="10.1.1.1", pkl_vrf="test-vrf", - ) + ), ) self.execute_module( changed=True, @@ -150,15 +147,13 @@ def test_nxos_vpc_vrf_2(self): def test_nxos_vpc_vrf_3(self): # vrf 'my_vrf' -> vrf 'obviously-different-vrf' # Existing pkl_src should be retained even though playbook does not specify it - self.get_config.return_value = load_fixture( - "nxos_vpc", "vrf_test_vpc_config" - ) + self.get_config.return_value = load_fixture("nxos_vpc", "vrf_test_vpc_config") set_module_args( dict( domain=100, pkl_dest="192.168.1.1", pkl_vrf="obviously-different-vrf", - ) + ), ) self.execute_module( changed=True, @@ -172,12 +167,8 @@ def test_nxos_vpc_vrf_3(self): def test_nxos_vpc_vrf_4(self): # vrf 'my_vrf'-> vrf 'management' # 'management' is the default value for vrf, it will not nvgen - self.get_config.return_value = load_fixture( - "nxos_vpc", "vrf_test_vpc_config" - ) - set_module_args( - dict(domain=100, pkl_dest="192.168.1.1", pkl_vrf="management") - ) + self.get_config.return_value = load_fixture("nxos_vpc", "vrf_test_vpc_config") + set_module_args(dict(domain=100, pkl_dest="192.168.1.1", pkl_vrf="management")) self.execute_module( changed=True, device="_vrf_test", @@ -189,24 +180,20 @@ def test_nxos_vpc_vrf_4(self): def test_nxos_vpc_vrf_5(self): # vrf 'my_vrf' -> vrf 'my_vrf' (idempotence) - self.get_config.return_value = load_fixture( - "nxos_vpc", "vrf_test_vpc_config" - ) + self.get_config.return_value = load_fixture("nxos_vpc", "vrf_test_vpc_config") set_module_args( dict( domain=100, pkl_dest="192.168.1.1", pkl_src="10.1.1.1", pkl_vrf="my_vrf", - ) + ), ) self.execute_module(changed=False, device="_vrf_test") def test_nxos_vpc_vrf_6(self): # vrf 'my_vrf' -> absent tests - self.get_config.return_value = load_fixture( - "nxos_vpc", "vrf_test_vpc_config" - ) + self.get_config.return_value = load_fixture("nxos_vpc", "vrf_test_vpc_config") set_module_args(dict(domain=100, state="absent")) self.execute_module( changed=True, @@ -217,19 +204,13 @@ def test_nxos_vpc_vrf_6(self): def test_nxos_vpc_vrf_7(self): # dest 192.168.1.1 source 10.1.1.1 vrf my_vrf -> (dest only) (idempotence) # pkl_src/pkl_vrf not in playbook but exists on device. - self.get_config.return_value = load_fixture( - "nxos_vpc", "vrf_test_vpc_config" - ) + self.get_config.return_value = load_fixture("nxos_vpc", "vrf_test_vpc_config") set_module_args(dict(domain=100, pkl_dest="192.168.1.1")) self.execute_module(changed=False, device="_vrf_test") def test_nxos_vpc_vrf_8(self): # dest 192.168.1.1 source 10.1.1.1 vrf my_vrf -> (optional vrf) (idempotence) # pkl_src not in playbook but exists on device. - self.get_config.return_value = load_fixture( - "nxos_vpc", "vrf_test_vpc_config" - ) - set_module_args( - dict(domain=100, pkl_dest="192.168.1.1", pkl_vrf="my_vrf") - ) + self.get_config.return_value = load_fixture("nxos_vpc", "vrf_test_vpc_config") + set_module_args(dict(domain=100, pkl_dest="192.168.1.1", pkl_vrf="my_vrf")) self.execute_module(changed=False, device="_vrf_test") diff --git a/tests/unit/modules/network/nxos/test_nxos_vpc_interface.py b/tests/unit/modules/network/nxos/test_nxos_vpc_interface.py index 233099795..de7ad79bd 100644 --- a/tests/unit/modules/network/nxos/test_nxos_vpc_interface.py +++ b/tests/unit/modules/network/nxos/test_nxos_vpc_interface.py @@ -19,32 +19,33 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from ansible_collections.cisco.nxos.plugins.modules import nxos_vpc_interface +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from .nxos_module import TestNxosModule, load_fixture, set_module_args class TestNxosVpcModule(TestNxosModule): - module = nxos_vpc_interface def setUp(self): super(TestNxosVpcModule, self).setUp() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_vpc_interface.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_vpc_interface.load_config", ) self.load_config = self.mock_load_config.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_vpc_interface.get_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_vpc_interface.get_config", ) self.get_config = self.mock_get_config.start() self.mock_run_commands = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_vpc_interface.run_commands" + "ansible_collections.cisco.nxos.plugins.modules.nxos_vpc_interface.run_commands", ) self.run_commands = self.mock_run_commands.start() @@ -69,13 +70,9 @@ def load_from_file(*args, **kwargs): def test_nxos_vpc_interface_absent(self): set_module_args(dict(portchannel=10, vpc=100, state="absent")) result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], ["interface port-channel10", "no vpc"] - ) + self.assertEqual(result["commands"], ["interface port-channel10", "no vpc"]) def test_nxos_vpc_interface_present(self): set_module_args(dict(portchannel=20, vpc=200, state="present")) result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], ["interface port-channel20", "vpc 200"] - ) + self.assertEqual(result["commands"], ["interface port-channel20", "vpc 200"]) diff --git a/tests/unit/modules/network/nxos/test_nxos_vrf.py b/tests/unit/modules/network/nxos/test_nxos_vrf.py index a2999cf83..8f2a2ae1d 100644 --- a/tests/unit/modules/network/nxos/test_nxos_vrf.py +++ b/tests/unit/modules/network/nxos/test_nxos_vrf.py @@ -19,27 +19,28 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from ansible_collections.cisco.nxos.plugins.modules import nxos_vrf +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from .nxos_module import TestNxosModule, load_fixture, set_module_args class TestNxosVrfModule(TestNxosModule): - module = nxos_vrf def setUp(self): super(TestNxosVrfModule, self).setUp() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_vrf.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_vrf.load_config", ) self.load_config = self.mock_load_config.start() self.mock_run_commands = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_vrf.run_commands" + "ansible_collections.cisco.nxos.plugins.modules.nxos_vrf.run_commands", ) self.run_commands = self.mock_run_commands.start() @@ -65,21 +66,15 @@ def load_from_file(*args, **kwargs): def test_nxos_vrf_present(self): set_module_args(dict(vrf="ntc", state="present", admin_state="up")) - self.execute_module( - changed=True, commands=["vrf context ntc", "no shutdown", "exit"] - ) + self.execute_module(changed=True, commands=["vrf context ntc", "no shutdown", "exit"]) def test_nxos_vrf_present_no_change(self): - set_module_args( - dict(vrf="management", state="present", admin_state="up") - ) + set_module_args(dict(vrf="management", state="present", admin_state="up")) self.execute_module(changed=False, commands=[]) def test_nxos_vrf_absent(self): set_module_args(dict(vrf="management", state="absent")) - self.execute_module( - changed=True, commands=["no vrf context management"] - ) + self.execute_module(changed=True, commands=["no vrf context management"]) def test_nxos_vrf_absent_no_change(self): set_module_args(dict(vrf="ntc", state="absent")) diff --git a/tests/unit/modules/network/nxos/test_nxos_vrf_af.py b/tests/unit/modules/network/nxos/test_nxos_vrf_af.py index f4ef571b5..bfc2adef8 100644 --- a/tests/unit/modules/network/nxos/test_nxos_vrf_af.py +++ b/tests/unit/modules/network/nxos/test_nxos_vrf_af.py @@ -19,37 +19,36 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from ansible_collections.cisco.nxos.plugins.modules import nxos_vrf_af +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from .nxos_module import TestNxosModule, load_fixture, set_module_args class TestNxosVrfafModule(TestNxosModule): - module = nxos_vrf_af def setUp(self): super(TestNxosVrfafModule, self).setUp() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_vrf_af.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_vrf_af.load_config", ) self.load_config = self.mock_load_config.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_vrf_af.get_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_vrf_af.get_config", ) self.get_config = self.mock_get_config.start() self.mock_get_capabilities = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_vrf_af.get_capabilities" + "ansible_collections.cisco.nxos.plugins.modules.nxos_vrf_af.get_capabilities", ) self.get_capabilities = self.mock_get_capabilities.start() - self.get_capabilities.return_value = { - "device_info": {"network_os_platform": "N7K-C7018"} - } + self.get_capabilities.return_value = {"device_info": {"network_os_platform": "N7K-C7018"}} def tearDown(self): super(TestNxosVrfafModule, self).tearDown() @@ -58,9 +57,7 @@ def tearDown(self): self.mock_get_capabilities.stop() def load_fixtures(self, commands=None, device=""): - self.get_config.return_value = load_fixture( - "nxos_vrf_af", "config.cfg" - ) + self.get_config.return_value = load_fixture("nxos_vrf_af", "config.cfg") self.load_config.return_value = None def test_nxos_vrf_af_present_current_non_existing(self): @@ -90,18 +87,14 @@ def test_nxos_vrf_af_absent_current_existing(self): ) def test_nxos_vrf_af_auto_evpn_route_target_present_current_existing(self): - set_module_args( - dict(vrf="vrf11", afi="ipv4", route_target_both_auto_evpn=True) - ) + set_module_args(dict(vrf="vrf11", afi="ipv4", route_target_both_auto_evpn=True)) result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) def test_nxos_vrf_af_auto_evpn_route_target_present_current_non_existing( self, ): - set_module_args( - dict(vrf="vrf10", afi="ipv4", route_target_both_auto_evpn=True) - ) + set_module_args(dict(vrf="vrf10", afi="ipv4", route_target_both_auto_evpn=True)) result = self.execute_module(changed=True) self.assertEqual( result["commands"], @@ -113,9 +106,7 @@ def test_nxos_vrf_af_auto_evpn_route_target_present_current_non_existing( ) def test_nxos_vrf_af_auto_evpn_route_target_absent_current_existing(self): - set_module_args( - dict(vrf="vrf11", afi="ipv4", route_target_both_auto_evpn=False) - ) + set_module_args(dict(vrf="vrf11", afi="ipv4", route_target_both_auto_evpn=False)) result = self.execute_module(changed=True) self.assertEqual( result["commands"], @@ -129,9 +120,7 @@ def test_nxos_vrf_af_auto_evpn_route_target_absent_current_existing(self): def test_nxos_vrf_af_auto_evpn_route_target_absent_current_non_existing( self, ): - set_module_args( - dict(vrf="vrf1", afi="ipv4", route_target_both_auto_evpn=False) - ) + set_module_args(dict(vrf="vrf1", afi="ipv4", route_target_both_auto_evpn=False)) result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) @@ -147,9 +136,9 @@ def test_nxos_vrf_af_route_target_import_present_current_non_existing( "rt": "65000:1000", "direction": "import", "state": "present", - } + }, ], - ) + ), ) result = self.execute_module(changed=True) self.assertEqual( @@ -169,7 +158,7 @@ def test_nxos_vrf_af_route_target_default_direction_present_current_non_existing vrf="vrf1", afi="ipv4", route_targets=[{"rt": "65000:1000", "state": "present"}], - ) + ), ) result = self.execute_module(changed=True) self.assertEqual( @@ -192,9 +181,9 @@ def test_nxos_vrf_af_route_target_import_present_current_existing(self): "rt": "65000:1000", "direction": "import", "state": "present", - } + }, ], - ) + ), ) result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) @@ -207,7 +196,7 @@ def test_nxos_vrf_af_route_target_default_direction_present_current_existing( vrf="vrf21", afi="ipv4", route_targets=[{"rt": "65000:1000", "state": "present"}], - ) + ), ) result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) @@ -236,7 +225,7 @@ def test_nxos_vrf_af_route_target_multi_import_present_current_non_existing( "state": "present", }, ], - ) + ), ) result = self.execute_module(changed=True) self.assertEqual( @@ -274,7 +263,7 @@ def test_nxos_vrf_af_route_target_multi_import_present_current_existing( "state": "present", }, ], - ) + ), ) result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) @@ -289,9 +278,9 @@ def test_nxos_vrf_af_route_target_import_absent_current_non_existing(self): "rt": "65000:1000", "direction": "import", "state": "absent", - } + }, ], - ) + ), ) result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) @@ -306,9 +295,9 @@ def test_nxos_vrf_af_route_target_import_absent_current_existing(self): "rt": "65000:1000", "direction": "import", "state": "absent", - } + }, ], - ) + ), ) result = self.execute_module(changed=True) self.assertEqual( @@ -344,7 +333,7 @@ def test_nxos_vrf_af_route_target_multi_import_absent_current_non_existing( "state": "absent", }, ], - ) + ), ) result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) @@ -373,7 +362,7 @@ def test_nxos_vrf_af_route_target_multi_import_absent_current_existing( "state": "absent", }, ], - ) + ), ) result = self.execute_module(changed=True) self.assertEqual( @@ -419,7 +408,7 @@ def test_nxos_vrf_af_route_target_multi_import_absent_current_mix(self): "state": "absent", }, ], - ) + ), ) result = self.execute_module(changed=True) self.assertEqual( @@ -444,9 +433,9 @@ def test_nxos_vrf_af_route_target_export_present_current_non_existing( "rt": "65000:1000", "direction": "export", "state": "present", - } + }, ], - ) + ), ) result = self.execute_module(changed=True) self.assertEqual( @@ -468,9 +457,9 @@ def test_nxos_vrf_af_route_target_export_present_current_existing(self): "rt": "65000:1000", "direction": "export", "state": "present", - } + }, ], - ) + ), ) result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) @@ -499,7 +488,7 @@ def test_nxos_vrf_af_route_target_multi_export_present_current_non_existing( "state": "present", }, ], - ) + ), ) result = self.execute_module(changed=True) self.assertEqual( @@ -537,7 +526,7 @@ def test_nxos_vrf_af_route_target_multi_export_present_current_existing( "state": "present", }, ], - ) + ), ) result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) @@ -552,9 +541,9 @@ def test_nxos_vrf_af_route_target_export_absent_current_non_existing(self): "rt": "65000:1000", "direction": "export", "state": "absent", - } + }, ], - ) + ), ) result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) @@ -569,9 +558,9 @@ def test_nxos_vrf_af_route_target_export_absent_current_existing(self): "rt": "65000:1000", "direction": "export", "state": "absent", - } + }, ], - ) + ), ) result = self.execute_module(changed=True) self.assertEqual( @@ -607,7 +596,7 @@ def test_nxos_vrf_af_route_target_multi_export_absent_current_non_existing( "state": "absent", }, ], - ) + ), ) result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) @@ -636,7 +625,7 @@ def test_nxos_vrf_af_route_target_multi_export_absent_current_existing( "state": "absent", }, ], - ) + ), ) result = self.execute_module(changed=True) self.assertEqual( @@ -682,7 +671,7 @@ def test_nxos_vrf_af_route_target_multi_export_absent_current_mix(self): "state": "absent", }, ], - ) + ), ) result = self.execute_module(changed=True) self.assertEqual( @@ -705,9 +694,9 @@ def test_nxos_vrf_af_route_target_both_present_current_non_existing(self): "rt": "65000:1000", "direction": "both", "state": "present", - } + }, ], - ) + ), ) result = self.execute_module(changed=True) self.assertEqual( @@ -730,9 +719,9 @@ def test_nxos_vrf_af_route_target_both_present_current_existing(self): "rt": "65000:1000", "direction": "both", "state": "present", - } + }, ], - ) + ), ) result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) @@ -761,7 +750,7 @@ def test_nxos_vrf_af_route_target_multi_both_present_current_non_existing( "state": "present", }, ], - ) + ), ) result = self.execute_module(changed=True) self.assertEqual( @@ -802,7 +791,7 @@ def test_nxos_vrf_af_route_target_multi_both_present_current_existing( "state": "present", }, ], - ) + ), ) result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) @@ -817,9 +806,9 @@ def test_nxos_vrf_af_route_target_both_absent_current_non_existing(self): "rt": "65000:1000", "direction": "both", "state": "absent", - } + }, ], - ) + ), ) result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) @@ -834,9 +823,9 @@ def test_nxos_vrf_af_route_target_both_absent_current_existing(self): "rt": "65000:1000", "direction": "both", "state": "absent", - } + }, ], - ) + ), ) result = self.execute_module(changed=True) self.assertEqual( @@ -873,7 +862,7 @@ def test_nxos_vrf_af_route_target_multi_both_absent_current_non_existing( "state": "absent", }, ], - ) + ), ) result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) @@ -900,7 +889,7 @@ def test_nxos_vrf_af_route_target_multi_both_absent_current_existing(self): "state": "absent", }, ], - ) + ), ) result = self.execute_module(changed=True) self.assertEqual( @@ -949,7 +938,7 @@ def test_nxos_vrf_af_route_target_multi_both_absent_current_mix(self): "state": "absent", }, ], - ) + ), ) result = self.execute_module(changed=True) self.assertEqual( @@ -993,7 +982,7 @@ def test_nxos_vrf_af_route_target_multi_both_current_only_import_or_export( "state": "absent", }, ], - ) + ), ) result = self.execute_module(changed=True) self.assertEqual( @@ -1033,7 +1022,7 @@ def test_nxos_vrf_af_route_target_multi_direction_current_only_import_or_export( "state": "absent", }, ], - ) + ), ) result = self.execute_module(changed=True) self.assertEqual( @@ -1058,9 +1047,9 @@ def test_nxos_vrf_af_auto_evpn_route_target_and_manual_route_target(self): "rt": "65000:1000", "direction": "both", "state": "present", - } + }, ], - ) + ), ) result = self.execute_module(changed=True) self.assertEqual( @@ -1088,9 +1077,9 @@ def test_nxos_vrf_af_auto_evpn_route_target_and_manual_route_targets_with_absent "rt": "65000:1000", "direction": "both", "state": "present", - } + }, ], - ) + ), ) result = self.execute_module(changed=True) self.assertEqual( @@ -1099,17 +1088,13 @@ def test_nxos_vrf_af_auto_evpn_route_target_and_manual_route_targets_with_absent ) def test_nxos_vrf_af_both_auto_N9K(self): - self.get_capabilities.return_value = { - "device_info": {"network_os_platform": "N9K-C9300v"} - } + self.get_capabilities.return_value = {"device_info": {"network_os_platform": "N9K-C9300v"}} set_module_args( dict( vrf="v2000", afi="ipv4", - route_targets=[ - {"rt": "auto", "direction": "both", "state": "present"} - ], - ) + route_targets=[{"rt": "auto", "direction": "both", "state": "present"}], + ), ) result = self.execute_module(changed=True) self.assertEqual( diff --git a/tests/unit/modules/network/nxos/storage/test_nxos_vsan.py b/tests/unit/modules/network/nxos/test_nxos_vsan.py similarity index 74% rename from tests/unit/modules/network/nxos/storage/test_nxos_vsan.py rename to tests/unit/modules/network/nxos/test_nxos_vsan.py index 691b05bc7..af9ee7ad3 100644 --- a/tests/unit/modules/network/nxos/storage/test_nxos_vsan.py +++ b/tests/unit/modules/network/nxos/test_nxos_vsan.py @@ -4,20 +4,16 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type import pytest +from ansible_collections.cisco.nxos.plugins.modules import nxos_vsan from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - AnsibleFailJson, -) -from ansible_collections.cisco.nxos.plugins.modules.storage import nxos_vsan -from ansible_collections.cisco.nxos.plugins.modules.storage.nxos_vsan import ( - GetVsanInfoFromSwitch, -) +from ansible_collections.cisco.nxos.tests.unit.modules.utils import AnsibleFailJson -from ..nxos_module import TestNxosModule, load_fixture, set_module_args +from .nxos_module import TestNxosModule, load_fixture, set_module_args class TestNxosVsanModule(TestNxosModule): @@ -25,24 +21,20 @@ class TestNxosVsanModule(TestNxosModule): def setUp(self): super(TestNxosVsanModule, self).setUp() - module_path = ( - "ansible_collections.cisco.nxos.plugins.modules.storage.nxos_vsan." - ) + module_path = "ansible_collections.cisco.nxos.plugins.modules.nxos_vsan." self.mock_run_commands = patch(module_path + "run_commands") self.run_commands = self.mock_run_commands.start() self.mock_execute_show_vsan_cmd = patch( - module_path + "GetVsanInfoFromSwitch.execute_show_vsan_cmd" + module_path + "GetVsanInfoFromSwitch.execute_show_vsan_cmd", ) self.execute_show_vsan_cmd = self.mock_execute_show_vsan_cmd.start() self.mock_execute_show_vsanmemcmd = patch( - module_path + "GetVsanInfoFromSwitch.execute_show_vsan_mem_cmd" - ) - self.execute_show_vsanmem_cmd = ( - self.mock_execute_show_vsanmemcmd.start() + module_path + "GetVsanInfoFromSwitch.execute_show_vsan_mem_cmd", ) + self.execute_show_vsanmem_cmd = self.mock_execute_show_vsanmemcmd.start() self.mock_load_config = patch(module_path + "load_config") self.load_config = self.mock_load_config.start() @@ -75,29 +67,19 @@ def test_vsan_add_remove_but_present_in_switch(self): "name": "vsan-SAN-B", }, {"id": 1923, "remove": True, "name": "vsan-SAN-Old"}, - ] + ], } set_module_args(margs, True) - self.execute_show_vsan_cmd.return_value = load_fixture( - "nxos_vsan", "shvsan.cfg" - ) - self.execute_show_vsanmem_cmd.return_value = load_fixture( - "nxos_vsan", "shvsanmem.cfg" - ) + self.execute_show_vsan_cmd.return_value = load_fixture("nxos_vsan", "shvsan.cfg") + self.execute_show_vsanmem_cmd.return_value = load_fixture("nxos_vsan", "shvsanmem.cfg") result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) def test_vsan_remove(self): - margs = { - "vsan": [{"id": 922, "remove": True}, {"id": 923, "remove": True}] - } + margs = {"vsan": [{"id": 922, "remove": True}, {"id": 923, "remove": True}]} set_module_args(margs, True) - self.execute_show_vsan_cmd.return_value = load_fixture( - "nxos_vsan", "shvsan.cfg" - ) - self.execute_show_vsanmem_cmd.return_value = load_fixture( - "nxos_vsan", "shvsanmem.cfg" - ) + self.execute_show_vsan_cmd.return_value = load_fixture("nxos_vsan", "shvsan.cfg") + self.execute_show_vsanmem_cmd.return_value = load_fixture("nxos_vsan", "shvsanmem.cfg") result = self.execute_module(changed=True) self.assertEqual( result["commands"], @@ -120,15 +102,11 @@ def test_vsan_add(self): "id": 925, "name": "vsan-SAN-925", }, - ] + ], } set_module_args(margs, True) - self.execute_show_vsan_cmd.return_value = load_fixture( - "nxos_vsan", "shvsan.cfg" - ) - self.execute_show_vsanmem_cmd.return_value = load_fixture( - "nxos_vsan", "shvsanmem.cfg" - ) + self.execute_show_vsan_cmd.return_value = load_fixture("nxos_vsan", "shvsan.cfg") + self.execute_show_vsanmem_cmd.return_value = load_fixture("nxos_vsan", "shvsanmem.cfg") result = self.execute_module(changed=True) self.assertEqual( result["commands"], @@ -161,15 +139,11 @@ def test_vsan_suspend(self): "name": "vsan-SAN-924", }, {"id": 925, "name": "vsan-SAN-925", "suspend": True}, - ] + ], } set_module_args(margs, True) - self.execute_show_vsan_cmd.return_value = load_fixture( - "nxos_vsan", "shvsan.cfg" - ) - self.execute_show_vsanmem_cmd.return_value = load_fixture( - "nxos_vsan", "shvsanmem.cfg" - ) + self.execute_show_vsan_cmd.return_value = load_fixture("nxos_vsan", "shvsan.cfg") + self.execute_show_vsanmem_cmd.return_value = load_fixture("nxos_vsan", "shvsanmem.cfg") result = self.execute_module(changed=True) self.assertEqual( result["commands"], @@ -187,16 +161,10 @@ def test_vsan_suspend(self): ) def test_vsan_invalid_vsan(self): - margs = { - "vsan": [{"id": 4096, "name": "vsan-SAN-925", "suspend": True}] - } + margs = {"vsan": [{"id": 4096, "name": "vsan-SAN-925", "suspend": True}]} set_module_args(margs, True) - self.execute_show_vsan_cmd.return_value = load_fixture( - "nxos_vsan", "shvsan.cfg" - ) - self.execute_show_vsanmem_cmd.return_value = load_fixture( - "nxos_vsan", "shvsanmem.cfg" - ) + self.execute_show_vsan_cmd.return_value = load_fixture("nxos_vsan", "shvsan.cfg") + self.execute_show_vsanmem_cmd.return_value = load_fixture("nxos_vsan", "shvsanmem.cfg") with pytest.raises(AnsibleFailJson) as errinfo: self.execute_module() testdata = errinfo.value.args[0] @@ -204,16 +172,10 @@ def test_vsan_invalid_vsan(self): assert testdata["failed"] def test_vsan_change_reserved_vsan(self): - margs = { - "vsan": [{"id": 4094, "name": "vsan-SAN-925", "suspend": True}] - } + margs = {"vsan": [{"id": 4094, "name": "vsan-SAN-925", "suspend": True}]} set_module_args(margs, True) - self.execute_show_vsan_cmd.return_value = load_fixture( - "nxos_vsan", "shvsan.cfg" - ) - self.execute_show_vsanmem_cmd.return_value = load_fixture( - "nxos_vsan", "shvsanmem.cfg" - ) + self.execute_show_vsan_cmd.return_value = load_fixture("nxos_vsan", "shvsan.cfg") + self.execute_show_vsanmem_cmd.return_value = load_fixture("nxos_vsan", "shvsanmem.cfg") result = self.execute_module(changed=False) assert "reserved vsan" in str(result["messages"]) self.assertEqual(result["commands"], []) @@ -224,16 +186,12 @@ def test_vsan_add_int_existing_vsan(self): { "interface": ["fc1/1", "fc1/40", "port-channel 155"], "id": 922, - } - ] + }, + ], } set_module_args(margs, True) - self.execute_show_vsan_cmd.return_value = load_fixture( - "nxos_vsan", "shvsan.cfg" - ) - self.execute_show_vsanmem_cmd.return_value = load_fixture( - "nxos_vsan", "shvsanmem.cfg" - ) + self.execute_show_vsan_cmd.return_value = load_fixture("nxos_vsan", "shvsan.cfg") + self.execute_show_vsanmem_cmd.return_value = load_fixture("nxos_vsan", "shvsanmem.cfg") result = self.execute_module(changed=True) self.assertEqual( result["commands"], @@ -249,12 +207,8 @@ def test_vsan_add_int_existing_vsan(self): def test_vsan_remove_non_existing_vsan(self): margs = {"vsan": [{"id": 1111, "remove": True}]} set_module_args(margs, True) - self.execute_show_vsan_cmd.return_value = load_fixture( - "nxos_vsan", "shvsan.cfg" - ) - self.execute_show_vsanmem_cmd.return_value = load_fixture( - "nxos_vsan", "shvsanmem.cfg" - ) + self.execute_show_vsan_cmd.return_value = load_fixture("nxos_vsan", "shvsan.cfg") + self.execute_show_vsanmem_cmd.return_value = load_fixture("nxos_vsan", "shvsanmem.cfg") result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) assert "no vsan" in str(result["messages"]) diff --git a/tests/unit/modules/network/nxos/test_nxos_vxlan_vtep.py b/tests/unit/modules/network/nxos/test_nxos_vxlan_vtep.py index e0011c15f..f6862a77e 100644 --- a/tests/unit/modules/network/nxos/test_nxos_vxlan_vtep.py +++ b/tests/unit/modules/network/nxos/test_nxos_vxlan_vtep.py @@ -19,27 +19,28 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from ansible_collections.cisco.nxos.plugins.modules import nxos_vxlan_vtep +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from .nxos_module import TestNxosModule, load_fixture, set_module_args class TestNxosVxlanVtepVniModule(TestNxosModule): - module = nxos_vxlan_vtep def setUp(self): super(TestNxosVxlanVtepVniModule, self).setUp() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_vxlan_vtep.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_vxlan_vtep.load_config", ) self.load_config = self.mock_load_config.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_vxlan_vtep.get_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_vxlan_vtep.get_config", ) self.get_config = self.mock_get_config.start() @@ -49,15 +50,11 @@ def tearDown(self): self.mock_load_config.stop() def load_fixtures(self, commands=None, device=""): - self.get_config.return_value = load_fixture( - "nxos_vxlan_vtep", "config.cfg" - ) + self.get_config.return_value = load_fixture("nxos_vxlan_vtep", "config.cfg") self.load_config.return_value = None def test_nxos_vxlan_vtep(self): - set_module_args( - dict(interface="nve1", description="simple description") - ) + set_module_args(dict(interface="nve1", description="simple description")) self.execute_module( changed=True, commands=[ @@ -84,7 +81,7 @@ def test_nxos_vxlan_vtep_multisite(self): dict( interface="nve1", multisite_border_gateway_interface="Loopback10", - ) + ), ) self.execute_module( changed=True, @@ -100,6 +97,22 @@ def test_nxos_vxlan_vtep_multisite_exists(self): dict( interface="nve1", multisite_border_gateway_interface="Loopback1", - ) + ), ) self.execute_module(changed=False, commands=[]) + + def test_nxos_vxlan_vtep_advertise_virtual_rmac(self): + set_module_args( + dict( + interface="nve1", + advertise_virtual_rmac="true", + ), + ) + self.execute_module( + changed=True, + commands=[ + "interface nve1", + "terminal dont-ask", + "advertise virtual-rmac", + ], + ) diff --git a/tests/unit/modules/network/nxos/test_nxos_vxlan_vtep_vni.py b/tests/unit/modules/network/nxos/test_nxos_vxlan_vtep_vni.py index a844d4b8f..c6dc6e8d8 100644 --- a/tests/unit/modules/network/nxos/test_nxos_vxlan_vtep_vni.py +++ b/tests/unit/modules/network/nxos/test_nxos_vxlan_vtep_vni.py @@ -19,27 +19,28 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from ansible_collections.cisco.nxos.plugins.modules import nxos_vxlan_vtep_vni +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + from .nxos_module import TestNxosModule, load_fixture, set_module_args class TestNxosVxlanVtepVniModule(TestNxosModule): - module = nxos_vxlan_vtep_vni def setUp(self): super(TestNxosVxlanVtepVniModule, self).setUp() self.mock_load_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_vxlan_vtep_vni.load_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_vxlan_vtep_vni.load_config", ) self.load_config = self.mock_load_config.start() self.mock_get_config = patch( - "ansible_collections.cisco.nxos.plugins.modules.nxos_vxlan_vtep_vni.get_config" + "ansible_collections.cisco.nxos.plugins.modules.nxos_vxlan_vtep_vni.get_config", ) self.get_config = self.mock_get_config.start() @@ -49,9 +50,7 @@ def tearDown(self): self.mock_load_config.stop() def load_fixtures(self, commands=None, device=""): - self.get_config.return_value = load_fixture( - "nxos_vxlan_vtep_vni", "config.cfg" - ) + self.get_config.return_value = load_fixture("nxos_vxlan_vtep_vni", "config.cfg") self.load_config.return_value = None def test_nxos_vxlan_vtep_vni_present_no_change(self): @@ -60,15 +59,11 @@ def test_nxos_vxlan_vtep_vni_present_no_change(self): def test_nxos_vxlan_vtep_vni(self): set_module_args(dict(interface="nve1", vni=5000)) - self.execute_module( - changed=True, commands=["interface nve1", "member vni 5000"] - ) + self.execute_module(changed=True, commands=["interface nve1", "member vni 5000"]) def test_nxos_vxlan_vtep_vni_absent(self): set_module_args(dict(interface="nve1", vni=6000, state="absent")) - self.execute_module( - changed=True, commands=["interface nve1", "no member vni 6000"] - ) + self.execute_module(changed=True, commands=["interface nve1", "no member vni 6000"]) def test_nxos_vxlan_vtep_vni_absent_no_change(self): set_module_args(dict(interface="nve2", vni=6000, state="absent")) @@ -80,7 +75,7 @@ def test_nxos_vxlan_vtep_vni_multi_ingress_repl(self): interface="nve1", vni=5000, multisite_ingress_replication="enable", - ) + ), ) commands = [ "interface nve1", @@ -96,7 +91,7 @@ def test_nxos_vxlan_vtep_vni_multi_ingress_repl_opt(self): interface="nve1", vni=5000, multisite_ingress_replication="optimized", - ) + ), ) commands = [ "interface nve1", @@ -112,6 +107,6 @@ def test_nxos_vxlan_vtep_vni_multi_ingress_repl_opt_exists(self): interface="nve1", vni=6000, multisite_ingress_replication="optimized", - ) + ), ) self.execute_module(changed=False, commands=[]) diff --git a/tests/unit/modules/network/nxos/storage/test_nxos_zone_zoneset.py b/tests/unit/modules/network/nxos/test_nxos_zone_zoneset.py similarity index 80% rename from tests/unit/modules/network/nxos/storage/test_nxos_zone_zoneset.py rename to tests/unit/modules/network/nxos/test_nxos_zone_zoneset.py index c86f7259b..6afe78a5b 100644 --- a/tests/unit/modules/network/nxos/storage/test_nxos_zone_zoneset.py +++ b/tests/unit/modules/network/nxos/test_nxos_zone_zoneset.py @@ -5,26 +5,13 @@ from __future__ import absolute_import, division, print_function -__metaclass__ = type -import pytest +__metaclass__ = type +from ansible_collections.cisco.nxos.plugins.modules import nxos_zone_zoneset from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch -from ansible_collections.cisco.nxos.tests.unit.modules.utils import ( - AnsibleFailJson, - AnsibleExitJson, -) -from ansible_collections.cisco.nxos.plugins.modules.storage import ( - nxos_zone_zoneset, -) -from ansible_collections.cisco.nxos.plugins.modules.storage.nxos_zone_zoneset import ( - ShowZonesetActive, - ShowZoneset, - ShowZone, - ShowZoneStatus, -) - -from ..nxos_module import TestNxosModule, load_fixture, set_module_args + +from .nxos_module import TestNxosModule, load_fixture, set_module_args class TestNxosZoneZonesetModule(TestNxosModule): @@ -32,36 +19,30 @@ class TestNxosZoneZonesetModule(TestNxosModule): def setUp(self): super(TestNxosZoneZonesetModule, self).setUp() - module_path = "ansible_collections.cisco.nxos.plugins.modules.storage.nxos_zone_zoneset." + module_path = "ansible_collections.cisco.nxos.plugins.modules.nxos_zone_zoneset." self.mock_run_commands = patch(module_path + "run_commands") self.run_commands = self.mock_run_commands.start() self.mock_execute_show_cmd_zoneset_active = patch( - module_path + "ShowZonesetActive.execute_show_zoneset_active_cmd" - ) - self.execute_show_cmd_zoneset_active = ( - self.mock_execute_show_cmd_zoneset_active.start() + module_path + "ShowZonesetActive.execute_show_zoneset_active_cmd", ) + self.execute_show_cmd_zoneset_active = self.mock_execute_show_cmd_zoneset_active.start() self.mock_execute_show_cmd_zoneset = patch( - module_path + "ShowZoneset.execute_show_zoneset_cmd" - ) - self.execute_show_cmd_zoneset = ( - self.mock_execute_show_cmd_zoneset.start() + module_path + "ShowZoneset.execute_show_zoneset_cmd", ) + self.execute_show_cmd_zoneset = self.mock_execute_show_cmd_zoneset.start() self.mock_execute_show_cmd_zone = patch( - module_path + "ShowZone.execute_show_zone_vsan_cmd" + module_path + "ShowZone.execute_show_zone_vsan_cmd", ) self.execute_show_cmd_zone = self.mock_execute_show_cmd_zone.start() self.mock_execute_show_cmd_zone_status = patch( - module_path + "ShowZoneStatus.execute_show_zone_status_cmd" - ) - self.execute_show_cmd_zone_status = ( - self.mock_execute_show_cmd_zone_status.start() + module_path + "ShowZoneStatus.execute_show_zone_status_cmd", ) + self.execute_show_cmd_zone_status = self.mock_execute_show_cmd_zone_status.start() self.mock_load_config = patch(module_path + "load_config") self.load_config = self.mock_load_config.start() @@ -86,7 +67,8 @@ def test_zone_defzone_deny_to_permit(self): a = dict(zone_zoneset_details=[dict(vsan=922, default_zone="permit")]) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_0.cfg" + "nxos_zone_zoneset", + "shzonestatus_0.cfg", ) result = self.execute_module(changed=True) self.assertEqual( @@ -103,7 +85,8 @@ def test_zone_defzone_deny_to_permit_1(self): a = dict(zone_zoneset_details=[dict(vsan=922, default_zone="permit")]) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_1.cfg" + "nxos_zone_zoneset", + "shzonestatus_1.cfg", ) result = self.execute_module(changed=True) self.assertEqual( @@ -121,7 +104,8 @@ def test_zone_defzone_permit_to_deny_1(self): a = dict(zone_zoneset_details=[dict(vsan=923, default_zone="deny")]) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_2.cfg" + "nxos_zone_zoneset", + "shzonestatus_2.cfg", ) result = self.execute_module(changed=True) self.assertEqual( @@ -139,7 +123,8 @@ def test_zone_defzone_permit_to_deny_2(self): a = dict(zone_zoneset_details=[dict(vsan=923, default_zone="deny")]) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_3.cfg" + "nxos_zone_zoneset", + "shzonestatus_3.cfg", ) result = self.execute_module(changed=True) self.assertEqual( @@ -157,7 +142,8 @@ def test_zone_mode_basic_to_enh(self): a = dict(zone_zoneset_details=[dict(vsan=922, mode="enhanced")]) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_0.cfg" + "nxos_zone_zoneset", + "shzonestatus_0.cfg", ) result = self.execute_module(changed=True) self.assertEqual( @@ -176,7 +162,8 @@ def test_zone_mode_basic_to_enh_1(self): a = dict(zone_zoneset_details=[dict(vsan=922, mode="basic")]) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_1.cfg" + "nxos_zone_zoneset", + "shzonestatus_1.cfg", ) result = self.execute_module(changed=True) self.assertEqual( @@ -194,7 +181,8 @@ def test_zone_smart_zone(self): a = dict(zone_zoneset_details=[dict(vsan=922, smart_zoning=False)]) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_0.cfg" + "nxos_zone_zoneset", + "shzonestatus_0.cfg", ) result = self.execute_module(changed=True) self.assertEqual( @@ -211,7 +199,8 @@ def test_zone_smart_zone_1(self): a = dict(zone_zoneset_details=[dict(vsan=923, smart_zoning=True)]) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_1.cfg" + "nxos_zone_zoneset", + "shzonestatus_1.cfg", ) result = self.execute_module(changed=True) self.assertEqual( @@ -228,15 +217,17 @@ def test_zone_smart_zone_1(self): def test_zone_add_rem(self): a = dict( zone_zoneset_details=[ - dict(vsan=923, zone=[dict(name="zoneB", remove=True)]) - ] + dict(vsan=923, zone=[dict(name="zoneB", remove=True)]), + ], ) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_1.cfg" + "nxos_zone_zoneset", + "shzonestatus_1.cfg", ) self.execute_show_cmd_zone.return_value = load_fixture( - "nxos_zone_zoneset", "shzone_0.cfg" + "nxos_zone_zoneset", + "shzone_0.cfg", ) result = self.execute_module(changed=True) self.assertEqual( @@ -252,15 +243,17 @@ def test_zone_add_rem(self): def test_zone_add_rem_1(self): a = dict( zone_zoneset_details=[ - dict(vsan=923, zone=[dict(name="zoneC", remove=True)]) - ] + dict(vsan=923, zone=[dict(name="zoneC", remove=True)]), + ], ) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_1.cfg" + "nxos_zone_zoneset", + "shzonestatus_1.cfg", ) self.execute_show_cmd_zone.return_value = load_fixture( - "nxos_zone_zoneset", "shzone_0.cfg" + "nxos_zone_zoneset", + "shzone_0.cfg", ) result = self.execute_module(changed=False, failed=False) m = "zone 'zoneC' is not present in vsan 923" @@ -268,15 +261,15 @@ def test_zone_add_rem_1(self): self.assertEqual(result["commands"], []) def test_zone_add_rem_2(self): - a = dict( - zone_zoneset_details=[dict(vsan=923, zone=[dict(name="zoneBNew")])] - ) + a = dict(zone_zoneset_details=[dict(vsan=923, zone=[dict(name="zoneBNew")])]) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_1.cfg" + "nxos_zone_zoneset", + "shzonestatus_1.cfg", ) self.execute_show_cmd_zone.return_value = load_fixture( - "nxos_zone_zoneset", "shzone_0.cfg" + "nxos_zone_zoneset", + "shzone_0.cfg", ) result = self.execute_module(changed=True) self.assertEqual( @@ -290,15 +283,15 @@ def test_zone_add_rem_2(self): ) def test_zone_add_rem_3(self): - a = dict( - zone_zoneset_details=[dict(vsan=923, zone=[dict(name="zoneB")])] - ) + a = dict(zone_zoneset_details=[dict(vsan=923, zone=[dict(name="zoneB")])]) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_1.cfg" + "nxos_zone_zoneset", + "shzonestatus_1.cfg", ) self.execute_show_cmd_zone.return_value = load_fixture( - "nxos_zone_zoneset", "shzone_0.cfg" + "nxos_zone_zoneset", + "shzone_0.cfg", ) result = self.execute_module(changed=False, failed=False) m = "zone 'zoneB' is already present in vsan 923" @@ -314,15 +307,17 @@ def test_zonemem_add_rem(self): dict( vsan=923, zone=[dict(name="zoneBNew", members=[mem1, mem2])], - ) - ] + ), + ], ) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_1.cfg" + "nxos_zone_zoneset", + "shzonestatus_1.cfg", ) self.execute_show_cmd_zone.return_value = load_fixture( - "nxos_zone_zoneset", "shzone_0.cfg" + "nxos_zone_zoneset", + "shzone_0.cfg", ) result = self.execute_module(changed=True) self.assertEqual( @@ -343,15 +338,17 @@ def test_zonemem_add_rem_1(self): mem2 = {"device_alias": "test123", "remove": True} a = dict( zone_zoneset_details=[ - dict(vsan=923, zone=[dict(name="zoneA", members=[mem1, mem2])]) - ] + dict(vsan=923, zone=[dict(name="zoneA", members=[mem1, mem2])]), + ], ) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_1.cfg" + "nxos_zone_zoneset", + "shzonestatus_1.cfg", ) self.execute_show_cmd_zone.return_value = load_fixture( - "nxos_zone_zoneset", "shzone_0.cfg" + "nxos_zone_zoneset", + "shzone_0.cfg", ) result = self.execute_module(changed=True) self.assertEqual( @@ -372,17 +369,17 @@ def test_zonemem_add_rem_2(self): mem2 = {"device_alias": "test123", "remove": True} a = dict( zone_zoneset_details=[ - dict( - vsan=923, zone=[dict(name="zoneA1", members=[mem1, mem2])] - ) - ] + dict(vsan=923, zone=[dict(name="zoneA1", members=[mem1, mem2])]), + ], ) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_1.cfg" + "nxos_zone_zoneset", + "shzonestatus_1.cfg", ) self.execute_show_cmd_zone.return_value = load_fixture( - "nxos_zone_zoneset", "shzone_0.cfg" + "nxos_zone_zoneset", + "shzone_0.cfg", ) result = self.execute_module(changed=False, failed=False) m = "zone 'zoneA1' is not present in vsan 923 , hence cannot remove the members" @@ -399,15 +396,17 @@ def test_zonemem_add_rem_3(self): dict( vsan=922, zone=[dict(name="zoneBNew", members=[mem1, mem2, mem3])], - ) - ] + ), + ], ) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_0.cfg" + "nxos_zone_zoneset", + "shzonestatus_0.cfg", ) self.execute_show_cmd_zone.return_value = load_fixture( - "nxos_zone_zoneset", "shzone_1.cfg" + "nxos_zone_zoneset", + "shzone_1.cfg", ) result = self.execute_module(changed=True) self.assertEqual( @@ -428,15 +427,17 @@ def test_zonemem_add_rem_4(self): a = dict( zone_zoneset_details=[ - dict(vsan=922, zone=[dict(name="zoneA", members=[mem2])]) - ] + dict(vsan=922, zone=[dict(name="zoneA", members=[mem2])]), + ], ) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_0.cfg" + "nxos_zone_zoneset", + "shzonestatus_0.cfg", ) self.execute_show_cmd_zone.return_value = load_fixture( - "nxos_zone_zoneset", "shzone_1.cfg" + "nxos_zone_zoneset", + "shzone_1.cfg", ) result = self.execute_module(changed=True) self.assertEqual( @@ -453,15 +454,17 @@ def test_zonemem_add_rem_4(self): def test_zoneset_add_rem(self): a = dict( zone_zoneset_details=[ - dict(vsan=922, zoneset=[dict(name="zsetname21", remove=True)]) - ] + dict(vsan=922, zoneset=[dict(name="zsetname21", remove=True)]), + ], ) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_0.cfg" + "nxos_zone_zoneset", + "shzonestatus_0.cfg", ) self.execute_show_cmd_zoneset.return_value = load_fixture( - "nxos_zone_zoneset", "shzoneset_0.cfg" + "nxos_zone_zoneset", + "shzoneset_0.cfg", ) result = self.execute_module(changed=True) self.assertEqual( @@ -475,16 +478,16 @@ def test_zoneset_add_rem(self): def test_zoneset_add_rem_1(self): a = dict( - zone_zoneset_details=[ - dict(vsan=922, zoneset=[dict(name="zsetname21New")]) - ] + zone_zoneset_details=[dict(vsan=922, zoneset=[dict(name="zsetname21New")])], ) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_0.cfg" + "nxos_zone_zoneset", + "shzonestatus_0.cfg", ) self.execute_show_cmd_zoneset.return_value = load_fixture( - "nxos_zone_zoneset", "shzoneset_0.cfg" + "nxos_zone_zoneset", + "shzoneset_0.cfg", ) result = self.execute_module(changed=True) self.assertEqual( @@ -498,16 +501,16 @@ def test_zoneset_add_rem_1(self): def test_zoneset_add_rem_2(self): a = dict( - zone_zoneset_details=[ - dict(vsan=922, zoneset=[dict(name="zsetname21")]) - ] + zone_zoneset_details=[dict(vsan=922, zoneset=[dict(name="zsetname21")])], ) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_0.cfg" + "nxos_zone_zoneset", + "shzonestatus_0.cfg", ) self.execute_show_cmd_zoneset.return_value = load_fixture( - "nxos_zone_zoneset", "shzoneset_0.cfg" + "nxos_zone_zoneset", + "shzoneset_0.cfg", ) result = self.execute_module(changed=False, failed=False) m = "zoneset 'zsetname21' is already present in vsan 922" @@ -517,17 +520,17 @@ def test_zoneset_add_rem_2(self): def test_zoneset_add_rem_3(self): a = dict( zone_zoneset_details=[ - dict( - vsan=922, zoneset=[dict(name="zsetname21New", remove=True)] - ) - ] + dict(vsan=922, zoneset=[dict(name="zsetname21New", remove=True)]), + ], ) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_0.cfg" + "nxos_zone_zoneset", + "shzonestatus_0.cfg", ) self.execute_show_cmd_zoneset.return_value = load_fixture( - "nxos_zone_zoneset", "shzoneset_0.cfg" + "nxos_zone_zoneset", + "shzoneset_0.cfg", ) result = self.execute_module(changed=False, failed=False) m = "zoneset 'zsetname21New' is not present in vsan 922 ,hence there is nothing to remove" @@ -540,17 +543,17 @@ def test_zoneset_mem_add_rem(self): a = dict( zone_zoneset_details=[ - dict( - vsan=922, zoneset=[dict(name="zsetname21", members=[mem1])] - ) - ] + dict(vsan=922, zoneset=[dict(name="zsetname21", members=[mem1])]), + ], ) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_0.cfg" + "nxos_zone_zoneset", + "shzonestatus_0.cfg", ) self.execute_show_cmd_zoneset.return_value = load_fixture( - "nxos_zone_zoneset", "shzoneset_0.cfg" + "nxos_zone_zoneset", + "shzoneset_0.cfg", ) result = self.execute_module(changed=True, failed=False) self.assertEqual( @@ -569,17 +572,17 @@ def test_zoneset_mem_add_rem_1(self): a = dict( zone_zoneset_details=[ - dict( - vsan=922, zoneset=[dict(name="zsetname21", members=[mem1])] - ) - ] + dict(vsan=922, zoneset=[dict(name="zsetname21", members=[mem1])]), + ], ) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_0.cfg" + "nxos_zone_zoneset", + "shzonestatus_0.cfg", ) self.execute_show_cmd_zoneset.return_value = load_fixture( - "nxos_zone_zoneset", "shzoneset_0.cfg" + "nxos_zone_zoneset", + "shzoneset_0.cfg", ) result = self.execute_module(changed=True, failed=False) self.assertEqual( @@ -598,17 +601,17 @@ def test_zoneset_mem_add_rem_2(self): a = dict( zone_zoneset_details=[ - dict( - vsan=922, zoneset=[dict(name="zsetname21", members=[mem1])] - ) - ] + dict(vsan=922, zoneset=[dict(name="zsetname21", members=[mem1])]), + ], ) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_0.cfg" + "nxos_zone_zoneset", + "shzonestatus_0.cfg", ) self.execute_show_cmd_zoneset.return_value = load_fixture( - "nxos_zone_zoneset", "shzoneset_0.cfg" + "nxos_zone_zoneset", + "shzoneset_0.cfg", ) result = self.execute_module(changed=False, failed=False) m = "zoneset member 'zone21' is not present in zoneset 'zsetname21' in vsan 922 ,hence there is nothing to remove" @@ -619,20 +622,21 @@ def test_zoneset_mem_add_rem_2(self): def test_zoneset_activate_deactivate(self): a = dict( zone_zoneset_details=[ - dict( - vsan=221, zoneset=[dict(name="zsv221", action="activate")] - ) - ] + dict(vsan=221, zoneset=[dict(name="zsv221", action="activate")]), + ], ) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_4.cfg" + "nxos_zone_zoneset", + "shzonestatus_4.cfg", ) self.execute_show_cmd_zoneset.return_value = load_fixture( - "nxos_zone_zoneset", "shzoneset_2.cfg" + "nxos_zone_zoneset", + "shzoneset_2.cfg", ) self.execute_show_cmd_zoneset_active.return_value = load_fixture( - "nxos_zone_zoneset", "shzonesetactive_0.cfg" + "nxos_zone_zoneset", + "shzonesetactive_0.cfg", ) result = self.execute_module(changed=False, failed=False) self.assertEqual(result["commands"], []) @@ -643,18 +647,21 @@ def test_zoneset_activate_deactivate_1(self): dict( vsan=221, zoneset=[dict(name="zsv221", action="deactivate")], - ) - ] + ), + ], ) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_4.cfg" + "nxos_zone_zoneset", + "shzonestatus_4.cfg", ) self.execute_show_cmd_zoneset.return_value = load_fixture( - "nxos_zone_zoneset", "shzoneset_2.cfg" + "nxos_zone_zoneset", + "shzoneset_2.cfg", ) self.execute_show_cmd_zoneset_active.return_value = load_fixture( - "nxos_zone_zoneset", "shzonesetactive_0.cfg" + "nxos_zone_zoneset", + "shzonesetactive_0.cfg", ) result = self.execute_module(changed=True, failed=False) self.assertEqual( @@ -673,18 +680,21 @@ def test_zoneset_activate_deactivate_2(self): dict( vsan=221, zoneset=[dict(name="zsv221New", action="activate")], - ) - ] + ), + ], ) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_4.cfg" + "nxos_zone_zoneset", + "shzonestatus_4.cfg", ) self.execute_show_cmd_zoneset.return_value = load_fixture( - "nxos_zone_zoneset", "shzoneset_2.cfg" + "nxos_zone_zoneset", + "shzoneset_2.cfg", ) self.execute_show_cmd_zoneset_active.return_value = load_fixture( - "nxos_zone_zoneset", "shzonesetactive_0.cfg" + "nxos_zone_zoneset", + "shzonesetactive_0.cfg", ) result = self.execute_module(changed=True, failed=False) self.assertEqual( @@ -703,18 +713,21 @@ def test_bug_zone_remove(self): mem2 = {"pwwn": "50:06:01:6a:47:e4:6e:59", "remove": True} a = dict( zone_zoneset_details=[ - dict(vsan=221, zone=[dict(name="zv221", members=[mem1, mem2])]) - ] + dict(vsan=221, zone=[dict(name="zv221", members=[mem1, mem2])]), + ], ) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_4.cfg" + "nxos_zone_zoneset", + "shzonestatus_4.cfg", ) self.execute_show_cmd_zone.return_value = load_fixture( - "nxos_zone_zoneset", "shzone_2.cfg" + "nxos_zone_zoneset", + "shzone_2.cfg", ) self.execute_show_cmd_zoneset_active.return_value = load_fixture( - "nxos_zone_zoneset", "shzonesetactive_0.cfg" + "nxos_zone_zoneset", + "shzonesetactive_0.cfg", ) result = self.execute_module(changed=True) self.assertEqual( @@ -735,18 +748,21 @@ def test_bug_from_active_zoneset_act(self): dict( vsan=221, zoneset=[dict(name="zsv221New", action="activate")], - ) - ] + ), + ], ) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_4.cfg" + "nxos_zone_zoneset", + "shzonestatus_4.cfg", ) self.execute_show_cmd_zoneset.return_value = load_fixture( - "nxos_zone_zoneset", "shzoneset_2.cfg" + "nxos_zone_zoneset", + "shzoneset_2.cfg", ) self.execute_show_cmd_zoneset_active.return_value = load_fixture( - "nxos_zone_zoneset", "shzonesetactive_0.cfg" + "nxos_zone_zoneset", + "shzonesetactive_0.cfg", ) result = self.execute_module(changed=True, failed=False) self.assertEqual( @@ -769,15 +785,17 @@ def test_for_bug_339(self): vsan=100, smart_zoning=True, zone=[dict(name="SZ-WLD-IAAS1-HUABVA07", members=[mem1])], - ) - ] + ), + ], ) self.execute_show_cmd_zone.return_value = load_fixture( - "nxos_zone_zoneset", "shzone_bug339.cfg" + "nxos_zone_zoneset", + "shzone_bug339.cfg", ) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "shzonestatus_0.cfg" + "nxos_zone_zoneset", + "shzonestatus_0.cfg", ) set_module_args(a, True) result = self.execute_module(changed=False, failed=False) @@ -795,20 +813,23 @@ def test_bug_zone_remove_oliver(self): dict( name="z50_azusant_f0_unity8174_spa1", members=[mem1], - ) + ), ], - ) - ] + ), + ], ) set_module_args(a, True) self.execute_show_cmd_zone_status.return_value = load_fixture( - "nxos_zone_zoneset", "show_zone_status_vsan.out" + "nxos_zone_zoneset", + "show_zone_status_vsan.out", ) self.execute_show_cmd_zone.return_value = load_fixture( - "nxos_zone_zoneset", "show_zone_vsan.out" + "nxos_zone_zoneset", + "show_zone_vsan.out", ) self.execute_show_cmd_zoneset_active.return_value = load_fixture( - "nxos_zone_zoneset", "show_zoneset_active_vsan.out" + "nxos_zone_zoneset", + "show_zoneset_active_vsan.out", ) result = self.execute_module(changed=True) self.assertEqual( diff --git a/tests/unit/modules/utils.py b/tests/unit/modules/utils.py index dbfae7649..cd3b7b05f 100644 --- a/tests/unit/modules/utils.py +++ b/tests/unit/modules/utils.py @@ -1,13 +1,15 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type import json -from ansible_collections.cisco.nxos.tests.unit.compat import unittest -from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch from ansible.module_utils import basic from ansible.module_utils._text import to_bytes +from ansible_collections.cisco.nxos.tests.unit.compat import unittest +from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch + def set_module_args(args): if "_ansible_remote_tmp" not in args: @@ -41,7 +43,9 @@ def fail_json(*args, **kwargs): class ModuleTestCase(unittest.TestCase): def setUp(self): self.mock_module = patch.multiple( - basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json + basic.AnsibleModule, + exit_json=exit_json, + fail_json=fail_json, ) self.mock_module.start() self.mock_sleep = patch("time.sleep") diff --git a/tox-ansible.ini b/tox-ansible.ini new file mode 100644 index 000000000..5e1f4b36a --- /dev/null +++ b/tox-ansible.ini @@ -0,0 +1,10 @@ +[ansible] + +skip = + py3.7 + py3.8 + 2.9 + 2.10 + 2.11 + 2.12 + 2.13 diff --git a/tox.ini b/tox.ini index a46d4a0c9..6ada631cb 100644 --- a/tox.ini +++ b/tox.ini @@ -10,12 +10,12 @@ deps = -r{toxinidir}/requirements.txt [testenv:black] install_command = pip install {opts} {packages} commands = - black -v -l79 {toxinidir} + black -v {toxinidir} [testenv:linters] install_command = pip install {opts} {packages} commands = - black -v -l79 --diff --check {toxinidir} + black -v --diff --check {toxinidir} flake8 {posargs} [testenv:venv]