Blame ansible-review-0.13.9-ansible-2.4-inventory.patch

6b7558b
From 78cc40b45b8ff38b3198502da24cd545865c248c Mon Sep 17 00:00:00 2001
6b7558b
From: Nils Philippsen <nils@redhat.com>
6b7558b
Date: Wed, 4 Dec 2019 17:21:14 +0100
6b7558b
Subject: [PATCH 1/3] Cope with exception object without message member.
6b7558b
6b7558b
Signed-off-by: Nils Philippsen <nils@redhat.com>
6b7558b
---
6b7558b
 lib/ansiblereview/inventory.py | 6 +++++-
6b7558b
 1 file changed, 5 insertions(+), 1 deletion(-)
6b7558b
6b7558b
diff --git a/lib/ansiblereview/inventory.py b/lib/ansiblereview/inventory.py
6b7558b
index dcb630e..196b556 100644
6b7558b
--- a/lib/ansiblereview/inventory.py
6b7558b
+++ b/lib/ansiblereview/inventory.py
6b7558b
@@ -38,5 +38,9 @@ def parse(candidate, options):
6b7558b
         else:
6b7558b
             ansible.inventory.Inventory(candidate.path)
6b7558b
     except Exception as e:
6b7558b
-        result.errors = [Error(None, "Inventory is broken: %s" % e.message)]
6b7558b
+        if hasattr(e, 'message'):
6b7558b
+            message = e.message
6b7558b
+        else:
6b7558b
+            message = str(e)
6b7558b
+        result.errors = [Error(None, "Inventory is broken: %s" % message)]
6b7558b
     return result
6b7558b
-- 
6b7558b
2.23.0
6b7558b
6b7558b
From 1a074d402837489c96f20bc52ccfbaf87d71e135 Mon Sep 17 00:00:00 2001
6b7558b
From: Nils Philippsen <nils@redhat.com>
6b7558b
Date: Wed, 4 Dec 2019 17:28:27 +0100
6b7558b
Subject: [PATCH 2/3] Rework imports for different Ansible versions.
6b7558b
6b7558b
Signed-off-by: Nils Philippsen <nils@redhat.com>
6b7558b
---
6b7558b
 lib/ansiblereview/inventory.py | 10 +++++-----
6b7558b
 1 file changed, 5 insertions(+), 5 deletions(-)
6b7558b
6b7558b
diff --git a/lib/ansiblereview/inventory.py b/lib/ansiblereview/inventory.py
6b7558b
index 196b556..2c6fc52 100644
6b7558b
--- a/lib/ansiblereview/inventory.py
6b7558b
+++ b/lib/ansiblereview/inventory.py
6b7558b
@@ -5,14 +5,14 @@ import yaml
6b7558b
 
6b7558b
 try:
6b7558b
     import ansible.parsing.dataloader
6b7558b
-    from ansible.vars.manager import VariableManager
6b7558b
-    ANSIBLE = 2
6b7558b
 except ImportError:
6b7558b
+    ANSIBLE = 1
6b7558b
+else:
6b7558b
+    ANSIBLE = 2
6b7558b
     try:
6b7558b
-        from ansible.vars import VariableManager
6b7558b
-        ANSIBLE = 2
6b7558b
+        from ansible.vars.manager import VariableManager
6b7558b
     except ImportError:
6b7558b
-        ANSIBLE = 1
6b7558b
+        from ansible.vars import VariableManager
6b7558b
 
6b7558b
 
6b7558b
 def no_vars_in_host_file(candidate, options):
6b7558b
-- 
6b7558b
2.23.0
6b7558b
6b7558b
From 267502c2b33174655047c272d805aee91bbcdd6d Mon Sep 17 00:00:00 2001
6b7558b
From: Nils Philippsen <nils@redhat.com>
6b7558b
Date: Thu, 5 Dec 2019 10:32:31 +0100
6b7558b
Subject: [PATCH 3/3] Cope with Ansible >= 2.4 inventory changes.
6b7558b
6b7558b
Signed-off-by: Nils Philippsen <nils@redhat.com>
6b7558b
---
6b7558b
 lib/ansiblereview/inventory.py | 18 +++++++++++++++---
6b7558b
 1 file changed, 15 insertions(+), 3 deletions(-)
6b7558b
6b7558b
diff --git a/lib/ansiblereview/inventory.py b/lib/ansiblereview/inventory.py
6b7558b
index 2c6fc52..05dfe53 100644
6b7558b
--- a/lib/ansiblereview/inventory.py
6b7558b
+++ b/lib/ansiblereview/inventory.py
6b7558b
@@ -13,6 +13,10 @@ else:
6b7558b
         from ansible.vars.manager import VariableManager
6b7558b
     except ImportError:
6b7558b
         from ansible.vars import VariableManager
6b7558b
+    if not hasattr(ansible.inventory, 'Inventory'):
6b7558b
+        # The inventory system was reworked in Ansible 2.4.
6b7558b
+        import ansible.inventory.manager
6b7558b
+        ANSIBLE = 2.4
6b7558b
 
6b7558b
 
6b7558b
 def no_vars_in_host_file(candidate, options):
6b7558b
@@ -32,9 +36,17 @@ def parse(candidate, options):
6b7558b
     try:
6b7558b
         if ANSIBLE > 1:
6b7558b
             loader = ansible.parsing.dataloader.DataLoader()
6b7558b
-            var_manager = VariableManager()
6b7558b
-            ansible.inventory.Inventory(loader=loader, variable_manager=var_manager,
6b7558b
-                                        host_list=candidate.path)
6b7558b
+            if ANSIBLE > 2:
6b7558b
+                inventory = ansible.inventory.manager.InventoryManager(
6b7558b
+                    sources=candidate.path,
6b7558b
+                    loader=loader,
6b7558b
+                )
6b7558b
+                VariableManager(loader=loader, inventory=inventory)
6b7558b
+            else:
6b7558b
+                var_manager = VariableManager()
6b7558b
+                ansible.inventory.Inventory(loader=loader,
6b7558b
+                                            variable_manager=var_manager,
6b7558b
+                                            host_list=candidate.path)
6b7558b
         else:
6b7558b
             ansible.inventory.Inventory(candidate.path)
6b7558b
     except Exception as e:
6b7558b
-- 
6b7558b
2.23.0
6b7558b