community.kubernetes.k8s_exec – Execute command in Pod¶
Note
This plugin is part of the community.kubernetes collection (version 1.1.1).
To install it use: ansible-galaxy collection install community.kubernetes
.
To use it in a playbook, specify: community.kubernetes.k8s_exec
.
New in version 0.10.0: of community.kubernetes
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 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
community.kubernetes.k8s_exec:
namespace: myproject
pod: zuul-scheduler
command: zuul-scheduler full-reconfigure
- name: Check RC status of command executed
community.kubernetes.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)