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:
parent
c717934b7e
commit
ee5f12cd40
2 changed files with 22 additions and 31 deletions
|
@ -16,25 +16,22 @@
|
||||||
# ansible-playbook foo.yml --extra-vars="foo=100 bar=101"
|
# ansible-playbook foo.yml --extra-vars="foo=100 bar=101"
|
||||||
# or through external inventory scripts (see online API docs)
|
# or through external inventory scripts (see online API docs)
|
||||||
|
|
||||||
# prompted variables are a list of variable names and a description
|
# here's basic mode prompting. Specify a hash of variable names and a prompt for
|
||||||
# that will be presented to the user, or a list of variable dictionaries
|
# each.
|
||||||
# with the following accepted keys / value types:
|
#
|
||||||
# 'name' / text
|
# vars_prompt:
|
||||||
# 'prompt' / text (optional)
|
# release_version: "product release version"
|
||||||
# 'private' / boolean (optional)
|
|
||||||
|
# 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
|
||||||
|
|
||||||
# prompted variables as key/value pairs:
|
|
||||||
vars_prompt:
|
vars_prompt:
|
||||||
release_version: "product release version"
|
- name: "some_password"
|
||||||
|
prompt: "Enter password"
|
||||||
# prompted variables as a list of variable dictionaries:
|
private: True
|
||||||
# vars_prompt:
|
- name: "release_version"
|
||||||
# - name: "some_password"
|
prompt: "Product release version"
|
||||||
# prompt: "Enter password: "
|
private: False
|
||||||
# private: True
|
|
||||||
# - name: "release_version"
|
|
||||||
# prompt: "Product release version: "
|
|
||||||
# private: False
|
|
||||||
|
|
||||||
# this is just a simple example to show that vars_prompt works, but
|
# 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
|
# you might ask for a tag to use with the git module or perhaps
|
||||||
|
|
|
@ -157,24 +157,18 @@ class Play(object):
|
||||||
|
|
||||||
if type(self.vars_prompt) == list:
|
if type(self.vars_prompt) == list:
|
||||||
for var in self.vars_prompt:
|
for var in self.vars_prompt:
|
||||||
try:
|
if not 'name' in var:
|
||||||
vname = var.get("name")
|
raise errors.AnsibleError("'vars_prompt' item is missing 'name:'")
|
||||||
except KeyError:
|
vname = var['name']
|
||||||
raise errors.AnsibleError("A variable dictionary in 'vars_prompt' must always have a 'name' key")
|
prompt = "%s: " % var.get("prompt", vname)
|
||||||
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)
|
|
||||||
private = var.get("private", True)
|
private = var.get("private", True)
|
||||||
|
|
||||||
vars[vname] = self.playbook.callbacks.on_vars_prompt(vname, private, prompt)
|
vars[vname] = self.playbook.callbacks.on_vars_prompt(vname, private, prompt)
|
||||||
elif type(self.vars_prompt) == dict:
|
elif type(self.vars_prompt) == dict:
|
||||||
for vname in self.vars_prompt:
|
for (vname, prompt) in self.vars_prompt.iteritems():
|
||||||
vars[vname] = self.playbook.callbacks.on_vars_prompt(vname)
|
prompt = "%s: " % prompt
|
||||||
|
vars[vname] = self.playbook.callbacks.on_vars_prompt(vname, False, prompt)
|
||||||
else:
|
else:
|
||||||
raise errors.AnsibleError("'vars_prompt' section must contain either key/value pairs or a list"
|
raise errors.AnsibleError("'vars_prompt' section is malformed, see docs")
|
||||||
" of variable dictionaries (see docs for accepted dictionary keys)")
|
|
||||||
|
|
||||||
results = self.playbook.extra_vars.copy()
|
results = self.playbook.extra_vars.copy()
|
||||||
results.update(vars)
|
results.update(vars)
|
||||||
|
|
Loading…
Reference in a new issue