Repository: ansible/ansible-modules-core

Issue:
junos_command: ValueError: need more than 1 value to unpack
##### ISSUE TYPE
- Bug Report
##### COMPONENT NAME

junos_command
##### ANSIBLE VERSION

```
ansible 2.2.0 (devel eb33ed4219) last updated 2016/09/27 09:18:44 (GMT +100)
  lib/ansible/modules/core: (devel c03697c81e) last updated 2016/09/27 09:18:49 (GMT +100)
  lib/ansible/modules/extras: (devel 119bc466be) last updated 2016/09/27 09:18:51 (GMT +100)
```

plus the following patch

```
diff --git a/lib/ansible/module_utils/junos.py b/lib/ansible/module_utils/junos.py
index 9cf36da..d3e3cb2 100644
--- a/lib/ansible/module_utils/junos.py
+++ b/lib/ansible/module_utils/junos.py
@@ -171,7 +171,7 @@ class Netconf(object):
             return ele

     def load_config(self, config, commit=False, replace=False, confirm=None,
-                    comment=None, config_format='text'):
+                    comment=None, config_format='text', **kwargs):

         if replace:
             merge = False
```
##### CONFIGURATION
##### OS / ENVIRONMENT
##### SUMMARY

Issue may need fixing in `module_utils/netcli.py`, though I'm triggering it from `junos_command`, so raising it in ansible-modules-core.
##### STEPS TO REPRODUCE

``` yaml
- name: test gt operator
  junos_command:
    commands:
      - show version
      - show interfaces fxp0
    format: xml
    wait_for:
      - "stdout[1]['interface-information']['physical-interface'].mtu[0]"
    provider: "{{ netconf }}"
  register: result

```
##### EXPECTED RESULTS
##### ACTUAL RESULTS

``` yaml
TASK [test_junos_command : test gt operator] ***********************************
task path: /home/johnb/git/ansible-inc/test-junos/roles/test_junos_command/tests/netconf_xml/greaterthan.yaml:4
Using module file /home/johnb/git/ansible-inc/ansible/lib/ansible/modules/core/network/junos/junos_command.py
<vsrx01> ESTABLISH LOCAL CONNECTION FOR USER: johnb
<vsrx01> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1475001874.51-177586194093154 `" && echo ansible-tmp-1475001874.51-177586194093154="` echo $HOME/.ansible/tmp/ansible-tmp-1475001874.51-177586194093154 `" ) && sleep 0'
<vsrx01> PUT /tmp/tmpbDvPHR TO /home/johnb/.ansible/tmp/ansible-tmp-1475001874.51-177586194093154/junos_command.py
<vsrx01> EXEC /bin/sh -c 'chmod u+x /home/johnb/.ansible/tmp/ansible-tmp-1475001874.51-177586194093154/ /home/johnb/.ansible/tmp/ansible-tmp-1475001874.51-177586194093154/junos_command.py && sleep 0'
<vsrx01> EXEC /bin/sh -c 'python /home/johnb/.ansible/tmp/ansible-tmp-1475001874.51-177586194093154/junos_command.py; rm -rf "/home/johnb/.ansible/tmp/ansible-tmp-1475001874.51-177586194093154/" > /dev/null 2>&1 && sleep 0'
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_rnv3rr/ansible_module_junos_command.py", line 304, in <module>
    main()
  File "/tmp/ansible_rnv3rr/ansible_module_junos_command.py", line 269, in main
    runner.add_conditional(item)
  File "/tmp/ansible_rnv3rr/ansible_modlib.zip/ansible/module_utils/netcli.py", line 153, in add_conditional
  File "/tmp/ansible_rnv3rr/ansible_modlib.zip/ansible/module_utils/netcli.py", line 195, in __init__
ValueError: need more than 1 value to unpack

fatal: [vsrx01]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_name": "junos_command"
    }, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_rnv3rr/ansible_module_junos_command.py\", line 304, in <module>\n    main()\n  File \"/tmp/ansible_rnv3rr/ansible_module_junos_command.py\", line 269, in main\n    runner.add_conditional(item)\n  File \"/tmp/ansible_rnv3rr/ansible_modlib.zip/ansible/module_utils/netcli.py\", line 153, in add_conditional\n  File \"/tmp/ansible_rnv3rr/ansible_modlib.zip/ansible/module_utils/netcli.py\", line 195, in __init__\nValueError: need more than 1 value to unpack\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE"
}
```



Discussion:

Resolving patch:
diff --git a/network/junos/junos_command.py b/network/junos/junos_command.py
--- a/network/junos/junos_command.py
+++ b/network/junos/junos_command.py
@@ -263,8 +263,12 @@ def main():
                 exc = get_exception()
                 warnings.append('duplicate command detected: %s' % cmd)
 
-    for item in conditionals:
-        runner.add_conditional(item)
+    try:
+        for item in conditionals:
+            runner.add_conditional(item)
+    except (ValueError, AttributeError):
+        exc = get_exception()
+        module.fail_json(msg=str(exc))
 
     runner.retries = module.params['retries']
     runner.interval = module.params['interval']


Test patch: