Repository: ansible/ansible

Issue:
ansible su prompt issue
<!---
Please do not report issues/requests related to Ansible modules here !!

Report them to the appropriate modules-core or modules-extras project:
  - https://github.com/ansible/ansible-modules-core/issues
  - https://github.com/ansible/ansible-modules-extras/issues

Also verify first that your issue/request is not already reported in GitHub
-->
##### ISSUE TYPE

<!--- Pick one below and delete the rest: -->
- Feature Idea
##### COMPONENT NAME

<!--- Name of the plugin/task/feature -->

play_context.py
##### ANSIBLE VERSION

<!--- Paste verbatim output from “ansible --version” between quotes below -->

```
ansible 2.1.0.0
  config file = /home/yd_hzj/project/rango/ansible/ansible.cfg
  configured module search path = Default w/o overrides
```
##### CONFIGURATION

<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
##### 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.
-->

control machine: redhat7
targetmachine: SUSE Linux Enterprise Server 11 (x86_64), LANG=zh_CN.UTF-8
##### SUMMARY

<!--- Explain the problem briefly -->

Timeout (32s) waiting for privilege escalation prompt:
##### STEPS TO REPRODUCE

<!---
For bugs, show exactly how to reproduce the problem.
For new features, show how the feature would be used.
-->

ansible host1  -m raw -a 'uname -a' -u foo -b --become-method=su -k -K 

<!--- Paste example playbooks or commands between quotes below -->

```
[root@localhost ~]# ansible host1  -m raw -a 'uname -a' -u admin4A   -b --become-method=su -k -K 
SSH password: 
SU password[defaults to SSH password]: 
10.223.25.101 | FAILED | rc=0 >>
Timeout (32s) waiting for privilege escalation prompt: 
```

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

<!--- What did you expect to happen when running the steps above? -->

expect all things goes well
##### ACTUAL RESULTS

<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

ansible cannot match the su prompt, 
 i login to the remote host, type su command,  the prompt is chinese;
it's a new prompt, not in the SU_PROMPT_LOCALIZATIONS of play_context.py, 
looks like below, notice the prompt composed by "口令" + "：" + " " ,  the colon is not ":" ,

admin4A@inter4:~> su  -
口令： 

<!--- Paste verbatim command output between quotes below -->

```

```



Discussion:

Resolving patch:
diff --git a/lib/ansible/playbook/play_context.py b/lib/ansible/playbook/play_context.py
--- a/lib/ansible/playbook/play_context.py
+++ b/lib/ansible/playbook/play_context.py
@@ -117,6 +117,7 @@
     to_bytes('හස්පදය'),
     to_bytes('密码'),
     to_bytes('密碼'),
+    to_bytes('口令'),
 ]
 
 TASK_ATTRIBUTE_OVERRIDES = (
@@ -510,7 +511,10 @@ def make_become_cmd(self, cmd, executable=None):
 
                 # passing code ref to examine prompt as simple string comparisson isn't good enough with su
                 def detect_su_prompt(b_data):
-                    b_SU_PROMPT_LOCALIZATIONS_RE = re.compile(b"|".join([b'(\w+\'s )?' + x + b' ?: ?' for x in b_SU_PROMPT_LOCALIZATIONS]), flags=re.IGNORECASE)
+                    b_password_string = b"|".join([b'(\w+\'s )?' + x for x in b_SU_PROMPT_LOCALIZATIONS])
+                    # Colon or unicode fullwidth colon
+                    b_password_string = b_password_string + to_bytes(u' ?(:|：) ?')
+                    b_SU_PROMPT_LOCALIZATIONS_RE = re.compile(b_password_string, flags=re.IGNORECASE)
                     return bool(b_SU_PROMPT_LOCALIZATIONS_RE.match(b_data))
                 prompt = detect_su_prompt
 


Test patch: