mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-03-28 22:33:03 +00:00
51 lines
1017 B
YAML
51 lines
1017 B
YAML
---
|
|
- vars:
|
|
ns: k8s-exec
|
|
pod: sleep-pod
|
|
pod_def:
|
|
apiVersion: v1
|
|
kind: Pod
|
|
metadata:
|
|
name: "{{ pod }}"
|
|
namespace: "{{ ns }}"
|
|
spec:
|
|
containers:
|
|
- name: sleeper
|
|
image: busybox
|
|
command: ["sleep", "infinity"]
|
|
|
|
block:
|
|
- name: Ensure that k8s-log namespace exists
|
|
k8s:
|
|
kind: Namespace
|
|
name: "{{ ns }}"
|
|
|
|
- name: Create a pod
|
|
k8s:
|
|
definition: "{{ pod_def }}"
|
|
wait: yes
|
|
wait_sleep: 1
|
|
wait_timeout: 30
|
|
|
|
- name: Execute a command
|
|
k8s_exec:
|
|
pod: "{{ pod }}"
|
|
namespace: "{{ ns }}"
|
|
command: cat /etc/resolv.conf
|
|
register: output
|
|
|
|
- name: Show k8s_exec output
|
|
debug:
|
|
var: output
|
|
|
|
- name: Assert k8s_exec output is correct
|
|
assert:
|
|
that:
|
|
- "'nameserver' in output.stdout"
|
|
|
|
- name: Cleanup namespace
|
|
k8s:
|
|
kind: Namespace
|
|
name: "{{ ns }}"
|
|
state: absent
|