Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inventory plugin should propagate docker_host variable #155

Closed
ytimenkov opened this issue Jun 16, 2021 · 6 comments · Fixed by #157
Closed

Inventory plugin should propagate docker_host variable #155

ytimenkov opened this issue Jun 16, 2021 · 6 comments · Fixed by #157

Comments

@ytimenkov
Copy link

SUMMARY

I use inventory plugin with remote docker_host. However it is not propagated to the connection plugin and the latter uses default local connection.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.docker.docker_containers

ANSIBLE VERSION
ansible 2.10.5
  config file = /home/default/dev-container/ansible.cfg
  configured module search path = ['/home/default/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.9.4 (default, Apr  4 2021, 19:38:44) [GCC 10.2.1 20210401]
CONFIGURATION
DEFAULT_HOST_LIST(/home/default/dev-container/ansible.cfg) = ['/home/default/dev-container/inventory']
OS / ENVIRONMENT

Ubuntu 21.04

STEPS TO REPRODUCE

Inventory:

plugin: community.docker.docker_containers
docker_host: tcp://my-host:2376
EXPECTED RESULTS

I can use those hosts in my playbook, they should connect to my-host:2376

ACTUAL RESULTS

Playbook fails with:

TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************************************
fatal: [dev-vm]: UNREACHABLE! => {"changed": false, "msg": "Could not find container \"dev-vm\" (404 Client Error for http+docker://localhost/v1.40/containers/dev-vm/exec: Not Found (\"No such container: dev-vm\"))", "unreachable": true}

However ansible-inventory successfully finds containers:

$ ansible-inventory --graph --vars
@all:
  |--@ungrouped:
  |  |--dev-vm
  |  |  |--{ansible_connection = community.docker.docker_api}
  |  |  |--{ansible_host = dev-vm}
  |  |  |--{docker_name = dev-vm}
  |  |  |--{docker_short_id = e1a86cd6a5599}
Workaround

To work around I added variable explicitly to inventory:

plugin: community.docker.docker_containers
docker_host: tcp://my-host:2376
compose:
  ansible_docker_docker_host: "'tcp://my-host:2376'"

But this looks like a hack and unnecessary duplication.

@felixfontein
Copy link
Collaborator

Thanks for the report! This definitely makes sense. I guess this would also apply to other configs that are needed to connect to the Docker daemon (like TLS setup).

@felixfontein
Copy link
Collaborator

I've implemented this in #157. Can you please try it out whether it works for you?

@ytimenkov
Copy link
Author

Dumb question: how can I install it? I tried the most obvious ansible-galaxy collection install https://github.com/felixfontein/community.docker/archive/refs/heads/pass-docker-params.tar.gz hoping it will pull your development branch, but it ansible-galaxy says: "Collection does not contain the required file MANIFEST.json.".

@felixfontein
Copy link
Collaborator

Here are some instructions on how you can try it locally: https://github.com/ansible/community-docs/blob/main/test_pr_locally_guide.rst

@ytimenkov
Copy link
Author

In my deleted comment I found that ansible didn't pick up the cloned repo and ran my local docker 😊

The instructions didn't work: it refused to parse inventory (for some reason), although showed that there are 2 community.docker collections are available. I tried ansible-galaxy collection build and then installed tarball.

After that I see variables added into inventory and I've ran playbook. (Had local docker turned off completely this time).

@felixfontein
Copy link
Collaborator

Thanks for testing the PR!

The instructions didn't work: it refused to parse inventory (for some reason), although showed that there are 2 community.docker collections are available. I tried ansible-galaxy collection build and then installed tarball.

Hmm, it would be interesting to know why it didn't work, so we can improve the instructions.

I guess "showed that there are 2 community.collections" means that you looked at the ansible-galaxy collection list output? That's to be expected; ansible-core uses the first one it finds, but collection list also shows other instances of the collection found in the collection search path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants