Skip to content
Snippets Groups Projects
Commit 3ae4fe1c authored by Thomas Woerner's avatar Thomas Woerner
Browse files

plugins: flake8 fixes to calm down ansible galaxy

parent 1fa1468b
Branches
Tags
No related merge requests found
......@@ -22,11 +22,10 @@
import os
import sys
import tempfile
import shutil
from datetime import datetime
from ipalib import api, errors
from ipalib import api
from ipalib.config import Env
from ipalib.constants import DEFAULT_CONFIG, LDAP_GENERALIZED_TIME_FORMAT
try:
......@@ -37,6 +36,7 @@ from ipapython.ipautil import run
from ipaplatform.paths import paths
from ipalib.krb_utils import get_credentials_if_valid
def valid_creds(principal):
"""
Get valid credintials matching the princial
......
......@@ -137,14 +137,12 @@ RETURN = """
"""
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_bytes, to_native, to_text
from ansible.module_utils._text import to_text
from ansible.module_utils.ansible_freeipa_module import temp_kinit, \
temp_kdestroy, valid_creds, api_connect, api_command, date_format, \
compare_args_ipa
temp_kdestroy, valid_creds, api_connect, api_command, compare_args_ipa
def find_group(module, name):
#module.warn("find_group(.., %s)" % to_text(name))
_args = {
"all": True,
"cn": to_text(name),
......@@ -264,7 +262,7 @@ def main():
for x in invalid:
if vars()[x] is not None:
ansible_module.fail_json(
msg="Argument '%s' can not be used with state '%s'" % \
msg="Argument '%s' can not be used with state '%s'" %
(x, state))
# Init
......@@ -284,7 +282,6 @@ def main():
for name in names:
# Make sure group exists
res_find = find_group(ansible_module, name)
#ansible_module.warn("res_find: %s" % repr(res_find))
# Create command
if state == "present":
......@@ -401,15 +398,14 @@ def main():
for name, command, args in commands:
try:
result = api_command(ansible_module, command,
to_text(name), args)
api_command(ansible_module, command, to_text(name), args)
changed = True
except Exception as e:
ansible_module.fail_json(msg="%s: %s: %s" % (command, name,
str(e)))
#except Exception as e:
# ansible_module.fail_json(msg=str(e))
except Exception as e:
ansible_module.fail_json(msg=str(e))
finally:
temp_kdestroy(ccache_dir, ccache_name)
......@@ -418,5 +414,6 @@ def main():
ansible_module.exit_json(changed=changed, **exit_args)
if __name__ == "__main__":
main()
......@@ -114,10 +114,11 @@ not-found:
"""
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_bytes, to_native, to_text
from ansible.module_utils._text import to_text
from ansible.module_utils.ansible_freeipa_module import temp_kinit, \
temp_kdestroy, valid_creds, api_connect, api_command
def find_left_right(module, suffix, left, right):
_args = {
"iparepltoposegmentleftnode": to_text(left),
......@@ -149,6 +150,7 @@ def find_cn(module, suffix, name):
else:
return None
def find_left_right_cn(module, suffix, left, right, name):
if left is not None and right is not None:
left_right = find_left_right(module, suffix, left, right)
......@@ -170,6 +172,7 @@ def find_left_right_cn(module, suffix, left, right, name):
msg="Either left and right or name need to be set.")
return None
def main():
ansible_module = AnsibleModule(
argument_spec=dict(
......@@ -313,8 +316,7 @@ def main():
# Execute command
for command, args in commands:
result = api_command(ansible_module, command,
to_text(suffix), args)
api_command(ansible_module, command, to_text(suffix), args)
changed = True
except Exception as e:
......@@ -327,5 +329,6 @@ def main():
ansible_module.exit_json(changed=changed, **exit_args)
if __name__ == "__main__":
main()
......@@ -60,9 +60,10 @@ RETURN = """
"""
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_bytes, to_native, to_text
from ansible.module_utils._text import to_text
from ansible.module_utils.ansible_freeipa_module import execute_api_command
def main():
ansible_module = AnsibleModule(
argument_spec=dict(
......@@ -105,5 +106,6 @@ def main():
ansible_module.exit_json(changed=True)
if __name__ == "__main__":
main()
......@@ -101,7 +101,8 @@ options:
# aliases: ["ipasshpubkey"]
# ..
update_password:
description: Set password for a user in present state only on creation or always
description:
Set password for a user in present state only on creation or always
default: 'always'
choices: ["always", "on_create"]
preserve:
......@@ -175,14 +176,13 @@ RETURN = """
"""
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_bytes, to_native, to_text
from ansible.module_utils._text import to_text
from ansible.module_utils.ansible_freeipa_module import temp_kinit, \
temp_kdestroy, valid_creds, api_connect, api_command, date_format, \
compare_args_ipa
def find_user(module, name, preserved=False):
#module.warn("find_user(.., %s)" % to_text(name))
_args = {
"all": True,
"uid": to_text(name),
......@@ -200,6 +200,7 @@ def find_user(module, name, preserved=False):
else:
return None
def gen_args(first, last, fullname, displayname, homedir, shell, emails,
principalname, passwordexpiration, password, uid, gid,
phones, title, sshpubkey):
......@@ -335,7 +336,7 @@ def main():
"update_password"]:
if vars()[x] is not None:
ansible_module.fail_json(
msg="Argument '%s' can not be used with state '%s'" % \
msg="Argument '%s' can not be used with state '%s'" %
(x, state))
else:
if preserve is not None:
......@@ -365,7 +366,6 @@ def main():
# Also search for preserved user
res_find_preserved = find_user(ansible_module, name,
preserved=True)
#ansible_module.warn("res_find: %s" % repr(res_find))
# Create command
if state == "present":
......@@ -413,14 +413,14 @@ def main():
elif state == "enabled":
if res_find is not None:
if res_find["nsaccountlock"] == True:
if res_find["nsaccountlock"]:
commands.append([name, "user_enable", {}])
else:
raise ValueError("No disabled user '%s'" % name)
elif state == "disabled":
if res_find is not None:
if res_find["nsaccountlock"] == False:
if not res_find["nsaccountlock"]:
commands.append([name, "user_disable", {}])
else:
raise ValueError("No user '%s'" % name)
......@@ -436,8 +436,7 @@ def main():
for name, command, args in commands:
try:
result = api_command(ansible_module, command,
to_text(name), args)
api_command(ansible_module, command, to_text(name), args)
changed = True
except Exception as e:
ansible_module.fail_json(msg="%s: %s: %s" % (command, name,
......@@ -453,5 +452,6 @@ def main():
ansible_module.exit_json(changed=changed, **exit_args)
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment