Repository: ansible/ansible-modules-core

Issue:
cloud/docker: creation of containers not possible because of "Could not convert 0 to integer" exception
##### Issue Type:
- Bug Report
##### Plugin Name:

cloud/docker
##### Ansible Version:

```
ansible 2.1.0
```
##### Ansible Configuration:
##### Environment:

Fedora 23
##### Summary:

Trying to create a Docker container fails with the following exception:

```
FAILED! => {"changed": false, "failed": true, "msg": "Could not convert 0 to integer"}
```

Issue is in method `_human_to_bytes` (https://github.com/ansible/ansible-modules-core/blob/devel/cloud/docker/docker.py#L531-L545).

Explicitly setting `memory_limit` parameter does not solve the issue. 
##### Steps To Reproduce:

```
- name: start a hello world container
  docker:
    name: container
    image: hello-world
```
##### Expected Results:

A running container.
##### Actual Results:

```
FAILED! => {"changed": false, "failed": true, "msg": "Could not convert 0 to integer"}
```



Discussion:
same issue here on Ubuntu 14.04 (clean install) with docker host from packages and ansible devel.

I tested on Ubuntu 15.10 with `docker-py (1.7.0)` (installed with pip). But it has not worked with the `python-docker` package provided by Ubuntu, too.

I have the same error. Docker-py 1.8 dev and Ansible 2.1.0

Just tested with Docker-py 1.8 dev and Ansible 2.0.1.0 and it works.

@kaczynskid Thanks! Your fix work for me! 

Having same issue on Centos 7, Ansible 2.1.0, and pip `docker-py`.

Same issue too (Fedora 23 and Ansible 2.1.0).

Same issue on Ubuntu 14.04,Ansible 2.1.0

PKMIL if the issue is resolved. I am trying to start the container centos:7 docker image with ansible 1.9

@CaptTofu : Can you please share how this problem resolved. Here my piece of code in my tasks file

### ```
- name: Install centos latest docker
  docker:
    name: centos
    image: centos
    state: present
- name: application service
  docker:
    image: centos:7
    name: lab
    state: reloaded

```
```

I have some error if i set memory_limit via jinja variable:

```
- name: run uwsgi docker container
  docker:
    name: "uwsgi-{{ item.key|replace('_', '-') }}"
    image: "{{ django_container.image }}"
    pull: missing
    expose:
      - "{{ django_container.uwsgi_socket }}"
    ports:
      - "{{ item.value.port }}:{{ django_container.uwsgi_socket }}"
    volumes:
      - "{{ django_container.django_settings }}:/etc/django.conf.py:ro"
      - "/mnt/media:/mnt/media:rw"
    env: "{{ django_container.environment|combine(item.value.get('environment', {})) }}"
    memory_limit: "{{ item.value.get('memory_limit', '0') }}"
    restart_policy: always
    restart_policy_retry: 10
    state: reloaded
    command: "uwsgi {{ item.value.config_name }}"
  with_dict: "{{ uwsgi_backends }}"
```

```
failed: [django1.stack.local] => (item={'value': {u'environment': {u'STATIC_URL': u'/static/'}, u'config_name': u'default_site', u'port': 9104, u'hosts_group': u'uwsgi_backends_ajax'}, 'key': u'ajax'}) => {"failed": true, "item": {"key": "ajax", "value": {"config_name": "default_site", "environment": {"STATIC_URL": "/static/"}, "hosts_group": "uwsgi_backends_ajax", "port": 9104}}, "msg": "Could not convert 0 to integer"}
```

This issue is not just a bug, it is a BLOCKER. Currently you can't start Docker containers with ansible/devel. Simply try to run any container like

```
- docker:
    name: myjenkins
    image: jenkins
```

and you will run into the `Could not convert 0 to integer` error. I propose to care about this issue before releasing a new version of Ansible.

My config works fine without section:

`memory_limit: "{{ item.value.get('memory_limit', '0') }}"`

ansible version 2.0.1.0

@puneetjindal To temporarily fix the issue run this on the machine that runs ansible (not the target machine):

```
curl https://github.com/kaczynskid/ansible-modules-core/commit/46970d6d7add50780e8cedb5067ae5d29a763141.patch | patch /usr/local/Cellar/ansible//HEAD/libexec/lib/python2.7/site-packages/ansible/modules/core/cloud/docker/docker.py
```

Of course, adjust the path if you're not using Mac/Homebrew, do the backups, etc.

@IlyaSemenov Your fix has worked successfully for me on Ubuntu 14.04
Path to patch file was `<repo_root_dir>/lib/ansible/modules/core/cloud/docker/docker.py`


Resolving patch:
diff --git a/cloud/docker/docker.py b/cloud/docker/docker.py
--- a/cloud/docker/docker.py
+++ b/cloud/docker/docker.py
@@ -1848,12 +1848,12 @@ def main():
             ports           = dict(required=False, default=None, type='list'),
             publish_all_ports = dict(default=False, type='bool'),
             volumes         = dict(default=None, type='list'),
-            volumes_from    = dict(default=None),
+            volumes_from    = dict(default=None, type='list'),
             links           = dict(default=None, type='list'),
             devices         = dict(default=None, type='list'),
-            memory_limit    = dict(default=0),
-            memory_swap     = dict(default=0),
-            cpu_shares      = dict(default=0),
+            memory_limit    = dict(default=0, type='int'),
+            memory_swap     = dict(default=0, type='int'),
+            cpu_shares      = dict(default=0, type='int'),
             docker_url      = dict(),
             use_tls         = dict(default=None, choices=['no', 'encrypt', 'verify']),
             tls_client_cert = dict(required=False, default=None, type='path'),


Test patch: