From 07ac24e42e21f2ffcf885b08bc7d707b8f2fc3e1 Mon Sep 17 00:00:00 2001 From: itaru2622 <70509350+itaru2622@users.noreply.github.com> Date: Mon, 13 Sep 2021 19:21:24 +0900 Subject: [PATCH] fix k8s_exec, returning rc attribute to follow ansible's common return values. (#230) fix k8s_exec, returning rc attribute to follow ansible's common return values. SUMMARY fix #229. ISSUE TYPE Bugfix Pull Request COMPONENT NAME k8s_exec ADDITIONAL INFORMATION Reviewed-by: None Reviewed-by: None --- .../230-k8sexec-has-new-returnvalue.yml | 2 ++ docs/kubernetes.core.k8s_exec_module.rst | 23 ++++++++++++++++--- molecule/default/tasks/exec.yml | 1 + plugins/modules/k8s_exec.py | 10 ++++++-- 4 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/230-k8sexec-has-new-returnvalue.yml diff --git a/changelogs/fragments/230-k8sexec-has-new-returnvalue.yml b/changelogs/fragments/230-k8sexec-has-new-returnvalue.yml new file mode 100644 index 00000000..ae1e6d6a --- /dev/null +++ b/changelogs/fragments/230-k8sexec-has-new-returnvalue.yml @@ -0,0 +1,2 @@ +bugfixes: +- k8s_exec - fix k8s_exec returning rc attribute, to follow ansible's common return values (https://github.com/ansible-collections/kubernetes.core/pull/230). diff --git a/docs/kubernetes.core.k8s_exec_module.rst b/docs/kubernetes.core.k8s_exec_module.rst index 72b980b2..a43c0fa9 100644 --- a/docs/kubernetes.core.k8s_exec_module.rst +++ b/docs/kubernetes.core.k8s_exec_module.rst @@ -382,7 +382,7 @@ Notes ----- .. note:: - - Return code ``return_code`` for the command executed is added in output in version 1.0.0. + - Return code ``rc`` for the command executed is added in output in version 1.0.0. - The authenticated user must have at least read access to the pods resource and write access to the pods/exec resource. - To avoid SSL certificate validation errors when ``validate_certs`` is *True*, the full certificate chain for the API server must be provided via ``ca_cert`` or in the kubeconfig file. @@ -410,7 +410,7 @@ Examples - name: Check last command status debug: msg: "cmd failed" - when: command_status.return_code != 0 + when: command_status.rc != 0 @@ -441,6 +441,23 @@ Common return values are documented `here + +   + +
+ rc + +
+ integer +
+ + + +
The command status code
+
+ + +   @@ -453,7 +470,7 @@ Common return values are documented `here -
The command status code
+
The command status code. This attribute is deprecated and will be removed in future release. Please use rc instead.

diff --git a/molecule/default/tasks/exec.yml b/molecule/default/tasks/exec.yml index 5397ab95..1878f91e 100644 --- a/molecule/default/tasks/exec.yml +++ b/molecule/default/tasks/exec.yml @@ -54,6 +54,7 @@ - name: Check last command status assert: that: + - command_status.rc != 0 - command_status.return_code != 0 always: diff --git a/plugins/modules/k8s_exec.py b/plugins/modules/k8s_exec.py index b72df56e..bdb8418d 100644 --- a/plugins/modules/k8s_exec.py +++ b/plugins/modules/k8s_exec.py @@ -31,6 +31,7 @@ requirements: - "PyYAML >= 3.11" notes: + - Return code C(rc) for the command executed is added in output in version 2.3.0, and depricates return code C(return_code). - Return code C(return_code) for the command executed is added in output in version 1.0.0. - The authenticated user must have at least read access to the pods resource and write access to the pods/exec resource. @@ -82,7 +83,7 @@ EXAMPLES = r''' - name: Check last command status debug: msg: "cmd failed" - when: command_status.return_code != 0 + when: command_status.rc != 0 ''' RETURN = r''' @@ -104,9 +105,13 @@ result: stderr_lines: description: The command stderr type: str - return_code: + rc: description: The command status code type: int + version_added: 2.3.0 + return_code: + description: The command status code. This attribute is depricated and will remove in future release. Please use rc instead. + type: int ''' import copy @@ -183,6 +188,7 @@ def execute_module(module, k8s_ansible_mixin): changed=True, stdout="".join(stdout), stderr="".join(stderr), + rc=rc, return_code=rc )