Repository: ansible/ansible-modules-core

Issue:
Can not use state: started when specify log_driver in docker_container module
##### ISSUE TYPE
- Bug Report
##### COMPONENT NAME

docker_container
##### ANSIBLE VERSION

```
ansible 2.1.1.0
```
##### OS / ENVIRONMENT

N/A
##### SUMMARY

When I use state: started to start container with container that created with log_driver option. It always remove container and show error Error creating container: 400 Client Error: Bad Request ("No command specified")
##### STEPS TO REPRODUCE

```

---
- name: Test create and start container
  hosts: localhost
  connection: local
  gather_facts: no
  tasks:
    - docker_container:
        name: test
        image: nginx
        log_driver: gelf
        log_options:
          gelf-address: udp://graylog.example.com:12201
        state: present

    - docker_container:
        name: test
        state: started
```
##### EXPECTED RESULTS

The container should start correctly
##### ACTUAL RESULTS

```
Using /home/username/git/ansible/ansible.cfg as config file
Loaded callback default of type stdout, v2.0

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

PLAY [Test Docker container] ***************************************************

TASK [docker_container] ********************************************************
task path: /home/username/git/ansible/test.yml:7
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: username
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1472553339.39-107102396799808 `" && echo ansible-tmp-1472553339.39-107102396799808="` echo $HOME/.ansible/tmp/ansible-tmp-1472553339.39-107102396799808 `" ) && sleep 0'
<localhost> PUT /tmp/tmpHnZwHc TO /home/username/.ansible/tmp/ansible-tmp-1472553339.39-107102396799808/docker_container
<localhost> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/username/.ansible/tmp/ansible-tmp-1472553339.39-107102396799808/docker_container; rm -rf "/home/username/.ansible/tmp/ansible-tmp-1472553339.39-107102396799808/" > /dev/null 2>&1 && sleep 0'
changed: [localhost] => {"ansible_facts": {"ansible_docker_container": {"AppArmorProfile": "", "Args": ["-g", "daemon off;"], "Config": {"AttachStderr": false, "AttachStdin": false, "AttachStdout": false, "Cmd": ["nginx", "-g", "daemon off;"], "Domainname": "", "Entrypoint": null, "Env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "NGINX_VERSION=1.11.3-1~jessie"], "ExposedPorts": {"443/tcp": {}, "80/tcp": {}}, "Hostname": "4dba25aa3867", "Image": "nginx", "Labels": {}, "OnBuild": null, "OpenStdin": false, "StdinOnce": false, "Tty": false, "User": "", "Volumes": null, "WorkingDir": ""}, "Created": "2016-08-30T10:35:49.623067185Z", "Driver": "overlay2", "ExecIDs": null, "GraphDriver": {"Data": {"LowerDir": "/var/lib/docker/overlay2/ab723dd251634a8c92d1a1fc933900861a9bddf52589e1303ebaaf0a899c5af7-init/diff:/var/lib/docker/overlay2/66ce9000f8d2ada07c7de4162b95a7fc120937c3f577d5ce992092129bf109ce/diff:/var/lib/docker/overlay2/8765c294e83460225a9626e86bb0ab00a33d6ff32ac4886c35526a00e2d80abf/diff:/var/lib/docker/overlay2/661c6e859f6ba5dc7c36934ec20f67aafaa8baa21af6e3e666539634ba7d96a7/diff", "MergedDir": "/var/lib/docker/overlay2/ab723dd251634a8c92d1a1fc933900861a9bddf52589e1303ebaaf0a899c5af7/merged", "UpperDir": "/var/lib/docker/overlay2/ab723dd251634a8c92d1a1fc933900861a9bddf52589e1303ebaaf0a899c5af7/diff", "WorkDir": "/var/lib/docker/overlay2/ab723dd251634a8c92d1a1fc933900861a9bddf52589e1303ebaaf0a899c5af7/work"}, "Name": "overlay2"}, "HostConfig": {"AutoRemove": false, "Binds": [], "BlkioDeviceReadBps": null, "BlkioDeviceReadIOps": null, "BlkioDeviceWriteBps": null, "BlkioDeviceWriteIOps": null, "BlkioWeight": 0, "BlkioWeightDevice": null, "CapAdd": null, "CapDrop": null, "Cgroup": "", "CgroupParent": "", "ConsoleSize": [0, 0], "ContainerIDFile": "", "CpuCount": 0, "CpuPercent": 0, "CpuPeriod": 0, "CpuQuota": 0, "CpuShares": 0, "CpusetCpus": "", "CpusetMems": "", "Devices": null, "DiskQuota": 0, "Dns": null, "DnsOptions": null, "DnsSearch": null, "ExtraHosts": null, "GroupAdd": null, "IOMaximumBandwidth": 0, "IOMaximumIOps": 0, "IpcMode": "", "Isolation": "", "KernelMemory": 0, "Links": null, "LogConfig": {"Config": {"gelf-address": "udp://graylog.example.com:12201"}, "Type": "gelf"}, "Memory": 0, "MemoryReservation": 0, "MemorySwap": 0, "MemorySwappiness": -1, "NetworkMode": "default", "OomKillDisable": false, "OomScoreAdj": 0, "PidMode": "", "PidsLimit": 0, "PortBindings": null, "Privileged": false, "PublishAllPorts": false, "ReadonlyRootfs": false, "RestartPolicy": {"MaximumRetryCount": 0, "Name": ""}, "Runtime": "runc", "SecurityOpt": null, "ShmSize": 67108864, "UTSMode": "", "Ulimits": null, "UsernsMode": "", "VolumeDriver": "", "VolumesFrom": null}, "HostnamePath": "", "HostsPath": "", "Id": "4dba25aa3867c34d9fbefeb5ac350619ec3125ffd9ef6b3623916f060631c969", "Image": "sha256:4efb2fcdb1ab05fb03c9435234343c1cc65289eeb016be86193e88d3a5d84f6b", "LogPath": "", "MountLabel": "", "Mounts": [], "Name": "/test", "NetworkSettings": {"Bridge": "", "EndpointID": "", "Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "HairpinMode": false, "IPAddress": "", "IPPrefixLen": 0, "IPv6Gateway": "", "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "MacAddress": "", "Networks": {"bridge": {"Aliases": null, "EndpointID": "", "Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "IPAMConfig": null, "IPAddress": "", "IPPrefixLen": 0, "IPv6Gateway": "", "Links": null, "MacAddress": "", "NetworkID": ""}}, "Ports": null, "SandboxID": "", "SandboxKey": "", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null}, "Path": "nginx", "ProcessLabel": "", "ResolvConfPath": "", "RestartCount": 0, "State": {"Dead": false, "Error": "", "ExitCode": 0, "FinishedAt": "0001-01-01T00:00:00Z", "OOMKilled": false, "Paused": false, "Pid": 0, "Restarting": false, "Running": false, "StartedAt": "0001-01-01T00:00:00Z", "Status": "created"}}}, "changed": true, "invocation": {"module_args": {"api_version": null, "blkio_weight": null, "cacert_path": null, "capabilities": null, "cert_path": null, "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": "nginx", "interactive": false, "ipc_mode": null, "keep_volumes": true, "kernel_memory": null, "key_path": null, "kill_signal": null, "labels": null, "links": null, "log_driver": "gelf", "log_options": {"gelf-address": "udp://graylog.example.com:12201"}, "mac_address": null, "memory": "0", "memory_reservation": null, "memory_swap": null, "memory_swappiness": null, "name": "test", "network_mode": null, "networks": null, "oom_killer": null, "paused": false, "pid_mode": null, "privileged": false, "published_ports": null, "pull": false, "purge_networks": null, "read_only": false, "recreate": false, "restart": false, "restart_policy": null, "restart_retries": 0, "security_opts": null, "shm_size": null, "ssl_version": null, "state": "present", "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"}}

TASK [docker_container] ********************************************************
task path: /home/username/git/ansible/test.yml:15
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: username
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1472553349.83-249876067720115 `" && echo ansible-tmp-1472553349.83-249876067720115="` echo $HOME/.ansible/tmp/ansible-tmp-1472553349.83-249876067720115 `" ) && sleep 0'
<localhost> PUT /tmp/tmpeeGOlf TO /home/username/.ansible/tmp/ansible-tmp-1472553349.83-249876067720115/docker_container
<localhost> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/username/.ansible/tmp/ansible-tmp-1472553349.83-249876067720115/docker_container; rm -rf "/home/username/.ansible/tmp/ansible-tmp-1472553349.83-249876067720115/" > /dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_args": {"api_version": null, "blkio_weight": null, "cacert_path": null, "capabilities": null, "cert_path": null, "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": null, "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": "test", "network_mode": null, "networks": null, "oom_killer": null, "paused": false, "pid_mode": null, "privileged": false, "published_ports": null, "pull": false, "purge_networks": null, "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": "Error creating container: 400 Client Error: Bad Request (\"No command specified\")"}

NO MORE HOSTS LEFT *************************************************************

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



Discussion:
<!-- @winggundamth: Thanks for filing this bug report! -->

@ansible ping, this issue is waiting for your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_bug_new --->

ping @chouseknecht can you help me on this?


Resolving patch:
diff --git a/cloud/docker/docker_container.py b/cloud/docker/docker_container.py
--- a/cloud/docker/docker_container.py
+++ b/cloud/docker/docker_container.py
@@ -200,7 +200,7 @@
     required: false
   log_driver:
     description:
-      - Specify the logging driver.
+      - Specify the logging driver. Docker uses json-file by default.
     choices:
       - json-file
       - syslog
@@ -209,7 +209,7 @@
       - fluentd
       - awslogs
       - splunk
-    default: json-file
+    default: null
     required: false
   log_options:
     description:
@@ -1906,7 +1906,7 @@ def main():
         kill_signal=dict(type='str'),
         labels=dict(type='dict'),
         links=dict(type='list'),
-        log_driver=dict(type='str', choices=['json-file', 'syslog', 'journald', 'gelf', 'fluentd', 'awslogs', 'splunk'], default='json-file'),
+        log_driver=dict(type='str', choices=['json-file', 'syslog', 'journald', 'gelf', 'fluentd', 'awslogs', 'splunk'], default=None),
         log_options=dict(type='dict', aliases=['log_opt']),
         mac_address=dict(type='str'),
         memory=dict(type='str', default='0'),


Test patch: