mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-03-26 21:33:05 +00:00
plugins: flake8 fixes to calm down ansible galaxy
This commit is contained in:
@@ -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
|
||||
@@ -152,7 +152,7 @@ def compare_args_ipa(module, args, ipa):
|
||||
# are lists, but not all.
|
||||
if isinstance(ipa_arg, list) and not isinstance(arg, list):
|
||||
arg = [arg]
|
||||
#module.warn("%s <=> %s" % (arg, ipa_arg))
|
||||
# module.warn("%s <=> %s" % (arg, ipa_arg))
|
||||
if arg != ipa_arg:
|
||||
return False
|
||||
|
||||
|
||||
@@ -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),
|
||||
@@ -197,7 +195,7 @@ def main():
|
||||
ipaadmin_password=dict(type="str", required=False, no_log=True),
|
||||
|
||||
name=dict(type="list", aliases=["cn"], default=None,
|
||||
required=True),
|
||||
required=True),
|
||||
# present
|
||||
description=dict(type="str", default=None),
|
||||
gid=dict(type="int", aliases=["gidnumber"], default=None),
|
||||
@@ -246,8 +244,8 @@ def main():
|
||||
ansible_module.fail_json(
|
||||
msg="Onle one group can be added at a time.")
|
||||
if action == "member":
|
||||
invalid = [ "description", "gid", "nonposix", "external",
|
||||
"nomembers" ]
|
||||
invalid = ["description", "gid", "nonposix", "external",
|
||||
"nomembers"]
|
||||
for x in invalid:
|
||||
if vars()[x] is not None:
|
||||
ansible_module.fail_json(
|
||||
@@ -258,19 +256,19 @@ def main():
|
||||
if len(names) < 1:
|
||||
ansible_module.fail_json(
|
||||
msg="No name given.")
|
||||
invalid = [ "description", "gid", "nonposix", "external", "nomembers" ]
|
||||
invalid = ["description", "gid", "nonposix", "external", "nomembers"]
|
||||
if action == "group":
|
||||
invalid.extend(["user", "group", "service"])
|
||||
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
|
||||
|
||||
changed = False
|
||||
exit_args = { }
|
||||
exit_args = {}
|
||||
ccache_dir = None
|
||||
ccache_name = None
|
||||
try:
|
||||
@@ -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":
|
||||
@@ -311,7 +308,7 @@ def main():
|
||||
res_find):
|
||||
# Generate addition and removal lists
|
||||
user_add = list(
|
||||
set(user or []) -
|
||||
set(user or []) -
|
||||
set(res_find.get("member_user", [])))
|
||||
user_del = list(
|
||||
set(res_find.get("member_user", [])) -
|
||||
@@ -349,7 +346,7 @@ def main():
|
||||
}])
|
||||
elif action == "member":
|
||||
user_add = list(
|
||||
set(user or []) -
|
||||
set(user or []) -
|
||||
set(res_find.get("member_user", [])))
|
||||
group_add = list(
|
||||
set(group or []) -
|
||||
@@ -376,7 +373,7 @@ def main():
|
||||
elif action == "member":
|
||||
# Remove intersection member
|
||||
user_del = list(
|
||||
set(user or []) &
|
||||
set(user or []) &
|
||||
set(res_find.get("member_user", [])))
|
||||
group_del = list(
|
||||
set(group or []) &
|
||||
@@ -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(
|
||||
@@ -210,7 +213,7 @@ def main():
|
||||
# Init
|
||||
|
||||
changed = False
|
||||
exit_args = { }
|
||||
exit_args = {}
|
||||
ccache_dir = None
|
||||
ccache_name = None
|
||||
try:
|
||||
@@ -247,8 +250,8 @@ def main():
|
||||
|
||||
# Left and right nodes and also the name can not be
|
||||
# changed
|
||||
for key in [ "iparepltoposegmentleftnode",
|
||||
"iparepltoposegmentrightnode" ]:
|
||||
for key in ["iparepltoposegmentleftnode",
|
||||
"iparepltoposegmentrightnode"]:
|
||||
if key in args:
|
||||
del args[key]
|
||||
if len(args) > 1:
|
||||
@@ -289,7 +292,7 @@ def main():
|
||||
elif state == "reinitialized":
|
||||
# Reinitialize segment
|
||||
|
||||
if direction not in [ "left-to-right", "right-to-left" ]:
|
||||
if direction not in ["left-to-right", "right-to-left"]:
|
||||
ansible_module.fail_json(msg="Unknown direction '%s'" %
|
||||
direction)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -39,7 +39,7 @@ options:
|
||||
description: The admin password
|
||||
required: false
|
||||
name:
|
||||
description: The list of users (internally uid).
|
||||
description: The list of users (internally uid).
|
||||
required: false
|
||||
first:
|
||||
description: The first name
|
||||
@@ -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):
|
||||
@@ -246,7 +247,7 @@ def main():
|
||||
ipaadmin_password=dict(type="str", required=False, no_log=True),
|
||||
|
||||
name=dict(type="list", aliases=["login"], default=None,
|
||||
required=True),
|
||||
required=True),
|
||||
# present
|
||||
first=dict(type="str", aliases=["givenname"], default=None),
|
||||
last=dict(type="str", default=None),
|
||||
@@ -265,8 +266,8 @@ def main():
|
||||
gid=dict(type="int", aliases=["gidnumber"], default=None),
|
||||
phone=dict(type="list", aliases=["telephonenumber"], default=None),
|
||||
title=dict(type="str", default=None),
|
||||
#sshpubkey=dict(type="list", aliases=["ipasshpubkey"],
|
||||
# default=None),
|
||||
# sshpubkey=dict(type="list", aliases=["ipasshpubkey"],
|
||||
# default=None),
|
||||
update_password=dict(type='str', default=None,
|
||||
choices=['always', 'on_create']),
|
||||
# deleted
|
||||
@@ -329,26 +330,26 @@ def main():
|
||||
if len(names) < 1:
|
||||
ansible_module.fail_json(
|
||||
msg="No name given.")
|
||||
for x in [ "first", "last", "fullname", "displayname", "homedir",
|
||||
"shell", "emails", "principalname", "passwordexpiration",
|
||||
"password", "uid", "gid", "phones", "title", "sshpubkey",
|
||||
"update_password" ]:
|
||||
for x in ["first", "last", "fullname", "displayname", "homedir",
|
||||
"shell", "emails", "principalname", "passwordexpiration",
|
||||
"password", "uid", "gid", "phones", "title", "sshpubkey",
|
||||
"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:
|
||||
ansible_module.fail_json(
|
||||
msg="Preserve is only possible for state=absent")
|
||||
|
||||
|
||||
if update_password is None:
|
||||
update_password = "always"
|
||||
|
||||
# Init
|
||||
|
||||
changed = False
|
||||
exit_args = { }
|
||||
exit_args = {}
|
||||
ccache_dir = None
|
||||
ccache_name = None
|
||||
try:
|
||||
@@ -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":
|
||||
@@ -379,7 +379,7 @@ def main():
|
||||
if res_find is None and res_find_preserved is not None:
|
||||
res_find = res_find_preserved
|
||||
|
||||
# Found the user
|
||||
# Found the user
|
||||
if res_find is not None:
|
||||
# Ignore password with update_password == on_create
|
||||
if update_password == "on_create" and \
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user