Prompting in Ansible Playbook

From bib. source

[…] you may require the user to enter the value of a variable that will be used in the playbook. […] and if there’s no other way this information can be configured (e.g. using environment variables, inventory variables, etc.), use vars_prompt.

That is, vars_prompt is an Ansible YAML field and module for the Ansible playbook that takes a list of entries providing prompt messages and name fields that act as variable names for the users’ responses to the provided prompt(s) (Geerling 2023, 117).

The vars_prompt module’s options and fields are as such (Geerling 2023, 117):

  • private: hides user’s input from the command line interface
  • default: sets a default value for the variable
  • encrypt / confirm / salt_size: values necessary to verification or encryption of the given variable’s value

An example of using vars_prompt (Geerling 2023, 117):

---
- hosts: all
 
  vars_prompt:
    - name: share_user
      prompt: "What is your network username?"
    - name: share_pass
      prompt: "What is your network password?"
      private: yes

environment_variable environment_variables configuration_management modules inventory_file command_line command_lines command_line_interface command_line_interfaces variables values prompts message option field YAML_Aint_Markup_Language Yet_Another_Markup_Language


bibliography

  • “Ansible Playbooks - Beyond the Basics.” In Ansible for DevOps: Server and Configuration Management for Humans, 2nd ed., 84–122. Leanpub, 2023.