Trying to use vars_prompt
on main.yml
task inside role but I get error:
tasks/main.yml file for role 'roleName' must contain a list of tasks
vars_prompt:
- name: 'variableName'
prompt: "Prompting User "
private: no
default: ''
- name: taskName
uri:
url: "{{ variableName }}"
register: response
ignore_errors: yes
- debug:
var: response
If I move the prompting to playbook main.yml
it works but I need to be able to do it within the task.
Thoughts?
If you want your playbook to prompt the user for certain input, add a 'vars_prompt' section. Prompting the user for variables lets you avoid recording sensitive data like passwords. In addition to security, prompts support flexibility.
To pass a value to nodes, use the --extra-vars or -e option while running the Ansible playbook, as seen below. This ensures you avoid accidental running of the playbook against hardcoded hosts.
Ansible uses a combination of a hosts file and a group_vars directory to pull variables per host group and run Ansible plays/tasks against hosts. group_vars/all is used to set variables that will be used for every host that Ansible is ran against.
What is Ansible pre_tasks? Ansible pretask is a conditional execution block that runs before running the play. It can be a task with some prerequisites check (or) validation.
vars_prompt
can only be defined on a play. A task list is so named because it can only consist of tasks; metadata like vars
, vars_prompt
, hosts
, etc. can only be set at the play level.
Consider avoiding the use of vars_prompt
if at all possible. If you need input from the user, have them provide it on the command line using -e variable=value
or in a file and using -e @somefile.yml
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With