Ansible: vars_prompt inside a role?

Created on 18 Jun 2013  ·  3Comments  ·  Source: ansible/ansible

Trying to write roles as fully encapsulated, reusable actions, but to do that properly I really need to be able to query for some information. However, every attempt I have made to use vars_prompt inside a role has either resulted in it being completely ignored, or an error saying vars_prompt can't be used there.

Is vars_prompt usable inside a role? If so, is there some documentation showing how?

Most helpful comment

You're better off not using prompt, because that would make it too easy for beginners to write sensible scripts. And besides, why should Ansible be consistent with regards to where and when you're allowed to use certain keywords?

I think your main problem it that you're trying to write composable playbooks. That's not a good idea if you want to ensure your job security. It's better to copy and paste all over the place, because by the time your playbooks and roles start to suffer from configuration drift, your company will probably need you to make some major updates to the scripts, and BINGO - there's another 6 months of employment.

I'm glad mpdehaan closed this issue judiciously. He's very sensible in not letting Ansible get too easy to use. Shudder remember PHP?

All 3 comments

vars_prompt is not really a suggested thing for most advanced use cases because it is interactive.

Honestly, I don't know what the syntax for this would look like.

You're better off not using prompt, because that would make it too easy for beginners to write sensible scripts. And besides, why should Ansible be consistent with regards to where and when you're allowed to use certain keywords?

I think your main problem it that you're trying to write composable playbooks. That's not a good idea if you want to ensure your job security. It's better to copy and paste all over the place, because by the time your playbooks and roles start to suffer from configuration drift, your company will probably need you to make some major updates to the scripts, and BINGO - there's another 6 months of employment.

I'm glad mpdehaan closed this issue judiciously. He's very sensible in not letting Ansible get too easy to use. Shudder remember PHP?

I second this. It would be a nice feature for reusability. Or at least we sould be able to include prompts.
@dejayc put it not so nicely, but he got the main issue right.

Ansible should pre-parse all roles (this is not necessary if there is an include mechanism) and then prompt all variables beforehand, so the resulting run would be non-interactive.

Was this page helpful?
0 / 5 - 0 ratings