【发布时间】:2019-10-22 05:19:38
【问题描述】:
我在 ansible playbook 中运行一个 shell 命令,我想在其中存储输出的最后一行但出现以下错误:
致命:[网络服务器]:失败! => {"更改": true, "cmd": "./hash.sh -p admin123 |& tail -1", "delta": "0:00:00.002563", "end ": "2019-06-06 16:25:56.597951", "failed": true, "msg": "非零返回码", "rc": 2, "start": "2019-06-06 16 :25:56.595388", "stderr": "/bin/sh: 1: 语法错误: \"&\" 意外", "stderr_lines": ["/bin/sh: 1: 语法错误: \"&\"意外”],“stdout”:“”,“stdout_lines”:[]}
main.yaml
- name: Get hash value of admin password
shell: "./hash.sh -p {{admin_password}} |& tail -1"
args:
chdir: /usr/share/tools
register: admin_password_hash
当我直接在远程机器上运行该命令 (./hash.sh -p admin123 |& tail -1) 时,它会给出正确的输出。
【问题讨论】:
-
|&无效/bin/sh语法。