mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-28 13:21:25 -07:00
EdgeOS module improvements (#39530)
* Update docs and use to_text on strings * Add warning to use network_cli
This commit is contained in:
parent
e8d02a3a0f
commit
d5dbd8c76d
4 changed files with 22 additions and 10 deletions
|
@ -25,6 +25,9 @@ description:
|
||||||
use a custom pager that can cause this module to hang. If the
|
use a custom pager that can cause this module to hang. If the
|
||||||
value of the environment variable C(ANSIBLE_EDGEOS_TERMINAL_LENGTH)
|
value of the environment variable C(ANSIBLE_EDGEOS_TERMINAL_LENGTH)
|
||||||
is not set, the default number of 10000 is used.
|
is not set, the default number of 10000 is used.
|
||||||
|
- "This is a network module and requires C(connection: network_cli)
|
||||||
|
in order to work properly."
|
||||||
|
- For more information please see the L(Network Guide,../network/getting_started/index.html).
|
||||||
options:
|
options:
|
||||||
commands:
|
commands:
|
||||||
description:
|
description:
|
||||||
|
@ -95,9 +98,10 @@ stdout_lines:
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from ansible.module_utils._text import to_text
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.network.common.utils import ComplexList
|
|
||||||
from ansible.module_utils.network.common.parsing import Conditional
|
from ansible.module_utils.network.common.parsing import Conditional
|
||||||
|
from ansible.module_utils.network.common.utils import ComplexList
|
||||||
from ansible.module_utils.network.edgeos.edgeos import run_commands
|
from ansible.module_utils.network.edgeos.edgeos import run_commands
|
||||||
from ansible.module_utils.six import string_types
|
from ansible.module_utils.six import string_types
|
||||||
|
|
||||||
|
@ -105,7 +109,7 @@ from ansible.module_utils.six import string_types
|
||||||
def to_lines(stdout):
|
def to_lines(stdout):
|
||||||
for item in stdout:
|
for item in stdout:
|
||||||
if isinstance(item, string_types):
|
if isinstance(item, string_types):
|
||||||
item = str(item).split('\n')
|
item = to_text(item).split('\n')
|
||||||
yield item
|
yield item
|
||||||
|
|
||||||
|
|
||||||
|
@ -149,7 +153,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
conditionals = [Conditional(c) for c in wait_for]
|
conditionals = [Conditional(c) for c in wait_for]
|
||||||
except AttributeError as e:
|
except AttributeError as e:
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=to_text(e))
|
||||||
|
|
||||||
retries = module.params['retries']
|
retries = module.params['retries']
|
||||||
interval = module.params['interval']
|
interval = module.params['interval']
|
||||||
|
|
|
@ -25,6 +25,9 @@ description:
|
||||||
configuration file and state of the active configuration. All
|
configuration file and state of the active configuration. All
|
||||||
configuration statements are based on `set` and `delete` commands
|
configuration statements are based on `set` and `delete` commands
|
||||||
in the device configuration.
|
in the device configuration.
|
||||||
|
- "This is a network module and requires the C(connection: network_cli) in order
|
||||||
|
to work properly."
|
||||||
|
- For more information please see the L(Network Guide,../network/getting_started/index.html).
|
||||||
notes:
|
notes:
|
||||||
- Tested against EdgeOS 1.9.7
|
- Tested against EdgeOS 1.9.7
|
||||||
- Setting C(ANSIBLE_PERSISTENT_COMMAND_TIMEOUT) to 30 is recommended since
|
- Setting C(ANSIBLE_PERSISTENT_COMMAND_TIMEOUT) to 30 is recommended since
|
||||||
|
@ -54,10 +57,12 @@ options:
|
||||||
choices: ['line', 'none']
|
choices: ['line', 'none']
|
||||||
backup:
|
backup:
|
||||||
description:
|
description:
|
||||||
- The C(backup) argument will backup the current devices active
|
- The C(backup) argument will backup the current device's active
|
||||||
configuration to the Ansible control host prior to making any
|
configuration to the Ansible control host prior to making any
|
||||||
changes. The backup file will be located in the backup folder
|
changes. The backup file will be located in the backup folder
|
||||||
in the root of the playbook
|
in the playbook root directory or role root directory if the
|
||||||
|
playbook is part of an ansible role. If the directory does not
|
||||||
|
exist, it is created.
|
||||||
type: bool
|
type: bool
|
||||||
default: 'no'
|
default: 'no'
|
||||||
comment:
|
comment:
|
||||||
|
@ -116,10 +121,12 @@ backup_path:
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from ansible.module_utils._text import to_native
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.network.common.config import NetworkConfig
|
from ansible.module_utils.network.common.config import NetworkConfig
|
||||||
from ansible.module_utils.network.edgeos.edgeos import load_config, get_config, run_commands
|
from ansible.module_utils.network.edgeos.edgeos import load_config, get_config, run_commands
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_COMMENT = 'configured by edgeos_config'
|
DEFAULT_COMMENT = 'configured by edgeos_config'
|
||||||
|
|
||||||
CONFIG_FILTERS = [
|
CONFIG_FILTERS = [
|
||||||
|
@ -144,7 +151,7 @@ def config_to_commands(config):
|
||||||
commands = ['set %s' % cmd.replace(' {', '') for cmd in commands]
|
commands = ['set %s' % cmd.replace(' {', '') for cmd in commands]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
commands = str(candidate).split('\n')
|
commands = to_native(candidate).split('\n')
|
||||||
|
|
||||||
return commands
|
return commands
|
||||||
|
|
||||||
|
@ -159,13 +166,13 @@ def get_candidate(module):
|
||||||
|
|
||||||
|
|
||||||
def diff_config(commands, config):
|
def diff_config(commands, config):
|
||||||
config = [str(c).replace("'", '') for c in config.splitlines()]
|
config = [to_native(c).replace("'", '') for c in config.splitlines()]
|
||||||
|
|
||||||
updates = list()
|
updates = list()
|
||||||
visited = set()
|
visited = set()
|
||||||
|
|
||||||
for line in commands:
|
for line in commands:
|
||||||
item = str(line).replace("'", '')
|
item = to_native(line).replace("'", '')
|
||||||
|
|
||||||
if not item.startswith('set') and not item.startswith('delete'):
|
if not item.startswith('set') and not item.startswith('delete'):
|
||||||
raise ValueError('line must start with either `set` or `delete`')
|
raise ValueError('line must start with either `set` or `delete`')
|
||||||
|
|
|
@ -35,6 +35,8 @@ PRIVATE_KEYS_RE = re.compile('__.+__')
|
||||||
class ActionModule(_ActionModule):
|
class ActionModule(_ActionModule):
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
def run(self, tmp=None, task_vars=None):
|
||||||
|
if self._play_context.connection != 'network_cli':
|
||||||
|
return {'failed': True, 'msg': 'Connection type %s is not valid for this module. Must use network_cli.' % self._play_context.connection}
|
||||||
|
|
||||||
if self._task.args.get('src'):
|
if self._task.args.get('src'):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# Copyright: (c) 2018, Ansible Project
|
# Copyright: (c) 2018, Ansible Project
|
||||||
# GNU General Public License v3.0+
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import (absolute_import, division, print_function)
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue