diff --git a/lib/ansible/modules/web_infrastructure/ejabberd_user.py b/lib/ansible/modules/web_infrastructure/ejabberd_user.py index 3b7f91c8d1..c606a84088 100644 --- a/lib/ansible/modules/web_infrastructure/ejabberd_user.py +++ b/lib/ansible/modules/web_infrastructure/ejabberd_user.py @@ -79,12 +79,14 @@ EXAMPLES = ''' import syslog from ansible.module_utils.pycompat24 import get_exception -from ansible.module_utils.basic import * +from ansible.module_utils.basic import AnsibleModule + class EjabberdUserException(Exception): """ Base exception for EjabberdUser class object """ pass + class EjabberdUser(object): """ This object represents a user resource for an ejabberd server. The object manages user creation and deletion using ejabberdctl. The following @@ -181,22 +183,23 @@ class EjabberdUser(object): (rc, out, err) = (1, None, "required attribute(s) missing") return (rc, out, err) + def main(): module = AnsibleModule( - argument_spec = dict( + argument_spec=dict( host=dict(default=None, type='str'), username=dict(default=None, type='str'), password=dict(default=None, type='str', no_log=True), state=dict(default='present', choices=['present', 'absent']), logging=dict(default=False, type='bool') ), - supports_check_mode = True + supports_check_mode=True ) obj = EjabberdUser(module) rc = None - result = dict() + result = dict(changed=False) if obj.state == 'absent': if obj.exists: diff --git a/lib/ansible/modules/web_infrastructure/jboss.py b/lib/ansible/modules/web_infrastructure/jboss.py index 96ece165fc..53d671428a 100644 --- a/lib/ansible/modules/web_infrastructure/jboss.py +++ b/lib/ansible/modules/web_infrastructure/jboss.py @@ -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() diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index 132e294de5..2258648497 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -570,5 +570,3 @@ lib/ansible/modules/utilities/helper/_accelerate.py lib/ansible/modules/utilities/logic/async_status.py lib/ansible/modules/utilities/logic/async_wrapper.py lib/ansible/modules/utilities/logic/wait_for.py -lib/ansible/modules/web_infrastructure/ejabberd_user.py -lib/ansible/modules/web_infrastructure/jboss.py