From 8731fcc64bd11e448e9299d36b5d4e1ddbe3527b Mon Sep 17 00:00:00 2001
From: Dmitry Tantsur <dtantsur@protonmail.com>
Date: Fri, 24 Jul 2020 17:46:53 +0200
Subject: [PATCH] Do not require ironic_url if cloud or auth.endpoint is
 provided

The endpoint may be specified in clouds.yaml or via auth, do not
force ironic_url in either of these cases.

Finally, accept "none" as a valid no-auth plugin name.

Change-Id: I4d50b7c55727f022d79df85fb4a163fe3e5fca7b
---
 plugins/modules/baremetal_inspect.py     | 12 +++++++++---
 plugins/modules/baremetal_node.py        | 12 +++++++++---
 plugins/modules/baremetal_node_action.py | 14 ++++++++++----
 3 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/plugins/modules/baremetal_inspect.py b/plugins/modules/baremetal_inspect.py
index 8e9c88e1..d85191d1 100644
--- a/plugins/modules/baremetal_inspect.py
+++ b/plugins/modules/baremetal_inspect.py
@@ -102,15 +102,21 @@ def main():
     module = AnsibleModule(argument_spec, **module_kwargs)
 
     if (
-        module.params['auth_type'] in [None, 'None']
+        module.params['auth_type'] in [None, 'None', 'none']
         and module.params['ironic_url'] is None
+        and not module.params['cloud']
+        and not (module.params['auth']
+                 and module.params['auth'].get('endpoint'))
     ):
         module.fail_json(msg="Authentication appears to be disabled, "
-                             "Please define an ironic_url parameter")
+                             "Please define either ironic_url, or cloud, "
+                             "or auth.endpoint")
 
     if (
         module.params['ironic_url']
-        and module.params['auth_type'] in [None, 'None']
+        and module.params['auth_type'] in [None, 'None', 'none']
+        and not (module.params['auth']
+                 and module.params['auth'].get('endpoint'))
     ):
         module.params['auth'] = dict(
             endpoint=module.params['ironic_url']
diff --git a/plugins/modules/baremetal_node.py b/plugins/modules/baremetal_node.py
index d53b313f..e8c51067 100644
--- a/plugins/modules/baremetal_node.py
+++ b/plugins/modules/baremetal_node.py
@@ -248,15 +248,21 @@ def main():
     if not HAS_JSONPATCH:
         module.fail_json(msg='jsonpatch is required for this module')
     if (
-        module.params['auth_type'] in [None, 'None']
+        module.params['auth_type'] in [None, 'None', 'none']
         and module.params['ironic_url'] is None
+        and not module.params['cloud']
+        and not (module.params['auth']
+                 and module.params['auth'].get('endpoint'))
     ):
         module.fail_json(msg="Authentication appears to be disabled, "
-                             "Please define an ironic_url parameter")
+                             "Please define either ironic_url, or cloud, "
+                             "or auth.endpoint")
 
     if (
         module.params['ironic_url']
-        and module.params['auth_type'] in [None, 'None']
+        and module.params['auth_type'] in [None, 'None', 'none']
+        and not (module.params['auth']
+                 and module.params['auth'].get('endpoint'))
     ):
         module.params['auth'] = dict(
             endpoint=module.params['ironic_url']
diff --git a/plugins/modules/baremetal_node_action.py b/plugins/modules/baremetal_node_action.py
index 73207878..ae0bef97 100644
--- a/plugins/modules/baremetal_node_action.py
+++ b/plugins/modules/baremetal_node_action.py
@@ -245,15 +245,21 @@ def main():
     module = AnsibleModule(argument_spec, **module_kwargs)
 
     if (
-        module.params['auth_type'] in [None, 'None']
+        module.params['auth_type'] in [None, 'None', 'none']
         and module.params['ironic_url'] is None
+        and not module.params['cloud']
+        and not (module.params['auth']
+                 and module.params['auth'].get('endpoint'))
     ):
-        module.fail_json(msg="Authentication appears disabled, Please "
-                             "define an ironic_url parameter")
+        module.fail_json(msg="Authentication appears to be disabled, "
+                             "Please define either ironic_url, or cloud, "
+                             "or auth.endpoint")
 
     if (
         module.params['ironic_url']
-        and module.params['auth_type'] in [None, 'None']
+        and module.params['auth_type'] in [None, 'None', 'none']
+        and not (module.params['auth']
+                 and module.params['auth'].get('endpoint'))
     ):
         module.params['auth'] = dict(
             endpoint=module.params['ironic_url']