kubernetes.core.k8s_exec – Execute command in Pod¶
Note
This plugin is part of the kubernetes.core collection (version 1.2.1).
To install it use: ansible-galaxy collection install kubernetes.core
.
To use it in a playbook, specify: kubernetes.core.k8s_exec
.
New in version 0.10.0: of kubernetes.core
Synopsis¶
Use the Kubernetes Python client to execute command on K8s pods.
Note
This module has a corresponding action plugin.
Requirements¶
The below requirements are needed on the host that executes this module.
python >= 2.7
openshift == 0.4.3
PyYAML >= 3.11
Parameters¶
Notes¶
Note
Return code
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.
The OpenShift Python client wraps the K8s Python client, providing full access to all of the APIS and models available on both platforms. For API version details and additional information visit https://github.com/openshift/openshift-restclient-python
To avoid SSL certificate validation errors when
validate_certs
is True, the full certificate chain for the API server must be provided viaca_cert
or in the kubeconfig file.
Examples¶
- name: Execute a command
kubernetes.core.k8s_exec:
namespace: myproject
pod: zuul-scheduler
command: zuul-scheduler full-reconfigure
- name: Check RC status of command executed
kubernetes.core.k8s_exec:
namespace: myproject
pod: busybox-test
command: cmd_with_non_zero_exit_code
register: command_status
ignore_errors: True
- name: Check last command status
debug:
msg: "cmd failed"
when: command_status.return_code != 0
Return Values¶
Common return values are documented here, the following are the fields unique to this module:
Authors¶
Tristan de Cacqueray (@tristanC)