mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-22 14:01:42 -07:00
Pep8 fixes for ejabberd_user and jboss (#24586)
* PEP* Fixes * Refactor code Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
894b86a467
commit
677a6c2982
3 changed files with 32 additions and 31 deletions
|
@ -77,36 +77,39 @@ EXAMPLES = """
|
|||
import os
|
||||
import shutil
|
||||
import time
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def is_deployed(deploy_path, deployment):
|
||||
return os.path.exists(os.path.join(deploy_path, "%s.deployed"%(deployment)))
|
||||
return os.path.exists(os.path.join(deploy_path, "%s.deployed" % deployment))
|
||||
|
||||
|
||||
def is_undeployed(deploy_path, deployment):
|
||||
return os.path.exists(os.path.join(deploy_path, "%s.undeployed"%(deployment)))
|
||||
return os.path.exists(os.path.join(deploy_path, "%s.undeployed" % deployment))
|
||||
|
||||
|
||||
def is_failed(deploy_path, deployment):
|
||||
return os.path.exists(os.path.join(deploy_path, "%s.failed"%(deployment)))
|
||||
return os.path.exists(os.path.join(deploy_path, "%s.failed" % deployment))
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
src=dict(),
|
||||
argument_spec=dict(
|
||||
src=dict(type='path'),
|
||||
deployment=dict(required=True),
|
||||
deploy_path=dict(default='/var/lib/jbossas/standalone/deployments'),
|
||||
deploy_path=dict(type='path', default='/var/lib/jbossas/standalone/deployments'),
|
||||
state=dict(choices=['absent', 'present'], default='present'),
|
||||
),
|
||||
required_if=[('state', 'present', ('src',))]
|
||||
)
|
||||
|
||||
changed = False
|
||||
result = dict(changed=False)
|
||||
|
||||
src = module.params['src']
|
||||
deployment = module.params['deployment']
|
||||
deploy_path = module.params['deploy_path']
|
||||
state = module.params['state']
|
||||
|
||||
if state == 'present' and not src:
|
||||
module.fail_json(msg="Argument 'src' required.")
|
||||
|
||||
if not os.path.exists(deploy_path):
|
||||
module.fail_json(msg="deploy_path does not exist.")
|
||||
|
||||
|
@ -114,44 +117,41 @@ def main():
|
|||
|
||||
if state == 'present' and not deployed:
|
||||
if not os.path.exists(src):
|
||||
module.fail_json(msg='Source file %s does not exist.'%(src))
|
||||
module.fail_json(msg='Source file %s does not exist.' % src)
|
||||
if is_failed(deploy_path, deployment):
|
||||
### Clean up old failed deployment
|
||||
os.remove(os.path.join(deploy_path, "%s.failed"%(deployment)))
|
||||
# Clean up old failed deployment
|
||||
os.remove(os.path.join(deploy_path, "%s.failed" % deployment))
|
||||
|
||||
shutil.copyfile(src, os.path.join(deploy_path, deployment))
|
||||
while not deployed:
|
||||
deployed = is_deployed(deploy_path, deployment)
|
||||
if is_failed(deploy_path, deployment):
|
||||
module.fail_json(msg='Deploying %s failed.'%(deployment))
|
||||
module.fail_json(msg='Deploying %s failed.' % deployment)
|
||||
time.sleep(1)
|
||||
changed = True
|
||||
result['changed'] = True
|
||||
|
||||
if state == 'present' and deployed:
|
||||
if module.sha1(src) != module.sha1(os.path.join(deploy_path, deployment)):
|
||||
os.remove(os.path.join(deploy_path, "%s.deployed"%(deployment)))
|
||||
os.remove(os.path.join(deploy_path, "%s.deployed" % deployment))
|
||||
shutil.copyfile(src, os.path.join(deploy_path, deployment))
|
||||
deployed = False
|
||||
while not deployed:
|
||||
deployed = is_deployed(deploy_path, deployment)
|
||||
if is_failed(deploy_path, deployment):
|
||||
module.fail_json(msg='Deploying %s failed.'%(deployment))
|
||||
module.fail_json(msg='Deploying %s failed.' % deployment)
|
||||
time.sleep(1)
|
||||
changed = True
|
||||
result['changed'] = True
|
||||
|
||||
if state == 'absent' and deployed:
|
||||
os.remove(os.path.join(deploy_path, "%s.deployed"%(deployment)))
|
||||
os.remove(os.path.join(deploy_path, "%s.deployed" % deployment))
|
||||
while deployed:
|
||||
deployed = not is_undeployed(deploy_path, deployment)
|
||||
if is_failed(deploy_path, deployment):
|
||||
module.fail_json(msg='Undeploying %s failed.'%(deployment))
|
||||
module.fail_json(msg='Undeploying %s failed.' % deployment)
|
||||
time.sleep(1)
|
||||
changed = True
|
||||
result['changed'] = True
|
||||
|
||||
module.exit_json(changed=changed)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
module.exit_json(**result)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue