mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-07-31 03:44:41 +00:00
Adjusted doc strings to follow PEP 257.
This commit is contained in:
@@ -63,9 +63,7 @@ if six.PY3:
|
|||||||
|
|
||||||
|
|
||||||
def valid_creds(module, principal): # noqa
|
def valid_creds(module, principal): # noqa
|
||||||
"""
|
"""Get valid credintials matching the princial, try GSSAPI first."""
|
||||||
Get valid credintials matching the princial, try GSSAPI first
|
|
||||||
"""
|
|
||||||
if "KRB5CCNAME" in os.environ:
|
if "KRB5CCNAME" in os.environ:
|
||||||
ccache = os.environ["KRB5CCNAME"]
|
ccache = os.environ["KRB5CCNAME"]
|
||||||
module.debug('KRB5CCNAME set to %s' % ccache)
|
module.debug('KRB5CCNAME set to %s' % ccache)
|
||||||
@@ -103,9 +101,7 @@ def valid_creds(module, principal): # noqa
|
|||||||
|
|
||||||
|
|
||||||
def temp_kinit(principal, password):
|
def temp_kinit(principal, password):
|
||||||
"""
|
"""Kinit with password using a temporary ccache."""
|
||||||
kinit with password using a temporary ccache
|
|
||||||
"""
|
|
||||||
if not password:
|
if not password:
|
||||||
raise RuntimeError("The password is not set")
|
raise RuntimeError("The password is not set")
|
||||||
if not principal:
|
if not principal:
|
||||||
@@ -123,9 +119,7 @@ def temp_kinit(principal, password):
|
|||||||
|
|
||||||
|
|
||||||
def temp_kdestroy(ccache_dir, ccache_name):
|
def temp_kdestroy(ccache_dir, ccache_name):
|
||||||
"""
|
"""Destroy temporary ticket and remove temporary ccache."""
|
||||||
Destroy temporary ticket and remove temporary ccache
|
|
||||||
"""
|
|
||||||
if ccache_name is not None:
|
if ccache_name is not None:
|
||||||
run([paths.KDESTROY, '-c', ccache_name], raiseonerr=False)
|
run([paths.KDESTROY, '-c', ccache_name], raiseonerr=False)
|
||||||
if ccache_dir is not None:
|
if ccache_dir is not None:
|
||||||
@@ -133,9 +127,7 @@ def temp_kdestroy(ccache_dir, ccache_name):
|
|||||||
|
|
||||||
|
|
||||||
def api_connect(context=None):
|
def api_connect(context=None):
|
||||||
"""
|
"""Create environment, initialize api and connect to ldap2."""
|
||||||
Create environment, initialize api and connect to ldap2
|
|
||||||
"""
|
|
||||||
env = Env()
|
env = Env()
|
||||||
env._bootstrap()
|
env._bootstrap()
|
||||||
env._finalize_core(**dict(DEFAULT_CONFIG))
|
env._finalize_core(**dict(DEFAULT_CONFIG))
|
||||||
@@ -157,28 +149,24 @@ def api_connect(context=None):
|
|||||||
|
|
||||||
|
|
||||||
def api_command(module, command, name, args):
|
def api_command(module, command, name, args):
|
||||||
"""
|
"""Call ipa.Command."""
|
||||||
Call ipa.Command
|
|
||||||
"""
|
|
||||||
return api.Command[command](name, **args)
|
return api.Command[command](name, **args)
|
||||||
|
|
||||||
|
|
||||||
def api_command_no_name(module, command, args):
|
def api_command_no_name(module, command, args):
|
||||||
"""
|
"""Call ipa.Command without a name."""
|
||||||
Call ipa.Command without a name.
|
|
||||||
"""
|
|
||||||
return api.Command[command](**args)
|
return api.Command[command](**args)
|
||||||
|
|
||||||
|
|
||||||
def api_check_param(command, name):
|
def api_check_param(command, name):
|
||||||
"""
|
"""Return if param exists in command param list."""
|
||||||
Return if param exists in command param list
|
|
||||||
"""
|
|
||||||
return name in api.Command[command].params
|
return name in api.Command[command].params
|
||||||
|
|
||||||
|
|
||||||
def execute_api_command(module, principal, password, command, name, args):
|
def execute_api_command(module, principal, password, command, name, args):
|
||||||
"""
|
"""
|
||||||
|
Execute an API command.
|
||||||
|
|
||||||
Get KRB ticket if not already there, initialize api, connect,
|
Get KRB ticket if not already there, initialize api, connect,
|
||||||
execute command and destroy ticket again if it has been created also.
|
execute command and destroy ticket again if it has been created also.
|
||||||
"""
|
"""
|
||||||
@@ -300,10 +288,7 @@ def api_get_realm():
|
|||||||
|
|
||||||
|
|
||||||
def gen_add_del_lists(user_list, res_list):
|
def gen_add_del_lists(user_list, res_list):
|
||||||
"""
|
"""Generate the lists for the addition and removal of members."""
|
||||||
Generate the lists for the addition and removal of members using the
|
|
||||||
provided user and ipa settings
|
|
||||||
"""
|
|
||||||
add_list = list(set(user_list or []) - set(res_list or []))
|
add_list = list(set(user_list or []) - set(res_list or []))
|
||||||
del_list = list(set(res_list or []) - set(user_list or []))
|
del_list = list(set(res_list or []) - set(user_list or []))
|
||||||
|
|
||||||
@@ -312,8 +297,9 @@ def gen_add_del_lists(user_list, res_list):
|
|||||||
|
|
||||||
def encode_certificate(cert):
|
def encode_certificate(cert):
|
||||||
"""
|
"""
|
||||||
Encode a certificate using base64 with also taking FreeIPA and Python
|
Encode a certificate using base64.
|
||||||
versions into account
|
|
||||||
|
It also takes FreeIPA and Python versions into account.
|
||||||
"""
|
"""
|
||||||
if isinstance(cert, (str, unicode, bytes)):
|
if isinstance(cert, (str, unicode, bytes)):
|
||||||
encoded = base64.b64encode(cert)
|
encoded = base64.b64encode(cert)
|
||||||
@@ -335,9 +321,7 @@ def is_valid_port(port):
|
|||||||
|
|
||||||
|
|
||||||
def is_ipv4_addr(ipaddr):
|
def is_ipv4_addr(ipaddr):
|
||||||
"""
|
"""Test if figen IP address is a valid IPv4 address."""
|
||||||
Test if figen IP address is a valid IPv4 address
|
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
socket.inet_pton(socket.AF_INET, ipaddr)
|
socket.inet_pton(socket.AF_INET, ipaddr)
|
||||||
except socket.error:
|
except socket.error:
|
||||||
@@ -346,9 +330,7 @@ def is_ipv4_addr(ipaddr):
|
|||||||
|
|
||||||
|
|
||||||
def is_ipv6_addr(ipaddr):
|
def is_ipv6_addr(ipaddr):
|
||||||
"""
|
"""Test if figen IP address is a valid IPv6 address."""
|
||||||
Test if figen IP address is a valid IPv6 address
|
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
socket.inet_pton(socket.AF_INET6, ipaddr)
|
socket.inet_pton(socket.AF_INET6, ipaddr)
|
||||||
except socket.error:
|
except socket.error:
|
||||||
|
|||||||
@@ -33,9 +33,7 @@ from ansible.plugins.action import ActionBase
|
|||||||
|
|
||||||
|
|
||||||
def run_cmd(args, stdin=None):
|
def run_cmd(args, stdin=None):
|
||||||
"""
|
"""Execute an external command."""
|
||||||
Execute an external command.
|
|
||||||
"""
|
|
||||||
p_in = None
|
p_in = None
|
||||||
p_out = subprocess.PIPE
|
p_out = subprocess.PIPE
|
||||||
p_err = subprocess.PIPE
|
p_err = subprocess.PIPE
|
||||||
@@ -53,8 +51,10 @@ def run_cmd(args, stdin=None):
|
|||||||
|
|
||||||
def kinit_password(principal, password, ccache_name, config):
|
def kinit_password(principal, password, ccache_name, config):
|
||||||
"""
|
"""
|
||||||
Perform kinit using principal/password, with the specified config file
|
Perform kinit using principal/password.
|
||||||
and store the TGT in ccache_name.
|
|
||||||
|
It uses the specified config file to kinit and stores the TGT
|
||||||
|
in ccache_name.
|
||||||
"""
|
"""
|
||||||
args = ["/usr/bin/kinit", principal, '-c', ccache_name]
|
args = ["/usr/bin/kinit", principal, '-c', ccache_name]
|
||||||
old_config = os.environ.get('KRB5_CONFIG')
|
old_config = os.environ.get('KRB5_CONFIG')
|
||||||
@@ -71,8 +71,10 @@ def kinit_password(principal, password, ccache_name, config):
|
|||||||
|
|
||||||
def kinit_keytab(principal, keytab, ccache_name, config):
|
def kinit_keytab(principal, keytab, ccache_name, config):
|
||||||
"""
|
"""
|
||||||
Perform kinit using principal/keytab, with the specified config file
|
Perform kinit using principal/keytab.
|
||||||
and store the TGT in ccache_name.
|
|
||||||
|
It uses the specified config file to kinit and stores the TGT
|
||||||
|
in ccache_name.
|
||||||
"""
|
"""
|
||||||
if gssapi is None:
|
if gssapi is None:
|
||||||
raise ImportError("gssapi is not available")
|
raise ImportError("gssapi is not available")
|
||||||
@@ -126,7 +128,7 @@ class ActionModule(ActionBase):
|
|||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
def run(self, tmp=None, task_vars=None):
|
||||||
"""
|
"""
|
||||||
handler for credential cache transfer
|
Handle credential cache transfer.
|
||||||
|
|
||||||
ipa* commands can either provide a password or a keytab file
|
ipa* commands can either provide a password or a keytab file
|
||||||
in order to authenticate on the managed node with Kerberos.
|
in order to authenticate on the managed node with Kerberos.
|
||||||
@@ -142,7 +144,6 @@ class ActionModule(ActionBase):
|
|||||||
|
|
||||||
Then the IPA commands can use this credential cache file.
|
Then the IPA commands can use this credential cache file.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if task_vars is None:
|
if task_vars is None:
|
||||||
task_vars = dict()
|
task_vars = dict()
|
||||||
|
|
||||||
|
|||||||
@@ -135,8 +135,7 @@ if six.PY3:
|
|||||||
|
|
||||||
def get_host_diff(ipa_host, module_host):
|
def get_host_diff(ipa_host, module_host):
|
||||||
"""
|
"""
|
||||||
Compares two dictionaries containing host attributes and builds a dict
|
Compare two host dicts and builds a dict of differences.
|
||||||
of differences.
|
|
||||||
|
|
||||||
:param ipa_host: the host structure seen from IPA
|
:param ipa_host: the host structure seen from IPA
|
||||||
:param module_host: the target host structure seen from the module params
|
:param module_host: the target host structure seen from the module params
|
||||||
@@ -164,7 +163,7 @@ def get_host_diff(ipa_host, module_host):
|
|||||||
|
|
||||||
def get_module_host(module):
|
def get_module_host(module):
|
||||||
"""
|
"""
|
||||||
Creates a structure representing the host information
|
Create a structure representing the host information.
|
||||||
|
|
||||||
Reads the module parameters and builds the host structure as expected from
|
Reads the module parameters and builds the host structure as expected from
|
||||||
the module
|
the module
|
||||||
@@ -189,7 +188,7 @@ def get_module_host(module):
|
|||||||
|
|
||||||
def ensure_host_present(module, api, ipahost):
|
def ensure_host_present(module, api, ipahost):
|
||||||
"""
|
"""
|
||||||
Ensures that the host exists in IPA and has the same attributes.
|
Ensure that the host exists in IPA and has the same attributes.
|
||||||
|
|
||||||
:param module: the ansible module
|
:param module: the ansible module
|
||||||
:param api: IPA api handle
|
:param api: IPA api handle
|
||||||
@@ -246,7 +245,7 @@ def ensure_host_present(module, api, ipahost):
|
|||||||
|
|
||||||
def ensure_host_absent(module, api, host):
|
def ensure_host_absent(module, api, host):
|
||||||
"""
|
"""
|
||||||
Ensures that the host does not exist in IPA
|
Ensure that the host does not exist in IPA.
|
||||||
|
|
||||||
:param module: the ansible module
|
:param module: the ansible module
|
||||||
:param api: the IPA API handle
|
:param api: the IPA API handle
|
||||||
@@ -271,9 +270,7 @@ def ensure_host_absent(module, api, host):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""
|
|
||||||
Main routine for the ansible module.
|
|
||||||
"""
|
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
principal=dict(default='admin'),
|
principal=dict(default='admin'),
|
||||||
|
|||||||
@@ -235,7 +235,6 @@ def is_client_configured():
|
|||||||
|
|
||||||
:returns: boolean
|
:returns: boolean
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return (os.path.isfile(paths.IPA_DEFAULT_CONF) and
|
return (os.path.isfile(paths.IPA_DEFAULT_CONF) and
|
||||||
os.path.isfile(os.path.join(paths.IPA_CLIENT_SYSRESTORE,
|
os.path.isfile(os.path.join(paths.IPA_CLIENT_SYSRESTORE,
|
||||||
sysrestore.SYSRESTORE_STATEFILE)))
|
sysrestore.SYSRESTORE_STATEFILE)))
|
||||||
@@ -243,11 +242,10 @@ def is_client_configured():
|
|||||||
|
|
||||||
def get_ipa_conf():
|
def get_ipa_conf():
|
||||||
"""
|
"""
|
||||||
Return IPA configuration read from /etc/ipa/default.conf
|
Return IPA configuration read from `/etc/ipa/default.conf`.
|
||||||
|
|
||||||
:returns: dict containing key,value
|
:returns: dict containing key,value
|
||||||
"""
|
"""
|
||||||
|
|
||||||
parser = RawConfigParser()
|
parser = RawConfigParser()
|
||||||
parser.read(paths.IPA_DEFAULT_CONF)
|
parser.read(paths.IPA_DEFAULT_CONF)
|
||||||
result = dict()
|
result = dict()
|
||||||
|
|||||||
Reference in New Issue
Block a user