Removing provider from facts, command and config (#54623)
This commit is contained in:
parent
4b3662605d
commit
c2958df3a4
18 changed files with 13 additions and 243 deletions
|
@ -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}
|
||||
|
||||
|
|
|
@ -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')]
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
- display interface brief
|
||||
wait_for:
|
||||
- result[0] contains 'Description: Foo'
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
ignore_errors: yes
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
wait_for:
|
||||
- "result[0] contains 'Lenovo'"
|
||||
- "result[1] contains 'Mem:'"
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
- display version
|
||||
wait_for:
|
||||
- "result[0] contains bad_value_string"
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
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.
|
||||
|
||||
|
||||
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
|
||||
---
|
||||
<add dependencies information below>
|
||||
|
|
|
@ -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 <username> and <password> with appropriate value for your switch.
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
- "'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"
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
---
|
||||
cli:
|
||||
host: "{{ inventory_hostname }}"
|
||||
port: 22
|
||||
username: admin
|
||||
password: admin
|
||||
timeout: 30
|
||||
authorize: True
|
||||
auth_pass:
|
Loading…
Reference in a new issue