Repository: ansible/ansible

Issue:
Stack trace with 1.9 rc using Vagrant's ansible integration
Ansible version: 

```
ansible 1.9.0 (detached HEAD bce4bb2ce2) last updated 2015/03/11 09:38:29 (GMT -700)
  lib/ansible/modules/core: (detached HEAD 0206cc8133) last updated 2015/03/11 09:38:37 (GMT -700)
  lib/ansible/modules/extras: (detached HEAD 4c0b7cb55a) last updated 2015/03/11 09:38:39 (GMT -700)
  v2/ansible/modules/core: (detached HEAD 34784b7a61) last updated 2015/03/11 09:38:40 (GMT -700)
  v2/ansible/modules/extras: (detached HEAD 46e316a20a) last updated 2015/03/11 09:38:42 (GMT -700)
  configured module search path = None
```

Stack trace:

```
fatal: [shared-testbox] => Traceback (most recent call last):
  File "/home/xxx/src/ansible/lib/ansible/runner/__init__.py", line 582, in _executor
    exec_rc = self._executor_internal(host, new_stdin)
  File "/home/xxx/src/ansible/lib/ansible/runner/__init__.py", line 785, in _executor_internal
    return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)
  File "/home/xxx/src/ansible/lib/ansible/runner/__init__.py", line 1026, in _executor_internal_inner
    result = handler.run(conn, tmp, module_name, module_args, inject, complex_args)
  File "/home/xxx/src/ansible/lib/ansible/runner/action_plugins/normal.py", line 57, in run
    return self.runner._execute_module(conn, tmp, module_name, module_args, inject=inject, complex_args=complex_args)
  File "/home/xxx/src/ansible/lib/ansible/runner/__init__.py", line 547, in _execute_module
    res = self._low_level_exec_command(conn, cmd, tmp, become=self.become, sudoable=sudoable, in_data=in_data)
  File "/home/xxx/src/ansible/lib/ansible/runner/__init__.py", line 1163, in _low_level_exec_command
    in_data=in_data)
  File "/home/xxx/src/ansible/lib/ansible/runner/connection_plugins/ssh.py", line 362, in exec_command
    (returncode, stdout, stderr) = self._communicate(p, stdin, in_data, sudoable=sudoable, prompt=prompt)
  File "/home/xxx/src/ansible/lib/ansible/runner/connection_plugins/ssh.py", line 176, in _communicate
    elif stdout.endswith("%s\r\n%s" % (incorrect_password, prompt)):
UnboundLocalError: local variable 'incorrect_password' referenced before assignment
```



Discussion:

Resolving patch:
diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py
--- a/lib/ansible/constants.py
+++ b/lib/ansible/constants.py
@@ -137,7 +137,8 @@ def shell_expand_path(path):
 DEFAULT_LOG_PATH               = shell_expand_path(get_config(p, DEFAULTS, 'log_path',           'ANSIBLE_LOG_PATH', ''))
 
 #TODO: get rid of ternary chain mess
-BECOME_METHODS            = ['sudo','su','pbrun','runas','pfexec']
+BECOME_METHODS            = ['sudo','su','pbrun','pfexec','runas']
+BECOME_ERROR_STRINGS      = {'sudo': 'Sorry, try again.', 'su': 'Authentication failure', 'pbrun': '', 'pfexec': '', 'runas': ''}
 DEFAULT_BECOME            = get_config(p, 'privilege_escalation', 'become', 'ANSIBLE_BECOME',True if DEFAULT_SUDO or DEFAULT_SU else False, boolean=True)
 DEFAULT_BECOME_METHOD     = get_config(p, 'privilege_escalation', 'become_method', 'ANSIBLE_BECOME_METHOD','sudo' if DEFAULT_SUDO else 'su' if DEFAULT_SU else 'sudo' ).lower()
 DEFAULT_BECOME_USER       = get_config(p, 'privilege_escalation', 'become_user', 'ANSIBLE_BECOME_USER',DEFAULT_SUDO_USER if DEFAULT_SUDO else DEFAULT_SU_USER if DEFAULT_SU else 'root')
diff --git a/lib/ansible/runner/connection_plugins/ssh.py b/lib/ansible/runner/connection_plugins/ssh.py
--- a/lib/ansible/runner/connection_plugins/ssh.py
+++ b/lib/ansible/runner/connection_plugins/ssh.py
@@ -163,18 +163,17 @@ def _communicate(self, p, stdin, indata, sudoable=False, prompt=None):
 
             # fail early if the become password is wrong
             if self.runner.become and sudoable:
-                if self.runner.become_pass:
-                    incorrect_password = gettext.dgettext(
-                        "Privilege Escalation", "Sorry, try again.")
-                    if stdout.endswith("%s\r\n%s" % (incorrect_password,
-                                                     prompt)):
-                        raise errors.AnsibleError('Incorrect become password')
+                incorrect_password = gettext.dgettext(self.runner.become_method, C.BECOME_ERROR_STRINGS[self.runner.become_method])
 
                 if prompt:
+                    if self.runner.become_pass:
+                        if stdout.endswith("%s\r\n%s" % (incorrect_password, prompt)):
+                            raise errors.AnsibleError('Incorrect become password')
+
                     if stdout.endswith(prompt):
                         raise errors.AnsibleError('Missing become password')
                     elif stdout.endswith("%s\r\n%s" % (incorrect_password, prompt)):
-                        raise errors.AnsibleError('Incorrect becom password')
+                        raise errors.AnsibleError('Incorrect become password')
 
             if p.stdout in rfd:
                 dat = os.read(p.stdout.fileno(), 9000)


Test patch:
diff --git a/test/units/TestSynchronize.py b/test/units/TestSynchronize.py
--- a/test/units/TestSynchronize.py
+++ b/test/units/TestSynchronize.py
@@ -97,9 +97,9 @@ def test_synchronize_action_sudo(self):
         x.run(conn, "/tmp", "synchronize", "src=/tmp/foo dest=/tmp/bar", inject)
 
         assert runner.executed_inject['delegate_to'] == "127.0.0.1", "was not delegated to 127.0.0.1"
-        assert runner.executed_complex_args == {'dest':'root@el6.lab.net:/tmp/bar',
-                                                'src':'/tmp/foo',
-                                                'rsync_path':'"sudo rsync"'}, "wrong args used"
+        #assert runner.executed_complex_args == {'dest':'root@el6.lab.net:/tmp/bar',
+        #                                        'src':'/tmp/foo',
+        #                                        'rsync_path':'"sudo rsync"'}, "wrong args used"
         assert runner.become == True, "sudo was not reset to True"