ansible / ansible-modules-extras

Ansible extra modules - these modules ship with ansible
947 stars 1.46k forks source link

docker_container unable to attach named volumes #2418

Closed r4j4h closed 8 years ago

r4j4h commented 8 years ago

@drajen reported this over at https://github.com/ansible/ansible/issues/16230 and I am forwarding here so it gets taken care of so no one else suffers data loss or 6 hours of their life for nothing.

ISSUE TYPE

docker_container

ANSIBLE VERSION
ansible 2.1.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
CONFIGURATION

None.

OS / ENVIRONMENT

Ubuntu Linux 14.04.4 source/destination

SUMMARY

In a 'volumes' array I would expect to use the same named volume syntax available with the docker command. Instead, docker_container creates a bind to a directory it created in cwd. I'm unable to identify if this is a bug in ansible or docker-py.

STEPS TO REPRODUCE

Steps to reproduce below:

dri@zen:~/code/resthome$ ls -l
total 22
-rw-rw-r-- 1 dri superiors  10 Jun  9 16:08 playbook.retry
-rw-rw-r-- 1 dri superiors 791 Jun  9 16:01 playbook.yml
dri@zen:~/code/resthome$ ansible-playbook playbook.yml 
 [WARNING]: provided hosts list is empty, only localhost is available

PLAY [localhost] ***************************************************************

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

TASK [Ensure docker-py is installed] *******************************************
changed: [localhost]

TASK [Ensure influxdb py module is too] ****************************************
changed: [localhost]

TASK [InfluxDB docker volume inspect] ******************************************
ERRO[63818] Handler for GET /v1.23/volumes/resthomedb returned error: get resthomedb: no such volume 
changed: [localhost]

TASK [InfluxDB docker volume create] *******************************************
changed: [localhost]

TASK [InfluxDB Container] ******************************************************
changed: [localhost]

TASK [Create rest-home DB] *****************************************************
changed: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=7    changed=6    unreachable=0    failed=0   

dri@zen:~/code/resthome$ ls
playbook.retry  playbook.yml  resthomedb
dri@zen:~/code/resthome$ docker inspect influxdb
...
        "Mounts": [
            {
                "Name": "e2fe64aa92090a65f6532d0f7eeb3116e145b9803c603f57bfff13b98ddb3f62",
                "Source": "/var/lib/docker/volumes/e2fe64aa92090a65f6532d0f7eeb3116e145b9803c603f57bfff13b98ddb3f62/_data",
                "Destination": "/home/dri/code/resthome/resthomedb",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            },
            {
                "Source": "/home/dri/code/resthome/resthomedb",
                "Destination": "/var/lib/influxdb",
                "Mode": "rw",
                "RW": true,
                "Propagation": "rprivate"
            }
...
            "Volumes": {
                "/home/dri/code/resthome/resthomedb": {},
                "/var/lib/influxdb": {}
            },
...
dri@zen:~/code/resthome$ docker volume ls
DRIVER              VOLUME NAME
local               e2fe64aa92090a65f6532d0f7eeb3116e145b9803c603f57bfff13b98ddb3f62
local               resthomedb
dri@zen:~/code/resthome$ ls -l
total 22
-rw-rw-r-- 1 dri superiors  10 Jun  9 16:08 playbook.retry
-rw-rw-r-- 1 dri superiors 791 Jun  9 16:01 playbook.yml

This is the playbook:


---

- hosts: localhost
  tasks:

  - name: Ensure docker-py is installed
    command: pip install docker-py

  - name: Ensure influxdb py module is too
    command: pip install influxdb

  - name: InfluxDB docker volume inspect
    command: docker volume inspect resthomedb
    register: resthomedb_exists
    failed_when: false

  - name: InfluxDB docker volume create
    command: docker volume create --name resthomedb
    when: resthomedb_exists|failed

  - name: InfluxDB Container
    docker_container:
      name: influxdb
      image: influxdb
      volumes:
        - resthomedb:/var/lib/influxdb
      ports:
      - 8083:8083
      - 8086:8086

  - name: Create rest-home DB
    influxdb_database:
      hostname: localhost
      database_name: resthomedb
      state: present
EXPECTED RESULTS

Manual docker commands:

dri@zen:~/code/resthome$ docker  -H localhost:2375 run -d -p 8083:8083 -p 8086:8086 -v resthomedb:/var/lib/influxdb influxdb
b8794cf435a5cd4903a187e4415acf2a9eb65d18aba46b564bf15334653bad7c
dri@zen:~/code/resthome$ docker inspect b8
...
        "Mounts": [
            {
                "Name": "resthomedb",
                "Source": "/var/lib/docker/volumes/resthomedb/_data",
                "Destination": "/var/lib/influxdb",
                "Driver": "local",
                "Mode": "z",
                "RW": true,
                "Propagation": "rprivate"
            }
..
            "Volumes": {
                "/var/lib/influxdb": {}
            },
..
ACTUAL RESULTS
dri@zen:~/code/resthome$ ansible-playbook -vvvv playbook.yml Using /etc/ansible/ansible.cfg as config file
 [WARNING]: provided hosts list is empty, only localhost is available

Loaded callback default of type stdout, v2.0

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

PLAY [localhost] ***************************************************************

TASK [setup] *******************************************************************
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: dri
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1465576986.06-216937825051000 `" && echo ansible-tmp-1465576986.06-216937825051000="` echo $HOME/.ansible/tmp/ansible-tmp-1465576986.06-216937825051000 `" ) && sleep 0'
<127.0.0.1> PUT /tmp/tmpAQXQYR TO /home/dri/.ansible/tmp/ansible-tmp-1465576986.06-216937825051000/setup
<127.0.0.1> 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/dri/.ansible/tmp/ansible-tmp-1465576986.06-216937825051000/setup; rm -rf "/home/dri/.ansible/tmp/ansible-tmp-1465576986.06-216937825051000/" > /dev/null 2>&1 && sleep 0'
ok: [localhost]

TASK [Ensure docker-py is installed] *******************************************
task path: /home/dri/code/resthome/playbook.yml:6
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: dri
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1465576986.82-231566864418906 `" && echo ansible-tmp-1465576986.82-231566864418906="` echo $HOME/.ansible/tmp/ansible-tmp-1465576986.82-231566864418906 `" ) && sleep 0'
<127.0.0.1> PUT /tmp/tmpzQb47F TO /home/dri/.ansible/tmp/ansible-tmp-1465576986.82-231566864418906/command
<127.0.0.1> 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/dri/.ansible/tmp/ansible-tmp-1465576986.82-231566864418906/command; rm -rf "/home/dri/.ansible/tmp/ansible-tmp-1465576986.82-231566864418906/" > /dev/null 2>&1 && sleep 0'
changed: [localhost] => {"changed": true, "cmd": ["pip", "install", "docker-py"], "delta": "0:00:00.329090", "end": "2016-06-10 09:43:07.241183", "invocation": {"module_args": {"_raw_params": "pip install docker-py", "_uses_shell": false, "chdir": null, "creates": null, "executable": null, "removes": null, "warn": true}, "module_name": "command"}, "rc": 0, "start": "2016-06-10 09:43:06.912093", "stderr": "", "stdout": "Requirement already satisfied (use --upgrade to upgrade): docker-py in /usr/local/lib/python2.7/dist-packages\nCleaning up...", "stdout_lines": ["Requirement already satisfied (use --upgrade to upgrade): docker-py in /usr/local/lib/python2.7/dist-packages", "Cleaning up..."], "warnings": []}

TASK [Ensure influxdb py module is too] ****************************************
task path: /home/dri/code/resthome/playbook.yml:9
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: dri
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1465576987.29-74813143058619 `" && echo ansible-tmp-1465576987.29-74813143058619="` echo $HOME/.ansible/tmp/ansible-tmp-1465576987.29-74813143058619 `" ) && sleep 0'
<127.0.0.1> PUT /tmp/tmp1OWGWi TO /home/dri/.ansible/tmp/ansible-tmp-1465576987.29-74813143058619/command
<127.0.0.1> 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/dri/.ansible/tmp/ansible-tmp-1465576987.29-74813143058619/command; rm -rf "/home/dri/.ansible/tmp/ansible-tmp-1465576987.29-74813143058619/" > /dev/null 2>&1 && sleep 0'
changed: [localhost] => {"changed": true, "cmd": ["pip", "install", "influxdb"], "delta": "0:00:00.328842", "end": "2016-06-10 09:43:07.720867", "invocation": {"module_args": {"_raw_params": "pip install influxdb", "_uses_shell": false, "chdir": null, "creates": null, "executable": null, "removes": null, "warn": true}, "module_name": "command"}, "rc": 0, "start": "2016-06-10 09:43:07.392025", "stderr": "", "stdout": "Requirement already satisfied (use --upgrade to upgrade): influxdb in /usr/local/lib/python2.7/dist-packages\nCleaning up...", "stdout_lines": ["Requirement already satisfied (use --upgrade to upgrade): influxdb in /usr/local/lib/python2.7/dist-packages", "Cleaning up..."], "warnings": []}

TASK [InfluxDB docker volume inspect] ******************************************
task path: /home/dri/code/resthome/playbook.yml:12
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: dri
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1465576987.75-264041188908831 `" && echo ansible-tmp-1465576987.75-264041188908831="` echo $HOME/.ansible/tmp/ansible-tmp-1465576987.75-264041188908831 `" ) && sleep 0'
<127.0.0.1> PUT /tmp/tmpt1er6M TO /home/dri/.ansible/tmp/ansible-tmp-1465576987.75-264041188908831/command
<127.0.0.1> 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/dri/.ansible/tmp/ansible-tmp-1465576987.75-264041188908831/command; rm -rf "/home/dri/.ansible/tmp/ansible-tmp-1465576987.75-264041188908831/" > /dev/null 2>&1 && sleep 0'
ERRO[65090] Handler for GET /v1.23/volumes/resthomedb returned error: get resthomedb: no such volume 
changed: [localhost] => {"changed": true, "cmd": ["docker", "volume", "inspect", "resthomedb"], "delta": "0:00:00.052402", "end": "2016-06-10 09:43:07.891712", "failed": false, "failed_when_result": false, "invocation": {"module_args": {"_raw_params": "docker volume inspect resthomedb", "_uses_shell": false, "chdir": null, "creates": null, "executable": null, "removes": null, "warn": true}, "module_name": "command"}, "rc": 1, "start": "2016-06-10 09:43:07.839310", "stderr": "Error: No such volume: resthomedb", "stdout": "[]", "stdout_lines": ["[]"], "warnings": []}

TASK [InfluxDB docker volume create] *******************************************
task path: /home/dri/code/resthome/playbook.yml:17
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: dri
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1465576987.94-169760926353451 `" && echo ansible-tmp-1465576987.94-169760926353451="` echo $HOME/.ansible/tmp/ansible-tmp-1465576987.94-169760926353451 `" ) && sleep 0'
<127.0.0.1> PUT /tmp/tmpTWqmLJ TO /home/dri/.ansible/tmp/ansible-tmp-1465576987.94-169760926353451/command
<127.0.0.1> 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/dri/.ansible/tmp/ansible-tmp-1465576987.94-169760926353451/command; rm -rf "/home/dri/.ansible/tmp/ansible-tmp-1465576987.94-169760926353451/" > /dev/null 2>&1 && sleep 0'
changed: [localhost] => {"changed": true, "cmd": ["docker", "volume", "create", "--name", "resthomedb"], "delta": "0:00:00.046558", "end": "2016-06-10 09:43:08.078800", "invocation": {"module_args": {"_raw_params": "docker volume create --name resthomedb", "_uses_shell": false, "chdir": null, "creates": null, "executable": null, "removes": null, "warn": true}, "module_name": "command"}, "rc": 0, "start": "2016-06-10 09:43:08.032242", "stderr": "", "stdout": "resthomedb", "stdout_lines": ["resthomedb"], "warnings": []}

TASK [InfluxDB Container] ******************************************************
task path: /home/dri/code/resthome/playbook.yml:21
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: dri
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1465576988.24-181737680387450 `" && echo ansible-tmp-1465576988.24-181737680387450="` echo $HOME/.ansible/tmp/ansible-tmp-1465576988.24-181737680387450 `" ) && sleep 0'
<127.0.0.1> PUT /tmp/tmpbAAVgC TO /home/dri/.ansible/tmp/ansible-tmp-1465576988.24-181737680387450/docker_container
<127.0.0.1> 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/dri/.ansible/tmp/ansible-tmp-1465576988.24-181737680387450/docker_container; rm -rf "/home/dri/.ansible/tmp/ansible-tmp-1465576988.24-181737680387450/" > /dev/null 2>&1 && sleep 0'
changed: [localhost] => {"ansbile_facts": {"ansible_docker_container": {"AppArmorProfile": "", "Args": ["influxd"], "Config": {"AttachStderr": false, "AttachStdin": false, "AttachStdout": false, "Cmd": ["influxd"], "Domainname": "", "Entrypoint": ["/entrypoint.sh"], "Env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "INFLUXDB_VERSION=0.13.0"], "ExposedPorts": {"8083/tcp": {}, "8086/tcp": {}}, "Hostname": "67bea61bb3ce", "Image": "influxdb", "Labels": {}, "OnBuild": null, "OpenStdin": false, "StdinOnce": false, "Tty": false, "User": "", "Volumes": {"/home/dri/code/resthome/resthomedb": {}, "/var/lib/influxdb": {}}, "WorkingDir": ""}, "Created": "2016-06-10T16:43:08.442774133Z", "Driver": "aufs", "ExecIDs": null, "GraphDriver": {"Data": null, "Name": "aufs"}, "HostConfig": {"AutoRemove": false, "Binds": ["/home/dri/code/resthome/resthomedb:/var/lib/influxdb:rw"], "BlkioBps": 0, "BlkioDeviceReadBps": null, "BlkioDeviceReadIOps": null, "BlkioDeviceWriteBps": null, "BlkioDeviceWriteIOps": null, "BlkioIOps": 0, "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, "IpcMode": "", "Isolation": "", "KernelMemory": 0, "Links": null, "LogConfig": {"Config": {}, "Type": "json-file"}, "Memory": 0, "MemoryReservation": 0, "MemorySwap": 0, "MemorySwappiness": -1, "NetworkMode": "default", "OomKillDisable": false, "OomScoreAdj": 0, "PidMode": "", "PidsLimit": 0, "PortBindings": {"8083/tcp": [{"HostIp": "0.0.0.0", "HostPort": "8083"}], "8086/tcp": [{"HostIp": "0.0.0.0", "HostPort": "8086"}]}, "Privileged": false, "PublishAllPorts": false, "ReadonlyRootfs": false, "RestartPolicy": {"MaximumRetryCount": 0, "Name": ""}, "SandboxSize": 0, "SecurityOpt": null, "ShmSize": 67108864, "StorageOpt": null, "UTSMode": "", "Ulimits": null, "UsernsMode": "", "VolumeDriver": "", "VolumesFrom": null}, "HostnamePath": "/var/lib/docker/containers/67bea61bb3ce1e45237cbe2c68a22f54991f7b6454d6a725d33f922b84876704/hostname", "HostsPath": "/var/lib/docker/containers/67bea61bb3ce1e45237cbe2c68a22f54991f7b6454d6a725d33f922b84876704/hosts", "Id": "67bea61bb3ce1e45237cbe2c68a22f54991f7b6454d6a725d33f922b84876704", "Image": "sha256:8fd72d12d9100053850a6a6827e2cd2741e7c99270795fb978f897f7efb520e9", "LogPath": "/var/lib/docker/containers/67bea61bb3ce1e45237cbe2c68a22f54991f7b6454d6a725d33f922b84876704/67bea61bb3ce1e45237cbe2c68a22f54991f7b6454d6a725d33f922b84876704-json.log", "MountLabel": "", "Mounts": [{"Destination": "/var/lib/influxdb", "Mode": "rw", "Propagation": "rprivate", "RW": true, "Source": "/home/dri/code/resthome/resthomedb"}, {"Destination": "/home/dri/code/resthome/resthomedb", "Driver": "local", "Mode": "", "Name": "4df348baf3e47704b5ec51344319976e7207303da8c2a32895d5e54f74c4ee30", "Propagation": "", "RW": true, "Source": "/var/lib/docker/volumes/4df348baf3e47704b5ec51344319976e7207303da8c2a32895d5e54f74c4ee30/_data"}], "Name": "/influxdb", "NetworkSettings": {"Bridge": "", "EndpointID": "cea6fc1fab9435cd942ed0a63de03343bf8cfde8982225bc8c2c0c750a9afcb8", "Gateway": "172.17.0.1", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "HairpinMode": false, "IPAddress": "172.17.0.2", "IPPrefixLen": 16, "IPv6Gateway": "", "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "MacAddress": "02:42:ac:11:00:02", "Networks": {"bridge": {"Aliases": null, "EndpointID": "cea6fc1fab9435cd942ed0a63de03343bf8cfde8982225bc8c2c0c750a9afcb8", "Gateway": "172.17.0.1", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "IPAMConfig": null, "IPAddress": "172.17.0.2", "IPPrefixLen": 16, "IPv6Gateway": "", "Links": null, "MacAddress": "02:42:ac:11:00:02", "NetworkID": "308ad78df6d90e386a7e0d6a7f7dba12ca6711583a6b84b267e110410734258f"}}, "Ports": {"8083/tcp": [{"HostIp": "0.0.0.0", "HostPort": "8083"}], "8086/tcp": [{"HostIp": "0.0.0.0", "HostPort": "8086"}]}, "SandboxID": "c234193d040e71adc92eaad182840dd5691ee51389818eaa898e5f40c8d2eef8", "SandboxKey": "/var/run/docker/netns/c234193d040e", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null}, "Path": "/entrypoint.sh", "ProcessLabel": "", "ResolvConfPath": "/var/lib/docker/containers/67bea61bb3ce1e45237cbe2c68a22f54991f7b6454d6a725d33f922b84876704/resolv.conf", "RestartCount": 0, "State": {"Dead": false, "Error": "", "ExitCode": 0, "FinishedAt": "0001-01-01T00:00:00Z", "OOMKilled": false, "Paused": false, "Pid": 30268, "Restarting": false, "Running": true, "StartedAt": "2016-06-10T16:43:08.888217854Z", "Status": "running"}}}, "changed": 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": "influxdb", "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": "influxdb", "network_mode": null, "networks": null, "oom_killer": null, "paused": false, "pid_mode": null, "ports": ["8083:8083", "8086:8086"], "privileged": false, "published_ports": ["8083:8083", "8086:8086"], "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": ["resthomedb:/var/lib/influxdb"], "volumes_from": null}, "module_name": "docker_container"}}

TASK [Create rest-home DB] *****************************************************
task path: /home/dri/code/resthome/playbook.yml:31
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: dri
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1465576989.05-212281794492658 `" && echo ansible-tmp-1465576989.05-212281794492658="` echo $HOME/.ansible/tmp/ansible-tmp-1465576989.05-212281794492658 `" ) && sleep 0'
<127.0.0.1> PUT /tmp/tmp4S8G0a TO /home/dri/.ansible/tmp/ansible-tmp-1465576989.05-212281794492658/influxdb_database
<127.0.0.1> 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/dri/.ansible/tmp/ansible-tmp-1465576989.05-212281794492658/influxdb_database; rm -rf "/home/dri/.ansible/tmp/ansible-tmp-1465576989.05-212281794492658/" > /dev/null 2>&1 && sleep 0'
ok: [localhost] => {"changed": false, "invocation": {"module_args": {"database_name": "resthomedb", "hostname": "localhost", "password": "root", "port": 8086, "state": "present", "username": "root"}, "module_name": "influxdb_database"}}

PLAY RECAP *********************************************************************
localhost                  : ok=7    changed=5    unreachable=0    failed=0   

I left drajen's report unmodified, but I experienced the same problem. cwd or home directory is where volumes go.

I hypothesize the named volume is being misdetected as a relative path.

While I can see relative path being a common case, I think being explicit with a dot is a good way to go. Docker's -v argument supports named volumes on the left-hand side of the colon, so If it is not prefixed with a dot then a check to see if a valid volume matches the name should be made first. Maybe only that. Maybe if there is no volume it could fall back to defaulting to a relative path. Or maybe requiring the . to be explicit would be safer long-term..

chouseknecht commented 8 years ago

This was fixed in commit https://github.com/ansible/ansible-modules-core/commit/e2d8d9d09a0a62d7aaa2ac915ef56d5a10fc673e. It's in devel and cherry-picked to stable-2.1 branch, though it has not made into an official release.

I tested again, just to make sure. Here's the playbook and results:

- name: docker_container testing
  hosts: localhost
  connection: local
  gather_facts: no
  tasks:
    - name: InfluxDB docker volume create
      command: docker volume create --name resthomedb
      ignore_errors: yes

    - docker_container:
        name: influxdb
        image: influxdb
        volumes:
          - resthomedb:/var/lib/influxdb
        ports:
          - 8083:8083
          - 8086:8086

It produces the following Mounts and Volumes:

"Mounts": [
            {
                "Name": "resthomedb",
                "Source": "/mnt/sda1/var/lib/docker/volumes/resthomedb/_data",
                "Destination": "/var/lib/influxdb",
                "Driver": "local",
                "Mode": "rw",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],

"Volumes": {
                "/var/lib/influxdb": {}
            },
datamattsson commented 8 years ago

Thanks folks for recognizing and having this issue fixed already!

r4j4h commented 8 years ago

For real! :fireworks: :tada: :)