Repository: ansible/ansible

Issue:
vyos_command: Bad operator returns backtrace
##### ISSUE TYPE
 - Bug Report
##### COMPONENT NAME
vyos_command

##### ANSIBLE VERSION
```
b8d308d919c89d86dc72d4fd62335b9f948544f1
```

##### SUMMARY

Running `vyos_command` with an invalid operator returns a backtrace, rather than a more meaningful error message:
 
```yaml
- name: test bad operator
  vyos_command:
    commands:
      - show version
      - show interfaces
    wait_for:
      - result[0] is 'VyOS'
    provider: "{{ cli }}"
  register: result
  ignore_errors: yes
```

Gives:
```yaml
 [WARNING]: Removed unexpected internal key in module return: _ansible_parsed = False

An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_xgjgIX/ansible_module_vyos_command.py", line 225, in <module>
    main()
  File "/tmp/ansible_xgjgIX/ansible_module_vyos_command.py", line 188, in main
    conditionals = [Conditional(c) for c in wait_for]
  File "/tmp/ansible_xgjgIX/ansible_modlib.zip/ansible/module_utils/netcli.py", line 213, in __init__
  File "/tmp/ansible_xgjgIX/ansible_modlib.zip/ansible/module_utils/netcli.py", line 236, in _func
AttributeError: unknown operator: is

fatal: [vyos01]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_xgjgIX/ansible_module_vyos_command.py\", line 225, in <module>\n    main()\n  File \"/tmp/ansible_xgjgIX/ansible_module_vyos_command.py\", line 188, in main\n    conditionals = [Conditional(c) for c in wait_for]\n  File \"/tmp/ansible_xgjgIX/ansible_modlib.zip/ansible/module_utils/netcli.py\", line 213, in __init__\n  File \"/tmp/ansible_xgjgIX/ansible_modlib.zip/ansible/module_utils/netcli.py\", line 236, in _func\nAttributeError: unknown operator: is\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "rc": 0
}
```



##### Repo steps
```
cd test/integration
time ANSIBLE_ROLES_PATH=targets  ansible-playbook -vvvvv  -i  inventory.network-jobarker vyos.yaml  -e "limit_to=vyos_command"
```


Discussion:
cc @privateip @Qalthos
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/network/vyos/vyos_command.py b/lib/ansible/modules/network/vyos/vyos_command.py
--- a/lib/ansible/modules/network/vyos/vyos_command.py
+++ b/lib/ansible/modules/network/vyos/vyos_command.py
@@ -134,6 +134,7 @@
 import time
 
 from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils.pycompat24 import get_exception
 from ansible.module_utils.netcli import Conditional
 from ansible.module_utils.network_common import ComplexList
 from ansible.module_utils.six import string_types
@@ -185,7 +186,11 @@ def main():
     commands = parse_commands(module, warnings)
 
     wait_for = module.params['wait_for'] or list()
-    conditionals = [Conditional(c) for c in wait_for]
+    try:
+        conditionals = [Conditional(c) for c in wait_for]
+    except AttributeError:
+        exc = get_exception()
+        module.fail_json(msg=str(exc))
 
     retries = module.params['retries']
     interval = module.params['interval']


Test patch: