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

Fix update_failure_action KeyError in docker_swarm_service #100

Conversation

sgpinkus
Copy link
Contributor

SUMMARY

I get this error in docker_swarm_service module with python docker 3.4.1 and docker 20:

    Traceback (most recent call last):
      File \"/home/admin/.ansible/tmp/ansible-tmp-1615509171.9495375-199788209305166/AnsiballZ_docker_swarm_service.py\", line 102, in <module>
        _ansiballz_main()
      File \"/home/admin/.ansible/tmp/ansible-tmp-1615509171.9495375-199788209305166/AnsiballZ_docker_swarm_service.py\", line 94, in _ansiballz_main
        invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
      File \"/home/admin/.ansible/tmp/ansible-tmp-1615509171.9495375-199788209305166/AnsiballZ_docker_swarm_service.py\", line 40, in invoke_module
        runpy.run_module(mod_name='ansible_collections.community.docker.plugins.modules.docker_swarm_service', init_globals=None, run_name='__main__', alter_sys=True)
      File \"/usr/lib/python2.7/runpy.py\", line 188, in run_module
        fname, loader, pkg_name)
      File \"/usr/lib/python2.7/runpy.py\", line 82, in _run_module_code
        mod_name, mod_fname, mod_loader, pkg_name)
      File \"/usr/lib/python2.7/runpy.py\", line 72, in _run_code
        exec code in run_globals
      File \"/tmp/ansible_community.docker.docker_swarm_service_payload__rn1HO/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py\", line 2833, in <module>
      File \"/tmp/ansible_community.docker.docker_swarm_service_payload__rn1HO/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py\", line 2807, in main
      File \"/tmp/ansible_community.docker.docker_swarm_service_payload__rn1HO/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/module_utils/common.py\", line 678, in __init__
      File \"/tmp/ansible_community.docker.docker_swarm_service_payload__rn1HO/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/module_utils/common.py\", line 709, in _get_minimal_versions
      File \"/tmp/ansible_community.docker.docker_swarm_service_payload__rn1HO/ansible_community.docker.docker_swarm_service_payload.zip/ansible_collections/community/docker/plugins/modules/docker_swarm_service.py\", line 2555, in _detect_update_config_failure_action_rollback
    KeyError: 'update_failure_action'
ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

docker_swarm_service

ADDITIONAL INFORMATION

To reproduce the error in a playbook:

- hosts: swarm-master
  tasks:
    - name: add swarm service
      community.docker.docker_swarm_service:
        state: present
        name: my-test-service
        replicas: 1
        force_update: yes
        debug: yes
        image: nginx
        publish:
          - target_port: 8080
          - published_port: 8080
      register: result
    - debug: var=result

Where swarm-master is configure swarm master.

After change above exception goes away.

@@ -2551,7 +2551,9 @@ def _detect_update_config_failure_action_rollback(client):
rollback_config_failure_action = (
(client.module.params['update_config'] or {}).get('failure_action')
)
update_failure_action = client.module.params['update_failure_action']
update_failure_action = (
client.module.params.get('update_failure_action')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure that this is the wrong fix. A module option of this name no longer exists. I suspect we forgot to remove this part when removing some deprecated options.

It's probably best to remove this line and change the next two to

     return rollback_config_failure_action == 'rollback'

CC @dariko @jwitko @hannseman @WojciechowskiPiotr

Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the following suggestion and a changelog fragment, I think this would be ok.

plugins/modules/docker_swarm_service.py Outdated Show resolved Hide resolved
@sgpinkus sgpinkus force-pushed the fix/update_failure_action-KeyError branch from c81332a to 1ad7f48 Compare March 14, 2021 00:37
@sgpinkus sgpinkus force-pushed the fix/update_failure_action-KeyError branch from 1ad7f48 to 27a97fc Compare March 14, 2021 21:14
@felixfontein felixfontein merged commit 149a3ab into ansible-collections:main Mar 14, 2021
@felixfontein
Copy link
Collaborator

@sgpinkus thanks a lot for fixing this!

@sgpinkus sgpinkus deleted the fix/update_failure_action-KeyError branch March 14, 2021 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants