mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 05:10:22 -07:00
Initial commit
This commit is contained in:
commit
aebc1b03fd
4861 changed files with 812621 additions and 0 deletions
0
plugins/terminal/__init__.py
Normal file
0
plugins/terminal/__init__.py
Normal file
59
plugins/terminal/aireos.py
Normal file
59
plugins/terminal/aireos.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
#
|
||||
# (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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
import re
|
||||
import time
|
||||
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
from ansible.plugins.terminal import TerminalBase
|
||||
|
||||
|
||||
class TerminalModule(TerminalBase):
|
||||
|
||||
terminal_stdout_re = [
|
||||
re.compile(br"[\r\n]?[\w]*\(.+\)?[>#\$](?:\s*)$"),
|
||||
re.compile(br"User:")
|
||||
]
|
||||
|
||||
terminal_stderr_re = [
|
||||
re.compile(br"% ?Error"),
|
||||
re.compile(br"% ?Bad secret"),
|
||||
re.compile(br"invalid input", re.I),
|
||||
re.compile(br"incorrect usage", re.I),
|
||||
re.compile(br"(?:incomplete|ambiguous) command", re.I),
|
||||
re.compile(br"connection timed out", re.I),
|
||||
re.compile(br"[^\r\n]+ not found", re.I),
|
||||
re.compile(br"'[^']' +returned error code: ?\d+"),
|
||||
]
|
||||
|
||||
def on_open_shell(self):
|
||||
try:
|
||||
commands = ('{"command": "' + self._connection._play_context.remote_user + '", "prompt": "Password:", "answer": "' +
|
||||
self._connection._play_context.password + '"}',
|
||||
'{"command": "config paging disable"}')
|
||||
for cmd in commands:
|
||||
self._exec_cli_command(cmd)
|
||||
except AnsibleConnectionFailure:
|
||||
try:
|
||||
self._exec_cli_command(b'config paging disable')
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to set terminal parameters')
|
35
plugins/terminal/apconos.py
Normal file
35
plugins/terminal/apconos.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
# (C) 2017 Red Hat Inc.
|
||||
# Copyright (C) 2019 APCON.
|
||||
#
|
||||
# GNU General Public License v3.0+
|
||||
#
|
||||
# This program 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.
|
||||
#
|
||||
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
#
|
||||
# Contains terminal Plugin methods for apconos Config Module
|
||||
# Apcon Networking
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
import re
|
||||
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
from ansible.module_utils._text import to_text, to_bytes
|
||||
from ansible.plugins.terminal import TerminalBase
|
||||
|
||||
|
||||
class TerminalModule(TerminalBase):
|
||||
|
||||
terminal_stdout_re = [
|
||||
re.compile(br'>>\ |#\ |\$\ ')
|
||||
]
|
||||
|
||||
terminal_stderr_re = [
|
||||
re.compile(br"connection timed out", re.I),
|
||||
]
|
68
plugins/terminal/aruba.py
Normal file
68
plugins/terminal/aruba.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
#
|
||||
# (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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
import re
|
||||
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
from ansible.module_utils._text import to_text, to_bytes
|
||||
from ansible.plugins.terminal import TerminalBase
|
||||
|
||||
|
||||
class TerminalModule(TerminalBase):
|
||||
|
||||
ansi_re = [
|
||||
# check ECMA-48 Section 5.4 (Control Sequences)
|
||||
re.compile(br'(\x1b\[\?1h\x1b=)'),
|
||||
re.compile(br'((?:\x9b|\x1b\x5b)[\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e])'),
|
||||
re.compile(br'\x08.')
|
||||
]
|
||||
|
||||
terminal_stdout_re = [
|
||||
re.compile(br"[\r\n]?[\w]*\(.+\)\s*[\^\*]?(?:\[.+\])? ?#(?:\s*)$"),
|
||||
re.compile(br"[pP]assword:$"),
|
||||
re.compile(br"(?<=\s)[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?\s*#\s*$"),
|
||||
re.compile(br"[\r\n]?[\w\+\-\.:\/\[\]]+(?:\([^\)]+\)){0,3}(?:[>#]) ?$"),
|
||||
]
|
||||
|
||||
terminal_stderr_re = [
|
||||
re.compile(br"% ?Error"),
|
||||
re.compile(br"Error:", re.M),
|
||||
re.compile(br"^% \w+", re.M),
|
||||
re.compile(br"% ?Bad secret"),
|
||||
re.compile(br"invalid input", re.I),
|
||||
re.compile(br"(?:incomplete|ambiguous) command", re.I),
|
||||
re.compile(br"connection timed out", re.I),
|
||||
re.compile(br"[^\r\n]+ not found", re.I),
|
||||
re.compile(br"'[^']' +returned error code: ?\d+"),
|
||||
]
|
||||
|
||||
terminal_initial_prompt = b'Press any key to continue'
|
||||
|
||||
terminal_initial_answer = b'\r'
|
||||
|
||||
terminal_inital_prompt_newline = False
|
||||
|
||||
def on_open_shell(self):
|
||||
try:
|
||||
self._exec_cli_command(b'no pag')
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to set terminal parameters')
|
60
plugins/terminal/ce.py
Normal file
60
plugins/terminal/ce.py
Normal file
|
@ -0,0 +1,60 @@
|
|||
#
|
||||
# (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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import re
|
||||
|
||||
from ansible.plugins.terminal import TerminalBase
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
|
||||
|
||||
class TerminalModule(TerminalBase):
|
||||
|
||||
terminal_stdout_re = [
|
||||
re.compile(br'[\r\n]?<.+>(?:\s*)$'),
|
||||
re.compile(br'[\r\n]?\[.+\](?:\s*)$'),
|
||||
]
|
||||
#: terminal initial prompt
|
||||
#: The password needs to be changed. Change now? [Y/N]:
|
||||
terminal_initial_prompt = br'Change\s*now\s*\?\s*\[Y\/N\]\s*:'
|
||||
|
||||
#: terminal initial answer
|
||||
#: do not change password when it is asked to change with initial connection.
|
||||
terminal_initial_answer = b'N'
|
||||
terminal_stderr_re = [
|
||||
re.compile(br"% ?Error: "),
|
||||
re.compile(br"^% \w+", re.M),
|
||||
re.compile(br"% ?Bad secret"),
|
||||
re.compile(br"invalid input", re.I),
|
||||
re.compile(br"(?:incomplete|ambiguous) command", re.I),
|
||||
re.compile(br"connection timed out", re.I),
|
||||
re.compile(br"[^\r\n]+ not found", re.I),
|
||||
re.compile(br"'[^']' +returned error code: ?\d+"),
|
||||
re.compile(br"syntax error"),
|
||||
re.compile(br"unknown command"),
|
||||
re.compile(br"Error\[\d+\]: ", re.I),
|
||||
re.compile(br"Error:", re.I)
|
||||
]
|
||||
|
||||
def on_open_shell(self):
|
||||
try:
|
||||
self._exec_cli_command('screen-length 0 temporary')
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to set terminal parameters')
|
83
plugins/terminal/cnos.py
Normal file
83
plugins/terminal/cnos.py
Normal file
|
@ -0,0 +1,83 @@
|
|||
# (C) 2017 Red Hat Inc.
|
||||
# Copyright (C) 2017 Lenovo.
|
||||
#
|
||||
# GNU General Public License v3.0+
|
||||
#
|
||||
# This program 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.
|
||||
#
|
||||
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
#
|
||||
# Contains terminal Plugin methods for CNOS Config Module
|
||||
# Lenovo Networking
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
import re
|
||||
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
from ansible.module_utils._text import to_text, to_bytes
|
||||
from ansible.plugins.terminal import TerminalBase
|
||||
|
||||
|
||||
class TerminalModule(TerminalBase):
|
||||
|
||||
terminal_stdout_re = [
|
||||
re.compile(br"[\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#) ?$"),
|
||||
re.compile(br"\[\w+\@[\w\-\.]+(?: [^\]])\] ?[>#\$] ?$"),
|
||||
re.compile(br">[\r\n]?")
|
||||
]
|
||||
|
||||
terminal_stderr_re = [
|
||||
re.compile(br"% ?Error"),
|
||||
re.compile(br"% ?Bad secret"),
|
||||
re.compile(br"invalid input", re.I),
|
||||
re.compile(br"(?:incomplete|ambiguous) command", re.I),
|
||||
re.compile(br"connection timed out", re.I),
|
||||
re.compile(br"[^\r\n]+ not found"),
|
||||
re.compile(br"'[^']' +returned error code: ?\d+"),
|
||||
]
|
||||
|
||||
def on_open_shell(self):
|
||||
try:
|
||||
for cmd in (b'\n', b'terminal length 0\n'):
|
||||
self._exec_cli_command(cmd)
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to set terminal parameters')
|
||||
|
||||
def on_become(self, passwd=None):
|
||||
if self._get_prompt().endswith(b'#'):
|
||||
return
|
||||
|
||||
cmd = {u'command': u'enable'}
|
||||
if passwd:
|
||||
# Note: python-3.5 cannot combine u"" and r"" together. Thus make
|
||||
# an r string and use to_text to ensure it's text
|
||||
# on both py2 and py3.
|
||||
cmd[u'prompt'] = to_text(r"[\r\n]?password: $",
|
||||
errors='surrogate_or_strict')
|
||||
cmd[u'answer'] = passwd
|
||||
|
||||
try:
|
||||
self._exec_cli_command(to_bytes(json.dumps(cmd),
|
||||
errors='surrogate_or_strict'))
|
||||
except AnsibleConnectionFailure:
|
||||
msg = 'unable to elevate privilege to enable mode'
|
||||
raise AnsibleConnectionFailure(msg)
|
||||
|
||||
def on_unbecome(self):
|
||||
prompt = self._get_prompt()
|
||||
if prompt is None:
|
||||
# if prompt is None most likely the terminal is hung up at a prompt
|
||||
return
|
||||
|
||||
if b'(config' in prompt:
|
||||
self._exec_cli_command(b'end')
|
||||
self._exec_cli_command(b'disable')
|
||||
|
||||
elif prompt.endswith(b'#'):
|
||||
self._exec_cli_command(b'disable')
|
35
plugins/terminal/edgeos.py
Normal file
35
plugins/terminal/edgeos.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
# Copyright: (c) 2018, 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)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
from ansible.plugins.terminal import TerminalBase
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
|
||||
|
||||
class TerminalModule(TerminalBase):
|
||||
|
||||
terminal_stdout_re = [
|
||||
re.compile(br"[\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#) ?$"),
|
||||
re.compile(br"\@[\w\-\.]+:\S+?[>#\$] ?$")
|
||||
]
|
||||
|
||||
terminal_stderr_re = [
|
||||
re.compile(br"\n\s*command not found"),
|
||||
re.compile(br"\nInvalid command"),
|
||||
re.compile(br"\nCommit failed"),
|
||||
re.compile(br"\n\s*Set failed"),
|
||||
]
|
||||
|
||||
terminal_length = os.getenv('ANSIBLE_EDGEOS_TERMINAL_LENGTH', 10000)
|
||||
|
||||
def on_open_shell(self):
|
||||
try:
|
||||
self._exec_cli_command('export VYATTA_PAGER=cat')
|
||||
self._exec_cli_command('stty rows %s' % self.terminal_length)
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to set terminal parameters')
|
87
plugins/terminal/edgeswitch.py
Normal file
87
plugins/terminal/edgeswitch.py
Normal file
|
@ -0,0 +1,87 @@
|
|||
#
|
||||
# (c) 2018 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
import re
|
||||
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
from ansible.module_utils._text import to_text, to_bytes
|
||||
from ansible.plugins.terminal import TerminalBase
|
||||
|
||||
|
||||
class TerminalModule(TerminalBase):
|
||||
|
||||
terminal_stdout_re = [
|
||||
re.compile(br"\(([^\(\)]+)\) [>#]$"),
|
||||
re.compile(br"\(([^\(\)]+)\) \(([^\(\)]+)\)#$")
|
||||
]
|
||||
|
||||
terminal_stderr_re = [
|
||||
re.compile(br"% ?Error"),
|
||||
re.compile(br"% ?Bad secret"),
|
||||
re.compile(br"invalid input", re.I),
|
||||
re.compile(br"(?:incomplete|ambiguous) command", re.I),
|
||||
re.compile(br"connection timed out", re.I),
|
||||
re.compile(br"[^\r\n]+ not found"),
|
||||
re.compile(br"'[^']' +returned error code: ?\d+"),
|
||||
re.compile(br"An invalid")
|
||||
]
|
||||
|
||||
def on_open_shell(self):
|
||||
return
|
||||
|
||||
def on_become(self, passwd=None):
|
||||
prompt = self._get_prompt()
|
||||
if prompt and prompt.endswith(b'#'):
|
||||
return
|
||||
|
||||
cmd = {u'command': u'enable'}
|
||||
if passwd:
|
||||
cmd[u'prompt'] = to_text(r"[\r\n]?[Pp]assword: ?$", errors='surrogate_or_strict')
|
||||
cmd[u'answer'] = passwd
|
||||
try:
|
||||
self._exec_cli_command(to_bytes(json.dumps(cmd), errors='surrogate_or_strict'))
|
||||
prompt = self._get_prompt()
|
||||
if prompt is None or not prompt.endswith(b'#'):
|
||||
raise AnsibleConnectionFailure('failed to elevate privilege to enable mode still at prompt [%s]' % prompt)
|
||||
|
||||
cmd = {u'command': u'terminal length 0'}
|
||||
self._exec_cli_command(to_bytes(json.dumps(cmd), errors='surrogate_or_strict'))
|
||||
prompt = self._get_prompt()
|
||||
if prompt is None or not prompt.endswith(b'#'):
|
||||
raise AnsibleConnectionFailure('failed to setup terminal in enable mode')
|
||||
|
||||
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))
|
||||
|
||||
def on_unbecome(self):
|
||||
prompt = self._get_prompt()
|
||||
if prompt is None:
|
||||
# if prompt is None most likely the terminal is hung up at a prompt
|
||||
return
|
||||
|
||||
if b'(Config' in prompt:
|
||||
self._exec_cli_command(b'end')
|
||||
self._exec_cli_command(b'exit')
|
||||
|
||||
elif prompt.endswith(b'#'):
|
||||
self._exec_cli_command(b'exit')
|
83
plugins/terminal/enos.py
Normal file
83
plugins/terminal/enos.py
Normal file
|
@ -0,0 +1,83 @@
|
|||
# (C) 2017 Red Hat Inc.
|
||||
# Copyright (C) 2017 Lenovo.
|
||||
#
|
||||
# GNU General Public License v3.0+
|
||||
#
|
||||
# This program 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.
|
||||
#
|
||||
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
#
|
||||
# Contains terminal Plugin methods for ENOS Config Module
|
||||
# Lenovo Networking
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
import re
|
||||
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
from ansible.module_utils._text import to_text, to_bytes
|
||||
from ansible.plugins.terminal import TerminalBase
|
||||
|
||||
|
||||
class TerminalModule(TerminalBase):
|
||||
|
||||
terminal_stdout_re = [
|
||||
re.compile(br"[\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#) ?$"),
|
||||
re.compile(br"\[\w+\@[\w\-\.]+(?: [^\]])\] ?[>#\$] ?$"),
|
||||
re.compile(br">[\r\n]?")
|
||||
]
|
||||
|
||||
terminal_stderr_re = [
|
||||
re.compile(br"% ?Error"),
|
||||
re.compile(br"% ?Bad secret"),
|
||||
re.compile(br"invalid input", re.I),
|
||||
re.compile(br"(?:incomplete|ambiguous) command", re.I),
|
||||
re.compile(br"connection timed out", re.I),
|
||||
re.compile(br"[^\r\n]+ not found"),
|
||||
re.compile(br"'[^']' +returned error code: ?\d+"),
|
||||
]
|
||||
|
||||
def on_open_shell(self):
|
||||
try:
|
||||
for cmd in (b'\n', b'terminal-length 0\n'):
|
||||
self._exec_cli_command(cmd)
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to set terminal parameters')
|
||||
|
||||
def on_become(self, passwd=None):
|
||||
if self._get_prompt().endswith(b'#'):
|
||||
return
|
||||
|
||||
cmd = {u'command': u'enable'}
|
||||
if passwd:
|
||||
# Note: python-3.5 cannot combine u"" and r"" together. Thus make
|
||||
# an r string and use to_text to ensure it's text
|
||||
# on both py2 and py3.
|
||||
cmd[u'prompt'] = to_text(r"[\r\n]?password: $",
|
||||
errors='surrogate_or_strict')
|
||||
cmd[u'answer'] = passwd
|
||||
|
||||
try:
|
||||
self._exec_cli_command(to_bytes(json.dumps(cmd),
|
||||
errors='surrogate_or_strict'))
|
||||
except AnsibleConnectionFailure:
|
||||
msg = 'unable to elevate privilege to enable mode'
|
||||
raise AnsibleConnectionFailure(msg)
|
||||
|
||||
def on_unbecome(self):
|
||||
prompt = self._get_prompt()
|
||||
if prompt is None:
|
||||
# if prompt is None most likely the terminal is hung up at a prompt
|
||||
return
|
||||
|
||||
if b'(config' in prompt:
|
||||
self._exec_cli_command(b'end')
|
||||
self._exec_cli_command(b'disable')
|
||||
|
||||
elif prompt.endswith(b'#'):
|
||||
self._exec_cli_command(b'disable')
|
59
plugins/terminal/eric_eccli.py
Normal file
59
plugins/terminal/eric_eccli.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
#
|
||||
# Copyright (c) 2019 Ericsson AB.
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
import re
|
||||
|
||||
from ansible import constants as C
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
from ansible.module_utils._text import to_text, to_bytes
|
||||
from ansible.plugins.terminal import TerminalBase
|
||||
from ansible.utils.display import Display
|
||||
from ansible.module_utils.six import PY3
|
||||
|
||||
display = Display()
|
||||
|
||||
|
||||
class TerminalModule(TerminalBase):
|
||||
|
||||
terminal_stdout_re = [
|
||||
re.compile(br"[\r\n]?\[.*\][a-zA-Z0-9_.-]*[>\#] ?$"),
|
||||
re.compile(br"[\r\n]?[a-zA-Z0-9_.-]*(?:\([^\)]+\))(?:[>#]) ?$"),
|
||||
re.compile(br"bash\-\d\.\d(?:[$#]) ?"),
|
||||
re.compile(br"[a-zA-Z0-9_.-]*\@[a-zA-Z0-9_.-]*\[\]\:\/flash\>")
|
||||
]
|
||||
|
||||
terminal_stderr_re = [
|
||||
re.compile(br"[\r\n]+syntax error: .*"),
|
||||
re.compile(br"Aborted: .*"),
|
||||
re.compile(br"[\r\n]+Error: .*"),
|
||||
re.compile(br"[\r\n]+% Error:.*"),
|
||||
re.compile(br"[\r\n]+% Invalid input.*"),
|
||||
re.compile(br"[\r\n]+% Incomplete command:.*")
|
||||
]
|
||||
|
||||
def on_open_shell(self):
|
||||
|
||||
try:
|
||||
for cmd in (b'screen-length 0', b'screen-width 512'):
|
||||
self._exec_cli_command(cmd)
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to set terminal parameters')
|
59
plugins/terminal/exos.py
Normal file
59
plugins/terminal/exos.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
#
|
||||
# (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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import re
|
||||
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
from ansible.plugins.terminal import TerminalBase
|
||||
|
||||
|
||||
class TerminalModule(TerminalBase):
|
||||
|
||||
terminal_stdout_re = [
|
||||
re.compile(br"[\r\n](?:! )?(?:\* )?(?:\(.*\) )?(?:Slot-\d+ )?(?:VPEX )?\S+\.\d+ (?:[>#]) ?$")
|
||||
]
|
||||
|
||||
terminal_stderr_re = [
|
||||
re.compile(br"% ?Error"),
|
||||
re.compile(br"% ?Bad secret"),
|
||||
re.compile(br"[\r\n%] Bad passwords"),
|
||||
re.compile(br"invalid input", re.I),
|
||||
re.compile(br"(?:incomplete|ambiguous) command", re.I),
|
||||
re.compile(br"connection timed out", re.I),
|
||||
re.compile(br"[^\r\n]+ not found"),
|
||||
re.compile(br"'[^']' +returned error code: ?\d+"),
|
||||
re.compile(br"Bad mask", re.I),
|
||||
re.compile(br"% ?(\S+) ?overlaps with ?(\S+)", re.I),
|
||||
re.compile(br"[%\S] ?Error: ?[\s]+", re.I),
|
||||
re.compile(br"[%\S] ?Informational: ?[\s]+", re.I),
|
||||
re.compile(br"%% Invalid .* at '\^' marker.", re.I),
|
||||
]
|
||||
|
||||
def on_open_shell(self):
|
||||
try:
|
||||
self._exec_cli_command(b'disable clipaging')
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to set terminal parameters')
|
||||
|
||||
try:
|
||||
self._exec_cli_command(b'configure cli columns 256')
|
||||
except AnsibleConnectionFailure:
|
||||
self._connection.queue_message('warning', 'Unable to configure cli columns, command responses may be truncated')
|
81
plugins/terminal/icx.py
Normal file
81
plugins/terminal/icx.py
Normal file
|
@ -0,0 +1,81 @@
|
|||
# Copyright: (c) 2019, 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)
|
||||
__metaclass__ = type
|
||||
|
||||
import re
|
||||
|
||||
from ansible.plugins.terminal import TerminalBase
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
from ansible.module_utils._text import to_text, to_bytes
|
||||
import json
|
||||
|
||||
|
||||
class TerminalModule(TerminalBase):
|
||||
|
||||
terminal_stdout_re = [
|
||||
re.compile(br"[\r\n]?[\w\+\-\.:\/\[\]]+(?:\([^\)]+\)){0,3}(?:[>#]) ?$")
|
||||
]
|
||||
|
||||
terminal_stderr_re = [
|
||||
re.compile(br"% ?Error"),
|
||||
re.compile(br"% ?Bad secret"),
|
||||
re.compile(br"[\r\n%] Bad passwords"),
|
||||
re.compile(br"invalid input", re.I),
|
||||
re.compile(br"(?:incomplete|ambiguous) command", re.I),
|
||||
re.compile(br"connection timed out", re.I),
|
||||
re.compile(br"[^\r\n]+ not found"),
|
||||
re.compile(br"'[^']' +returned error code: ?\d+"),
|
||||
re.compile(br"Bad mask", re.I),
|
||||
re.compile(br"% ?(\S+) ?overlaps with ?(\S+)", re.I),
|
||||
re.compile(br"[%\S] ?Error: ?[\s]+", re.I),
|
||||
re.compile(br"[%\S] ?Informational: ?[\s]+", re.I),
|
||||
re.compile(br"Command authorization failed"),
|
||||
re.compile(br"Error - *"),
|
||||
re.compile(br"Error - Incorrect username or password."),
|
||||
re.compile(br"Invalid input"),
|
||||
re.compile(br"Already a http operation is in progress"),
|
||||
re.compile(br"Flash access in progress. Please try later"),
|
||||
re.compile(br"Error: .*"),
|
||||
re.compile(br"^Error: .*", re.I),
|
||||
re.compile(br"^Ambiguous input"),
|
||||
re.compile(br"Errno")
|
||||
]
|
||||
|
||||
def on_open_shell(self):
|
||||
pass
|
||||
|
||||
def __del__(self):
|
||||
try:
|
||||
self.close()
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to set terminal parameters')
|
||||
|
||||
def on_become(self, passwd=None):
|
||||
if self._get_prompt().endswith(b'#'):
|
||||
return
|
||||
|
||||
cmd = {u'command': u'enable'}
|
||||
cmd[u'prompt'] = to_text(r"[\r\n](?:Local_)?[Pp]assword: ?$", errors='surrogate_or_strict')
|
||||
cmd[u'answer'] = passwd
|
||||
cmd[u'prompt_retry_check'] = True
|
||||
try:
|
||||
self._exec_cli_command(to_bytes(json.dumps(cmd), errors='surrogate_or_strict'))
|
||||
prompt = self._get_prompt()
|
||||
if prompt is None or not prompt.endswith(b'#'):
|
||||
raise AnsibleConnectionFailure('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))
|
||||
|
||||
def on_unbecome(self):
|
||||
prompt = self._get_prompt()
|
||||
if prompt is None:
|
||||
return
|
||||
|
||||
if b'(config' in prompt:
|
||||
self._exec_cli_command(b'exit')
|
||||
|
||||
elif prompt.endswith(b'#'):
|
||||
self._exec_cli_command(b'exit')
|
78
plugins/terminal/ironware.py
Normal file
78
plugins/terminal/ironware.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
#
|
||||
# (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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import re
|
||||
import json
|
||||
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
from ansible.module_utils._text import to_text, to_bytes
|
||||
from ansible.plugins.terminal import TerminalBase
|
||||
|
||||
|
||||
class TerminalModule(TerminalBase):
|
||||
|
||||
terminal_stdout_re = [
|
||||
re.compile(br"[\r\n]?(?:\w+@)?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#) ?$")
|
||||
]
|
||||
|
||||
terminal_stderr_re = [
|
||||
re.compile(br"[\r\n]Error - "),
|
||||
re.compile(br"[\r\n](?:incomplete|ambiguous|unrecognised|invalid) (?:command|input)", re.I)
|
||||
]
|
||||
|
||||
def on_open_shell(self):
|
||||
self.disable_pager()
|
||||
|
||||
def disable_pager(self):
|
||||
cmd = {u'command': u'terminal length 0'}
|
||||
try:
|
||||
self._exec_cli_command(u'terminal length 0')
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to disable terminal pager')
|
||||
|
||||
def on_become(self, passwd=None):
|
||||
if self._get_prompt().strip().endswith(b'#'):
|
||||
return
|
||||
|
||||
cmd = {u'command': u'enable'}
|
||||
if passwd:
|
||||
# Note: python-3.5 cannot combine u"" and r"" together. Thus make
|
||||
# an r string and use to_text to ensure it's text on both py2 and py3.
|
||||
cmd[u'prompt'] = to_text(r"[\r\n]?password: ?$", errors='surrogate_or_strict')
|
||||
cmd[u'answer'] = passwd
|
||||
|
||||
try:
|
||||
self._exec_cli_command(to_bytes(json.dumps(cmd), errors='surrogate_or_strict'))
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to elevate privilege to enable mode')
|
||||
|
||||
def on_unbecome(self):
|
||||
prompt = self._get_prompt()
|
||||
if prompt is None:
|
||||
# if prompt is None most likely the terminal is hung up at a prompt
|
||||
return
|
||||
|
||||
if b'(config' in prompt:
|
||||
self._exec_cli_command(b'end')
|
||||
self._exec_cli_command(b'exit')
|
||||
|
||||
elif prompt.endswith(b'#'):
|
||||
self._exec_cli_command(b'exit')
|
39
plugins/terminal/netvisor.py
Normal file
39
plugins/terminal/netvisor.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
#
|
||||
# (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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
import re
|
||||
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
from ansible.module_utils._text import to_text, to_bytes
|
||||
from ansible.plugins.terminal import TerminalBase
|
||||
|
||||
|
||||
class TerminalModule(TerminalBase):
|
||||
|
||||
terminal_stdout_re = [
|
||||
re.compile(br">.*[\r\n]?(.*)")
|
||||
|
||||
]
|
||||
|
||||
terminal_stderr_re = [
|
||||
re.compile(br"% ?Error: (?!\bdoes not exist\b)(?!\balready exists\b)")
|
||||
]
|
54
plugins/terminal/nos.py
Normal file
54
plugins/terminal/nos.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
#
|
||||
# (c) 2018 Extreme Networks 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import re
|
||||
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
from ansible.plugins.terminal import TerminalBase
|
||||
|
||||
|
||||
class TerminalModule(TerminalBase):
|
||||
|
||||
terminal_stdout_re = [
|
||||
re.compile(br"([\r\n]|(\x1b\[\?7h))[\w\+\-\.:\/\[\]]+(?:\([^\)]+\)){0,3}(?:[>#]) ?$")
|
||||
]
|
||||
|
||||
terminal_stderr_re = [
|
||||
re.compile(br"% ?Error"),
|
||||
# re.compile(br"^% \w+", re.M),
|
||||
re.compile(br"% ?Bad secret"),
|
||||
re.compile(br"[\r\n%] Bad passwords"),
|
||||
re.compile(br"invalid input", re.I),
|
||||
re.compile(br"(?:incomplete|ambiguous) command", re.I),
|
||||
re.compile(br"connection timed out", re.I),
|
||||
re.compile(br"[^\r\n]+ not found"),
|
||||
re.compile(br"'[^']' +returned error code: ?\d+"),
|
||||
re.compile(br"Bad mask", re.I),
|
||||
re.compile(br"% ?(\S+) ?overlaps with ?(\S+)", re.I),
|
||||
re.compile(br"[%\S] ?Informational: ?[\s]+", re.I),
|
||||
re.compile(br"syntax error: unknown argument.", re.I)
|
||||
]
|
||||
|
||||
def on_open_shell(self):
|
||||
try:
|
||||
self._exec_cli_command(u'terminal length 0')
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to set terminal parameters')
|
80
plugins/terminal/onyx.py
Normal file
80
plugins/terminal/onyx.py
Normal file
|
@ -0,0 +1,80 @@
|
|||
#
|
||||
# (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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
import re
|
||||
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
from ansible.module_utils._text import to_text, to_bytes
|
||||
from ansible.plugins.terminal import TerminalBase
|
||||
|
||||
|
||||
class TerminalModule(TerminalBase):
|
||||
|
||||
terminal_stdout_re = [
|
||||
re.compile(br"(?P<prompt>(.*)( > | # )\Z)"),
|
||||
]
|
||||
|
||||
terminal_stderr_re = [
|
||||
re.compile(br"\A%|\r\n%|\n%"),
|
||||
]
|
||||
|
||||
init_commands = [b'no cli session paging enable', ]
|
||||
|
||||
def on_open_shell(self):
|
||||
try:
|
||||
for cmd in self.init_commands:
|
||||
self._exec_cli_command(cmd)
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to set terminal parameters')
|
||||
|
||||
def on_become(self, passwd=None):
|
||||
if self._get_prompt().endswith(b'#'):
|
||||
return
|
||||
|
||||
cmd = {u'command': u'enable'}
|
||||
if passwd:
|
||||
# Note: python-3.5 cannot combine u"" and r"" together. Thus make
|
||||
# an r string and use to_text to ensure it's text on both py2 and
|
||||
# py3.
|
||||
cmd[u'prompt'] = to_text(r"[\r\n]?password: $",
|
||||
errors='surrogate_or_strict')
|
||||
cmd[u'answer'] = passwd
|
||||
|
||||
try:
|
||||
self._exec_cli_command(to_bytes(json.dumps(cmd),
|
||||
errors='surrogate_or_strict'))
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure(
|
||||
'unable to elevate privilege to enable mode')
|
||||
|
||||
def on_unbecome(self):
|
||||
prompt = self._get_prompt()
|
||||
if prompt is None:
|
||||
# if prompt is None most likely the terminal is hung up at a prompt
|
||||
return
|
||||
|
||||
if b'(config' in prompt:
|
||||
self._exec_cli_command(b'exit')
|
||||
self._exec_cli_command(b'disable')
|
||||
|
||||
elif prompt.endswith(b'#'):
|
||||
self._exec_cli_command(b'disable')
|
69
plugins/terminal/routeros.py
Normal file
69
plugins/terminal/routeros.py
Normal file
|
@ -0,0 +1,69 @@
|
|||
#
|
||||
# (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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
import re
|
||||
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
from ansible.module_utils._text import to_text, to_bytes
|
||||
from ansible.plugins.terminal import TerminalBase
|
||||
from ansible.utils.display import Display
|
||||
|
||||
display = Display()
|
||||
|
||||
|
||||
class TerminalModule(TerminalBase):
|
||||
|
||||
ansi_re = [
|
||||
# check ECMA-48 Section 5.4 (Control Sequences)
|
||||
re.compile(br'(\x1b\[\?1h\x1b=)'),
|
||||
re.compile(br'((?:\x9b|\x1b\x5b)[\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e])'),
|
||||
re.compile(br'\x08.')
|
||||
]
|
||||
|
||||
terminal_initial_prompt = [
|
||||
br'\x1bZ',
|
||||
]
|
||||
|
||||
terminal_initial_answer = b'\x1b/Z'
|
||||
|
||||
terminal_stdout_re = [
|
||||
re.compile(br"\x1b<"),
|
||||
re.compile(br"\[[\w\.]+\@[\w\s\-\.]+\] ?> ?$"),
|
||||
re.compile(br"Please press \"Enter\" to continue!"),
|
||||
re.compile(br"Do you want to see the software license\? \[Y\/n\]: ?"),
|
||||
]
|
||||
|
||||
terminal_stderr_re = [
|
||||
re.compile(br"\nbad command name"),
|
||||
re.compile(br"\nno such item"),
|
||||
re.compile(br"\ninvalid value for"),
|
||||
]
|
||||
|
||||
def on_open_shell(self):
|
||||
prompt = self._get_prompt()
|
||||
try:
|
||||
if prompt.strip().endswith(b':'):
|
||||
self._exec_cli_command(b' ')
|
||||
if prompt.strip().endswith(b'!'):
|
||||
self._exec_cli_command(b'\n')
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to bypass license prompt')
|
54
plugins/terminal/slxos.py
Normal file
54
plugins/terminal/slxos.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
#
|
||||
# (c) 2018 Extreme Networks 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import re
|
||||
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
from ansible.plugins.terminal import TerminalBase
|
||||
|
||||
|
||||
class TerminalModule(TerminalBase):
|
||||
|
||||
terminal_stdout_re = [
|
||||
re.compile(br"([\r\n]|(\x1b\[\?7h))[\w\+\-\.:\/\[\]]+(?:\([^\)]+\)){0,3}(?:[>#]) ?$")
|
||||
]
|
||||
|
||||
terminal_stderr_re = [
|
||||
re.compile(br"% ?Error"),
|
||||
# re.compile(br"^% \w+", re.M),
|
||||
re.compile(br"% ?Bad secret"),
|
||||
re.compile(br"[\r\n%] Bad passwords"),
|
||||
re.compile(br"invalid input", re.I),
|
||||
re.compile(br"(?:incomplete|ambiguous) command", re.I),
|
||||
re.compile(br"connection timed out", re.I),
|
||||
re.compile(br"[^\r\n]+ not found"),
|
||||
re.compile(br"'[^']' +returned error code: ?\d+"),
|
||||
re.compile(br"Bad mask", re.I),
|
||||
re.compile(br"% ?(\S+) ?overlaps with ?(\S+)", re.I),
|
||||
re.compile(br"[%\S] ?Informational: ?[\s]+", re.I),
|
||||
re.compile(br"syntax error: unknown argument.", re.I)
|
||||
]
|
||||
|
||||
def on_open_shell(self):
|
||||
try:
|
||||
self._exec_cli_command(u'terminal length 0')
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to set terminal parameters')
|
43
plugins/terminal/sros.py
Normal file
43
plugins/terminal/sros.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
#
|
||||
# (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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import re
|
||||
|
||||
from ansible.plugins.terminal import TerminalBase
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
|
||||
|
||||
class TerminalModule(TerminalBase):
|
||||
|
||||
terminal_stdout_re = [
|
||||
re.compile(br"[\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#|\$|>#) ?$"),
|
||||
re.compile(br"\[\w+\@[\w\-\.]+(?: [^\]])\] ?[>#\$] ?$")
|
||||
]
|
||||
|
||||
terminal_stderr_re = [
|
||||
re.compile(br"Error:"),
|
||||
]
|
||||
|
||||
def on_open_shell(self):
|
||||
try:
|
||||
self._exec_cli_command(b'environment no more')
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to set terminal parameters')
|
89
plugins/terminal/voss.py
Normal file
89
plugins/terminal/voss.py
Normal file
|
@ -0,0 +1,89 @@
|
|||
#
|
||||
# (c) 2018 Extreme Networks 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
import re
|
||||
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
from ansible.module_utils._text import to_text, to_bytes
|
||||
from ansible.plugins.terminal import TerminalBase
|
||||
|
||||
|
||||
class TerminalModule(TerminalBase):
|
||||
|
||||
terminal_stdout_re = [
|
||||
re.compile(br"[\r\n]+[^\s#>]+(?:[>#])$", re.M)
|
||||
]
|
||||
|
||||
terminal_stderr_re = [
|
||||
re.compile(br"% ?Error"),
|
||||
re.compile(br"% ?Bad secret"),
|
||||
re.compile(br"[\r\n%] Bad passwords"),
|
||||
re.compile(br"invalid input", re.I),
|
||||
re.compile(br"(?:incomplete|ambiguous) command", re.I),
|
||||
re.compile(br"connection timed out", re.I),
|
||||
re.compile(br"[^\r\n]+ not found"),
|
||||
re.compile(br"'[^']' +returned error code: ?\d+"),
|
||||
re.compile(br"Discontiguous Subnet Mask"),
|
||||
re.compile(br"Conflicting IP address"),
|
||||
re.compile(br"[\r\n]Error: ?[\S]+"),
|
||||
re.compile(br"[%\S] ?Informational: ?[\s]+", re.I),
|
||||
re.compile(br"Command authorization failed")
|
||||
]
|
||||
|
||||
def on_open_shell(self):
|
||||
try:
|
||||
self._exec_cli_command(u'terminal more disable')
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to set terminal parameters')
|
||||
|
||||
def on_become(self, passwd=None):
|
||||
if self._get_prompt().endswith(b'#'):
|
||||
return
|
||||
|
||||
cmd = {u'command': u'enable'}
|
||||
if passwd:
|
||||
# Note: python-3.5 cannot combine u"" and r"" together. Thus make
|
||||
# an r string and use to_text to ensure it's text on both py2 and py3.
|
||||
cmd[u'prompt'] = to_text(r"[\r\n](?:Local_)?[Pp]assword: ?$", errors='surrogate_or_strict')
|
||||
cmd[u'answer'] = passwd
|
||||
cmd[u'prompt_retry_check'] = True
|
||||
try:
|
||||
self._exec_cli_command(to_bytes(json.dumps(cmd), errors='surrogate_or_strict'))
|
||||
prompt = self._get_prompt()
|
||||
if prompt is None or not prompt.endswith(b'#'):
|
||||
raise AnsibleConnectionFailure('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))
|
||||
|
||||
def on_unbecome(self):
|
||||
prompt = self._get_prompt()
|
||||
if prompt is None:
|
||||
# if prompt is None most likely the terminal is hung up at a prompt
|
||||
return
|
||||
|
||||
if prompt.endswith(b')#'):
|
||||
self._exec_cli_command(b'end')
|
||||
self._exec_cli_command(b'disable')
|
||||
|
||||
elif prompt.endswith(b'#'):
|
||||
self._exec_cli_command(b'disable')
|
Loading…
Add table
Add a link
Reference in a new issue