mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #14317 from resmo/feature/fail_on_missing_params
module_utils/basic: add generic method for checking for missing param…
This commit is contained in:
commit
1aaf5a399c
1 changed files with 35 additions and 22 deletions
|
@ -1597,6 +1597,19 @@ class AnsibleModule(object):
|
||||||
print(self.jsonify(kwargs))
|
print(self.jsonify(kwargs))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
def fail_on_missing_params(self, required_params=None):
|
||||||
|
''' This is for checking for required params when we can not check via argspec because we
|
||||||
|
need more information than is simply given in the argspec.
|
||||||
|
'''
|
||||||
|
if not required_params:
|
||||||
|
return
|
||||||
|
missing_params = []
|
||||||
|
for required_param in required_params:
|
||||||
|
if not self.params.get(required_param):
|
||||||
|
missing_params.append(required_param)
|
||||||
|
if missing_params:
|
||||||
|
self.fail_json(msg="missing required arguments: %s" % ','.join(missing_params))
|
||||||
|
|
||||||
def digest_from_file(self, filename, algorithm):
|
def digest_from_file(self, filename, algorithm):
|
||||||
''' Return hex digest of local file for a digest_method specified by name, or None if file is not present. '''
|
''' Return hex digest of local file for a digest_method specified by name, or None if file is not present. '''
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
|
|
Loading…
Add table
Reference in a new issue