We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
ios_config incorrectly claims success when commands fail
##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
ios_config

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
[ansible@localhost cmdauthz]$ ansible --version
ansible 2.3.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
```

##### CONFIGURATION
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"

Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).

-->
ansible.cfg modification:
forks = 20
gathering = explicit
host_key_checking = false
timeout = 60
vault_password_file = ~/.ansible/vault-pass.txt
retry_files_enabled = false

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
AWS AMI CentOS7
```
[ansible@localhost cmdauthz]$ uname -a
Linux localhost.localdomain 3.10.0-514.26.2.el7.x86_64 #1 SMP Tue Jul 4 15:04:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
```

##### SUMMARY
<!--- Explain the problem briefly -->
There is no stdout from "ios_config". When you issue commands that are TACACS-unauthorized, ansible still reports "changed", comes back and reports success, and ignores the fact they were rejected. I assume the module is ignoring all CLI output and only looking for the next config prompt to claim success. This makes it difficult to validate that unauthorized commands were rejected and authorized commands were accepted. Such a playbook is useful as a AAA security posture checker.

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->
Task sub-list shown below.
<!--- Paste example playbooks or commands between quotes below -->
```
---
- name: "SYS >> Capture current username"
  set_fact:
    USER: "{{ PARAM_CREDS.username }}"

- name: "IOS >> {{ USER }}: Issue unauthorized conf commands"
  ios_config:
    provider: "{{ PARAM_CREDS }}"
    match: none
    commands:
    - "{{ item }}"
  register: OUTPUT
  with_items: "{{ unauth_conf_cmds_t2 }}"

- debug:
    var: OUTPUT
...
```

Relevant variables included.

```
---
unauth_conf_cmds_t2:
- "ip bgp new-format"
- "interface Loopback12345"
...
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
When `ios_config` determines that the commands being issued are new (a change), of if, `match: none` is set, the module should attempt to issue command in question. It should also collect any parser output, to include `Command authorization failed.`, so that the playbook writer can perform checks against it. I would recommend returning `stdout` and `stdout_lines` in much the same way that ios_command works, for consistency.

Note that if you don't want to set up a TACACS server, using a `do` statement to run a show command from config mode would probably be a valid test to ensure output is being collected.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
`ios_config` returns correct fields per the documentation, but the lack of seeing CLI output makes it hard to discern why commands were rejected.

<!--- Paste verbatim command output between quotes below -->
```
[ansible@localhost cmdauthz]$ ansible-playbook cmdauthz-playbook.yml 

PLAY [localhost] ************************************************************************************************************

TASK [SYS >> Define string match facts] *************************************************************************************
ok: [localhost]

PLAY [Verify AAA command authorization functionality] ***********************************************************************

TASK [SYS >> Capture current username] **************************************************************************************
ok: [APG_6010_PER]

TASK [IOS >> ansible2: Issue unauthorized conf commands] ********************************************************************
changed: [APG_6010_PER] => (item=ip bgp new-format)
changed: [APG_6010_PER] => (item=interface Loopback12345)

TASK [debug] ****************************************************************************************************************
ok: [APG_6010_PER] => {
    "OUTPUT": {
        "changed": true, 
        "msg": "All items completed", 
        "results": [
            {
                "_ansible_item_result": true, 
                "_ansible_no_log": false, 
                "_ansible_parsed": true, 
                "banners": {}, 
                "changed": true, 
                "commands": [
                    "ip bgp new-format"
                ], 
                "invocation": {
                    "module_args": {
                        "after": null, 
                        "auth_pass": null, 
                        "authorize": null, 
                        "backup": false, 
                        "before": null, 
                        "commands": [
                            "ip bgp new-format"
                        ], 
                        "config": null, 
                        "defaults": false, 
                        "force": false, 
                        "host": null, 
                        "lines": [
                            "ip bgp new-format"
                        ], 
                        "match": "none", 
                        "multiline_delimiter": "@", 
                        "parents": null, 
                        "password": null, 
                        "port": null, 
                        "provider": {
                            "auth_pass": null, 
                            "authorize": null, 
                            "host": "APG_6010_PER", 
                            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
                            "port": 3022, 
                            "ssh_keyfile": null, 
                            "timeout": 30, 
                            "username": "ansible2"
                        }, 
                        "replace": "line", 
                        "save": false, 
                        "src": null, 
                        "ssh_keyfile": null, 
                        "timeout": null, 
                        "username": null
                    }
                }, 
                "item": "ip bgp new-format", 
                "updates": [
                    "ip bgp new-format"
                ]
            }, 
            {
                "_ansible_item_result": true, 
                "_ansible_no_log": false, 
                "_ansible_parsed": true, 
                "banners": {}, 
                "changed": true, 
                "commands": [
                    "interface Loopback12345"
                ], 
                "invocation": {
                    "module_args": {
                        "after": null, 
                        "auth_pass": null, 
                        "authorize": null, 
                        "backup": false, 
                        "before": null, 
                        "commands": [
                            "interface Loopback12345"
                        ], 
                        "config": null, 
                        "defaults": false, 
                        "force": false, 
                        "host": null, 
                        "lines": [
                            "interface Loopback12345"
                        ], 
                        "match": "none", 
                        "multiline_delimiter": "@", 
                        "parents": null, 
                        "password": null, 
                        "port": null, 
                        "provider": {
                            "auth_pass": null, 
                            "authorize": null, 
                            "host": "APG_6010_PER", 
                            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
                            "port": 3022, 
                            "ssh_keyfile": null, 
                            "timeout": 30, 
                            "username": "ansible2"
                        }, 
                        "replace": "line", 
                        "save": false, 
                        "src": null, 
                        "ssh_keyfile": null, 
                        "timeout": null, 
                        "username": null
                    }
                }, 
                "item": "interface Loopback12345", 
                "updates": [
                    "interface Loopback12345"
                ]
            }
        ]
    }
}
```

Manually logging into the router and issuing the commands is shown below. The commands are rejected and no changes are observed.

```
APG_6010_XPER#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
APG_6010_XPER(config)#ip bgp new-format
Command authorization failed.

APG_6010_XPER(config)#interface Loopback12345
Command authorization failed.

APG_6010_XPER(config)#end

APG_6010_XPER#show run | include Loopback12345|^ip_bgp
APG_6010_XPER#
APG_6010_XPER#show archive config differences nvram:startup-config

!Contextual Config Diffs:
!No changes were found
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `lib/ansible/plugins/terminal/ios.py`
Content:
```
1 #
2 # (c) 2016 Red Hat Inc.
3 #
4 # This file is part of Ansible
5 #
6 # Ansible is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Ansible is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 from __future__ import (absolute_import, division, print_function)
20 __metaclass__ = type
21 
22 import json
23 import re
24 
25 from ansible.errors import AnsibleConnectionFailure
26 from ansible.module_utils._text import to_text, to_bytes
27 from ansible.plugins.terminal import TerminalBase
28 
29 
30 class TerminalModule(TerminalBase):
31 
32     terminal_stdout_re = [
33         re.compile(br"[\r\n]?[\w\+\-\.:\/\[\]]+(?:\([^\)]+\)){0,3}(?:[>#]) ?$")
34     ]
35 
36     terminal_stderr_re = [
37         re.compile(br"% ?Error"),
38         # re.compile(br"^% \w+", re.M),
39         re.compile(br"% ?Bad secret"),
40         re.compile(br"[\r\n%] Bad passwords"),
41         re.compile(br"invalid input", re.I),
42         re.compile(br"(?:incomplete|ambiguous) command", re.I),
43         re.compile(br"connection timed out", re.I),
44         re.compile(br"[^\r\n]+ not found"),
45         re.compile(br"'[^']' +returned error code: ?\d+"),
46         re.compile(br"Bad mask", re.I),
47         re.compile(br"% ?(\S+) ?overlaps with ?(\S+)", re.I),
48         re.compile(br"[%\S] ?Error: ?[\s]+", re.I),
49         re.compile(br"[%\S] ?Informational: ?[\s]+", re.I)
50     ]
51 
52     def on_open_shell(self):
53         try:
54             for cmd in (b'terminal length 0', b'terminal width 512'):
55                 self._exec_cli_command(cmd)
56         except AnsibleConnectionFailure:
57             raise AnsibleConnectionFailure('unable to set terminal parameters')
58 
59     def on_become(self, passwd=None):
60         if self._get_prompt().endswith(b'#'):
61             return
62 
63         cmd = {u'command': u'enable'}
64         if passwd:
65             # Note: python-3.5 cannot combine u"" and r"" together.  Thus make
66             # an r string and use to_text to ensure it's text on both py2 and py3.
67             cmd[u'prompt'] = to_text(r"[\r\n]password: ?$", errors='surrogate_or_strict')
68             cmd[u'answer'] = passwd
69             cmd[u'prompt_retry_check'] = True
70         try:
71             self._exec_cli_command(to_bytes(json.dumps(cmd), errors='surrogate_or_strict'))
72             prompt = self._get_prompt()
73             if prompt is None or not prompt.endswith(b'#'):
74                 raise AnsibleConnectionFailure('failed to elevate privilege to enable mode still at prompt [%s]' % prompt)
75         except AnsibleConnectionFailure as e:
76             prompt = self._get_prompt()
77             raise AnsibleConnectionFailure('unable to elevate privilege to enable mode, at prompt [%s] with error: %s' % (prompt, e.message))
78 
79     def on_unbecome(self):
80         prompt = self._get_prompt()
81         if prompt is None:
82             # if prompt is None most likely the terminal is hung up at a prompt
83             return
84 
85         if b'(config' in prompt:
86             self._exec_cli_command(b'end')
87             self._exec_cli_command(b'disable')
88 
89         elif prompt.endswith(b'#'):
90             self._exec_cli_command(b'disable')
91
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/lib/ansible/plugins/terminal/ios.py b/lib/ansible/plugins/terminal/ios.py
--- a/lib/ansible/plugins/terminal/ios.py
+++ b/lib/ansible/plugins/terminal/ios.py
@@ -46,7 +46,8 @@
         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"[%\S] ?Informational: ?[\s]+", re.I),
+        re.compile(br"Command authorization failed")
     ]
 
     def on_open_shell(self):

{"golden_diff": "diff --git a/lib/ansible/plugins/terminal/ios.py b/lib/ansible/plugins/terminal/ios.py\n--- a/lib/ansible/plugins/terminal/ios.py\n+++ b/lib/ansible/plugins/terminal/ios.py\n@@ -46,7 +46,8 @@\n         re.compile(br\"Bad mask\", re.I),\n         re.compile(br\"% ?(\\S+) ?overlaps with ?(\\S+)\", re.I),\n         re.compile(br\"[%\\S] ?Error: ?[\\s]+\", re.I),\n-        re.compile(br\"[%\\S] ?Informational: ?[\\s]+\", re.I)\n+        re.compile(br\"[%\\S] ?Informational: ?[\\s]+\", re.I),\n+        re.compile(br\"Command authorization failed\")\n     ]\n \n     def on_open_shell(self):\n", "issue": "ios_config incorrectly claims success when commands fail\n##### ISSUE TYPE\r\n<!--- Pick one below and delete the rest: -->\r\n - Bug Report\r\n\r\n##### COMPONENT NAME\r\n<!--- Name of the module/plugin/task/feature -->\r\nios_config\r\n\r\n##### ANSIBLE VERSION\r\n<!--- Paste verbatim output from \"ansible --version\" between quotes below -->\r\n```\r\n[ansible@localhost cmdauthz]$ ansible --version\r\nansible 2.3.1.0\r\n  config file = /etc/ansible/ansible.cfg\r\n  configured module search path = Default w/o overrides\r\n  python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]\r\n```\r\n\r\n##### CONFIGURATION\r\n<!---\r\nIf using Ansible 2.4 or above, paste the results of \"ansible-config dump --only-changed\"\r\n\r\nOtherwise, mention any settings you have changed/added/removed in ansible.cfg\r\n(or using the ANSIBLE_* environment variables).\r\n\r\n-->\r\nansible.cfg modification:\r\nforks = 20\r\ngathering = explicit\r\nhost_key_checking = false\r\ntimeout = 60\r\nvault_password_file = ~/.ansible/vault-pass.txt\r\nretry_files_enabled = false\r\n\r\n##### OS / ENVIRONMENT\r\n<!---\r\nMention the OS you are running Ansible from, and the OS you are\r\nmanaging, or say \"N/A\" for anything that is not platform-specific.\r\nAlso mention the specific version of what you are trying to control,\r\ne.g. if this is a network bug the version of firmware on the network device.\r\n-->\r\nAWS AMI CentOS7\r\n```\r\n[ansible@localhost cmdauthz]$ uname -a\r\nLinux localhost.localdomain 3.10.0-514.26.2.el7.x86_64 #1 SMP Tue Jul 4 15:04:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux\r\n```\r\n\r\n##### SUMMARY\r\n<!--- Explain the problem briefly -->\r\nThere is no stdout from \"ios_config\". When you issue commands that are TACACS-unauthorized, ansible still reports \"changed\", comes back and reports success, and ignores the fact they were rejected. I assume the module is ignoring all CLI output and only looking for the next config prompt to claim success. This makes it difficult to validate that unauthorized commands were rejected and authorized commands were accepted. Such a playbook is useful as a AAA security posture checker.\r\n\r\n##### STEPS TO REPRODUCE\r\n<!---\r\nFor bugs, show exactly how to reproduce the problem, using a minimal test-case.\r\nFor new features, show how the feature would be used.\r\n-->\r\nTask sub-list shown below.\r\n<!--- Paste example playbooks or commands between quotes below -->\r\n```\r\n---\r\n- name: \"SYS >> Capture current username\"\r\n  set_fact:\r\n    USER: \"{{ PARAM_CREDS.username }}\"\r\n\r\n- name: \"IOS >> {{ USER }}: Issue unauthorized conf commands\"\r\n  ios_config:\r\n    provider: \"{{ PARAM_CREDS }}\"\r\n    match: none\r\n    commands:\r\n    - \"{{ item }}\"\r\n  register: OUTPUT\r\n  with_items: \"{{ unauth_conf_cmds_t2 }}\"\r\n\r\n- debug:\r\n    var: OUTPUT\r\n...\r\n```\r\n\r\nRelevant variables included.\r\n\r\n```\r\n---\r\nunauth_conf_cmds_t2:\r\n- \"ip bgp new-format\"\r\n- \"interface Loopback12345\"\r\n...\r\n```\r\n\r\n<!--- You can also paste gist.github.com links for larger files -->\r\n\r\n##### EXPECTED RESULTS\r\n<!--- What did you expect to happen when running the steps above? -->\r\nWhen `ios_config` determines that the commands being issued are new (a change), of if, `match: none` is set, the module should attempt to issue command in question. It should also collect any parser output, to include `Command authorization failed.`, so that the playbook writer can perform checks against it. I would recommend returning `stdout` and `stdout_lines` in much the same way that ios_command works, for consistency.\r\n\r\nNote that if you don't want to set up a TACACS server, using a `do` statement to run a show command from config mode would probably be a valid test to ensure output is being collected.\r\n\r\n##### ACTUAL RESULTS\r\n<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->\r\n`ios_config` returns correct fields per the documentation, but the lack of seeing CLI output makes it hard to discern why commands were rejected.\r\n\r\n<!--- Paste verbatim command output between quotes below -->\r\n```\r\n[ansible@localhost cmdauthz]$ ansible-playbook cmdauthz-playbook.yml \r\n\r\nPLAY [localhost] ************************************************************************************************************\r\n\r\nTASK [SYS >> Define string match facts] *************************************************************************************\r\nok: [localhost]\r\n\r\nPLAY [Verify AAA command authorization functionality] ***********************************************************************\r\n\r\nTASK [SYS >> Capture current username] **************************************************************************************\r\nok: [APG_6010_PER]\r\n\r\nTASK [IOS >> ansible2: Issue unauthorized conf commands] ********************************************************************\r\nchanged: [APG_6010_PER] => (item=ip bgp new-format)\r\nchanged: [APG_6010_PER] => (item=interface Loopback12345)\r\n\r\nTASK [debug] ****************************************************************************************************************\r\nok: [APG_6010_PER] => {\r\n    \"OUTPUT\": {\r\n        \"changed\": true, \r\n        \"msg\": \"All items completed\", \r\n        \"results\": [\r\n            {\r\n                \"_ansible_item_result\": true, \r\n                \"_ansible_no_log\": false, \r\n                \"_ansible_parsed\": true, \r\n                \"banners\": {}, \r\n                \"changed\": true, \r\n                \"commands\": [\r\n                    \"ip bgp new-format\"\r\n                ], \r\n                \"invocation\": {\r\n                    \"module_args\": {\r\n                        \"after\": null, \r\n                        \"auth_pass\": null, \r\n                        \"authorize\": null, \r\n                        \"backup\": false, \r\n                        \"before\": null, \r\n                        \"commands\": [\r\n                            \"ip bgp new-format\"\r\n                        ], \r\n                        \"config\": null, \r\n                        \"defaults\": false, \r\n                        \"force\": false, \r\n                        \"host\": null, \r\n                        \"lines\": [\r\n                            \"ip bgp new-format\"\r\n                        ], \r\n                        \"match\": \"none\", \r\n                        \"multiline_delimiter\": \"@\", \r\n                        \"parents\": null, \r\n                        \"password\": null, \r\n                        \"port\": null, \r\n                        \"provider\": {\r\n                            \"auth_pass\": null, \r\n                            \"authorize\": null, \r\n                            \"host\": \"APG_6010_PER\", \r\n                            \"password\": \"VALUE_SPECIFIED_IN_NO_LOG_PARAMETER\", \r\n                            \"port\": 3022, \r\n                            \"ssh_keyfile\": null, \r\n                            \"timeout\": 30, \r\n                            \"username\": \"ansible2\"\r\n                        }, \r\n                        \"replace\": \"line\", \r\n                        \"save\": false, \r\n                        \"src\": null, \r\n                        \"ssh_keyfile\": null, \r\n                        \"timeout\": null, \r\n                        \"username\": null\r\n                    }\r\n                }, \r\n                \"item\": \"ip bgp new-format\", \r\n                \"updates\": [\r\n                    \"ip bgp new-format\"\r\n                ]\r\n            }, \r\n            {\r\n                \"_ansible_item_result\": true, \r\n                \"_ansible_no_log\": false, \r\n                \"_ansible_parsed\": true, \r\n                \"banners\": {}, \r\n                \"changed\": true, \r\n                \"commands\": [\r\n                    \"interface Loopback12345\"\r\n                ], \r\n                \"invocation\": {\r\n                    \"module_args\": {\r\n                        \"after\": null, \r\n                        \"auth_pass\": null, \r\n                        \"authorize\": null, \r\n                        \"backup\": false, \r\n                        \"before\": null, \r\n                        \"commands\": [\r\n                            \"interface Loopback12345\"\r\n                        ], \r\n                        \"config\": null, \r\n                        \"defaults\": false, \r\n                        \"force\": false, \r\n                        \"host\": null, \r\n                        \"lines\": [\r\n                            \"interface Loopback12345\"\r\n                        ], \r\n                        \"match\": \"none\", \r\n                        \"multiline_delimiter\": \"@\", \r\n                        \"parents\": null, \r\n                        \"password\": null, \r\n                        \"port\": null, \r\n                        \"provider\": {\r\n                            \"auth_pass\": null, \r\n                            \"authorize\": null, \r\n                            \"host\": \"APG_6010_PER\", \r\n                            \"password\": \"VALUE_SPECIFIED_IN_NO_LOG_PARAMETER\", \r\n                            \"port\": 3022, \r\n                            \"ssh_keyfile\": null, \r\n                            \"timeout\": 30, \r\n                            \"username\": \"ansible2\"\r\n                        }, \r\n                        \"replace\": \"line\", \r\n                        \"save\": false, \r\n                        \"src\": null, \r\n                        \"ssh_keyfile\": null, \r\n                        \"timeout\": null, \r\n                        \"username\": null\r\n                    }\r\n                }, \r\n                \"item\": \"interface Loopback12345\", \r\n                \"updates\": [\r\n                    \"interface Loopback12345\"\r\n                ]\r\n            }\r\n        ]\r\n    }\r\n}\r\n```\r\n\r\nManually logging into the router and issuing the commands is shown below. The commands are rejected and no changes are observed.\r\n\r\n```\r\nAPG_6010_XPER#conf t\r\nEnter configuration commands, one per line.  End with CNTL/Z.\r\nAPG_6010_XPER(config)#ip bgp new-format\r\nCommand authorization failed.\r\n\r\nAPG_6010_XPER(config)#interface Loopback12345\r\nCommand authorization failed.\r\n\r\nAPG_6010_XPER(config)#end\r\n\r\nAPG_6010_XPER#show run | include Loopback12345|^ip_bgp\r\nAPG_6010_XPER#\r\nAPG_6010_XPER#show archive config differences nvram:startup-config\r\n\r\n!Contextual Config Diffs:\r\n!No changes were found\r\n```\n", "before_files": [{"content": "#\n# (c) 2016 Red Hat Inc.\n#\n# This file is part of Ansible\n#\n# Ansible is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# Ansible is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.\n#\nfrom __future__ import (absolute_import, division, print_function)\n__metaclass__ = type\n\nimport json\nimport re\n\nfrom ansible.errors import AnsibleConnectionFailure\nfrom ansible.module_utils._text import to_text, to_bytes\nfrom ansible.plugins.terminal import TerminalBase\n\n\nclass TerminalModule(TerminalBase):\n\n    terminal_stdout_re = [\n        re.compile(br\"[\\r\\n]?[\\w\\+\\-\\.:\\/\\[\\]]+(?:\\([^\\)]+\\)){0,3}(?:[>#]) ?$\")\n    ]\n\n    terminal_stderr_re = [\n        re.compile(br\"% ?Error\"),\n        # re.compile(br\"^% \\w+\", re.M),\n        re.compile(br\"% ?Bad secret\"),\n        re.compile(br\"[\\r\\n%] Bad passwords\"),\n        re.compile(br\"invalid input\", re.I),\n        re.compile(br\"(?:incomplete|ambiguous) command\", re.I),\n        re.compile(br\"connection timed out\", re.I),\n        re.compile(br\"[^\\r\\n]+ not found\"),\n        re.compile(br\"'[^']' +returned error code: ?\\d+\"),\n        re.compile(br\"Bad mask\", re.I),\n        re.compile(br\"% ?(\\S+) ?overlaps with ?(\\S+)\", re.I),\n        re.compile(br\"[%\\S] ?Error: ?[\\s]+\", re.I),\n        re.compile(br\"[%\\S] ?Informational: ?[\\s]+\", re.I)\n    ]\n\n    def on_open_shell(self):\n        try:\n            for cmd in (b'terminal length 0', b'terminal width 512'):\n                self._exec_cli_command(cmd)\n        except AnsibleConnectionFailure:\n            raise AnsibleConnectionFailure('unable to set terminal parameters')\n\n    def on_become(self, passwd=None):\n        if self._get_prompt().endswith(b'#'):\n            return\n\n        cmd = {u'command': u'enable'}\n        if passwd:\n            # Note: python-3.5 cannot combine u\"\" and r\"\" together.  Thus make\n            # an r string and use to_text to ensure it's text on both py2 and py3.\n            cmd[u'prompt'] = to_text(r\"[\\r\\n]password: ?$\", errors='surrogate_or_strict')\n            cmd[u'answer'] = passwd\n            cmd[u'prompt_retry_check'] = True\n        try:\n            self._exec_cli_command(to_bytes(json.dumps(cmd), errors='surrogate_or_strict'))\n            prompt = self._get_prompt()\n            if prompt is None or not prompt.endswith(b'#'):\n                raise AnsibleConnectionFailure('failed to elevate privilege to enable mode still at prompt [%s]' % prompt)\n        except AnsibleConnectionFailure as e:\n            prompt = self._get_prompt()\n            raise AnsibleConnectionFailure('unable to elevate privilege to enable mode, at prompt [%s] with error: %s' % (prompt, e.message))\n\n    def on_unbecome(self):\n        prompt = self._get_prompt()\n        if prompt is None:\n            # if prompt is None most likely the terminal is hung up at a prompt\n            return\n\n        if b'(config' in prompt:\n            self._exec_cli_command(b'end')\n            self._exec_cli_command(b'disable')\n\n        elif prompt.endswith(b'#'):\n            self._exec_cli_command(b'disable')\n", "path": "lib/ansible/plugins/terminal/ios.py"}], "after_files": [{"content": "#\n# (c) 2016 Red Hat Inc.\n#\n# This file is part of Ansible\n#\n# Ansible is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# Ansible is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.\n#\nfrom __future__ import (absolute_import, division, print_function)\n__metaclass__ = type\n\nimport json\nimport re\n\nfrom ansible.errors import AnsibleConnectionFailure\nfrom ansible.module_utils._text import to_text, to_bytes\nfrom ansible.plugins.terminal import TerminalBase\n\n\nclass TerminalModule(TerminalBase):\n\n    terminal_stdout_re = [\n        re.compile(br\"[\\r\\n]?[\\w\\+\\-\\.:\\/\\[\\]]+(?:\\([^\\)]+\\)){0,3}(?:[>#]) ?$\")\n    ]\n\n    terminal_stderr_re = [\n        re.compile(br\"% ?Error\"),\n        # re.compile(br\"^% \\w+\", re.M),\n        re.compile(br\"% ?Bad secret\"),\n        re.compile(br\"[\\r\\n%] Bad passwords\"),\n        re.compile(br\"invalid input\", re.I),\n        re.compile(br\"(?:incomplete|ambiguous) command\", re.I),\n        re.compile(br\"connection timed out\", re.I),\n        re.compile(br\"[^\\r\\n]+ not found\"),\n        re.compile(br\"'[^']' +returned error code: ?\\d+\"),\n        re.compile(br\"Bad mask\", re.I),\n        re.compile(br\"% ?(\\S+) ?overlaps with ?(\\S+)\", re.I),\n        re.compile(br\"[%\\S] ?Error: ?[\\s]+\", re.I),\n        re.compile(br\"[%\\S] ?Informational: ?[\\s]+\", re.I),\n        re.compile(br\"Command authorization failed\")\n    ]\n\n    def on_open_shell(self):\n        try:\n            for cmd in (b'terminal length 0', b'terminal width 512'):\n                self._exec_cli_command(cmd)\n        except AnsibleConnectionFailure:\n            raise AnsibleConnectionFailure('unable to set terminal parameters')\n\n    def on_become(self, passwd=None):\n        if self._get_prompt().endswith(b'#'):\n            return\n\n        cmd = {u'command': u'enable'}\n        if passwd:\n            # Note: python-3.5 cannot combine u\"\" and r\"\" together.  Thus make\n            # an r string and use to_text to ensure it's text on both py2 and py3.\n            cmd[u'prompt'] = to_text(r\"[\\r\\n]password: ?$\", errors='surrogate_or_strict')\n            cmd[u'answer'] = passwd\n            cmd[u'prompt_retry_check'] = True\n        try:\n            self._exec_cli_command(to_bytes(json.dumps(cmd), errors='surrogate_or_strict'))\n            prompt = self._get_prompt()\n            if prompt is None or not prompt.endswith(b'#'):\n                raise AnsibleConnectionFailure('failed to elevate privilege to enable mode still at prompt [%s]' % prompt)\n        except AnsibleConnectionFailure as e:\n            prompt = self._get_prompt()\n            raise AnsibleConnectionFailure('unable to elevate privilege to enable mode, at prompt [%s] with error: %s' % (prompt, e.message))\n\n    def on_unbecome(self):\n        prompt = self._get_prompt()\n        if prompt is None:\n            # if prompt is None most likely the terminal is hung up at a prompt\n            return\n\n        if b'(config' in prompt:\n            self._exec_cli_command(b'end')\n            self._exec_cli_command(b'disable')\n\n        elif prompt.endswith(b'#'):\n            self._exec_cli_command(b'disable')\n", "path": "lib/ansible/plugins/terminal/ios.py"}]}