Repository: ansible/ansible
Pull request: Don't fail if exos can't configure cli columns


##### SUMMARY
<!--- Describe the change below, including rationale and design decisions -->

<!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
Fixes #51363 

Some exos versions don't have ```configure cli columns``` command, don't fail in this case

##### ISSUE TYPE
<!--- Pick one below and delete the rest -->
- Bugfix Pull Request


##### COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below -->
ansible-connection

##### ADDITIONAL INFORMATION
<!--- Include additional information to help people understand the change here -->
<!--- A step-by-step reproduction of the problem is helpful if there is no related issue -->

<!--- Paste verbatim command output below, e.g. before and after your change -->
```paste below

```


Problem statement:
Network_cli error "unable to set terminal parameters" for EXOS devices
<!--- Verify first that your issue is not already reported on GitHub -->
<!--- Also test if the latest release and devel branch are affected too -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY
Connection module ```network_cli``` always report error ```unable to set terminal parameters``` 
 with ```ansible_network_os: exos``` for Extreme Networks x650 devices EXOS v.15.3.5.2

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below, use your best guess if unsure -->
plugins/terminal/exos.py

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes -->
```paste below
ansible 2.7.6
  config file = /home/xxx/.ansible.cfg
  configured module search path = ['/home/xxx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.6.3 (default, Oct  3 2017, 21:16:13) [GCC 7.2.0]
```

##### CONFIGURATION
<!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes -->
```paste below
HOST_KEY_CHECKING(/home/xxx/.ansible.cfg) = False
PARAMIKO_HOST_KEY_AUTO_ADD(/home/xxx/.ansible.cfg) = True
PARAMIKO_LOOK_FOR_KEYS(/home/xxx/.ansible.cfg) = False
PERSISTENT_COMMAND_TIMEOUT(/home/xxx/.ansible.cfg) = 60
PERSISTENT_CONNECT_RETRY_TIMEOUT(/home/xxx/.ansible.cfg) = 15
PERSISTENT_CONNECT_TIMEOUT(/home/xxx/.ansible.cfg) = 120
```

##### OS / ENVIRONMENT
<!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. -->
```
OS: Debian Stretch
Network device: Extreme Networks X650-24x v.15.3.5.2 patch-19
```
##### STEPS TO REPRODUCE
<!--- Describe exactly how to reproduce the problem, using a minimal test-case -->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
  tasks:
  - name: run show version on remote devices
    exos_command:
      commands: show version
```

<!--- HINT: You can paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- Describe what you expected to happen when running the steps above -->
Command executed on device

##### ACTUAL RESULTS
<!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes -->
```paste below
Traceback (most recent call last):                                                             
  File "/usr/local/lib/python3.6/dist-packages/ansible/plugins/terminal/exos.py", line 53, in on_open_shell
    self._exec_cli_command(cmd)                                                                                        
  File "/usr/local/lib/python3.6/dist-packages/ansible/plugins/terminal/__init__.py", line 73, in _exec_cli_command
    return self._connection.exec_command(cmd)                                                  
  File "/usr/local/lib/python3.6/dist-packages/ansible/plugins/connection/network_cli.py", line 257, in exec_command                                                                          
    return self.send(command=cmd)                                                                                                                                                             
  File "/usr/local/lib/python3.6/dist-packages/ansible/plugins/connection/network_cli.py", line 454, in send                                                                                  
    response = self.receive(command, prompt, answer, newline, prompt_retry_check, check_all)                                                                                                  
  File "/usr/local/lib/python3.6/dist-packages/ansible/plugins/connection/network_cli.py", line 429, in receive                                                                               
    if self._find_prompt(window):                                                                                                                                                             
  File "/usr/local/lib/python3.6/dist-packages/ansible/plugins/connection/network_cli.py", line 559, in _find_prompt                                                                          
    raise AnsibleConnectionFailure(errored_response)                                                                                                                                          
ansible.errors.AnsibleConnectionFailure: configure cli columns 256                             
                                  ^                                                            
%% Invalid input detected at '^' marker.                                                       
device1 #                                                                            
                                                                                               
During handling of the above exception, another exception occurred:                                                                                                                           
                                                                                                                                                                                              
Traceback (most recent call last):                                                                                                                                                            
  File "/usr/local/bin/ansible-connection", line 106, in start                                                                                                                                
    self.connection._connect()                                                                                                                                                                
  File "/usr/local/lib/python3.6/dist-packages/ansible/plugins/connection/network_cli.py", line 334, in _connect                                                                              
    self._terminal.on_open_shell()                                                                                                                                                            
  File "/usr/local/lib/python3.6/dist-packages/ansible/plugins/terminal/exos.py", line 55, in on_open_shell                                                                                   
    raise AnsibleConnectionFailure('unable to set terminal parameters')                                                                                                                       
ansible.errors.AnsibleConnectionFailure: unable to set terminal parameters                     
```

Hints from issue discussion:
Files identified in the description:
* [lib/ansible/plugins/connection/network_cli.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/connection/network_cli.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @NilashishC @Qalthos @ganeshrn @gdpak @justjais @rcarrillocruz @trishnaguha
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Commit message: Don't fail if exos can't configure cli columns

Signed-off-by: Misha Komarovskiy <zombah@gmail.com>

Patch to review:
diff --git a/lib/ansible/plugins/terminal/exos.py b/lib/ansible/plugins/terminal/exos.py
index 6c17e467bfa7cb..0b6e8b51cc5750 100644
--- a/lib/ansible/plugins/terminal/exos.py
+++ b/lib/ansible/plugins/terminal/exos.py
@@ -23,6 +23,9 @@
 
 from ansible.errors import AnsibleConnectionFailure
 from ansible.plugins.terminal import TerminalBase
+from ansible.utils.display import Display
+
+display = Display()
 
 
 class TerminalModule(TerminalBase):
@@ -49,7 +52,11 @@ class TerminalModule(TerminalBase):
 
     def on_open_shell(self):
         try:
-            for cmd in (b'disable clipaging', b'configure cli columns 256'):
-                self._exec_cli_command(cmd)
+            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:
+            display.display('WARNING: Unable to configure cli columns, command responses may be truncated')


Code review comments:
diff_hunk: @@ -49,7 +52,11 @@ class TerminalModule(TerminalBase):
 
     def on_open_shell(self):
         try:
-            for cmd in (b'disable clipaging', b'configure cli columns 256'):
-                self._exec_cli_command(cmd)
+            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:
+            display.display('WARNING: Unable to configure cli columns, command responses may be truncated')
path: lib/ansible/plugins/terminal/exos.py
text: @user1:
```suggestion
            self._connection.queue_message('warning', 'Unable to configure cli columns, command responses may be truncated')
```

And then remove the `Display` import above.

@author:
Resolved and tested, works fine.