From 21d2069a749c885b591298d1743792646c4aad94 Mon Sep 17 00:00:00 2001 From: Alek Storm Date: Wed, 21 Aug 2013 17:12:42 -0700 Subject: [PATCH] Support multiple --extra-vars flags --- bin/ansible-playbook | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bin/ansible-playbook b/bin/ansible-playbook index 818e50cf77d..78e5ca40bcd 100755 --- a/bin/ansible-playbook +++ b/bin/ansible-playbook @@ -61,8 +61,8 @@ def main(args): check_opts=True, diff_opts=True ) - parser.add_option('-e', '--extra-vars', dest="extra_vars", default=None, - help="set additional key=value variables from the CLI") + parser.add_option('-e', '--extra-vars', dest="extra_vars", action="append", + help="set additional variables as key=value or JSON", default=[]) parser.add_option('-t', '--tags', dest='tags', default='all', help="only run plays and tasks tagged with these values") parser.add_option('--skip-tags', dest='skip_tags', @@ -99,17 +99,17 @@ def main(args): options.sudo_user = options.sudo_user or C.DEFAULT_SUDO_USER extra_vars = {} - if options.extra_vars: - if options.extra_vars.startswith("@"): + for extra_vars_opt in options.extra_vars: + if extra_vars_opt.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 '[{': + with open(extra_vars_opt[1:]) as fd: + extra_vars = utils.combine_vars(extra_vars, utils.json_loads(fd.read())) + elif extra_vars_opt[0] in '[{': # Arguments as JSON - extra_vars = utils.json_loads(options.extra_vars) + extra_vars = utils.combine_vars(extra_vars, utils.json_loads(extra_vars_opt)) else: # Arguments as Key-value - extra_vars = utils.parse_kv(options.extra_vars) + extra_vars = utils.combine_vars(extra_vars, utils.parse_kv(extra_vars_opt)) only_tags = options.tags.split(",") skip_tags = options.skip_tags