From 13be47c7a6bf4f224391708b624834f945374344 Mon Sep 17 00:00:00 2001
From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com>
Date: Thu, 23 Jan 2025 20:47:59 +0100
Subject: [PATCH] [PR #9612/f5cbf5ac backport][stable-10] apache2-mod-proxy:
 use deps to handle dependencies (#9617)

apache2-mod-proxy: use deps to handle dependencies (#9612)

* apache2-mod-proxy: use deps to handle dependencies

* add changelog frag

* fix errors

(cherry picked from commit f5cbf5acc7e0465169b5bbf2dc634a9d9acc7986)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
---
 .../fragments/9612-apache2-mod-proxy-revamp5.yml  |  2 ++
 plugins/modules/apache2_mod_proxy.py              | 15 ++++-----------
 2 files changed, 6 insertions(+), 11 deletions(-)
 create mode 100644 changelogs/fragments/9612-apache2-mod-proxy-revamp5.yml

diff --git a/changelogs/fragments/9612-apache2-mod-proxy-revamp5.yml b/changelogs/fragments/9612-apache2-mod-proxy-revamp5.yml
new file mode 100644
index 0000000000..57fdccbf3e
--- /dev/null
+++ b/changelogs/fragments/9612-apache2-mod-proxy-revamp5.yml
@@ -0,0 +1,2 @@
+minor_changes:
+  - apache2_mod_proxy - use ``deps`` to handle dependencies (https://github.com/ansible-collections/community.general/pull/9612).
diff --git a/plugins/modules/apache2_mod_proxy.py b/plugins/modules/apache2_mod_proxy.py
index d2be6be612..c14c61663b 100644
--- a/plugins/modules/apache2_mod_proxy.py
+++ b/plugins/modules/apache2_mod_proxy.py
@@ -204,20 +204,14 @@ members:
 """
 
 import re
-import traceback
 
-from ansible.module_utils.basic import AnsibleModule, missing_required_lib
+from ansible_collections.community.general.plugins.module_utils import deps
+from ansible.module_utils.basic import AnsibleModule
 from ansible.module_utils.urls import fetch_url
 from ansible.module_utils.six import iteritems
 
-BEAUTIFUL_SOUP_IMP_ERR = None
-try:
+with deps.declare("BeautifulSoup"):
     from BeautifulSoup import BeautifulSoup
-except ImportError:
-    BEAUTIFUL_SOUP_IMP_ERR = traceback.format_exc()
-    HAS_BEAUTIFULSOUP = False
-else:
-    HAS_BEAUTIFULSOUP = True
 
 # balancer member attributes extraction regexp:
 EXPRESSION = re.compile(r"(b=([\w\.\-]+)&w=(https?|ajp|wss?|ftp|[sf]cgi)://([\w\.\-]+):?(\d*)([/\w\.\-]*)&?[\w\-\=]*)")
@@ -381,8 +375,7 @@ def main():
         supports_check_mode=True
     )
 
-    if HAS_BEAUTIFULSOUP is False:
-        module.fail_json(msg=missing_required_lib('BeautifulSoup'), exception=BEAUTIFUL_SOUP_IMP_ERR)
+    deps.validate(module)
 
     if module.params['state'] is not None:
         states = module.params['state']