5

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?

itms
  • 183
  • 2
  • 14
  • Declaration of "tasks:" before "- name: taskName" is missing. – Vladimir Botka May 15 '19 at 22:28
  • This is invalid YAML, you cannot have both key-value pairs and sequence items at under the same node (i.e. the root level). Please update your post with the corrected YAML. – Anthon May 15 '19 at 22:54

1 Answers1

5

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.

larsks
  • 277,717
  • 41
  • 399
  • 399