Issue 1:
From @jansauer on 2016-11-21T09:40:13Z

ISSUE TYPE

Bug Report

COMPONENT NAME

docker_container

ANSIBLE VERSION

ansible 2.2.0.0
config file =
configured module search path = Default w/o overrides

OS / ENVIRONMENT

macOS 10.12.1

ansible, docker and python installed with brew

SUMMARY

I try to setup a docker container with ansible docker_container via a docker tls connection.

STEPS TO REPRODUCE

hosts:

[local]
localhost ansible_connection=local

provision.yml

---
- hosts: all
tasks:

- name: Create a data container
docker_container:
name: test
image: abiosoft/caddy:0.9.3
tls_hostname: tcp://[xxxx:xxxx:xxxx:xxxx::xxxx]:2376
tls_verify: true
key_path: /Users/jan/.docker/custom/server/key.pem
cert_path: /Users/jan/.docker/custom/server/cert.pem
cacert_path: /Users/jan/.docker/custom/server/ca.pem

ansible-playbook -i hosts provision.yml

EXPECTED RESULTS

Ansible create a new container

ACTUAL RESULTS

PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [Create a data container] *************************************************
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Failed to import docker-py - No module named requests.exceptions. Try `pip install docker-py`"}
to retry, use: --limit @/Users/jan/Workspace/ansible/provision.retry

PLAY RECAP *********************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1

I found a workaround for this in another issue...

export PYTHONPATH=/usr/local/lib/python2.7/site-packages/:$PYTHONPATH

After that I get a new error

No config file found; using defaults
Loading callback plugin default of type stdout, v2.0 from /usr/local/Cellar/ansible/2.2.0.0_1/libexec/lib/python2.7/site-packages/ansible/plugins/callback/__init__.pyc

PLAYBOOK: provision.yml ********************************************************
1 plays in provision.yml

PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
Using module file /usr/local/Cellar/ansible/2.2.0.0_1/libexec/lib/python2.7/site-packages/ansible/modules/core/system/setup.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: jan
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1479720959.87-168391919144561 `" && echo ansible-tmp-1479720959.87-168391919144561="` echo $HOME/.ansible/tmp/ansible-tmp-1479720959.87-168391919144561 `" ) && sleep 0'
<localhost> PUT /var/folders/nl/3d67s_ws47n3rhp7y2rq79x80000gn/T/tmpNQ_1vm TO /Users/jan/.ansible/tmp/ansible-tmp-1479720959.87-168391919144561/setup.py
<localhost> EXEC /bin/sh -c 'chmod u+x /Users/jan/.ansible/tmp/ansible-tmp-1479720959.87-168391919144561/ /Users/jan/.ansible/tmp/ansible-tmp-1479720959.87-168391919144561/setup.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python /Users/jan/.ansible/tmp/ansible-tmp-1479720959.87-168391919144561/setup.py; rm -rf "/Users/jan/.ansible/tmp/ansible-tmp-1479720959.87-168391919144561/" > /dev/null 2>&1 && sleep 0'
ok: [localhost]

TASK [Create a data container] *************************************************
task path: /Users/jan/Workspace/ansible/provision.yml:5
Using module file /usr/local/Cellar/ansible/2.2.0.0_1/libexec/lib/python2.7/site-packages/ansible/modules/core/cloud/docker/docker_container.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: jan
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1479720960.93-117306363195073 `" && echo ansible-tmp-1479720960.93-117306363195073="` echo $HOME/.ansible/tmp/ansible-tmp-1479720960.93-117306363195073 `" ) && sleep 0'
<localhost> PUT /var/folders/nl/3d67s_ws47n3rhp7y2rq79x80000gn/T/tmpdqVtwD TO /Users/jan/.ansible/tmp/ansible-tmp-1479720960.93-117306363195073/docker_container.py
<localhost> EXEC /bin/sh -c 'chmod u+x /Users/jan/.ansible/tmp/ansible-tmp-1479720960.93-117306363195073/ /Users/jan/.ansible/tmp/ansible-tmp-1479720960.93-117306363195073/docker_container.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python /Users/jan/.ansible/tmp/ansible-tmp-1479720960.93-117306363195073/docker_container.py; rm -rf "/Users/jan/.ansible/tmp/ansible-tmp-1479720960.93-117306363195073/" > /dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_args": {
"api_version": null,
"blkio_weight": null,
"cacert_path": "/Users/jan/.docker/custom/server/ca.pem",
"capabilities": null,
"cert_path": "/Users/jan/.docker/custom/server/cert.pem",
"cleanup": false,
"command": null,
"cpu_period": null,
"cpu_quota": null,
"cpu_shares": null,
"cpuset_cpus": null,
"cpuset_mems": null,
"debug": false,
"detach": true,
"devices": null,
"dns_opts": null,
"dns_search_domains": null,
"dns_servers": null,
"docker_host": null,
"entrypoint": null,
"env": null,
"env_file": null,
"etc_hosts": null,
"exposed_ports": null,
"filter_logger": false,
"force_kill": false,
"groups": null,
"hostname": null,
"ignore_image": false,
"image": "abiosoft/caddy:0.9.3",
"interactive": false,
"ipc_mode": null,
"keep_volumes": true,
"kernel_memory": null,
"key_path": "/Users/jan/.docker/custom/server/key.pem",
"kill_signal": null,
"labels": null,
"links": null,
"log_driver": null,
"log_options": null,
"mac_address": null,
"memory": "0",
"memory_reservation": null,
"memory_swap": null,
"memory_swappiness": null,
"name": "test",
"network_mode": null,
"networks": null,
"oom_killer": null,
"oom_score_adj": null,
"paused": false,
"pid_mode": null,
"privileged": false,
"published_ports": null,
"pull": false,
"purge_networks": false,
"read_only": false,
"recreate": false,
"restart": false,
"restart_policy": null,
"restart_retries": null,
"security_opts": null,
"shm_size": null,
"ssl_version": null,
"state": "started",
"stop_signal": null,
"stop_timeout": null,
"timeout": null,
"tls": null,
"tls_hostname": "tcp://[xxxx:xxxx:xxxx:xxxx::xxxx]:2376",
"tls_verify": true,
"trust_image_content": false,
"tty": false,
"ulimits": null,
"user": null,
"uts": null,
"volume_driver": null,
"volumes": null,
"volumes_from": null
},
"module_name": "docker_container"
},
"msg": "Error connecting: Error while fetching server API version: ('Connection aborted.', error(2, 'No such file or directory'))"
}
to retry, use: --limit @/Users/jan/Workspace/ansible/provision.retry

PLAY RECAP *********************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1
`
``

Copied from original issue: ansible/ansible-modules-core#5685

Issue 2:
ISSUE TYPE

Bug Report

COMPONENT NAME

docker_container module

ANSIBLE VERSION

ansible 2.1.0.0
config file =
configured module search path = Default w/o overrides

CONFIGURATION

No custom configuration.

OS / ENVIRONMENT

Using Ansible on OS X 10.11.5.

Docker version:

docker --version
Docker version 1.12.0-rc4, build e4a0dbc, experimental

docker-py version:

pip show docker-py

---
Metadata-Version: 2.0
Name: docker-py
Version: 1.8.1
Summary: Python client for Docker.
Home-page: https://github.com/docker/docker-py/
Author: UNKNOWN
Author-email: UNKNOWN
Installer: pip
License: UNKNOWN
Location: /Users/rick/tmp/ansible/module-tests/docker_container/env/lib/python2.7/site-packages
Requires: ipaddress, six, requests, backports.ssl-match-hostname, websocket-client
Classifiers:
Development Status :: 4 - Beta
Environment :: Other Environment
Intended Audience :: Developers
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 2.6
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3.3
Programming Language :: Python :: 3.4
Topic :: Utilities
License :: OSI Approved :: Apache Software License

SUMMARY

I want to build a custom container on top of a base OS container. So I am trying to start a base OS container.

STEPS TO REPRODUCE

I came across this issue in my normal work environment on my Mac. I reproduced it in a clean environment created with virtualenv.

Here is the playbook I reproduced it with.

- name: start an OS image
hosts: all
connection: local

tasks:

- name: pull the OS image
docker_container:
name: my-test-container
image: ubuntu:16.04
state: started

EXPECTED RESULTS

Docker container would be started.

ACTUAL RESULTS

Here is the verbose failure output of the playboook run.

fatal: [localhost]: FAILED! =>
{
"changed": false,
"failed": true,
"invocation": {
"module_args": {
"api_version": null,
"blkio_weight": null,
"cacert_path": null,
"capabilities": null,
"cert_path": null,
"command": null,
"cpu_period": null,
"cpu_quota": null,
"cpu_shares": null,
"cpuset_cpus": null,
"cpuset_mems": null,
"debug": false,
"detach": true,
"devices": null,
"dns_opts": null,
"dns_search_domains": null,
"dns_servers": null,
"docker_host": null,
"entrypoint": null,
"env": null,
"etc_hosts": null,
"exposed_ports": null,
"filter_logger": false,
"force_kill": false,
"groups": null,
"hostname": null,
"image": "ubuntu:16.04",
"interactive": false,
"ipc_mode": null,
"keep_volumes": true,
"kernel_memory": null,
"key_path": null,
"kill_signal": null,
"labels": null,
"links": null,
"log_driver": "json-file",
"log_options": null,
"mac_address": null,
"memory": "0",
"memory_reservation": null,
"memory_swap": null,
"memory_swappiness": null,
"name": "my-test-container",
"network_mode": null,
"networks": null,
"oom_killer": null,
"paused": false,
"pid_mode": null,
"privileged": false,
"published_ports": null,
"pull": false,
"read_only": false,
"recreate": false,
"restart": false,
"restart_policy": null,
"restart_retries": 0,
"security_opts": null,
"shm_size": null,
"ssl_version": null,
"state": "started",
"stop_signal": null,
"stop_timeout": null,
"timeout": null,
"tls": null,
"tls_hostname": null,
"tls_verify": null,
"trust_image_content": false,
"tty": false,
"ulimits": null,
"user": null,
"uts": null,
"volume_driver": null,
"volumes": null,
"volumes_from": null
},
"module_name": "docker_container"
},
"msg": "Failed to import docker-py - No module named requests.exceptions. Try `pip install docker-py`"
}

I am able to start the same container using the shell modue.

- name: start an OS image
hosts: all
connection: local

tasks:

- name: pull the OS image
shell: |
docker run --rm ubuntu:16.04

Here is the success output from that playbook.

changed: [localhost] =>
{
"changed": true,
"cmd": "docker run --rm ubuntu:16.04",
"delta": "0:00:00.625392",
"end": "2016-07-24 17:34:22.476927",
"invocation": {
"module_args": {
"_raw_params": "docker run --rm ubuntu:16.04",
"_uses_shell": true,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"warn": true
},
"module_name": "command"
},
"rc": 0,
"start": "2016-07-24 17:34:21.851535",
"stderr": "",
"stdout": "",
"stdout_lines": [],
"warnings": []
}