# Buggy code
def init_swarm(self):
    if self.__isSwarmManager():
        self.__update_swarm()
        return

    if not self.check_mode:
        try:
            self.client.init_swarm(
                advertise_addr=self.parameters.advertise_addr,
                listen_addr=self.parameters.listen_addr,
                force_new_cluster=self.parameters.force_new_cluster,
                swarm_spec=self.parameters.spec,
            )
        except APIError as exc:
            self.client.fail("Can not create a new Swarm Cluster: %s" % to_native(exc))

    self.__isSwarmManager()
    self.results["actions"].append(
        "New Swarm cluster created: %s" % (self.swarm_info.get("ID"))
    )
    self.results["changed"] = True
    self.results["swarm_facts"] = {"JoinTokens": self.swarm_info.get("JoinTokens")}


# Traceback (nKeyError)
fatal: [node-01]: FAILED! => {"changed": false, "module_stderr": "Shared connection to node-01 closed.\r\n", "module_stdout": "/usr/lib/python2.7/site-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.24.1) or chardet (2.2.1) doesn't match a supported version!\r\n  RequestsDependencyWarning)\r\nTraceback (most recent call last):\r\n  File \"/root/.ansible/tmp/ansible-tmp-1548156057.5468266-261250085584743/AnsiballZ_docker_swarm.py\", line 113, in <module>\r\n    _ansiballz_main()\r\n  File \"/root/.ansible/tmp/ansible-tmp-1548156057.5468266-261250085584743/AnsiballZ_docker_swarm.py\", line 105, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/root/.ansible/tmp/ansible-tmp-1548156057.5468266-261250085584743/AnsiballZ_docker_swarm.py\", line 48, in invoke_module\r\n    imp.load_module('__main__', mod, module, MOD_DESC)\r\n  File \"/tmp/ansible_docker_swarm_payload_2QlvP8/__main__.py\", line 535, in <module>\r\n  File \"/tmp/ansible_docker_swarm_payload_2QlvP8/__main__.py\", line 530, in main\r\n  File \"/tmp/ansible_docker_swarm_payload_2QlvP8/__main__.py\", line 310, in __call__\r\n  File \"/tmp/ansible_docker_swarm_payload_2QlvP8/__main__.py\", line 333, in init_swarm\r\n  File \"/tmp/ansible_docker_swarm_payload_2QlvP8/__main__.py\", line 390, in __update_swarm\r\n  File \"/tmp/ansible_docker_swarm_payload_2QlvP8/__main__.py\", line 376, in __update_spec\r\nKeyError: 'Labels'\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

# Fixed code
def init_swarm(self):
    if self.__isSwarmManager():
        self.__update_swarm()
        return

    if not self.check_mode:
        try:
            self.client.init_swarm(
                advertise_addr=self.parameters.advertise_addr,
                listen_addr=self.parameters.listen_addr,
                force_new_cluster=self.parameters.force_new_cluster,
                swarm_spec=self.parameters.spec,
            )
        except APIError as exc:
            self.client.fail("Can not create a new Swarm Cluster: %s" % to_native(exc))

    self.__isSwarmManager()
    self.results["actions"].append(
        "New Swarm cluster created: %s" % (self.swarm_info.get("ID"))
    )
    self.differences.add("state", parameter="absent", active="present")
    self.results["changed"] = True
    self.results["swarm_facts"] = {"JoinTokens": self.swarm_info.get("JoinTokens")}