ansible,命令模块和带有管道的jq [英] ansible, command module and jq with pipe
问题描述
我正在尝试运行一个docker命令,该命令返回一个容器列表及其大小.
I'm trying to run a docker command that returns a list of containers, and their size.
命令是docker container ls --format "{\"name\":\"{{.Names}}\", \"size\":\"{{.Size}}\"} " --all | jq --slurp
当我尝试在Ansible剧本中运行它时,它会爆炸:
When I try to run this in an Ansible playbook it explodes:
- name: Get cointainer size
raw: /path/to/script/docker-cointainer-size.sh
截断的错误是:
fatal: [localhost]: FAILED! => changed=true
msg: non-zero return code
rc: 2
stderr: |-
jq - commandline JSON processor [version 1.5-1-a5b5cbe]
Usage: jq [options] <jq filter> [file...]
...
我怀疑这与管道(|)的使用有关,因为当我删除它和随后的jq
命令时,剧本已成功完成.
I suspect this has something to do with the use of the pipe (|), as when I remove this, and the subsequent jq
command, the playbook completes successfully.
.sh
脚本在手动运行时可以正常工作.
The .sh
script does work correctly when run manually.
我还尝试过使用shell
模块以及command
模块-两者都无法运行脚本.
I have also tried using the shell
module, as well as the command
module - both are unable to run the script.
如何在Ansible剧本中使用jq
和管道功能?
How can I use jq
and the pipe function in an Ansible playbook?
推荐答案
退出代码显示:
rc:2 stderr:|- jq-命令行JSON处理器[版本1.5-1-a5b5cbe] 用法:jq [选项] [文件...]
rc: 2 stderr: |- jq - commandline JSON processor [version 1.5-1-a5b5cbe] Usage: jq [options] [file...]
jq 退出代码2 表示:
存在使用问题或系统错误
there was any usage problem or system error
man jq显示:
jq [选项...]过滤器[文件...]
jq [options...] filter [files...]
过滤器"丢失.放一个."例如复制输入
"filter" is missing. Put a "." for example to copy the input
jq --slurp.
jq --slurp .
这篇关于ansible,命令模块和带有管道的jq的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!