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: - vars:
ns: k8s-exec exec_namespace: k8s-exec
pod: sleep-pod pod: sleep-pod
pod_def: exec_pod_definition:
apiVersion: v1 apiVersion: v1
kind: Pod kind: Pod
metadata: metadata:
name: "{{ pod }}" name: "{{ pod }}"
namespace: "{{ ns }}" namespace: "{{ exec_namespace }}"
spec: spec:
containers: containers:
- name: sleeper - name: sleeper
@@ -15,36 +15,37 @@
command: ["sleep", "infinity"] command: ["sleep", "infinity"]
block: block:
- name: Ensure that k8s-log namespace exists - name: "Ensure that {{ exec_namespace }} namespace exists"
k8s: k8s:
kind: Namespace kind: Namespace
name: "{{ ns }}" name: "{{ exec_namespace }}"
- name: Create a pod - name: "Create a pod"
k8s: k8s:
definition: "{{ pod_def }}" definition: "{{ exec_pod_definition }}"
wait: yes wait: yes
wait_sleep: 1 wait_sleep: 1
wait_timeout: 30 wait_timeout: 30
- name: Execute a command - name: "Execute a command"
k8s_exec: k8s_exec:
pod: "{{ pod }}" pod: "{{ pod }}"
namespace: "{{ ns }}" namespace: "{{ exec_namespace }}"
command: cat /etc/resolv.conf command: cat /etc/resolv.conf
register: output register: output
- name: Show k8s_exec output - name: "Show k8s_exec output"
debug: debug:
var: output var: output
- name: Assert k8s_exec output is correct - name: "Assert k8s_exec output is correct"
assert: assert:
that: that:
- "'nameserver' in output.stdout" - "'nameserver' in output.stdout"
- name: Cleanup namespace always:
- name: "Cleanup namespace"
k8s: k8s:
kind: Namespace kind: Namespace
name: "{{ ns }}" name: "{{ exec_namespace }}"
state: absent 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 = ''' DOCUMENTATION = '''
module: k8s_exec module: k8s_exec
short_description: Execute command in Pod short_description: Execute command in Pod
version_added: "2.10" version_added: "1.0.0"
author: "Tristan de Cacqueray (@tristanC)" author: "Tristan de Cacqueray (@tristanC)"
description: description:
- Use the Kubernetes Python client to execute command on K8s pods. - Use the Kubernetes Python client to execute command on K8s pods.