1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

deploy_helper - changed in-code condition to required_if (#3104)

* changed in-code condition to required_if

* added changelog fragment
This commit is contained in:
Alexei Znamensky 2021-07-29 17:49:52 +12:00 committed by GitHub
parent 549dfaae64
commit cde9564163
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 12 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- deploy_helper - improved parameter checking by using standard Ansible construct (https://github.com/ansible-collections/community.general/pull/3104).

View file

@ -359,8 +359,6 @@ class DeployHelper(object):
self.module.fail_json(msg="%s exists but is not a symbolic link" % path) self.module.fail_json(msg="%s exists but is not a symbolic link" % path)
def create_link(self, source, link_name): def create_link(self, source, link_name):
changed = False
if os.path.islink(link_name): if os.path.islink(link_name):
norm_link = os.path.normpath(os.path.realpath(link_name)) norm_link = os.path.normpath(os.path.realpath(link_name))
norm_source = os.path.normpath(os.path.realpath(source)) norm_source = os.path.normpath(os.path.realpath(source))
@ -458,15 +456,18 @@ def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
path=dict(aliases=['dest'], required=True, type='path'), path=dict(aliases=['dest'], required=True, type='path'),
release=dict(required=False, type='str', default=None), release=dict(type='str'),
releases_path=dict(required=False, type='str', default='releases'), releases_path=dict(type='str', default='releases'),
shared_path=dict(required=False, type='path', default='shared'), shared_path=dict(type='path', default='shared'),
current_path=dict(required=False, type='path', default='current'), current_path=dict(type='path', default='current'),
keep_releases=dict(required=False, type='int', default=5), keep_releases=dict(type='int', default=5),
clean=dict(required=False, type='bool', default=True), clean=dict(type='bool', default=True),
unfinished_filename=dict(required=False, type='str', default='DEPLOY_UNFINISHED'), unfinished_filename=dict(type='str', default='DEPLOY_UNFINISHED'),
state=dict(required=False, choices=['present', 'absent', 'clean', 'finalize', 'query'], default='present') state=dict(choices=['present', 'absent', 'clean', 'finalize', 'query'], default='present')
), ),
required_if=[
('state', 'finalize', ['release']),
],
add_file_common_args=True, add_file_common_args=True,
supports_check_mode=True supports_check_mode=True
) )
@ -493,8 +494,6 @@ def main():
result['ansible_facts'] = {'deploy_helper': facts} result['ansible_facts'] = {'deploy_helper': facts}
elif deploy_helper.state == 'finalize': elif deploy_helper.state == 'finalize':
if not deploy_helper.release:
module.fail_json(msg="'release' is a required parameter for state=finalize (try the 'deploy_helper.new_release' fact)")
if deploy_helper.keep_releases <= 0: if deploy_helper.keep_releases <= 0:
module.fail_json(msg="'keep_releases' should be at least 1") module.fail_json(msg="'keep_releases' should be at least 1")