From 6e857468a222e3f1481b5da9b1372ccdf8099082 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Sun, 17 Sep 2017 12:25:56 -0400 Subject: [PATCH] expose soem options as vars (#30379) * expose some useful options as vars for plays and plugins --- lib/ansible/utils/vars.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/ansible/utils/vars.py b/lib/ansible/utils/vars.py index 3d0ce388bb8..7270e79599f 100644 --- a/lib/ansible/utils/vars.py +++ b/lib/ansible/utils/vars.py @@ -144,12 +144,19 @@ def load_extra_vars(loader, options): def load_options_vars(options, version): - options_vars = {} - # For now only return check mode, but we can easily return more - # options if we need variables for them - if hasattr(options, 'check'): - options_vars['ansible_check_mode'] = options.check - options_vars['ansible_version'] = version + + options_vars = {'ansible_version': version} + aliases = {'check': 'check_mode', + 'diff': 'diff_mode', + 'inventory': 'inventory_sources', + 'subset': 'limit', + 'tags': 'run_tags'} + + for attr in ('check', 'diff', 'forks', 'inventory', 'skip_tags', 'subset', 'tags'): + opt = getattr(options, attr, None) + if opt is not None: + options_vars['ansible_%s' % aliases.get(attr, attr)] = opt + return options_vars