Issue 1:
I believe there's an ansible parsing error in this shell task that then leads to a template error.

Here's a sample playbook, test.yml, that I ran against a host with docker installed. ansible-playbook test.yml -e hosts=dockerhost -v

---
# test.yml
- name: Simple test
hosts: "{{ hosts }}"
gather_facts: no
sudo: true
tasks:
- name: remove previous container if it exists
command: docker rm -f busybox-container
ignore_errors: yes
- name: run simple docker container
command: docker run -di --name=busybox-container busybox:latest
- name: get image name
shell: docker inspect --format="{{'{{.Config.Image}}'}}" busybox-container
#shell: docker ps -a | grep busybox | awk '{print $2}'
register: image_name
- name: print debug
debug: msg={{ image_name.stdout }}

Compare the output of the shell task "get image name" using docker inspect (which uses a go template similar to jinja2 syntax and therefore must be escaped) to the shell task that parses the same value through a series of shell commands. The stdout value is the same for each shell, but the debug task fails for docker inpect but not the other.

Issue 2:
Issue Type:

Bug Report

Ansible Version:

ansible 1.8.2
configured module search path = /usr/share/ansible

Environment:

Debian unstable

Summary:

Trying to use the registed output of docker inspect --format=... ... results in a fatal error.

Interestingly enough this works with Ansible 1.7.2 but not with 1.8.2. Also works when just using the output of docker inspect ... without the --format option.

Steps To Reproduce:

Use the following playbook.yml:

- hosts: localhost
connection: local
tasks:
## I know this task returns the information we inpect below
## in ansible_facts.docker_containers[0]. But to uncover
## the bug `docker inspect --format=...` will be used.
- name: start test container
docker:
image: busybox
name: sleep
command: sleep 10
volumes:
- /srv
state: running
- name: read image hash of container
command: docker inspect sleep
register: inspect
- name: read image hash of container
command: docker inspect --format='{{ "{{" }}index . "Image"{{ "}}" }}' sleep
register: image
- name: read name of container
command: docker inspect --format='{{ "{{" }}.Name{{ "}}" }}' sleep
register: name
- name: read directory of container volume
command: docker inspect --format='{{ "{{" }}index .Volumes "/srv"{{ "}}" }}' sleep
register: volume
## We can't us with_items on the variable names since the
## encountered FATALs will end the loop prematurely.
- debug:
var: "{{ i }}.stdout"
- name: clean up test container
docker:
image: busybox
name: sleep
state: absent

Execute it on a host which has Docker installed and running:

for i in inspect image name volume; do
ansible-playbook -e i=$i playbook.yml
done

Expected Results:

inspect.stdout should contain the complete JSON output

image.stdout should be the hash of the official busybox Docker image

name.stdout should be /sleep

volume.stdout should be something like /var/lib/docker/vfs/dir/92fd93ceedababafb4d61615749e093dd170cae4f2f1ec092fc11159b6b0b7c5

Actual Results:

inspect.stdout correctly contains the complete JSON output with

the debug task for image.stdout fails with: fatal: [localhost] => template error while templating string: expected name or number

the debug task for name.stdout fails with: fatal: [localhost] => template error while templating string: unexpected '.'

the debug task for volume.stdout fails with: fatal: [localhost] => template error while templating string: expected token 'end of print statement', got 'string'