Repository: ansible/ansible

Issue:
'prompt' of pause module does not display if seconds/minutes passed
##### ISSUE TYPE
 - Bug Report
 - Documentation Report

##### COMPONENT NAME
pause

##### ANSIBLE VERSION
```
ansible 2.4.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Aug  4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
```

##### CONFIGURATION

```
DEFAULT_ROLES_PATH(/etc/ansible/ansible.cfg) = [u'/etc/ansible/roles', u'/usr/share/ansible/roles']
```

##### OS / ENVIRONMENT

CentOS 7

##### SUMMARY

According to the docs, the pause module supports three arguments:

```
minutes | no |   |   | A positive number of minutes to pause for.
prompt | no |   |   | Optional text to use for the prompt message.
seconds | no |   |   | A positive number of seconds to pause for.
```

The assumption would be that 'prompt' is always honored. It is not.
(This could be a bug in the module docs)

##### STEPS TO REPRODUCE
```
ansible -m pause -a "seconds=5 prompt='yo a prompt'" localhost
```

##### EXPECTED RESULTS
```
yo a prompt
(ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort)
localhost | SUCCESS => {
    "changed": false, 
...
```

##### ACTUAL RESULTS
```
Pausing for 5 seconds
(ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort)
localhost | SUCCESS => {
    "changed": false, 
...
```



Discussion:
Files identified in the description:
* [lib/ansible/modules/utilities/logic/pause.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/utilities/logic/pause.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 @tbielawa
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
It behaves properly in `devel`:

```
Pausing for 5 seconds
(ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort)
[pause]
yo a prompt:
```

I'll work on backporting a fix to `stable-2.4`.

Resolving patch:
diff --git a/lib/ansible/plugins/action/pause.py b/lib/ansible/plugins/action/pause.py
--- a/lib/ansible/plugins/action/pause.py
+++ b/lib/ansible/plugins/action/pause.py
@@ -70,12 +70,20 @@ def run(self, tmp=None, task_vars=None):
             delta=None,
         ))
 
-        # Is 'args' empty, then this is the default prompted pause
-        if self._task.args is None or len(self._task.args.keys()) == 0:
-            prompt = "[%s]\nPress enter to continue:" % self._task.get_name().strip()
+        if not set(self._task.args.keys()) <= set(self.PAUSE_TYPES):
+            result['failed'] = True
+            result['msg'] = "Invalid argument given. Must be one of: %s" % ", ".join(x for x in self.PAUSE_TYPES if x != '')
+            return result
+
+        # Is 'prompt' a key in 'args'?
+        if 'prompt' in self._task.args:
+            prompt = "[%s]\n%s:" % (self._task.get_name().strip(), self._task.args['prompt'])
+        else:
+            # If no custom prompt is specified, set a default prompt
+            prompt = "[%s]\n%s:" % (self._task.get_name().strip(), 'Press enter to continue')
 
         # Are 'minutes' or 'seconds' keys that exist in 'args'?
-        elif 'minutes' in self._task.args or 'seconds' in self._task.args:
+        if 'minutes' in self._task.args or 'seconds' in self._task.args:
             try:
                 if 'minutes' in self._task.args:
                     # The time() command operates in seconds so we need to
@@ -90,16 +98,6 @@ def run(self, tmp=None, task_vars=None):
                 result['msg'] = u"non-integer value given for prompt duration:\n%s" % to_text(e)
                 return result
 
-        # Is 'prompt' a key in 'args'?
-        elif 'prompt' in self._task.args:
-            prompt = "[%s]\n%s:" % (self._task.get_name().strip(), self._task.args['prompt'])
-
-        else:
-            # I have no idea what you're trying to do. But it's so wrong.
-            result['failed'] = True
-            result['msg'] = "invalid pause type given. must be one of: %s" % ", ".join(self.PAUSE_TYPES)
-            return result
-
         ########################################################################
         # Begin the hard work!
 
@@ -119,6 +117,11 @@ def run(self, tmp=None, task_vars=None):
                 # show the prompt
                 display.display("Pausing for %d seconds" % seconds)
                 display.display("(ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort)\r"),
+
+                # show the prompt specified in the task
+                if 'prompt' in self._task.args:
+                    display.display(prompt)
+
             else:
                 display.display(prompt)
 


Test patch: