mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Parse --extra-vars as YAML (which includes JSON)
This commit is contained in:
parent
dfbe1132d2
commit
8c9f84f6f8
1 changed files with 5 additions and 6 deletions
|
@ -62,7 +62,7 @@ def main(args):
|
||||||
diff_opts=True
|
diff_opts=True
|
||||||
)
|
)
|
||||||
parser.add_option('-e', '--extra-vars', dest="extra_vars", action="append",
|
parser.add_option('-e', '--extra-vars', dest="extra_vars", action="append",
|
||||||
help="set additional variables as key=value or JSON", default=[])
|
help="set additional variables as key=value or YAML/JSON", default=[])
|
||||||
parser.add_option('-t', '--tags', dest='tags', default='all',
|
parser.add_option('-t', '--tags', dest='tags', default='all',
|
||||||
help="only run plays and tasks tagged with these values")
|
help="only run plays and tasks tagged with these values")
|
||||||
parser.add_option('--skip-tags', dest='skip_tags',
|
parser.add_option('--skip-tags', dest='skip_tags',
|
||||||
|
@ -101,12 +101,11 @@ def main(args):
|
||||||
extra_vars = {}
|
extra_vars = {}
|
||||||
for extra_vars_opt in options.extra_vars:
|
for extra_vars_opt in options.extra_vars:
|
||||||
if extra_vars_opt.startswith("@"):
|
if extra_vars_opt.startswith("@"):
|
||||||
# Argument is a JSON file
|
# Argument is a YAML file (JSON is a subset of YAML)
|
||||||
with open(extra_vars_opt[1:]) as fd:
|
extra_vars = utils.combine_vars(extra_vars, utils.parse_yaml_from_file(extra_vars_opt[1:]))
|
||||||
extra_vars = utils.combine_vars(extra_vars, utils.json_loads(fd.read()))
|
|
||||||
elif extra_vars_opt[0] in '[{':
|
elif extra_vars_opt[0] in '[{':
|
||||||
# Arguments as JSON
|
# Arguments as YAML
|
||||||
extra_vars = utils.combine_vars(extra_vars, utils.json_loads(extra_vars_opt))
|
extra_vars = utils.combine_vars(extra_vars, utils.parse_yaml(extra_vars_opt))
|
||||||
else:
|
else:
|
||||||
# Arguments as Key-value
|
# Arguments as Key-value
|
||||||
extra_vars = utils.combine_vars(extra_vars, utils.parse_kv(extra_vars_opt))
|
extra_vars = utils.combine_vars(extra_vars, utils.parse_kv(extra_vars_opt))
|
||||||
|
|
Loading…
Reference in a new issue