diff --git a/molecule/default/tasks/exec.yml b/molecule/default/tasks/exec.yml index 39c7e997..77a69f3e 100644 --- a/molecule/default/tasks/exec.yml +++ b/molecule/default/tasks/exec.yml @@ -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 diff --git a/plugins/modules/k8s_exec.py b/plugins/modules/k8s_exec.py old mode 100644 new mode 100755 index bd7b1b9e..f91a7466 --- a/plugins/modules/k8s_exec.py +++ b/plugins/modules/k8s_exec.py @@ -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.