From 67e457eb837b970497b09e5c5525393b43f34513 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Fri, 15 Nov 2019 18:05:54 +0000
Subject: [PATCH] Add checks to verify that the plugin has been loaded

Provides a nice error message to the user: otherwise the only
sign that something went wrong is a series of warnings from
Ansible about the inventory, and then presumably some undefined
variable errors later on...
---
 playbooks/init-credentials.yml          | 3 +++
 plugins/inventory/float.py              | 1 +
 roles/base/meta/main.yml                | 3 +++
 roles/float-plugin-check/tasks/main.yml | 6 ++++++
 4 files changed, 13 insertions(+)
 create mode 100644 roles/base/meta/main.yml
 create mode 100644 roles/float-plugin-check/tasks/main.yml

diff --git a/playbooks/init-credentials.yml b/playbooks/init-credentials.yml
index 817f8ad1..3d9ce94d 100644
--- a/playbooks/init-credentials.yml
+++ b/playbooks/init-credentials.yml
@@ -14,6 +14,9 @@
   gather_facts: no
   become: no
   tasks:
+    # Check that "float" is properly set up.
+    - include_role: float-plugin-check
+
     # Create the paths below credentials_dir that we're going to use.
     - name: "Create paths below {{ credentials_dir }}"
       file:
diff --git a/plugins/inventory/float.py b/plugins/inventory/float.py
index 04346f6d..01884794 100644
--- a/plugins/inventory/float.py
+++ b/plugins/inventory/float.py
@@ -530,6 +530,7 @@ def run_scheduler(config):
     all_vars = inventory.setdefault('group_vars', {}).setdefault('all', {})
     all_vars.update(config['vars'])
     all_vars.update({
+        'float_plugin_loaded': True,
         'services': services,
         'default_service_credentials': DEFAULT_SERVICE_CREDENTIALS,
         'float_global_dns_map': _global_dns_map(inventory),
diff --git a/roles/base/meta/main.yml b/roles/base/meta/main.yml
new file mode 100644
index 00000000..c62444d5
--- /dev/null
+++ b/roles/base/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+  - { role: float-plugin-check }
diff --git a/roles/float-plugin-check/tasks/main.yml b/roles/float-plugin-check/tasks/main.yml
new file mode 100644
index 00000000..166ab4ba
--- /dev/null
+++ b/roles/float-plugin-check/tasks/main.yml
@@ -0,0 +1,6 @@
+---
+
+- fail:
+    msg: "The 'float' plugin was not loaded! This could be due to multiple reasons: wrong paths in ansible.cfg, problems with the Python version used by Ansible, etc..."
+  when: "not float_plugin_loaded | default(False)"
+
-- 
GitLab