Merge pull request #3649 from dekked/extra-vars-from-file

Extra vars from file
pull/3685/merge
Michael DeHaan 11 years ago
commit d039fbe200

@ -94,10 +94,20 @@ def main(args):
options.ask_sudo_pass = options.ask_sudo_pass or C.DEFAULT_ASK_SUDO_PASS options.ask_sudo_pass = options.ask_sudo_pass or C.DEFAULT_ASK_SUDO_PASS
( sshpass, sudopass ) = utils.ask_passwords(ask_pass=options.ask_pass, ask_sudo_pass=options.ask_sudo_pass) ( sshpass, sudopass ) = utils.ask_passwords(ask_pass=options.ask_pass, ask_sudo_pass=options.ask_sudo_pass)
options.sudo_user = options.sudo_user or C.DEFAULT_SUDO_USER options.sudo_user = options.sudo_user or C.DEFAULT_SUDO_USER
if options.extra_vars and options.extra_vars[0] in '[{':
extra_vars = {}
if options.extra_vars:
if options.extra_vars.startswith("@"):
# Argument is a JSON file
with open(options.extra_vars[1:]) as fd:
extra_vars = utils.json_loads(fd.read())
elif options.extra_vars[0] in '[{':
# Arguments as JSON
extra_vars = utils.json_loads(options.extra_vars) extra_vars = utils.json_loads(options.extra_vars)
else: else:
# Arguments as Key-value
extra_vars = utils.parse_kv(options.extra_vars) extra_vars = utils.parse_kv(options.extra_vars)
only_tags = options.tags.split(",") only_tags = options.tags.split(",")
skip_tags = options.skip_tags skip_tags = options.skip_tags
if options.skip_tags is not None: if options.skip_tags is not None:

@ -289,6 +289,9 @@ As of Ansible 1.2, you can also pass in extra vars as quoted JSON, like so::
The key=value form is obviously simpler, but it's there if you need it! The key=value form is obviously simpler, but it's there if you need it!
As of Ansible 1.3, extra vars can be loaded from a JSON file with the "@" syntax::
--extra-vars "@some_file.json"
Conditional Execution Conditional Execution
````````````````````` `````````````````````

Loading…
Cancel
Save