diff --git a/lib/ansible/modules/network/cnos/cnos_command.py b/lib/ansible/modules/network/cnos/cnos_command.py index 95a90ca272..65b8c0d958 100644 --- a/lib/ansible/modules/network/cnos/cnos_command.py +++ b/lib/ansible/modules/network/cnos/cnos_command.py @@ -37,54 +37,14 @@ description: argument that will cause the module to wait for a specific condition before returning or timing out if the condition is not met. options: - provider: - version_added: "2.6" - description: - - A dict object containing connection details. - 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. - required: true - port: - description: - - Specifies the port to use when building the connection to the remote device. - default: 22 - username: - description: - - Configures the username to use to authenticate the connection to - the remote device. This value is used to authenticate - the SSH session. If the value is not specified in the task, the - value of environment variable C(ANSIBLE_NET_USERNAME) will be used instead. - password: - description: - - Specifies the password to use to authenticate the connection to - the remote device. This value is used to authenticate - the SSH session. If the value is not specified in the task, the - value of environment variable C(ANSIBLE_NET_PASSWORD) will be used instead. - 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. - default: 10 - ssh_keyfile: - description: - - Specifies the SSH key to use to authenticate the connection to - the remote device. This value is the path to the - key used to authenticate the SSH session. If the value is not specified - in the task, the value of environment variable C(ANSIBLE_NET_SSH_KEYFILE) - will be used instead. commands: version_added: "2.6" description: - - List of commands to send to the remote device over the - configured provider. The resulting output from the command - is returned. If the I(wait_for) argument is provided, the - module is not returned until the condition is satisfied or - the number of retires as expired. + - List of commands to send to the remote device. + The resulting output from the command is returned. + If the I(wait_for) argument is provided, the module is not + returned until the condition is satisfied or the number of + retires is expired. required: true wait_for: version_added: "2.6" @@ -124,17 +84,6 @@ options: """ EXAMPLES = """ -# Note: examples below use the following provider dict to handle -# transport and authentication to the node. ---- -vars: - cli: - host: "{{ inventory_hostname }}" - port: 22 - username: admin - password: admin - timeout: 30 - --- - name: test contains operator cnos_command: @@ -144,7 +93,6 @@ vars: wait_for: - "result[0] contains 'Lenovo'" - "result[1] contains 'MemFree'" - provider: "{{ cli }}" register: result - assert: @@ -155,7 +103,6 @@ vars: - name: get output for single command cnos_command: commands: ['show version'] - provider: "{{ cli }}" register: result - assert: @@ -168,7 +115,6 @@ vars: commands: - show version - show interface information - provider: "{{ cli }}" register: result - assert: @@ -200,7 +146,6 @@ import time from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.network.cnos.cnos import run_commands, check_args -from ansible.module_utils.network.cnos.cnos import cnos_argument_spec from ansible.module_utils.network.common.parsing import Conditional from ansible.module_utils.six import string_types @@ -224,8 +169,6 @@ def main(): interval=dict(default=1, type='int') ) - spec.update(cnos_argument_spec) - module = AnsibleModule(argument_spec=spec, supports_check_mode=True) result = {'changed': False} diff --git a/lib/ansible/modules/network/cnos/cnos_config.py b/lib/ansible/modules/network/cnos/cnos_config.py index e9db206bcd..5d52e8823b 100644 --- a/lib/ansible/modules/network/cnos/cnos_config.py +++ b/lib/ansible/modules/network/cnos/cnos_config.py @@ -37,48 +37,8 @@ description: an implementation for working with CNOS configuration sections in a deterministic way. notes: - - Tested against CNOS 10.8.1 + - Tested against CNOS 10.9.1 options: - provider: - version_added: "2.6" - description: - - A dict object containing connection details. - 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. - required: true - port: - description: - - Specifies the port to use when building the connection to the remote device. - default: 22 - username: - description: - - Configures the username to use to authenticate the connection to - the remote device. This value is used to authenticate - the SSH session. If the value is not specified in the task, the - value of environment variable C(ANSIBLE_NET_USERNAME) will be used instead. - password: - description: - - Specifies the password to use to authenticate the connection to - the remote device. This value is used to authenticate - the SSH session. If the value is not specified in the task, the - value of environment variable C(ANSIBLE_NET_PASSWORD) will be used instead. - 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. - default: 10 - ssh_keyfile: - description: - - Specifies the SSH key to use to authenticate the connection to - the remote device. This value is the path to the - key used to authenticate the SSH session. If the value is not specified - in the task, the value of environment variable C(ANSIBLE_NET_SSH_KEYFILE) - will be used instead. lines: description: - The ordered set of commands that should be configured in the @@ -231,7 +191,6 @@ backup_path: """ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.network.cnos.cnos import load_config, get_config -from ansible.module_utils.network.cnos.cnos import cnos_argument_spec from ansible.module_utils.network.cnos.cnos import check_args from ansible.module_utils.network.common.config import NetworkConfig, dumps @@ -320,8 +279,6 @@ def main(): admin=dict(type='bool', default=False) ) - argument_spec.update(cnos_argument_spec) - mutually_exclusive = [('lines', 'src'), ('parents', 'src')] diff --git a/lib/ansible/modules/network/cnos/cnos_facts.py b/lib/ansible/modules/network/cnos/cnos_facts.py index aa2eba449c..3f6f5e9188 100644 --- a/lib/ansible/modules/network/cnos/cnos_facts.py +++ b/lib/ansible/modules/network/cnos/cnos_facts.py @@ -1,8 +1,8 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # -# (C) 2017 Red Hat Inc. -# Copyright (C) 2017 Lenovo. +# (C) 2019 Red Hat Inc. +# Copyright (C) 2019 Lenovo. # # GNU General Public License v3.0+ # @@ -55,50 +55,6 @@ options: 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. - provider: - version_added: "2.6" - description: - - A dict object containing connection details. - 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. - required: true - port: - description: - - Specifies the port to use when building the connection to the - remote device. - default: 22 - username: - description: - - Configures the username to use to authenticate the connection to - the remote device. This value is used to authenticate - the SSH session. If the value is not specified in the task, the - value of environment variable C(ANSIBLE_NET_USERNAME) will be used - instead. - password: - description: - - Specifies the password to use to authenticate the connection to - the remote device. This value is used to authenticate - the SSH session. If the value is not specified in the task, the - value of environment variable C(ANSIBLE_NET_PASSWORD) will be used - instead. - 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. - default: 10 - ssh_keyfile: - description: - - Specifies the SSH key to use to authenticate the connection to - the remote device. This value is the path to the - key used to authenticate the SSH session. If the value is not - specified in the task, the value of environment variable - C(ANSIBLE_NET_SSH_KEYFILE) will be used instead. gather_subset: version_added: "2.6" description: @@ -116,36 +72,21 @@ Tasks: The following are examples of using the module cnos_facts. --- - name: Test cnos Facts cnos_facts: - provider={{ cli }} - - vars: - cli: - host: "{{ inventory_hostname }}" - port: 22 - username: admin - password: admin - transport: cli - timeout: 30 - authorize: True - auth_pass: --- # Collect all facts from the device - cnos_facts: gather_subset: all - provider: "{{ cli }}" # Collect only the config and default facts - cnos_facts: gather_subset: - config - provider: "{{ cli }}" # Do not collect hardware facts - cnos_facts: gather_subset: - "!hardware" - provider: "{{ cli }}" ''' RETURN = ''' ansible_net_gather_subset: @@ -207,7 +148,6 @@ RETURN = ''' import re from ansible.module_utils.network.cnos.cnos import run_commands -from ansible.module_utils.network.cnos.cnos import cnos_argument_spec from ansible.module_utils.network.cnos.cnos import check_args from ansible.module_utils._text import to_text from ansible.module_utils.basic import AnsibleModule @@ -452,10 +392,6 @@ class Interfaces(FactsBase): if match: key = match.group(1) parsed.append(line) - # match = re.match(r'^(loopback+)', line) - # if match: - # key = match.group(1) - # parsed.append(line) return parsed def set_ip_interfaces(self, line4): @@ -545,8 +481,6 @@ def main(): gather_subset=dict(default=['!config'], type='list') ) - argument_spec.update(cnos_argument_spec) - module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) diff --git a/test/integration/targets/cnos_command/README.md b/test/integration/targets/cnos_command/README.md index 5195a59d13..1992473830 100644 --- a/test/integration/targets/cnos_command/README.md +++ b/test/integration/targets/cnos_command/README.md @@ -34,7 +34,7 @@ These are the various options the customer have in executing the cnos_command mo Variable | Description --- | --- -`commands` | List of commands to send to the remote device over the configured provider. The resulting output from the command is returned. If the I(wait_for) argument is provided, the module is not returned until the condition is satisfied or the number of retires as expired. +`commands` | List of commands to send to the remote device. The resulting output from the command is returned. If the I(wait_for) argument is provided, the module is not returned until the condition is satisfied or the number of retires as expired. `wait_for` | List of conditions to evaluate against the output of the command. The task will wait for each condition to be true before moving forward. If the conditional is not true within the configured number of retries, the task fails. See examples. `match` | The I(match) argument is used in conjunction with the I(wait_for) argument to specify the match policy. Valid values are C(all) or C(any). If the value is set to C(all) then all conditionals in the wait_for must be satisfied. If the value is set to C(any) then only one of the values must be satisfied. `retries` | 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 I(wait_for) conditions. diff --git a/test/integration/targets/cnos_command/tests/cli/bad_operator.yaml b/test/integration/targets/cnos_command/tests/cli/bad_operator.yaml index 79bba2b4f6..0e885c4c21 100644 --- a/test/integration/targets/cnos_command/tests/cli/bad_operator.yaml +++ b/test/integration/targets/cnos_command/tests/cli/bad_operator.yaml @@ -8,7 +8,6 @@ - display interface brief wait_for: - result[0] contains 'Description: Foo' - provider: "{{ cli }}" register: result ignore_errors: yes diff --git a/test/integration/targets/cnos_command/tests/cli/contains.yaml b/test/integration/targets/cnos_command/tests/cli/contains.yaml index 78fbf0a9fb..87a4035e72 100644 --- a/test/integration/targets/cnos_command/tests/cli/contains.yaml +++ b/test/integration/targets/cnos_command/tests/cli/contains.yaml @@ -9,7 +9,6 @@ wait_for: - "result[0] contains 'Lenovo'" - "result[1] contains 'Mem:'" - provider: "{{ cli }}" register: result - assert: diff --git a/test/integration/targets/cnos_command/tests/cli/invalid.yaml b/test/integration/targets/cnos_command/tests/cli/invalid.yaml index 017e6d6234..f4df0c3f24 100644 --- a/test/integration/targets/cnos_command/tests/cli/invalid.yaml +++ b/test/integration/targets/cnos_command/tests/cli/invalid.yaml @@ -4,7 +4,6 @@ - name: run invalid command cnos_command: commands: ['display foo'] - provider: "{{ cli }}" register: result ignore_errors: yes @@ -17,7 +16,6 @@ commands: - display version - display foo - provider: "{{ cli }}" register: result ignore_errors: yes diff --git a/test/integration/targets/cnos_command/tests/cli/output.yaml b/test/integration/targets/cnos_command/tests/cli/output.yaml index 4b262a98bc..a9a328507e 100644 --- a/test/integration/targets/cnos_command/tests/cli/output.yaml +++ b/test/integration/targets/cnos_command/tests/cli/output.yaml @@ -4,7 +4,6 @@ - name: get output for single command cnos_command: commands: ['display version'] - provider: "{{ cli }}" register: result - assert: @@ -17,7 +16,6 @@ commands: - display version - display interface brief - provider: "{{ cli }}" register: result - assert: diff --git a/test/integration/targets/cnos_command/tests/cli/timeout.yaml b/test/integration/targets/cnos_command/tests/cli/timeout.yaml index 5502ee8f1c..54781db0ed 100644 --- a/test/integration/targets/cnos_command/tests/cli/timeout.yaml +++ b/test/integration/targets/cnos_command/tests/cli/timeout.yaml @@ -7,7 +7,6 @@ - display version wait_for: - "result[0] contains bad_value_string" - provider: "{{ cli }}" register: result ignore_errors: yes diff --git a/test/integration/targets/cnos_command/vars/main.yaml b/test/integration/targets/cnos_command/vars/main.yaml deleted file mode 100644 index a5cf22b798..0000000000 --- a/test/integration/targets/cnos_command/vars/main.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -cli: - host: "{{ inventory_hostname }}" - port: 22 - username: admin - password: admin -# transport: cli - timeout: 30 - authorize: True - auth_pass: diff --git a/test/integration/targets/cnos_config/README.md b/test/integration/targets/cnos_config/README.md index da5ab5d4b6..e871c785e4 100644 --- a/test/integration/targets/cnos_config/README.md +++ b/test/integration/targets/cnos_config/README.md @@ -47,19 +47,6 @@ Variable | Description `admin` | Enters into administration configuration mode for making config changes to the device. -Need to specify these variables in vars/main.yml under variable `cli` - -Variable | Description ---- | --- -`host` | Has to be "{{ inventory_hostname }}" -`port` | Has to be`22` -`username` | User Name of switch -`password` | Password of switch -`timeout` | time out value for CLI -`authorixe` | Whether u have to enter enable mode for data collection. -`auth_pass`| Enable Password if required - - ## Dependencies --- diff --git a/test/integration/targets/cnos_config/cnos_config_sample_hosts b/test/integration/targets/cnos_config/cnos_config_sample_hosts index 4e61a81581..aa860b3cf6 100644 --- a/test/integration/targets/cnos_config/cnos_config_sample_hosts +++ b/test/integration/targets/cnos_config/cnos_config_sample_hosts @@ -6,7 +6,7 @@ # - You can enter hostnames or ip Addresses # - A hostname/ip can be a member of multiple groups # -# In the /etc/ansible/hosts file u have to enter [cnos_command_sample] tag +# In the /etc/ansible/hosts file u have to enter [cnos_config_sample] tag # Following you should specify IP Addresses details # Please change and with appropriate value for your switch. diff --git a/test/integration/targets/cnos_config/tests/cli/backup.yaml b/test/integration/targets/cnos_config/tests/cli/backup.yaml index 3f385311fd..2f1673b699 100644 --- a/test/integration/targets/cnos_config/tests/cli/backup.yaml +++ b/test/integration/targets/cnos_config/tests/cli/backup.yaml @@ -5,7 +5,6 @@ cnos_config: commands: - no vlan 13 - provider: "{{ cli }}" ignore_errors: yes - name: collect any backup files @@ -25,12 +24,11 @@ cnos_config: src: roles/cnos_config/templates/basic/config.j2 backup: yes - provider: "{{ cli }}" register: result - assert: that: - - "result.changed == false" + - "result.changed == true" - name: collect any backup files find: @@ -47,6 +45,5 @@ cnos_config: commands: - no vlan 13 - provider: "{{ cli }}" - debug: msg="END cli/backup.yaml" diff --git a/test/integration/targets/cnos_config/tests/cli/basic.yaml b/test/integration/targets/cnos_config/tests/cli/basic.yaml index 61773d2dcb..21a4d2c35a 100644 --- a/test/integration/targets/cnos_config/tests/cli/basic.yaml +++ b/test/integration/targets/cnos_config/tests/cli/basic.yaml @@ -5,35 +5,31 @@ cnos_config: commands: - no vlan 13\n - provider: "{{ cli }}" ignore_errors: yes - name: configure device with config cnos_config: src: roles/cnos_config/templates/basic/config.j2 - provider: "{{ cli }}" register: result - assert: that: - - "result.changed == false" + - "result.changed == true" - "result.updates is not defined" - name: check device with config cnos_config: src: roles/cnos_config/templates/basic/config.j2 - provider: "{{ cli }}" register: result - assert: that: - - "result.changed == false" + - "result.changed == true" - "result.updates is not defined" - name: teardown cnos_config: commands: - no vlan 13\n - provider: "{{ cli }}" - debug: msg="END cli/basic.yaml" diff --git a/test/integration/targets/cnos_config/tests/cli/defaults.yaml b/test/integration/targets/cnos_config/tests/cli/defaults.yaml index 3bea4e0c77..f557cd65e4 100644 --- a/test/integration/targets/cnos_config/tests/cli/defaults.yaml +++ b/test/integration/targets/cnos_config/tests/cli/defaults.yaml @@ -5,7 +5,6 @@ cnos_config: commands: - no vlan 13\n - provider: "{{ cli }}" ignore_errors: yes become: True become_method: enable @@ -13,7 +12,6 @@ - name: configure device with defaults included cnos_config: src: roles/cnos_config/templates/defaults/config.j2 - provider: "{{ cli }}" register: result become: True become_method: enable @@ -28,7 +26,6 @@ - name: check device with defaults included Hell cnos_config: src: roles/cnos_config/templates/defaults/config.j2 - provider: "{{ cli }}" register: result - debug: var=result @@ -42,7 +39,6 @@ cnos_config: commands: - no vlan 13\n - provider: "{{ cli }}" become: true become_method: enable ignore_errors: yes diff --git a/test/integration/targets/cnos_config/vars/main.yml b/test/integration/targets/cnos_config/vars/main.yml deleted file mode 100644 index d0fcdabf53..0000000000 --- a/test/integration/targets/cnos_config/vars/main.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- -cli: - host: "{{ inventory_hostname }}" - port: 22 - username: admin - password: admin - timeout: 60 - context: ansible - auth_pass: diff --git a/test/integration/targets/cnos_facts/tests/cli/default_facts.yaml b/test/integration/targets/cnos_facts/tests/cli/default_facts.yaml index e0fd6e3d8f..2b050f1b97 100644 --- a/test/integration/targets/cnos_facts/tests/cli/default_facts.yaml +++ b/test/integration/targets/cnos_facts/tests/cli/default_facts.yaml @@ -15,16 +15,11 @@ - "'hardware' in result.ansible_facts.ansible_net_gather_subset" - "'default' in result.ansible_facts.ansible_net_gather_subset" - "'interfaces' in result.ansible_facts.ansible_net_gather_subset" - #- "result.ansible_facts.ansible_net_filesystems is defined" - # ... and not present - "'config' not in result.ansible_facts.ansible_net_gather_subset" # Items from those subsets are present - #- "result.ansible_facts.ansible_net_filesystems is defined" #hw - "result.ansible_facts.ansible_net_memtotal_mb > 10" #hw - "result.ansible_facts.ansible_net_interfaces | length > 1" # more than one interface returned - - # ... and not present - "result.ansible_facts.ansible_net_config is not defined" # config - debug: msg="END cli/default.yaml" diff --git a/test/integration/targets/cnos_facts/vars/main.yml b/test/integration/targets/cnos_facts/vars/main.yml deleted file mode 100644 index aa25153ec8..0000000000 --- a/test/integration/targets/cnos_facts/vars/main.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- -cli: - host: "{{ inventory_hostname }}" - port: 22 - username: admin - password: admin - timeout: 30 - authorize: True - auth_pass: