Docker format strings in an ad-hoc Ansible command: wrap them in raw
ansible -m command -a with docker ps --format {{.Names}} fails, because Ansible runs the argument through Jinja before the shell ever sees it. Wrap the Go template in a raw block.
Before wiping a Raspberry Pi I wanted to know what its Docker still ran, so I reached for an ad-hoc command:
ansible pi -a "docker ps -a --format '{{.Names}}'"It failed with a template error and never reached the Pi. The {{.Names}} is a
Go template, which Docker evaluates, but Ansible gets there first. Every module
argument goes through Jinja, and {{ starts a Jinja expression. It was never
going to parse .Names.
The fix is to tell Jinja to leave the text alone:
ansible pi -a "docker ps -a --format '{% raw %}{{.Names}}{% endraw %}'"The same applies in playbooks, where it’s easy to forget because the command looks ordinary: any text with double braces that a program on the target is supposed to interpret has to be wrapped.