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

module docker_host_info never return expected can_talk_to_docker value on success. #993

Closed
ArKam opened this issue Nov 22, 2024 · 3 comments · Fixed by #995
Closed

module docker_host_info never return expected can_talk_to_docker value on success. #993

ArKam opened this issue Nov 22, 2024 · 3 comments · Fixed by #995
Labels
bug Something isn't working docker-plain plain Docker (no swarm, no compose, no stack)

Comments

@ArKam
Copy link

ArKam commented Nov 22, 2024

SUMMARY

When using docker_host_info module in order to check if the host have a working docker instance, like this:

- name: Get info on docker host
  community.docker.docker_host_info:
  register: result

the result output never contain expected result.can_to_docker element and fail.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

module: docker_host_info

ANSIBLE VERSION
ansible --version
ansible [core 2.18.0]
  config file = /home/ansible/workspace/project/ansible.cfg
  configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ansible/.venvs/ansible/lib/python3.12/site-packages/ansible
  ansible collection location = /home/ansible/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/ansible/.venvs/ansible/bin/ansible
  python version = 3.12.6 (main, Sep 11 2024, 08:48:26) [GCC 13.2.1 20240309] (/home/ansible/.venvs/ansible/bin/python)
  jinja version = 3.1.4
  libyaml = True
COLLECTION VERSION
ansible-galaxy collection list community.docker
# /home/user/.venvs/ansible/lib/python3.12/site-packages/ansible_collections
Collection       Version
---------------- -------
community.docker 4.0.1
CONFIGURATION
ansible-config dump --only-changed
CONFIG_FILE() = /home/user/workspace/project/ansible.cfg
DEFAULT_GATHERING(/home/user/workspace/project/ansible.cfg) = smart
DEFAULT_MANAGED_STR(/home/user/workspace/project/ansible.cfg) = # This is an ansible managed configuration, do not edit it manually as it will be overwrited automatically.
DEFAULT_TRANSPORT(/home/user/workspace/project/ansible.cfg) = smart
HOST_KEY_CHECKING(/home/user/workspace/project/ansible.cfg) = False
RETRY_FILES_ENABLED(/home/user/workspace/project/ansible.cfg) = False

GALAXY_SERVERS:
OS / ENVIRONMENT

Ubuntu 22.04.5 LTS.

STEPS TO REPRODUCE

Just create a task used to retrieve docker host info.

- name: Get info on docker host
  community.docker.docker_host_info:
  register: result
  failed_when: not result.can_talk_to_docker
EXPECTED RESULTS

the result registered fact should contain can_talk_to_docker boolean value both on success and/or on error.

ACTUAL RESULTS
fatal: [host.domain.tld]: FAILED! => {
  "msg": 
    "The task includes an option with an undefined variable.. 'dict object' has no attribute 'can_talk_to_docker'
     The error appears to be in '/home/user/workspace/project/site.yml': line 23, column 11, but may
     be elsewhere in the file depending on the exact syntax problem.
     
     The offending line appears to be:
      rescue:
        - name: "Get info on docker host"
          ^ here"
}

I think it comes from the fact that as you only include the fail_result dict when the client fails (when client.fail() is called).

The main function try/catch should inject the dict result on success like this I guess?
file: docker_host_info.py

try:
    results = dict(
        changed=False,
        can_talk_to_docker=True
    )
@felixfontein felixfontein added the bug Something isn't working label Nov 22, 2024
@felixfontein
Copy link
Collaborator

This looks like an oversight! It should be fixable as you suggest, though I'd like to also check whether the assignment in line 366 is really OK. I should manage to do that tomorrow.

@felixfontein felixfontein added the docker-plain plain Docker (no swarm, no compose, no stack) label Nov 22, 2024
@felixfontein
Copy link
Collaborator

#995 fixes this.

@ArKam
Copy link
Author

ArKam commented Nov 25, 2024

Woooh, thanks a lot! It was the fastest PR resolution that I ever experienced!

Cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working docker-plain plain Docker (no swarm, no compose, no stack)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants