Error while using kubectl copy with ansible

4/9/2019

I am trying to copy a few files from remote host to pods running.

This command works when directly ran on remote host.

kubectl cp /etc/passwd bus-service/ssh-jumphost-6954f877bf-p5fmq:/etc/passwd_test

But when using Ansible shell or command module I ran into this error.

But when using Ansible

    - name: Copy commands
      shell: "kubectl cp {{ item }} baas-service/{{ jumphost.stdout_lines }}:{{ item }}"
      with_items:
        - { '/etc/master.passwd' }
        - { '/etc/passwd' }
        - { '/etc/group' }

I get an error.

failed: [gngqnc014c] (item={u'/etc/master.passwd': None}) => {
    "changed": true, 
    "cmd": "kubectl cp {u'/etc/master.passwd': None}bus-service/[u'ssh-jumphost-6954f877bf-p5fmq', u'ssh-jumphost-6954f877bf-twg7j', u'ssh-jumphost-6954f877bf-xrmhs']:{u'/etc/master.passwd': None}", 
    "delta": "0:00:00.070410", 
    "end": "2019-04-08 16:04:49.551694", 
    "invocation": {
        "module_args": {
            "_raw_params": "kubectl cp {u'/etc/master.passwd': None}bus-service/[u'ssh-jumphost-6954f877bf-p5fmq', u'ssh-jumphost-6954f877bf-twg7j', u'ssh-jumphost-6954f877bf-xrmhs']:{u'/etc/master.passwd': None}", 
            "_uses_shell": true, 
            "argv": null, 
            "chdir": null, 
            "creates": null, 
            "executable": null, 
            "removes": null, 
            "stdin": null, 
            "warn": true
        }
    }, 
    "item": {
        "/etc/master.passwd": null
    }, 
    "msg": "non-zero return code", 
    "rc": 1, 
    "start": "2019-04-08 16:04:49.481284", 
    "stderr": "error: Filespec must match the canonical format: [[namespace/]pod:]file/path", 
    "stderr_lines": [
        "error: Filespec must match the canonical format: [[namespace/]pod:]file/path"
    ], 
    "stdout": "", 
    "stdout_lines": []
}
-- Bhalu
ansible
kubectl
kubernetes

0 Answers