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

docker_swarm_service.publish fails on 2nd run with host port and ingress #107

Closed
pmgad opened this issue Mar 24, 2021 · 3 comments · Fixed by #136
Closed

docker_swarm_service.publish fails on 2nd run with host port and ingress #107

pmgad opened this issue Mar 24, 2021 · 3 comments · Fixed by #136
Labels
docker-swarm Docker Swarm

Comments

@pmgad
Copy link

pmgad commented Mar 24, 2021

SUMMARY

docker_swarm_service publish with both a host port and ingress results in:
The error was: TypeError: '<' not supported between instances of 'NoneType' and 'int'

ISSUE TYPE
  • Bug Report
COMPONENT NAME

docker_swarm_service module

collections:

  • name: community.docker
    version: 1.4.0
ANSIBLE VERSION
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/XXX/.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.8.5 (default, Jan 27 2021, 15:41:15) [GCC 9.3.0]
CONFIGURATION
ANSIBLE_PIPELINING(/etc/ansible/ansible.cfg) = True

OS / ENVIRONMENT

Linux dev 5.4.0-66-generic #74-Ubuntu SMP Wed Jan 27 22:54:38 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.2 LTS"

STEPS TO REPRODUCE
  community.docker.docker_swarm_service:
    name: nginx
    image: nginx:1.19.8
    replicas: 2
    publish:       
      - published_port: 8080
        target_port: 80
      - mode: host
        target_port: 8009

Run the task:

Service is created with the ingress:

$ docker service ls
ID             NAME                MODE         REPLICAS   IMAGE                          PORTS
jje92z2mwfp5   nginx               replicated   2/2        nginx:1.19.8                   *:8080->80/tcp

And the randomly assigned host ports are good:

$ docker ps
CONTAINER ID   IMAGE                          COMMAND                  CREATED          STATUS          PORTS                             NAMES
2fa7b32bd5b2   nginx:1.19.8                   "/docker-entrypoint.…"   57 seconds ago   Up 54 seconds   80/tcp, 0.0.0.0:49155->8009/tcp   nginx.2.kwfhops5caw3rxzxoa04aqgpu
6dc5f8228903   nginx:1.19.8                   "/docker-entrypoint.…"   57 seconds ago   Up 54 seconds   80/tcp, 0.0.0.0:49156->8009/tcp   nginx.1.1qat6hknfigqtobg5qwuu5xj2

Just having this work is great thanks to #99
It allows service discovery of container metrics endpoints as described here:
https://prometheus.io/docs/guides/dockerswarm/#monitoring-containers

However, on a 2nd run of the task there is a problem.

EXPECTED RESULTS

Service unchanged

ACTUAL RESULTS
task path: /home/XXX/Documents/src/ansible-tracks/playbooks/deploy.yml:85
Using module file /home/XXX/.ansible/collections/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py
Pipelining is enabled.
<dev> ESTABLISH SSH CONNECTION FOR USER: ad
<dev> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="ad"' -o ConnectTimeout=10 -o StrictHostKeyChecking=no -R3443:dr.gs.l:3443 -o ControlPath=/home/XXX/.ansible/cp/af8281bcec dev '/bin/sh -c '"'"'sudo -H -S -n  -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-kwqnclljwusmanecyfimhkgifwxqjbvf ; /usr/bin/python3'"'"'"'"'"'"'"'"' && sleep 0'"'"''
Escalation succeeded
<dev> (1, b'', b'OpenSSH_8.2p1 Ubuntu-4ubuntu0.2, OpenSSL 1.1.1f  31 Mar 2020\r\ndebug1: Reading configuration data /home/XXX/.ssh/config\r\ndebug1: /home/XXX/.ssh/config line 53: Applying options for dev\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 1 remote\r\ndebug1: Requesting forwarding of remote forward LOCALHOST:3443 -> dr.gs.l:3443\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 12582\r\ndebug3: mux_client_request_session: session request sent\r\nTraceback (most recent call last):\n  File "<stdin>", line 102, in <module>\n  File "<stdin>", line 94, in _ansiballz_main\n  File "<stdin>", line 40, in invoke_module\n  File "/usr/lib/python3.8/runpy.py", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File "/usr/lib/python3.8/runpy.py", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code\n    exec(code, run_globals)\n  File "/tmp/ansible_community.docker.docker_swarm_service_payload_sqm0bgik/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py", line 2831, in <module>\n  File "/tmp/ansible_community.docker.docker_swarm_service_payload_sqm0bgik/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py", line 2810, in main\n  File "/tmp/ansible_community.docker.docker_swarm_service_payload_sqm0bgik/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py", line 2516, in run_safe\n  File "/tmp/ansible_community.docker.docker_swarm_service_payload_sqm0bgik/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py", line 2464, in run\n  File "/tmp/ansible_community.docker.docker_swarm_service_payload_sqm0bgik/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py", line 1726, in compare\n  File "/tmp/ansible_community.docker.docker_swarm_service_payload_sqm0bgik/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py", line 1796, in has_publish_changed\nTypeError: \'<\' not supported between instances of \'NoneType\' and \'int\'\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\n')
<dev> Failed to connect to the host via ssh: OpenSSH_8.2p1 Ubuntu-4ubuntu0.2, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /home/XXX/.ssh/config
debug1: /home/XXX/.ssh/config line 53: Applying options for dev
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: auto-mux: Trying existing master
debug2: fd 3 setting O_NONBLOCK
debug2: mux_client_hello_exchange: master version 4
debug3: mux_client_forwards: request forwardings: 0 local, 1 remote
debug1: Requesting forwarding of remote forward LOCALHOST:3443 -> dr.gs.l:3443
debug3: mux_client_request_session: entering
debug3: mux_client_request_alive: entering
debug3: mux_client_request_alive: done pid = 12582
debug3: mux_client_request_session: session request sent
Traceback (most recent call last):
  File "<stdin>", line 102, in <module>
  File "<stdin>", line 94, in _ansiballz_main
  File "<stdin>", line 40, in invoke_module
  File "/usr/lib/python3.8/runpy.py", line 207, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.8/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_community.docker.docker_swarm_service_payload_sqm0bgik/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py", line 2831, in <module>
  File "/tmp/ansible_community.docker.docker_swarm_service_payload_sqm0bgik/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py", line 2810, in main
  File "/tmp/ansible_community.docker.docker_swarm_service_payload_sqm0bgik/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py", line 2516, in run_safe
  File "/tmp/ansible_community.docker.docker_swarm_service_payload_sqm0bgik/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py", line 2464, in run
  File "/tmp/ansible_community.docker.docker_swarm_service_payload_sqm0bgik/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py", line 1726, in compare
  File "/tmp/ansible_community.docker.docker_swarm_service_payload_sqm0bgik/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py", line 1796, in has_publish_changed
TypeError: '<' not supported between instances of 'NoneType' and 'int'
debug3: mux_client_read_packet: read header failed: Broken pipe
debug2: Received exit status from master 1
fatal: [dev]: FAILED! => {
    "changed": false,
    "module_stderr": "OpenSSH_8.2p1 Ubuntu-4ubuntu0.2, OpenSSL 1.1.1f  31 Mar 2020\r\ndebug1: Reading configuration data /home/XXX/.ssh/config\r\ndebug1: /home/XXX/.ssh/config line 53: Applying options for dev\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 1 remote\r\ndebug1: Requesting forwarding of remote forward LOCALHOST:3443 -> dr.gs.l:3443\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 12582\r\ndebug3: mux_client_request_session: session request sent\r\nTraceback (most recent call last):\n  File \"<stdin>\", line 102, in <module>\n  File \"<stdin>\", line 94, in _ansiballz_main\n  File \"<stdin>\", line 40, in invoke_module\n  File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_community.docker.docker_swarm_service_payload_sqm0bgik/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py\", line 2831, in <module>\n  File \"/tmp/ansible_community.docker.docker_swarm_service_payload_sqm0bgik/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py\", line 2810, in main\n  File \"/tmp/ansible_community.docker.docker_swarm_service_payload_sqm0bgik/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py\", line 2516, in run_safe\n  File \"/tmp/ansible_community.docker.docker_swarm_service_payload_sqm0bgik/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py\", line 2464, in run\n  File \"/tmp/ansible_community.docker.docker_swarm_service_payload_sqm0bgik/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py\", line 1726, in compare\n  File \"/tmp/ansible_community.docker.docker_swarm_service_payload_sqm0bgik/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py\", line 1796, in has_publish_changed\nTypeError: '<' not supported between instances of 'NoneType' and 'int'\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

@pmgad pmgad changed the title docker_swarm_service.public fails on 2nd run with host port and ingress docker_swarm_service.publish fails on 2nd run with host port and ingress Mar 24, 2021
@felixfontein
Copy link
Collaborator

The problem is that published_port can not be specified (and thus will have value None) in https://github.com/ansible-collections/community.docker/blob/main/plugins/modules/docker_swarm_service.py#L1796.

@felixfontein
Copy link
Collaborator

resolved_by_pr #136

@pmgad
Copy link
Author

pmgad commented May 6, 2021

Fix is working perfect, thank you Felix!

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