mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-03-27 05:43:02 +00:00
Update test variable name and k8s_exec version_added attribute
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
---
|
||||
- vars:
|
||||
ns: k8s-exec
|
||||
exec_namespace: k8s-exec
|
||||
pod: sleep-pod
|
||||
pod_def:
|
||||
exec_pod_definition:
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: "{{ pod }}"
|
||||
namespace: "{{ ns }}"
|
||||
namespace: "{{ exec_namespace }}"
|
||||
spec:
|
||||
containers:
|
||||
- name: sleeper
|
||||
@@ -15,36 +15,37 @@
|
||||
command: ["sleep", "infinity"]
|
||||
|
||||
block:
|
||||
- name: Ensure that k8s-log namespace exists
|
||||
- name: "Ensure that {{ exec_namespace }} namespace exists"
|
||||
k8s:
|
||||
kind: Namespace
|
||||
name: "{{ ns }}"
|
||||
name: "{{ exec_namespace }}"
|
||||
|
||||
- name: Create a pod
|
||||
- name: "Create a pod"
|
||||
k8s:
|
||||
definition: "{{ pod_def }}"
|
||||
definition: "{{ exec_pod_definition }}"
|
||||
wait: yes
|
||||
wait_sleep: 1
|
||||
wait_timeout: 30
|
||||
|
||||
- name: Execute a command
|
||||
- name: "Execute a command"
|
||||
k8s_exec:
|
||||
pod: "{{ pod }}"
|
||||
namespace: "{{ ns }}"
|
||||
namespace: "{{ exec_namespace }}"
|
||||
command: cat /etc/resolv.conf
|
||||
register: output
|
||||
|
||||
- name: Show k8s_exec output
|
||||
- name: "Show k8s_exec output"
|
||||
debug:
|
||||
var: output
|
||||
|
||||
- name: Assert k8s_exec output is correct
|
||||
- name: "Assert k8s_exec output is correct"
|
||||
assert:
|
||||
that:
|
||||
- "'nameserver' in output.stdout"
|
||||
|
||||
- name: Cleanup namespace
|
||||
always:
|
||||
- name: "Cleanup namespace"
|
||||
k8s:
|
||||
kind: Namespace
|
||||
name: "{{ ns }}"
|
||||
name: "{{ exec_namespace }}"
|
||||
state: absent
|
||||
|
||||
2
plugins/modules/k8s_exec.py
Normal file → Executable file
2
plugins/modules/k8s_exec.py
Normal file → Executable file
@@ -16,7 +16,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
DOCUMENTATION = '''
|
||||
module: k8s_exec
|
||||
short_description: Execute command in Pod
|
||||
version_added: "2.10"
|
||||
version_added: "1.0.0"
|
||||
author: "Tristan de Cacqueray (@tristanC)"
|
||||
description:
|
||||
- Use the Kubernetes Python client to execute command on K8s pods.
|
||||
|
||||
Reference in New Issue
Block a user