ryankwilliams / docker-inventory

Ansible dynamic inventory script for Docker
GNU General Public License v3.0
7 stars 6 forks source link

Ignores environment variables for remote docker engine #3

Open heytrav opened 5 years ago

heytrav commented 5 years ago

I'm using docker-machine to control a number of remote clients. When I change the environment to point to one of the remote docker hosts I manage with

eval $(docker-machine env somehost)
env  | grep DOCKER

DOCKER_TLS=1
DOCKER_MACHINE_NAME=somehost
DOCKER_CERT_PATH=/home/gitlab-runner/.docker/machine/machines/somehost
DOCKER_TLS_VERIFY=1
DOCKER_HOST=tcp://123.45.57.123:2376

and then run docker ps I can see a list of containers running on the remote host.

docker ps
CONTAINER ID        IMAGE                                                            COMMAND                  CREATED             STATUS              PORTS                                NAMES
590f51318d0b        gitlab.catalyst.net.nz:4567/myproject-nginx:latest   "nginx -g 'daemon of…"   About an hour ago   Up About an hour    81/tcp                               docker_web_1
27a5094d9a01        gitlab.catalyst.net.nz:4567myproject-webapp:44405          "pact runserver 0.0.…"   About an hour ago   Up About an hour    8000/tcp                             docker_app_1

Expected behaviour

When I run the inventory script I expect to see a list of running containers on the remote host that corresponds to what I see with docker ps. These should be services running the host specified by DOCKER_HOST.

Actual behaviour

I get an empty result

./ansible/inventory/docker_inventory.py --list
{"all": {"hosts": []}, "_meta": {"hostvars": {}}}

I believe it is only looking at the local host and not the remote docker engine. If I start an alpine image locally and run the inventory again I get

{"all": {"hosts": ["upbeat_ride"]}, "_meta": {"hostvars": {"upbeat_ride": {"ansible_connection": "docker"}}}}
jhkrischel commented 5 years ago

Added pull request I think will fix it.