无法在远程主机上执行ansible play

无法在远程主机上执行ansible play

我试图在远程主机上的 ansible 中运行多个 shell 命令,但失败得很惨:

   - name: Mkdir on server and copy packages locally
     shell: |
      mkdir /root/vdbench
      cd /root
      cp vdbench50403.zip /root/vdbench
      cd /root/vdbench
      unzip vdbench50403.zip

错误:

TASK [Mkdir on server and copy packages locally] *******************************
fatal: [153.254.108.166]: FAILED! => {"changed": true, "cmd": "mkdir /root/vdbench\n cd /root\n cp vdbench50403.zip /root/vdbench\n cd /root/vdbench\n unzip vdbench50403.zip", "delta": "0:00:00.006011", "end": "2017-05-26 07:24:30.518445", "failed": true, "rc": 127, "start": "2017-05-26 07:24:30.512434", "stderr": "mkdir: cannot create directory ‘/root/vdbench’: File exists\n/bin/sh: line 4: unzip: command not found", "stdout": "", "stdout_lines": [], "warnings": ["Consider using file module with state=directory rather than running mkdir"]}
fatal: [153.254.108.165]: FAILED! => {"changed": true, "cmd": "mkdir /root/vdbench\n cd /root\n cp vdbench50403.zip /root/vdbench\n cd /root/vdbench\n unzip vdbench50403.zip", "delta": "0:00:00.005799", "end": "2017-05-26 07:24:30.740551", "failed": true, "rc": 127, "start": "2017-05-26 07:24:30.734752", "stderr": "mkdir: cannot create directory ‘/root/vdbench’: File exists\n/bin/sh: line 4: unzip: command not found", "stdout": "", "stdout_lines": [], "warnings": ["Consider using file module with state=directory rather than running mkdir"]}
fatal: [153.254.108.164]: FAILED! => {"changed": true, "cmd": "mkdir /root/vdbench\n cd /root\n cp vdbench50403.zip /root/vdbench\n cd /root/vdbench\n unzip vdbench50403.zip", "delta": "0:00:00.006032", "end": "2017-05-26 07:24:30.745565", "failed": true, "rc": 127, "start": "2017-05-26 07:24:30.739533", "stderr": "mkdir: cannot create directory ‘/root/vdbench’: File exists\n/bin/sh: line 4: unzip: command not found", "stdout": "", "stdout_lines": [], "warnings": ["Consider using file module with state=directory rather than running mkdir"]}
fatal: [153.254.108.163]: FAILED! => {"changed": true, "cmd": "mkdir /root/vdbench\n cd /root\n cp vdbench50403.zip /root/vdbench\n cd /root/vdbench\n unzip vdbench50403.zip", "delta": "0:00:00.006703", "end": "2017-05-26 07:24:30.832733", "failed": true, "rc": 127, "start": "2017-05-26 07:24:30.826030", "stderr": "mkdir: cannot create directory ‘/root/vdbench’: File exists\n/bin/sh: line 4: unzip: command not found", "stdout": "", "stdout_lines": [], "warnings": ["Consider using file module with state=directory rather than running mkdir"]}

答案1

阅读输出告诉您的内容:

  • mkdir 失败,因为目录已存在
  • 目标系统缺少 unzip 命令。

要修复错误,请执行以下操作:

  • 将 -p 标志传递给 mkdir
  • 在目标服务器上安装 unzip

或者,更好的是,更改您的剧本以使用 ansible 模块执行操作,而不是仅在目标主机上运行 shell 命令。

- name: Extract vdbench
  unarchive:
    src: vdbench50403.zip
    dest: /root/vdbench

请注意,src 是您运行 ansible 的计算机上的一个文件。

相关内容