From 0a468d32e8502eeb74e21c8b07cf3ad439b72dcf Mon Sep 17 00:00:00 2001
From: Thomas Woerner <twoerner@redhat.com>
Date: Wed, 7 Feb 2024 14:06:22 +0100
Subject: [PATCH] ipaclient_setup_automount with new install states

This is "Fix ipa-client-automount install/uninstall with new install
states" https://github.com/freeipa/freeipa/pull/7100 for ansible-freeipa:

Issue 8384 introduced a new installation state for the statestore
to identify when client/server installation is completely finished
rather than relying on has_files().

The problem is that ipa-client-automount may be called during
ipa-client-install and since installation is not complete at that
point the automount install was failing with "IPA client not
configured".

Add a new state, 'automount', to designate that automount installation
is in process. If check_client_configuration() fails it checks to
see if [installation] automount is True. If so it continues with the
installation.

This also addresses an issue where the filestore and statestore are
shared between the client and automount installers but the client
wasn't refreshing state after automount completed. This resulted in
an incomplete state and index file of backed-up files which caused
files to not be restored on uninstall and the state file to be
orphaned.

Fixes: https://pagure.io/freeipa/issue/9487
---
 .../library/ipaclient_setup_automount.py         | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/roles/ipaclient/library/ipaclient_setup_automount.py b/roles/ipaclient/library/ipaclient_setup_automount.py
index 091af9a4..1c5cf6db 100644
--- a/roles/ipaclient/library/ipaclient_setup_automount.py
+++ b/roles/ipaclient/library/ipaclient_setup_automount.py
@@ -68,7 +68,8 @@ RETURN = '''
 
 from ansible.module_utils.basic import AnsibleModule
 from ansible.module_utils.ansible_ipa_client import (
-    setup_logging, check_imports, options, configure_automount
+    setup_logging, check_imports, options, configure_automount, sysrestore,
+    paths, getargspec
 )
 
 
@@ -95,7 +96,18 @@ def main():
     options.location = options.automount_location
 
     if options.automount_location:
-        configure_automount(options)
+        argspec = getargspec(configure_automount)
+        if len(argspec.args) > 1:
+            fstore = sysrestore.FileStore(paths.IPA_CLIENT_SYSRESTORE)
+            statestore = sysrestore.StateFile(paths.IPA_CLIENT_SYSRESTORE)
+
+            configure_automount(options, statestore)
+
+            # Reload the state as automount install may have modified it
+            fstore._load()
+            statestore._load()
+        else:
+            configure_automount(options)
 
     module.exit_json(changed=True)
 
-- 
GitLab