1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Slight tweaks on vars_prompt upgrades

This commit is contained in:
Michael DeHaan 2012-07-27 19:00:29 -04:00
parent c717934b7e
commit ee5f12cd40
2 changed files with 22 additions and 31 deletions

View file

@ -16,25 +16,22 @@
# ansible-playbook foo.yml --extra-vars="foo=100 bar=101"
# or through external inventory scripts (see online API docs)
# prompted variables are a list of variable names and a description
# that will be presented to the user, or a list of variable dictionaries
# with the following accepted keys / value types:
# 'name' / text
# 'prompt' / text (optional)
# 'private' / boolean (optional)
# prompted variables as key/value pairs:
vars_prompt:
release_version: "product release version"
# prompted variables as a list of variable dictionaries:
# here's basic mode prompting. Specify a hash of variable names and a prompt for
# each.
#
# vars_prompt:
# - name: "some_password"
# prompt: "Enter password: "
# private: True
# - name: "release_version"
# prompt: "Product release version: "
# private: False
# release_version: "product release version"
# prompts can also be specified like this, allowing for hiding the prompt as
# entered. In the future, this may also be used to support crypted variables
vars_prompt:
- name: "some_password"
prompt: "Enter password"
private: True
- name: "release_version"
prompt: "Product release version"
private: False
# this is just a simple example to show that vars_prompt works, but
# you might ask for a tag to use with the git module or perhaps

View file

@ -157,24 +157,18 @@ class Play(object):
if type(self.vars_prompt) == list:
for var in self.vars_prompt:
try:
vname = var.get("name")
except KeyError:
raise errors.AnsibleError("A variable dictionary in 'vars_prompt' must always have a 'name' key")
if not ((vname[0].isalpha() or vname[0] == '_') and vname.replace('_','').isalnum()):
raise errors.AnsibleError("'%s' cannot be used as a variable name. Variable names must consist of"
" a letter or underscore, followed by a string of letters, numbers, and underscores"
% vname)
prompt = var.get("prompt", None)
if not 'name' in var:
raise errors.AnsibleError("'vars_prompt' item is missing 'name:'")
vname = var['name']
prompt = "%s: " % var.get("prompt", vname)
private = var.get("private", True)
vars[vname] = self.playbook.callbacks.on_vars_prompt(vname, private, prompt)
elif type(self.vars_prompt) == dict:
for vname in self.vars_prompt:
vars[vname] = self.playbook.callbacks.on_vars_prompt(vname)
for (vname, prompt) in self.vars_prompt.iteritems():
prompt = "%s: " % prompt
vars[vname] = self.playbook.callbacks.on_vars_prompt(vname, False, prompt)
else:
raise errors.AnsibleError("'vars_prompt' section must contain either key/value pairs or a list"
" of variable dictionaries (see docs for accepted dictionary keys)")
raise errors.AnsibleError("'vars_prompt' section is malformed, see docs")
results = self.playbook.extra_vars.copy()
results.update(vars)