+

Search Tips   |   Advanced Search

Interactive input: prompts

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. For example, if you use one playbook across multiple software releases, you could prompt for the particular release version.

Here is a most basic example:

The user input is hidden by default but it can be made visible by setting private: no.

Prompts for individual vars_prompt variables will be skipped for any variable that is already defined through the command line --extra-vars option, or when running from a non-interactive session (such as cron or Ansible Tower). See Defining variables at runtime.

If you have a variable that changes infrequently, you can provide a default value that can be overridden:


Encrypting values supplied by vars_prompt

You can encrypt the entered value so you can use it, for instance, with the user module to define a password:

If you have Passlib installed, you can use any crypt scheme the library supports:

The only parameters accepted are 'salt' or 'salt_size'. You can use your own salt by defining 'salt', or have one generated automatically using 'salt_size'. By default Ansible generates a salt of size 8.

If you do not have Passlib installed, Ansible uses the crypt library as a fallback. Ansible supports at most four crypt schemes, depending on your platform at most the following crypt schemes are supported:


Allowing special characters in vars_prompt values

Some special characters, such as { and % can create templating errors. If you need to accept special characters, use the unsafe option:


See also

Intro to playbooks

An introduction to playbooks

Conditionals

Conditional statements in playbooks

Using Variables

All about variables

User Mailing List

Have a question? Stop by the google group!

irc.freenode.net

#ansible IRC chat channel

Next Previous