Skip to content

Commit 1c56680

Browse files
committed
refactor: use the warn module method on newer Ansible
Starting with Ansible 2.20, modules should not return the `warnings` key in the module return. Instead, modules should use the `warn` method to specify the warnings. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
1 parent 3d7a3f8 commit 1c56680

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

library/network_connections.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,7 +1851,7 @@ def _complete_kwargs_loglines(self, rr, connections, idx):
18511851
)
18521852

18531853
def _complete_kwargs(self, connections, kwargs, traceback_msg=None, fail=False):
1854-
warning_logs = kwargs.get("warnings", [])
1854+
warning_logs = kwargs.pop("warnings", [])
18551855
debug_logs = []
18561856
loglines = []
18571857
for res in self._run_results:
@@ -1866,7 +1866,12 @@ def _complete_kwargs(self, connections, kwargs, traceback_msg=None, fail=False):
18661866
warning_logs.append(log_line)
18671867
if traceback_msg is not None:
18681868
warning_logs.append(traceback_msg)
1869-
kwargs["warnings"] = warning_logs
1869+
# see if the module object has the "warn" function
1870+
if callable(getattr(self.module, "warn", None)):
1871+
for msg in warning_logs:
1872+
self.module.warn(msg)
1873+
else:
1874+
kwargs["warnings"] = warning_logs
18701875
stderr = "\n".join(debug_logs) + "\n"
18711876
kwargs["stderr"] = stderr
18721877
kwargs["_invocation"] = {"module_args": self.module.params}

0 commit comments

Comments
 (0)