Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Add k8s_exec module to collection #7

Closed
geerlingguy opened this issue Jan 30, 2020 · 0 comments · Fixed by #14
Closed

Add k8s_exec module to collection #7

geerlingguy opened this issue Jan 30, 2020 · 0 comments · Fixed by #14
Labels
type/enhancement New feature or request

Comments

@geerlingguy
Copy link
Collaborator

SUMMARY

A new k8s_exec module would allow execution of command in a pod container through the API:
https://docs.okd.io/latest/dev_guide/executing_remote_commands.html#protocol

See: ansible/ansible#55029

Currently the only easy way to do this (without using a custom module) is via kubectl and the command or shell module, which requires more dependencies and setup, and is more fragile.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

k8s_exec

ADDITIONAL INFORMATION

Example playbook:

- hosts: localhost
  gather_facts: no
  vars:
    pod: example-sf-zuul-scheduler-84bf645594-kw9lr
    namespace: myproject
  tasks:
    - name: Test Exec
      k8s_exec:
        pod: "{{ pod }}"
        namespace: "{{ namespace }}"
        command: zuul --version

    - name: Test Stderr
      k8s_exec:
        pod: "{{ pod }}"
        namespace: "{{ namespace }}"
        command: sh -c "echo toto > /dev/stderr"

Results in:

$ ansible-playbook -v test-exec.yaml
PLAY [localhost] *************************************************************

TASK [Test Exec] *************************************************************
changed: [localhost] => {
  "changed": true, "stderr": "", "stderr_lines": [],
  "stdout": "Zuul version: 3.7.2.dev37\n",
  "stdout_lines": ["Zuul version: 3.7.2.dev37"]
}

TASK [Test Stderr] ***********************************************************
changed: [localhost] => {
  "changed": true, "stderr": "toto\n", "stderr_lines": ["toto"],
  "stdout": "", "stdout_lines": []
}

PLAY RECAP *******************************************************************
localhost                  : ok=2    changed=2    unreachable=0    failed=0
TristanCacqueray added a commit to TristanCacqueray/kubernetes that referenced this issue Feb 6, 2020
TristanCacqueray added a commit to TristanCacqueray/kubernetes that referenced this issue Feb 6, 2020
@geerlingguy geerlingguy added the type/enhancement New feature or request label Feb 6, 2020
TristanCacqueray added a commit to TristanCacqueray/kubernetes that referenced this issue Feb 12, 2020
TristanCacqueray added a commit to TristanCacqueray/kubernetes that referenced this issue Feb 12, 2020
TristanCacqueray added a commit to TristanCacqueray/kubernetes that referenced this issue Feb 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant