Ansible prompt a variable in a task
There is the pause module to prompt for an input inside a task.
For example
- hosts: localhost
tasks:
- pause:
prompt: "Please enter the value for kernel.shmmax "
echo: yes
register: result
- set_fact:
shmmax: "{{ result.user_input }}"
- debug:
var: shmmax
gives (abridged)
TASK [pause]
[pause]
Please enter the value for kernel.shmmax :
[ok: [localhost]
TASK [set_fact]
ok: [localhost]
TASK [debug]
ok: [localhost] => {
"shmmax": "new_kernel.shmmax_value"
}
Notes
- This part of the code from the question can't work because there is no module in the task
- name: shmmax
prompt: " Please enter the value for kernel.shmmax "
private: false
Running such code would produce
ERROR! Syntax Error while loading YAML.
mapping values are not allowed in this context
- A variable can be used in any task after it has been prompted for, registered, and declared with set_fact.