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

Misleading error when binding ports on IPv6 without square brackets #365

Closed
PeterNerlich opened this issue May 20, 2022 · 1 comment · Fixed by #367
Closed

Misleading error when binding ports on IPv6 without square brackets #365

PeterNerlich opened this issue May 20, 2022 · 1 comment · Fixed by #367
Labels
bug Something isn't working docker-plain plain Docker (no swarm, no compose, no stack)

Comments

@PeterNerlich
Copy link

SUMMARY

When binding ports to an IPv6 address for a container, the IPv6 address has to be in [square brackets]. If not, it only checks whether there are one, two or three parts split by colons, and fails to catch any remaining cases which would indicate improper handling. Instead, the module fails with UnboundLocalError: local variable 'port_binds' referenced before assignment where it should tell the user to put IPv6 addresses in square brackets.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

docker_container.py

ANSIBLE VERSION
$ ansible --version
ansible [core 2.13.0]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/peter/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.10/site-packages/ansible
  ansible collection location = /home/peter/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0]
  jinja version = 3.0.3
  libyaml = True
$ 
COLLECTION VERSION
$ ansible-galaxy collection list community.docker

# /usr/lib/python3.10/site-packages/ansible_collections
Collection       Version
---------------- -------
community.docker 2.5.1
$ 
CONFIGURATION
$ ansible-config dump --only-changed
$ 
OS / ENVIRONMENT
pi@pihole:~ $ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 11 (bullseye)
Release:	11
Codename:	bullseye
pi@pihole:~ $ uname -a
Linux pihole 5.15.32-v8+ #1538 SMP PREEMPT Thu Mar 31 19:40:39 BST 2022 aarch64 GNU/Linux
$ 
STEPS TO REPRODUCE
- hosts: all
  tasks:
    - name: Start/Update nginx-proxy container
      docker_container:
        image: "nginxproxy/nginx-proxy"
        env:
          ENABLE_IPV6: "true"
        ports:
          - "::1:80:80"         # ← wrong, but no helpful message
          #- "[::1]:80:80"      # ← intended form
          #- "127.0.0.1:80:80"  # ← IPv4 form
        volumes:
          - "/var/run/docker.sock:/tmp/docker.sock:ro"
EXPECTED RESULTS

Module fails with helpful message that the string describing the port binding is malformed and if the user meant to specify an IPv6 address, it should be put in square brackets.

ACTUAL RESULTS

Module fails with UnboundLocalError: local variable 'port_binds' referenced before assignment.

$ ansible-playbook -i inventory.yaml reverse-proxy.yml --diff

PLAY [all] ************************************************************************************************************

TASK [Gathering Facts] ************************************************************************************************
ok: [pihole]

TASK [Start/Update nginx-proxy container] *****************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: UnboundLocalError: local variable 'port_binds' referenced before assignment
fatal: [pihole]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"<stdin>\", line 107, in <module>\n  File \"<stdin>\", line 99, in _ansiballz_main\n  File \"<stdin>\", line 47, in invoke_module\n  File \"/usr/lib/python3.9/runpy.py\", line 210, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.9/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.9/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_docker_container_payload_jrqvzgva/ansible_docker_container_payload.zip/ansible/modules/docker_container.py\", line 3667, in <module>\n  File \"/tmp/ansible_docker_container_payload_jrqvzgva/ansible_docker_container_payload.zip/ansible/modules/docker_container.py\", line 3656, in main\n  File \"/tmp/ansible_docker_container_payload_jrqvzgva/ansible_docker_container_payload.zip/ansible/modules/docker_container.py\", line 2813, in __init__\n  File \"/tmp/ansible_docker_container_payload_jrqvzgva/ansible_docker_container_payload.zip/ansible/modules/docker_container.py\", line 1444, in __init__\n  File \"/tmp/ansible_docker_container_payload_jrqvzgva/ansible_docker_container_payload.zip/ansible/modules/docker_container.py\", line 1848, in _parse_publish_ports\nUnboundLocalError: local variable 'port_binds' referenced before assignment\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

PLAY RECAP ************************************************************************************************************
pihole                     : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

$ 
@felixfontein
Copy link
Collaborator

I created a PR to fix this in #367.

@felixfontein felixfontein added bug Something isn't working docker-plain plain Docker (no swarm, no compose, no stack) labels May 21, 2022
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