Update test variable name and k8s_exec version_added attribute

This commit is contained in:
Tristan Cacqueray
2020-02-14 18:28:16 +00:00
parent ea0326eab1
commit 5f1b88ba6f
2 changed files with 15 additions and 14 deletions

View File

@@ -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
View 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.