I am using Ansible to query a bunch of Linux servers, to see what version of Docker is installed.
My simple playbook looks like this:
---
- name: Query Docker
any_errors_fatal: false
hosts: all
gather_facts: false
tasks:
- name: Query Docker version - Debian/Ubuntu
ansible.builtin.command: docker version --format '{{.Server.Version}}'
become: no
register: result
- name: Output Debian/Ubuntu results
ansible.builtin.debug:
var: result
verbosity: 1
Running that docker command on the command line gives me the value I need, for example, something like "20.10.14" or "20.10.7".
When I try passing that command using ansible.builtin.command module, the templating breaks, with the error message:
template error while templating string: unexpected '.'. String: docker version --format '{{.Server.Version}}'
Note: I realize I can also get this information by using the community.docker.docker_host_info module, and that's actually what I am doing to accomplish my task, but I would still like to know how to pass a Go template string, with double curly-brackets, correctly quoted to an Ansible command.
EDIT: This was closed as a duplicate of another question, but I am going to leave it here in case it helps anyone else find the answer to a similar issue.
The fix was to put brackets around the text, like this:
---
- name: Query Docker
any_errors_fatal: false
hosts: all
gather_facts: false
tasks:
- name: Query Docker version - Debian/Ubuntu
ansible.builtin.command: docker version --format {{'{{.Server.Version}}'}}
become: no
register: result
- name: Output Debian/Ubuntu results
ansible.builtin.debug:
var: result
verbosity: 1