Fix Jinja2 template conflicts in Docker and Podman detection
Escape Go template syntax in shell commands to prevent Ansible from
interpreting them as Jinja2 templates.
Errors fixed:
template error while templating string: unexpected '.'
String: docker version --format '{{.Server.Version}}'
String: docker images --format "{{.Repository}}:{{.Tag}}"
String: podman version --format '{{.Version}}'
Changes:
- Docker version check: Escape {{.Server.Version}}
- Docker images list: Escape {{.Repository}} and {{.Tag}}
- Podman version check: Escape {{.Version}}
Solution:
Convert {{ to {{ "{{" }} and }} to {{ "}}" }}
This tells Ansible to output literal {{ }} in the shell command
The Docker/Podman CLI then interprets the Go templates correctly
Example:
Before: '{{.Server.Version}}'
After: '{{ "{{" }}.Server.Version{{ "}}" }}'
Result: Shell receives '{{.Server.Version}}' as intended
Testing: Playbook now completes successfully without template errors.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -164,7 +164,7 @@
|
|||||||
- name: Check for Docker
|
- name: Check for Docker
|
||||||
shell: |
|
shell: |
|
||||||
if command -v docker &> /dev/null; then
|
if command -v docker &> /dev/null; then
|
||||||
docker version --format '{{.Server.Version}}' 2>/dev/null || echo "Docker installed but not running"
|
docker version --format '{{ "{{" }}.Server.Version{{ "}}" }}' 2>/dev/null || echo "Docker installed but not running"
|
||||||
else
|
else
|
||||||
echo "Docker not installed"
|
echo "Docker not installed"
|
||||||
fi
|
fi
|
||||||
@@ -188,7 +188,7 @@
|
|||||||
failed_when: false
|
failed_when: false
|
||||||
|
|
||||||
- name: List Docker images
|
- name: List Docker images
|
||||||
shell: docker images --format "{{.Repository}}:{{.Tag}}" | wc -l
|
shell: docker images --format "{{ "{{" }}.Repository{{ "}}" }}:{{ "{{" }}.Tag{{ "}}" }}" | wc -l
|
||||||
register: system_info_docker_images_raw
|
register: system_info_docker_images_raw
|
||||||
changed_when: false
|
changed_when: false
|
||||||
failed_when: false
|
failed_when: false
|
||||||
@@ -201,7 +201,7 @@
|
|||||||
- name: Check for Podman
|
- name: Check for Podman
|
||||||
shell: |
|
shell: |
|
||||||
if command -v podman &> /dev/null; then
|
if command -v podman &> /dev/null; then
|
||||||
podman version --format '{{.Version}}'
|
podman version --format '{{ "{{" }}.Version{{ "}}" }}'
|
||||||
else
|
else
|
||||||
echo "Podman not installed"
|
echo "Podman not installed"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user