I'm trying to run a docker command that returns a list of containers, and their size.
The command is docker container ls --format "{\"name\":\"{{.Names}}\", \"size\":\"{{.Size}}\"} " --all | jq --slurp
When I try to run this in an Ansible playbook it explodes:
- name: Get cointainer size
raw: /path/to/script/docker-cointainer-size.sh
The truncated error is:
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...]
...
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.
The .sh
script does work correctly when run manually.
I have also tried using the shell
module, as well as the command
module - both are unable to run the script.
How can I use jq
and the pipe function in an Ansible playbook?
The exit code says:
jq exit code 2 means:
man jq shows:
"filter" is missing. Put a "." for example to copy the input