diff --git a/roles/ipa/server/files/cleanup-stage-users.py b/roles/ipa/server/files/cleanup-stage-users.py index d5c1ba55d9..a5cd3a1bd8 100644 --- a/roles/ipa/server/files/cleanup-stage-users.py +++ b/roles/ipa/server/files/cleanup-stage-users.py @@ -14,12 +14,16 @@ os.environ["KRB5_CLIENT_KTNAME"] = KEYTAB.format(hostname=hostname) client = ClientMeta(hostname) client.login_kerberos() threshold = datetime.utcnow() - timedelta(days=KEEP_DAYS) -for user in client.stageuser_find()["result"]: - username = user["uid"][0] - created_on = datetime.strptime( - user["fascreationtime"][0]["__datetime__"], "%Y%m%d%H%M%SZ" - ) - if created_on > threshold: - continue - print(f"Deleting old stage user: {username}") - client.stageuser_del(username) +while True: + response = client.stageuser_find() + for user in response["result"]: + username = user["uid"][0] + created_on = datetime.strptime( + user["fascreationtime"][0]["__datetime__"], "%Y%m%d%H%M%SZ" + ) + if created_on > threshold: + continue + print(f"Deleting old stage user: {username}") + client.stageuser_del(username) + if not response["truncated"]: + break