summaryrefslogtreecommitdiff
path: root/lib/ansible
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2021-09-01 12:36:25 -0400
committerGitHub <noreply@github.com>2021-09-01 11:36:25 -0500
commit8c105c0f61b2ef5a97d421f0788aca2ad0a68904 (patch)
tree9db104d94afa626380469619395e48b5c9372353 /lib/ansible
parent8b34aab73278cddea8a84f91f0dacf0d89c93506 (diff)
downloadansible-8c105c0f61b2ef5a97d421f0788aca2ad0a68904.tar.gz
validate_args_spec, use combine vars and in precedence (#75471) (#75602)
* combine vars and in correct precedence * add examples (cherry picked from commit 2462ec74a06a61fe548891844e998f7b747a7be7)
Diffstat (limited to 'lib/ansible')
-rw-r--r--lib/ansible/modules/validate_argument_spec.py33
-rw-r--r--lib/ansible/plugins/action/validate_argument_spec.py5
2 files changed, 35 insertions, 3 deletions
diff --git a/lib/ansible/modules/validate_argument_spec.py b/lib/ansible/modules/validate_argument_spec.py
index 79f43c0ed9..76942aa6e9 100644
--- a/lib/ansible/modules/validate_argument_spec.py
+++ b/lib/ansible/modules/validate_argument_spec.py
@@ -28,6 +28,39 @@ author:
'''
EXAMPLES = r'''
+- name: verify vars needed for this task file are present when included
+ validate_argument_spec:
+ argument_spec: '{{required_data}}'
+ vars:
+ required_data:
+ # unlike spec file, just put the options in directly
+ stuff:
+ description: stuff
+ type: str
+ choices: ['who', 'knows', 'what']
+ default: what
+ but:
+ description: i guess we need one
+ type: str
+ required: true
+
+
+- name: verify vars needed for this task file are present when included, with spec from a spec file
+ validate_argument_spec:
+ argument_spec: "{{lookup('file', 'myargspec.yml')['specname']['options']}}"
+
+
+- name: verify vars needed for next include and not from inside it, also with params i'll only define there
+ block:
+ - validate_argument_spec:
+ argument_spec: "{{lookup('file', 'nakedoptions.yml'}}"
+ provided_arguments:
+ but: "that i can define on the include itself, like in it's `vars:` keyword"
+
+ - name: the include itself
+ vars:
+ stuff: knows
+ but: nobuts!
'''
RETURN = r'''
diff --git a/lib/ansible/plugins/action/validate_argument_spec.py b/lib/ansible/plugins/action/validate_argument_spec.py
index 9ad0a46df6..e73729e050 100644
--- a/lib/ansible/plugins/action/validate_argument_spec.py
+++ b/lib/ansible/plugins/action/validate_argument_spec.py
@@ -9,6 +9,7 @@ from ansible.plugins.action import ActionBase
from ansible.module_utils.six import iteritems, string_types
from ansible.module_utils.common.arg_spec import ArgumentSpecValidator
from ansible.module_utils.errors import AnsibleValidationErrorMultiple
+from ansible.utils.vars import combine_vars
class ActionModule(ActionBase):
@@ -77,10 +78,8 @@ class ActionModule(ActionBase):
raise AnsibleError('Incorrect type for provided_arguments, expected dict and got %s' % type(provided_arguments))
args_from_vars = self.get_args_from_task_vars(argument_spec_data, task_vars)
- provided_arguments.update(args_from_vars)
-
validator = ArgumentSpecValidator(argument_spec_data)
- validation_result = validator.validate(provided_arguments)
+ validation_result = validator.validate(combine_vars(args_from_vars, provided_arguments))
if validation_result.error_messages:
result['failed'] = True