Validate against ansible variables on ad hoc launch

Share code between this check for ad hoc and JT callback
This commit is contained in:
AlanCoding
2017-10-05 12:14:05 -04:00
parent 02e3f45422
commit eacbeef660
5 changed files with 40 additions and 13 deletions
+6 -3
View File
@@ -56,7 +56,7 @@ from awx.main.utils import (get_ansible_version, get_ssh_version, decrypt_field,
check_proot_installed, build_proot_temp_dir, get_licenser,
wrap_args_with_proot, get_system_task_capacity, OutputEventFilter,
parse_yaml_or_json, ignore_inventory_computed_fields, ignore_inventory_group_removal,
get_type_for_model)
get_type_for_model, extract_ansible_vars)
from awx.main.utils.reload import restart_local_services, stop_local_services
from awx.main.utils.handlers import configure_external_logger
from awx.main.consumers import emit_channel_notification
@@ -2139,8 +2139,11 @@ class RunAdHocCommand(BaseTask):
args.append('-%s' % ('v' * min(5, ad_hoc_command.verbosity)))
if ad_hoc_command.extra_vars_dict:
if ad_hoc_command.extra_vars_dict.get('ansible_connection') == 'local':
raise ValueError(_("unable to use the `local` connection plugin with ad hoc commands"))
redacted_extra_vars, removed_vars = extract_ansible_vars(ad_hoc_command.extra_vars_dict)
if removed_vars:
raise ValueError(_(
"unable to use {} variables with ad hoc commands"
).format(",".format(removed_vars)))
args.extend(['-e', json.dumps(ad_hoc_command.extra_vars_dict)])