Removing provider from facts, command and config (#54623)

pull/54941/head
Anil Kumar Muraleedharan 6 years ago committed by Nathaniel Case
parent 4b3662605d
commit c2958df3a4

@ -37,54 +37,14 @@ description:
argument that will cause the module to wait for a specific condition argument that will cause the module to wait for a specific condition
before returning or timing out if the condition is not met. before returning or timing out if the condition is not met.
options: 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: commands:
version_added: "2.6" version_added: "2.6"
description: description:
- List of commands to send to the remote device over the - List of commands to send to the remote device.
configured provider. The resulting output from the command The resulting output from the command is returned.
is returned. If the I(wait_for) argument is provided, the If the I(wait_for) argument is provided, the module is not
module is not returned until the condition is satisfied or returned until the condition is satisfied or the number of
the number of retires as expired. retires is expired.
required: true required: true
wait_for: wait_for:
version_added: "2.6" version_added: "2.6"
@ -124,17 +84,6 @@ options:
""" """
EXAMPLES = """ 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 - name: test contains operator
cnos_command: cnos_command:
@ -144,7 +93,6 @@ vars:
wait_for: wait_for:
- "result[0] contains 'Lenovo'" - "result[0] contains 'Lenovo'"
- "result[1] contains 'MemFree'" - "result[1] contains 'MemFree'"
provider: "{{ cli }}"
register: result register: result
- assert: - assert:
@ -155,7 +103,6 @@ vars:
- name: get output for single command - name: get output for single command
cnos_command: cnos_command:
commands: ['show version'] commands: ['show version']
provider: "{{ cli }}"
register: result register: result
- assert: - assert:
@ -168,7 +115,6 @@ vars:
commands: commands:
- show version - show version
- show interface information - show interface information
provider: "{{ cli }}"
register: result register: result
- assert: - assert:
@ -200,7 +146,6 @@ import time
from ansible.module_utils.basic import AnsibleModule 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 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.network.common.parsing import Conditional
from ansible.module_utils.six import string_types from ansible.module_utils.six import string_types
@ -224,8 +169,6 @@ def main():
interval=dict(default=1, type='int') interval=dict(default=1, type='int')
) )
spec.update(cnos_argument_spec)
module = AnsibleModule(argument_spec=spec, supports_check_mode=True) module = AnsibleModule(argument_spec=spec, supports_check_mode=True)
result = {'changed': False} result = {'changed': False}

@ -37,48 +37,8 @@ description:
an implementation for working with CNOS configuration sections in an implementation for working with CNOS configuration sections in
a deterministic way. a deterministic way.
notes: notes:
- Tested against CNOS 10.8.1 - Tested against CNOS 10.9.1
options: 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: lines:
description: description:
- The ordered set of commands that should be configured in the - 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.basic import AnsibleModule
from ansible.module_utils.network.cnos.cnos import load_config, get_config 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.cnos.cnos import check_args
from ansible.module_utils.network.common.config import NetworkConfig, dumps from ansible.module_utils.network.common.config import NetworkConfig, dumps
@ -320,8 +279,6 @@ def main():
admin=dict(type='bool', default=False) admin=dict(type='bool', default=False)
) )
argument_spec.update(cnos_argument_spec)
mutually_exclusive = [('lines', 'src'), mutually_exclusive = [('lines', 'src'),
('parents', 'src')] ('parents', 'src')]

@ -1,8 +1,8 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# (C) 2017 Red Hat Inc. # (C) 2019 Red Hat Inc.
# Copyright (C) 2017 Lenovo. # Copyright (C) 2019 Lenovo.
# #
# GNU General Public License v3.0+ # GNU General Public License v3.0+
# #
@ -55,50 +55,6 @@ options:
on the remote device. If I(authorize) is false, then this argument 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 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. 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: gather_subset:
version_added: "2.6" version_added: "2.6"
description: description:
@ -116,36 +72,21 @@ Tasks: The following are examples of using the module cnos_facts.
--- ---
- name: Test cnos Facts - name: Test cnos Facts
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 # Collect all facts from the device
- cnos_facts: - cnos_facts:
gather_subset: all gather_subset: all
provider: "{{ cli }}"
# Collect only the config and default facts # Collect only the config and default facts
- cnos_facts: - cnos_facts:
gather_subset: gather_subset:
- config - config
provider: "{{ cli }}"
# Do not collect hardware facts # Do not collect hardware facts
- cnos_facts: - cnos_facts:
gather_subset: gather_subset:
- "!hardware" - "!hardware"
provider: "{{ cli }}"
''' '''
RETURN = ''' RETURN = '''
ansible_net_gather_subset: ansible_net_gather_subset:
@ -207,7 +148,6 @@ RETURN = '''
import re import re
from ansible.module_utils.network.cnos.cnos import run_commands 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.network.cnos.cnos import check_args
from ansible.module_utils._text import to_text from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
@ -452,10 +392,6 @@ class Interfaces(FactsBase):
if match: if match:
key = match.group(1) key = match.group(1)
parsed.append(line) parsed.append(line)
# match = re.match(r'^(loopback+)', line)
# if match:
# key = match.group(1)
# parsed.append(line)
return parsed return parsed
def set_ip_interfaces(self, line4): def set_ip_interfaces(self, line4):
@ -545,8 +481,6 @@ def main():
gather_subset=dict(default=['!config'], type='list') gather_subset=dict(default=['!config'], type='list')
) )
argument_spec.update(cnos_argument_spec)
module = AnsibleModule(argument_spec=argument_spec, module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True) supports_check_mode=True)

@ -34,7 +34,7 @@ These are the various options the customer have in executing the cnos_command mo
Variable | Description 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. `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. `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. `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.

@ -8,7 +8,6 @@
- display interface brief - display interface brief
wait_for: wait_for:
- result[0] contains 'Description: Foo' - result[0] contains 'Description: Foo'
provider: "{{ cli }}"
register: result register: result
ignore_errors: yes ignore_errors: yes

@ -9,7 +9,6 @@
wait_for: wait_for:
- "result[0] contains 'Lenovo'" - "result[0] contains 'Lenovo'"
- "result[1] contains 'Mem:'" - "result[1] contains 'Mem:'"
provider: "{{ cli }}"
register: result register: result
- assert: - assert:

@ -4,7 +4,6 @@
- name: run invalid command - name: run invalid command
cnos_command: cnos_command:
commands: ['display foo'] commands: ['display foo']
provider: "{{ cli }}"
register: result register: result
ignore_errors: yes ignore_errors: yes
@ -17,7 +16,6 @@
commands: commands:
- display version - display version
- display foo - display foo
provider: "{{ cli }}"
register: result register: result
ignore_errors: yes ignore_errors: yes

@ -4,7 +4,6 @@
- name: get output for single command - name: get output for single command
cnos_command: cnos_command:
commands: ['display version'] commands: ['display version']
provider: "{{ cli }}"
register: result register: result
- assert: - assert:
@ -17,7 +16,6 @@
commands: commands:
- display version - display version
- display interface brief - display interface brief
provider: "{{ cli }}"
register: result register: result
- assert: - assert:

@ -7,7 +7,6 @@
- display version - display version
wait_for: wait_for:
- "result[0] contains bad_value_string" - "result[0] contains bad_value_string"
provider: "{{ cli }}"
register: result register: result
ignore_errors: yes ignore_errors: yes

@ -1,10 +0,0 @@
---
cli:
host: "{{ inventory_hostname }}"
port: 22
username: admin
password: admin
# transport: cli
timeout: 30
authorize: True
auth_pass:

@ -47,19 +47,6 @@ Variable | Description
`admin` | Enters into administration configuration mode for making config changes to the device. `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 ## Dependencies
--- ---
<add dependencies information below> <add dependencies information below>

@ -6,7 +6,7 @@
# - You can enter hostnames or ip Addresses # - You can enter hostnames or ip Addresses
# - A hostname/ip can be a member of multiple groups # - 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 # Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch. # Please change <username> and <password> with appropriate value for your switch.

@ -5,7 +5,6 @@
cnos_config: cnos_config:
commands: commands:
- no vlan 13 - no vlan 13
provider: "{{ cli }}"
ignore_errors: yes ignore_errors: yes
- name: collect any backup files - name: collect any backup files
@ -25,12 +24,11 @@
cnos_config: cnos_config:
src: roles/cnos_config/templates/basic/config.j2 src: roles/cnos_config/templates/basic/config.j2
backup: yes backup: yes
provider: "{{ cli }}"
register: result register: result
- assert: - assert:
that: that:
- "result.changed == false" - "result.changed == true"
- name: collect any backup files - name: collect any backup files
find: find:
@ -47,6 +45,5 @@
cnos_config: cnos_config:
commands: commands:
- no vlan 13 - no vlan 13
provider: "{{ cli }}"
- debug: msg="END cli/backup.yaml" - debug: msg="END cli/backup.yaml"

@ -5,35 +5,31 @@
cnos_config: cnos_config:
commands: commands:
- no vlan 13\n - no vlan 13\n
provider: "{{ cli }}"
ignore_errors: yes ignore_errors: yes
- name: configure device with config - name: configure device with config
cnos_config: cnos_config:
src: roles/cnos_config/templates/basic/config.j2 src: roles/cnos_config/templates/basic/config.j2
provider: "{{ cli }}"
register: result register: result
- assert: - assert:
that: that:
- "result.changed == false" - "result.changed == true"
- "result.updates is not defined" - "result.updates is not defined"
- name: check device with config - name: check device with config
cnos_config: cnos_config:
src: roles/cnos_config/templates/basic/config.j2 src: roles/cnos_config/templates/basic/config.j2
provider: "{{ cli }}"
register: result register: result
- assert: - assert:
that: that:
- "result.changed == false" - "result.changed == true"
- "result.updates is not defined" - "result.updates is not defined"
- name: teardown - name: teardown
cnos_config: cnos_config:
commands: commands:
- no vlan 13\n - no vlan 13\n
provider: "{{ cli }}"
- debug: msg="END cli/basic.yaml" - debug: msg="END cli/basic.yaml"

@ -5,7 +5,6 @@
cnos_config: cnos_config:
commands: commands:
- no vlan 13\n - no vlan 13\n
provider: "{{ cli }}"
ignore_errors: yes ignore_errors: yes
become: True become: True
become_method: enable become_method: enable
@ -13,7 +12,6 @@
- name: configure device with defaults included - name: configure device with defaults included
cnos_config: cnos_config:
src: roles/cnos_config/templates/defaults/config.j2 src: roles/cnos_config/templates/defaults/config.j2
provider: "{{ cli }}"
register: result register: result
become: True become: True
become_method: enable become_method: enable
@ -28,7 +26,6 @@
- name: check device with defaults included Hell - name: check device with defaults included Hell
cnos_config: cnos_config:
src: roles/cnos_config/templates/defaults/config.j2 src: roles/cnos_config/templates/defaults/config.j2
provider: "{{ cli }}"
register: result register: result
- debug: var=result - debug: var=result
@ -42,7 +39,6 @@
cnos_config: cnos_config:
commands: commands:
- no vlan 13\n - no vlan 13\n
provider: "{{ cli }}"
become: true become: true
become_method: enable become_method: enable
ignore_errors: yes ignore_errors: yes

@ -1,9 +0,0 @@
---
cli:
host: "{{ inventory_hostname }}"
port: 22
username: admin
password: admin
timeout: 60
context: ansible
auth_pass:

@ -15,16 +15,11 @@
- "'hardware' in result.ansible_facts.ansible_net_gather_subset" - "'hardware' in result.ansible_facts.ansible_net_gather_subset"
- "'default' 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" - "'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" - "'config' not in result.ansible_facts.ansible_net_gather_subset"
# Items from those subsets are present # 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_memtotal_mb > 10" #hw
- "result.ansible_facts.ansible_net_interfaces | length > 1" # more than one interface returned - "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 - "result.ansible_facts.ansible_net_config is not defined" # config
- debug: msg="END cli/default.yaml" - debug: msg="END cli/default.yaml"

@ -1,9 +0,0 @@
---
cli:
host: "{{ inventory_hostname }}"
port: 22
username: admin
password: admin
timeout: 30
authorize: True
auth_pass:
Loading…
Cancel
Save