Blame SOURCES/ansible-freeipa-0.3.6-ipabackup-Use-module-to-get-IPA_BACKUP_DIR-from-ipap_rhbz#1969847.patch

5a21bc
From db208bd6c11afda738b254b4d21b3cfb5307a3fd Mon Sep 17 00:00:00 2001
5a21bc
From: Thomas Woerner <twoerner@redhat.com>
5a21bc
Date: Wed, 9 Jun 2021 10:53:34 +0200
5a21bc
Subject: [PATCH] ipabackup: Use module to get IPA_BACKUP_DIR from ipaplatform
5a21bc
5a21bc
Up to now a python snippet was used to get IPA_BACKUP_DIR from ipaplatform
5a21bc
but this was not working when ansible_facts was false due to not getting
5a21bc
ansible_python_interpreter set.
5a21bc
5a21bc
The module version is also working if gather_facts is turned off.
5a21bc
---
5a21bc
 .../library/ipabackup_get_backup_dir.py       | 69 +++++++++++++++++++
5a21bc
 roles/ipabackup/tasks/get_ipabackup_dir.yml   | 12 ++--
5a21bc
 2 files changed, 73 insertions(+), 8 deletions(-)
5a21bc
 create mode 100644 roles/ipabackup/library/ipabackup_get_backup_dir.py
5a21bc
5a21bc
diff --git a/roles/ipabackup/library/ipabackup_get_backup_dir.py b/roles/ipabackup/library/ipabackup_get_backup_dir.py
5a21bc
new file mode 100644
5a21bc
index 0000000..b76d01d
5a21bc
--- /dev/null
5a21bc
+++ b/roles/ipabackup/library/ipabackup_get_backup_dir.py
5a21bc
@@ -0,0 +1,69 @@
5a21bc
+#!/usr/bin/python
5a21bc
+# -*- coding: utf-8 -*-
5a21bc
+
5a21bc
+# Authors:
5a21bc
+#   Thomas Woerner <twoerner@redhat.com>
5a21bc
+#
5a21bc
+# Copyright (C) 2021  Red Hat
5a21bc
+# see file 'COPYING' for use and warranty information
5a21bc
+#
5a21bc
+# This program is free software; you can redistribute it and/or modify
5a21bc
+# it under the terms of the GNU General Public License as published by
5a21bc
+# the Free Software Foundation, either version 3 of the License, or
5a21bc
+# (at your option) any later version.
5a21bc
+#
5a21bc
+# This program is distributed in the hope that it will be useful,
5a21bc
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
5a21bc
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5a21bc
+# GNU General Public License for more details.
5a21bc
+#
5a21bc
+# You should have received a copy of the GNU General Public License
5a21bc
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
5a21bc
+
5a21bc
+ANSIBLE_METADATA = {
5a21bc
+    'metadata_version': '1.0',
5a21bc
+    'supported_by': 'community',
5a21bc
+    'status': ['preview'],
5a21bc
+}
5a21bc
+
5a21bc
+DOCUMENTATION = '''
5a21bc
+---
5a21bc
+module: ipabackup_get_backup_dir
5a21bc
+short description:
5a21bc
+  Get IPA_BACKUP_DIR from ipaplatform
5a21bc
+description:
5a21bc
+  Get IPA_BACKUP_DIR from ipaplatform
5a21bc
+options:
5a21bc
+author:
5a21bc
+    - Thomas Woerner
5a21bc
+'''
5a21bc
+
5a21bc
+EXAMPLES = '''
5a21bc
+# Get IPA_BACKUP_DIR from ipaplatform
5a21bc
+- name: ipabackup_get_backup_dir:
5a21bc
+  register result
5a21bc
+'''
5a21bc
+
5a21bc
+RETURN = '''
5a21bc
+backup_dir:
5a21bc
+  description: IPA_BACKUP_DIR from ipaplatform
5a21bc
+  returned: always
5a21bc
+  type: str
5a21bc
+'''
5a21bc
+
5a21bc
+from ansible.module_utils.basic import AnsibleModule
5a21bc
+from ipaplatform.paths import paths
5a21bc
+
5a21bc
+
5a21bc
+def main():
5a21bc
+    module = AnsibleModule(
5a21bc
+        argument_spec=dict(),
5a21bc
+        supports_check_mode=True,
5a21bc
+    )
5a21bc
+
5a21bc
+    module.exit_json(changed=False,
5a21bc
+                     backup_dir=paths.IPA_BACKUP_DIR)
5a21bc
+
5a21bc
+
5a21bc
+if __name__ == '__main__':
5a21bc
+    main()
5a21bc
diff --git a/roles/ipabackup/tasks/get_ipabackup_dir.yml b/roles/ipabackup/tasks/get_ipabackup_dir.yml
5a21bc
index 45cb48a..a7cb29d 100644
5a21bc
--- a/roles/ipabackup/tasks/get_ipabackup_dir.yml
5a21bc
+++ b/roles/ipabackup/tasks/get_ipabackup_dir.yml
5a21bc
@@ -1,12 +1,8 @@
5a21bc
 ---
5a21bc
-- name: Get IPA_BACKUP_DIR dir from ipaplatform
5a21bc
-  command: "{{ ansible_python_interpreter | default('/usr/bin/python') }}"
5a21bc
-  args:
5a21bc
-    stdin: |
5a21bc
-      from ipaplatform.paths import paths
5a21bc
-      print(paths.IPA_BACKUP_DIR)
5a21bc
-  register: result_ipaplatform_backup_dir
5a21bc
+- name: Get IPA_BACKUP_DIR from ipaplatform
5a21bc
+  ipabackup_get_backup_dir:
5a21bc
+  register: result_ipabackup_get_backup_dir
5a21bc
 
5a21bc
 - name: Set IPA backup dir
5a21bc
   set_fact:
5a21bc
-    ipabackup_dir: "{{ result_ipaplatform_backup_dir.stdout_lines | first }}"
5a21bc
+    ipabackup_dir: "{{ result_ipabackup_get_backup_dir.backup_dir }}"
5a21bc
-- 
5a21bc
2.31.1
5a21bc