在Ansible中使用kubectl复制时出错

时间:2019-04-09 02:50:19

标签: kubernetes ansible kubectl

我正在尝试将一些文件从远程主机复制到正在运行的Pod。

直接在远程主机上运行时,此命令有效。

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

但是当使用Ansible shell或命令模块时,我遇到了这个错误。

但是在使用Ansible时

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

我得到一个错误。

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": []
}

0 个答案:

没有答案