Repository: ansible/ansible

Issue:
Prompt for input as a task
##### ISSUE TYPE
- Feature Idea
##### SUMMARY

Adding a simple way to expect input for a role would make small, composable roles for simple tasks much easier. Of course, this has to be weighed against the expectation that many sessions will be run non-interactively.

It seems like there's a fairly straightforward way to do this: add a task that can prompt for a var, with a required default to use in a non-interactive session.

For better user experience, the input could be prompted for ahead of time of this task actually running, so that running a playbook with a large set of roles that each prompt for input would supply each prompt labeled with the target machine and task and then run each role with the prompt value substituted in.

For a potential example of use in a role:

```
ansible-do-a-github-thing/defaults/main.yml

---
github_username: ""
```

```
ansible-do-a-github-thing/tasks/main.yml

---
- name: Enter a Github username
  vars_prompt:
    name: github_username
    default: ""
  when: github_username == ""

- name: Authorize SSH keys from Github
  authorized_key:
    key: https://github.com/{{ github_username }}.keys
    user: "{{ ansible_user_id }}"
  when: github_username != ""
```

And using the role in a playbook would look like...

```
roles:
  - role: galaxy-username.do-a-github-thing
```

(Var prompted for if run interactively, or left blank if run non-interactively.)

```
roles:
  - role: galaxy-username.do-a-github-thing
    github_username: numberwang
```

(Var not prompted for.)



Discussion:
you can use pause module with a prompt and register the input.

@bcoca: Where is documentation on that? I've seen examples of it, but the [pause module documentation](http://docs.ansible.com/ansible/pause_module.html) doesn't even mention `register` or handling of input.

Another possible thought here, to better handle this kind of stuff in a standardized way: a new folder for `options`, that would effectively work the same as `defaults` except that each option would prompt for input at processing time (before roles are actually run). Prompts would get skipped over if an overriding value is supplied to the role.

For example, it could be something like:

```
ansible-do-a-github-thing/options/main.yml

---
- name: github_username
  prompt: Enter a Github username
  same_for_all_hosts: true
  default: ""
```

In a non-interactive session, this would be the same as having `github_username: ""` in `ansible-do-a-github-thing/defaults/main.yml`.

In an interactive session, if no value is supplied to the role for `github_username`, it would give the `Enter a Github username` prompt, labeled with the host name(s)/IP(s) and the `do-a-github-thing` role. `same_for_all_hosts` (or a similarly named parameter) would determine whether the prompt is only asked once for all hosts, or if it's asked once for every host and then supplied as a separate default value for each host.


Resolving patch:
diff --git a/lib/ansible/modules/utilities/logic/pause.py b/lib/ansible/modules/utilities/logic/pause.py
--- a/lib/ansible/modules/utilities/logic/pause.py
+++ b/lib/ansible/modules/utilities/logic/pause.py
@@ -61,3 +61,31 @@
 - pause:
     prompt: "Make sure org.foo.FooOverload exception is not present"
 '''
+
+RETURN = '''
+user_input:
+  description: User input from interactive console
+  returned: if no waiting time set
+  type: string
+  sample: Example user input
+start:
+  description: Time when started pausing
+  returned: always
+  type: string
+  sample: 2017-02-23 14:35:07.298862
+stop:
+  description: Time when ended pausing
+  returned: always
+  type: string
+  sample: 2017-02-23 14:35:09.552594
+delta:
+  description: Time paused in seconds
+  returned: always
+  type: string
+  sample: 2
+stdout:
+  description: Output of pause module
+  returned: always
+  type: string
+  sample: Paused for 0.04 minutes
+'''


Test patch: