mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-07-30 11:24:50 +00:00
plugins: flake8 fixes to calm down ansible galaxy
This commit is contained in:
@@ -22,11 +22,10 @@
|
|||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import shutil
|
import shutil
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from ipalib import api, errors
|
from ipalib import api
|
||||||
from ipalib.config import Env
|
from ipalib.config import Env
|
||||||
from ipalib.constants import DEFAULT_CONFIG, LDAP_GENERALIZED_TIME_FORMAT
|
from ipalib.constants import DEFAULT_CONFIG, LDAP_GENERALIZED_TIME_FORMAT
|
||||||
try:
|
try:
|
||||||
@@ -37,6 +36,7 @@ from ipapython.ipautil import run
|
|||||||
from ipaplatform.paths import paths
|
from ipaplatform.paths import paths
|
||||||
from ipalib.krb_utils import get_credentials_if_valid
|
from ipalib.krb_utils import get_credentials_if_valid
|
||||||
|
|
||||||
|
|
||||||
def valid_creds(principal):
|
def valid_creds(principal):
|
||||||
"""
|
"""
|
||||||
Get valid credintials matching the princial
|
Get valid credintials matching the princial
|
||||||
@@ -152,7 +152,7 @@ def compare_args_ipa(module, args, ipa):
|
|||||||
# are lists, but not all.
|
# are lists, but not all.
|
||||||
if isinstance(ipa_arg, list) and not isinstance(arg, list):
|
if isinstance(ipa_arg, list) and not isinstance(arg, list):
|
||||||
arg = [arg]
|
arg = [arg]
|
||||||
#module.warn("%s <=> %s" % (arg, ipa_arg))
|
# module.warn("%s <=> %s" % (arg, ipa_arg))
|
||||||
if arg != ipa_arg:
|
if arg != ipa_arg:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -137,14 +137,12 @@ RETURN = """
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
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, \
|
from ansible.module_utils.ansible_freeipa_module import temp_kinit, \
|
||||||
temp_kdestroy, valid_creds, api_connect, api_command, date_format, \
|
temp_kdestroy, valid_creds, api_connect, api_command, compare_args_ipa
|
||||||
compare_args_ipa
|
|
||||||
|
|
||||||
|
|
||||||
def find_group(module, name):
|
def find_group(module, name):
|
||||||
#module.warn("find_group(.., %s)" % to_text(name))
|
|
||||||
_args = {
|
_args = {
|
||||||
"all": True,
|
"all": True,
|
||||||
"cn": to_text(name),
|
"cn": to_text(name),
|
||||||
@@ -197,7 +195,7 @@ def main():
|
|||||||
ipaadmin_password=dict(type="str", required=False, no_log=True),
|
ipaadmin_password=dict(type="str", required=False, no_log=True),
|
||||||
|
|
||||||
name=dict(type="list", aliases=["cn"], default=None,
|
name=dict(type="list", aliases=["cn"], default=None,
|
||||||
required=True),
|
required=True),
|
||||||
# present
|
# present
|
||||||
description=dict(type="str", default=None),
|
description=dict(type="str", default=None),
|
||||||
gid=dict(type="int", aliases=["gidnumber"], default=None),
|
gid=dict(type="int", aliases=["gidnumber"], default=None),
|
||||||
@@ -246,8 +244,8 @@ def main():
|
|||||||
ansible_module.fail_json(
|
ansible_module.fail_json(
|
||||||
msg="Onle one group can be added at a time.")
|
msg="Onle one group can be added at a time.")
|
||||||
if action == "member":
|
if action == "member":
|
||||||
invalid = [ "description", "gid", "nonposix", "external",
|
invalid = ["description", "gid", "nonposix", "external",
|
||||||
"nomembers" ]
|
"nomembers"]
|
||||||
for x in invalid:
|
for x in invalid:
|
||||||
if vars()[x] is not None:
|
if vars()[x] is not None:
|
||||||
ansible_module.fail_json(
|
ansible_module.fail_json(
|
||||||
@@ -258,19 +256,19 @@ def main():
|
|||||||
if len(names) < 1:
|
if len(names) < 1:
|
||||||
ansible_module.fail_json(
|
ansible_module.fail_json(
|
||||||
msg="No name given.")
|
msg="No name given.")
|
||||||
invalid = [ "description", "gid", "nonposix", "external", "nomembers" ]
|
invalid = ["description", "gid", "nonposix", "external", "nomembers"]
|
||||||
if action == "group":
|
if action == "group":
|
||||||
invalid.extend(["user", "group", "service"])
|
invalid.extend(["user", "group", "service"])
|
||||||
for x in invalid:
|
for x in invalid:
|
||||||
if vars()[x] is not None:
|
if vars()[x] is not None:
|
||||||
ansible_module.fail_json(
|
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))
|
(x, state))
|
||||||
|
|
||||||
# Init
|
# Init
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
exit_args = { }
|
exit_args = {}
|
||||||
ccache_dir = None
|
ccache_dir = None
|
||||||
ccache_name = None
|
ccache_name = None
|
||||||
try:
|
try:
|
||||||
@@ -284,7 +282,6 @@ def main():
|
|||||||
for name in names:
|
for name in names:
|
||||||
# Make sure group exists
|
# Make sure group exists
|
||||||
res_find = find_group(ansible_module, name)
|
res_find = find_group(ansible_module, name)
|
||||||
#ansible_module.warn("res_find: %s" % repr(res_find))
|
|
||||||
|
|
||||||
# Create command
|
# Create command
|
||||||
if state == "present":
|
if state == "present":
|
||||||
@@ -401,15 +398,14 @@ def main():
|
|||||||
|
|
||||||
for name, command, args in commands:
|
for name, command, args in commands:
|
||||||
try:
|
try:
|
||||||
result = api_command(ansible_module, command,
|
api_command(ansible_module, command, to_text(name), args)
|
||||||
to_text(name), args)
|
|
||||||
changed = True
|
changed = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
ansible_module.fail_json(msg="%s: %s: %s" % (command, name,
|
ansible_module.fail_json(msg="%s: %s: %s" % (command, name,
|
||||||
str(e)))
|
str(e)))
|
||||||
|
|
||||||
#except Exception as e:
|
except Exception as e:
|
||||||
# ansible_module.fail_json(msg=str(e))
|
ansible_module.fail_json(msg=str(e))
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
temp_kdestroy(ccache_dir, ccache_name)
|
temp_kdestroy(ccache_dir, ccache_name)
|
||||||
@@ -418,5 +414,6 @@ def main():
|
|||||||
|
|
||||||
ansible_module.exit_json(changed=changed, **exit_args)
|
ansible_module.exit_json(changed=changed, **exit_args)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -114,10 +114,11 @@ not-found:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
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, \
|
from ansible.module_utils.ansible_freeipa_module import temp_kinit, \
|
||||||
temp_kdestroy, valid_creds, api_connect, api_command
|
temp_kdestroy, valid_creds, api_connect, api_command
|
||||||
|
|
||||||
|
|
||||||
def find_left_right(module, suffix, left, right):
|
def find_left_right(module, suffix, left, right):
|
||||||
_args = {
|
_args = {
|
||||||
"iparepltoposegmentleftnode": to_text(left),
|
"iparepltoposegmentleftnode": to_text(left),
|
||||||
@@ -149,6 +150,7 @@ def find_cn(module, suffix, name):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def find_left_right_cn(module, suffix, left, right, name):
|
def find_left_right_cn(module, suffix, left, right, name):
|
||||||
if left is not None and right is not None:
|
if left is not None and right is not None:
|
||||||
left_right = find_left_right(module, suffix, left, right)
|
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.")
|
msg="Either left and right or name need to be set.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
ansible_module = AnsibleModule(
|
ansible_module = AnsibleModule(
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
@@ -210,7 +213,7 @@ def main():
|
|||||||
# Init
|
# Init
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
exit_args = { }
|
exit_args = {}
|
||||||
ccache_dir = None
|
ccache_dir = None
|
||||||
ccache_name = None
|
ccache_name = None
|
||||||
try:
|
try:
|
||||||
@@ -247,8 +250,8 @@ def main():
|
|||||||
|
|
||||||
# Left and right nodes and also the name can not be
|
# Left and right nodes and also the name can not be
|
||||||
# changed
|
# changed
|
||||||
for key in [ "iparepltoposegmentleftnode",
|
for key in ["iparepltoposegmentleftnode",
|
||||||
"iparepltoposegmentrightnode" ]:
|
"iparepltoposegmentrightnode"]:
|
||||||
if key in args:
|
if key in args:
|
||||||
del args[key]
|
del args[key]
|
||||||
if len(args) > 1:
|
if len(args) > 1:
|
||||||
@@ -289,7 +292,7 @@ def main():
|
|||||||
elif state == "reinitialized":
|
elif state == "reinitialized":
|
||||||
# Reinitialize segment
|
# 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'" %
|
ansible_module.fail_json(msg="Unknown direction '%s'" %
|
||||||
direction)
|
direction)
|
||||||
|
|
||||||
@@ -313,8 +316,7 @@ def main():
|
|||||||
# Execute command
|
# Execute command
|
||||||
|
|
||||||
for command, args in commands:
|
for command, args in commands:
|
||||||
result = api_command(ansible_module, command,
|
api_command(ansible_module, command, to_text(suffix), args)
|
||||||
to_text(suffix), args)
|
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -327,5 +329,6 @@ def main():
|
|||||||
|
|
||||||
ansible_module.exit_json(changed=changed, **exit_args)
|
ansible_module.exit_json(changed=changed, **exit_args)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -60,9 +60,10 @@ RETURN = """
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
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
|
from ansible.module_utils.ansible_freeipa_module import execute_api_command
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
ansible_module = AnsibleModule(
|
ansible_module = AnsibleModule(
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
@@ -105,5 +106,6 @@ def main():
|
|||||||
|
|
||||||
ansible_module.exit_json(changed=True)
|
ansible_module.exit_json(changed=True)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -101,7 +101,8 @@ options:
|
|||||||
# aliases: ["ipasshpubkey"]
|
# aliases: ["ipasshpubkey"]
|
||||||
# ..
|
# ..
|
||||||
update_password:
|
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'
|
default: 'always'
|
||||||
choices: ["always", "on_create"]
|
choices: ["always", "on_create"]
|
||||||
preserve:
|
preserve:
|
||||||
@@ -175,14 +176,13 @@ RETURN = """
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
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, \
|
from ansible.module_utils.ansible_freeipa_module import temp_kinit, \
|
||||||
temp_kdestroy, valid_creds, api_connect, api_command, date_format, \
|
temp_kdestroy, valid_creds, api_connect, api_command, date_format, \
|
||||||
compare_args_ipa
|
compare_args_ipa
|
||||||
|
|
||||||
|
|
||||||
def find_user(module, name, preserved=False):
|
def find_user(module, name, preserved=False):
|
||||||
#module.warn("find_user(.., %s)" % to_text(name))
|
|
||||||
_args = {
|
_args = {
|
||||||
"all": True,
|
"all": True,
|
||||||
"uid": to_text(name),
|
"uid": to_text(name),
|
||||||
@@ -200,6 +200,7 @@ def find_user(module, name, preserved=False):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def gen_args(first, last, fullname, displayname, homedir, shell, emails,
|
def gen_args(first, last, fullname, displayname, homedir, shell, emails,
|
||||||
principalname, passwordexpiration, password, uid, gid,
|
principalname, passwordexpiration, password, uid, gid,
|
||||||
phones, title, sshpubkey):
|
phones, title, sshpubkey):
|
||||||
@@ -246,7 +247,7 @@ def main():
|
|||||||
ipaadmin_password=dict(type="str", required=False, no_log=True),
|
ipaadmin_password=dict(type="str", required=False, no_log=True),
|
||||||
|
|
||||||
name=dict(type="list", aliases=["login"], default=None,
|
name=dict(type="list", aliases=["login"], default=None,
|
||||||
required=True),
|
required=True),
|
||||||
# present
|
# present
|
||||||
first=dict(type="str", aliases=["givenname"], default=None),
|
first=dict(type="str", aliases=["givenname"], default=None),
|
||||||
last=dict(type="str", default=None),
|
last=dict(type="str", default=None),
|
||||||
@@ -265,8 +266,8 @@ def main():
|
|||||||
gid=dict(type="int", aliases=["gidnumber"], default=None),
|
gid=dict(type="int", aliases=["gidnumber"], default=None),
|
||||||
phone=dict(type="list", aliases=["telephonenumber"], default=None),
|
phone=dict(type="list", aliases=["telephonenumber"], default=None),
|
||||||
title=dict(type="str", default=None),
|
title=dict(type="str", default=None),
|
||||||
#sshpubkey=dict(type="list", aliases=["ipasshpubkey"],
|
# sshpubkey=dict(type="list", aliases=["ipasshpubkey"],
|
||||||
# default=None),
|
# default=None),
|
||||||
update_password=dict(type='str', default=None,
|
update_password=dict(type='str', default=None,
|
||||||
choices=['always', 'on_create']),
|
choices=['always', 'on_create']),
|
||||||
# deleted
|
# deleted
|
||||||
@@ -329,13 +330,13 @@ def main():
|
|||||||
if len(names) < 1:
|
if len(names) < 1:
|
||||||
ansible_module.fail_json(
|
ansible_module.fail_json(
|
||||||
msg="No name given.")
|
msg="No name given.")
|
||||||
for x in [ "first", "last", "fullname", "displayname", "homedir",
|
for x in ["first", "last", "fullname", "displayname", "homedir",
|
||||||
"shell", "emails", "principalname", "passwordexpiration",
|
"shell", "emails", "principalname", "passwordexpiration",
|
||||||
"password", "uid", "gid", "phones", "title", "sshpubkey",
|
"password", "uid", "gid", "phones", "title", "sshpubkey",
|
||||||
"update_password" ]:
|
"update_password"]:
|
||||||
if vars()[x] is not None:
|
if vars()[x] is not None:
|
||||||
ansible_module.fail_json(
|
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))
|
(x, state))
|
||||||
else:
|
else:
|
||||||
if preserve is not None:
|
if preserve is not None:
|
||||||
@@ -348,7 +349,7 @@ def main():
|
|||||||
# Init
|
# Init
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
exit_args = { }
|
exit_args = {}
|
||||||
ccache_dir = None
|
ccache_dir = None
|
||||||
ccache_name = None
|
ccache_name = None
|
||||||
try:
|
try:
|
||||||
@@ -365,7 +366,6 @@ def main():
|
|||||||
# Also search for preserved user
|
# Also search for preserved user
|
||||||
res_find_preserved = find_user(ansible_module, name,
|
res_find_preserved = find_user(ansible_module, name,
|
||||||
preserved=True)
|
preserved=True)
|
||||||
#ansible_module.warn("res_find: %s" % repr(res_find))
|
|
||||||
|
|
||||||
# Create command
|
# Create command
|
||||||
if state == "present":
|
if state == "present":
|
||||||
@@ -413,14 +413,14 @@ def main():
|
|||||||
|
|
||||||
elif state == "enabled":
|
elif state == "enabled":
|
||||||
if res_find is not None:
|
if res_find is not None:
|
||||||
if res_find["nsaccountlock"] == True:
|
if res_find["nsaccountlock"]:
|
||||||
commands.append([name, "user_enable", {}])
|
commands.append([name, "user_enable", {}])
|
||||||
else:
|
else:
|
||||||
raise ValueError("No disabled user '%s'" % name)
|
raise ValueError("No disabled user '%s'" % name)
|
||||||
|
|
||||||
elif state == "disabled":
|
elif state == "disabled":
|
||||||
if res_find is not None:
|
if res_find is not None:
|
||||||
if res_find["nsaccountlock"] == False:
|
if not res_find["nsaccountlock"]:
|
||||||
commands.append([name, "user_disable", {}])
|
commands.append([name, "user_disable", {}])
|
||||||
else:
|
else:
|
||||||
raise ValueError("No user '%s'" % name)
|
raise ValueError("No user '%s'" % name)
|
||||||
@@ -436,8 +436,7 @@ def main():
|
|||||||
|
|
||||||
for name, command, args in commands:
|
for name, command, args in commands:
|
||||||
try:
|
try:
|
||||||
result = api_command(ansible_module, command,
|
api_command(ansible_module, command, to_text(name), args)
|
||||||
to_text(name), args)
|
|
||||||
changed = True
|
changed = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
ansible_module.fail_json(msg="%s: %s: %s" % (command, name,
|
ansible_module.fail_json(msg="%s: %s: %s" % (command, name,
|
||||||
@@ -453,5 +452,6 @@ def main():
|
|||||||
|
|
||||||
ansible_module.exit_json(changed=changed, **exit_args)
|
ansible_module.exit_json(changed=changed, **exit_args)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user