Ask for variable value if variable not defined.

Hi,

Have question whether is possible (ansible 1.4.2 >) setup prompt for volue for variable in variable is not defined.

For example:
First run of playbook:

  • variable is not defined
  • ask for value
  • task write value of variable to some ansible vars file

… Do other tasks…

Next run of playbook:

  • variable is read from ansible vars file
  • no prompt for value

… Do other tasks …

Tried find this in ansible help, but so far no luck.

Best regards,
Marcin Praczko

There’s no mechanism for this.

vars_prompt always prompts for the variable.

The following is pseudo code, parts of it may not be entirely correct.
But the real trick is to use when.

Hi Micheal,
Do you have any advice for it? It doesn’t accept when condition.
Best.

As politely as possible… Please don’t share made-up syntax on this list, it confuses everyone :slight_smile:

Nope, it doesn’t do this. Simple as that :slight_smile:

I’d suggest setting a role default instead, or putting a good default value in group_vars/all, and you can override that on the CLI with “-e”.

vars_prompt in Ansible is not usually a good idea as it limits the ability of someone to automate a workflow in Ansible, since it’s interactive.

Hi,
You’re right, i was using default variables and extra parameters to override but i thought that maybe i can also use it for basic system playbooks.
Thanks.