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

library/ipajoin.py: Return changed state and new parameter already_joined

The choined tag is only set if changes have been done with the join.

already_joined is set if the ipa-join command is filing with error 13
(already joined). The module is not calling fail_json in this case anymore.
parent b19db21c
Branches
Tags
No related merge requests found
...@@ -108,6 +108,10 @@ EXAMPLES = ''' ...@@ -108,6 +108,10 @@ EXAMPLES = '''
''' '''
RETURN = ''' RETURN = '''
already_joined:
description: The flag describes if the host is arelady joined.
returned: always
type: bool
''' '''
class Object(object): class Object(object):
...@@ -238,6 +242,8 @@ def main(): ...@@ -238,6 +242,8 @@ def main():
options.password = password options.password = password
ccache_dir = None ccache_dir = None
changed = False
already_joined = False
try: try:
(krb_fd, krb_name) = tempfile.mkstemp() (krb_fd, krb_name) = tempfile.mkstemp()
os.close(krb_fd) os.close(krb_fd)
...@@ -315,8 +321,15 @@ def main(): ...@@ -315,8 +321,15 @@ def main():
stderr = result.error_output stderr = result.error_output
if result.returncode != 0: if result.returncode != 0:
if result.returncode == 13:
already_joined = True
module.log("Host is already joined")
else:
if principal:
run(["kdestroy"], raiseonerr=False, env=env)
module.fail_json(msg="Joining realm failed: %s" % stderr) module.fail_json(msg="Joining realm failed: %s" % stderr)
else: else:
changed = True
module.log("Enrolled in IPA realm %s" % realm) module.log("Enrolled in IPA realm %s" % realm)
start = stderr.find('Certificate subject base is: ') start = stderr.find('Certificate subject base is: ')
...@@ -360,7 +373,8 @@ def main(): ...@@ -360,7 +373,8 @@ def main():
except OSError: except OSError:
module.fail_json(msg="Could not remove %s.ipabkp" % krb_name) module.fail_json(msg="Could not remove %s.ipabkp" % krb_name)
module.exit_json(changed=True) module.exit_json(changed=changed,
already_joined=already_joined)
if __name__ == '__main__': if __name__ == '__main__':
main() main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment