# Buggy code
def __init__(self, client):
    self.client = client
    self.parameters = TaskParameters(client)
    self.check_mode = self.client.check_mode
    self.results = {"changed": False, "actions": []}
    self.diff = self.client.module._diff

    self.existing_network = self.get_existing_network()

    if not self.parameters.connected and self.existing_network:
        self.parameters.connected = container_names_in_network(self.existing_network)

    state = self.parameters.state
    if state == "present":
        self.present()
    elif state == "absent":
        self.absent()


# Traceback (ndocker.errors.APIError)
<52.209.236.86> ESTABLISH SSH CONNECTION FOR USER: root
<52.209.236.86> 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=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c215ba3b0 52.209.236.86 '/bin/sh -c '"'"'echo ~ &amp;&amp; sleep 0'"'"''
<52.209.236.86> (0, '/root\n', 'OpenSSH_6.7p1 Debian-5+deb8u3, OpenSSL 1.0.1t  3 May 2016\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: 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, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 9723\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<52.209.236.86> ESTABLISH SSH CONNECTION FOR USER: root
<52.209.236.86> 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=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c215ba3b0 52.209.236.86 '/bin/sh -c '"'"'( umask 77 &amp;&amp; mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1499872806.12-83391838048787 `" &amp;&amp; echo ansible-tmp-1499872806.12-83391838048787="` echo /root/.ansible/tmp/ansible-tmp-1499872806.12-83391838048787 `" ) &amp;&amp; sleep 0'"'"''
<52.209.236.86> (0, 'ansible-tmp-1499872806.12-83391838048787=/root/.ansible/tmp/ansible-tmp-1499872806.12-83391838048787\n', 'OpenSSH_6.7p1 Debian-5+deb8u3, OpenSSL 1.0.1t  3 May 2016\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: 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, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 9723\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<52.209.236.86> PUT /tmp/tmpqcFGAd TO /root/.ansible/tmp/ansible-tmp-1499872806.12-83391838048787/docker_network.py
<52.209.236.86> SSH: EXEC sftp -b - -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=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c215ba3b0 '[52.209.236.86]'
<52.209.236.86> (0, 'sftp> put /tmp/tmpqcFGAd /root/.ansible/tmp/ansible-tmp-1499872806.12-83391838048787/docker_network.py\n', 'OpenSSH_6.7p1 Debian-5+deb8u3, OpenSSL 1.0.1t  3 May 2016\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: 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, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 9723\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug2: Remote version: 3\r\ndebug2: Server supports extension "posix-rename@openssh.com" revision 1\r\ndebug2: Server supports extension "statvfs@openssh.com" revision 2\r\ndebug2: Server supports extension "fstatvfs@openssh.com" revision 2\r\ndebug2: Server supports extension "hardlink@openssh.com" revision 1\r\ndebug2: Server supports extension "fsync@openssh.com" revision 1\r\ndebug3: Sent message fd 5 T:16 I:1\r\ndebug3: SSH_FXP_REALPATH . -> /root size 0\r\ndebug3: Looking up /tmp/tmpqcFGAd\r\ndebug3: Sent message fd 5 T:17 I:2\r\ndebug3: Received stat reply T:101 I:2\r\ndebug1: Couldn\'t stat remote file: No such file or directory\r\ndebug3: Sent message SSH2_FXP_OPEN I:3 P:/root/.ansible/tmp/ansible-tmp-1499872806.12-83391838048787/docker_network.py\r\ndebug3: Sent message SSH2_FXP_WRITE I:4 O:0 S:32768\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 4 32768 bytes at 0\r\ndebug3: Sent message SSH2_FXP_WRITE I:5 O:32768 S:32697\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 5 32697 bytes at 32768\r\ndebug3: Sent message SSH2_FXP_CLOSE I:4\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<52.209.236.86> ESTABLISH SSH CONNECTION FOR USER: root
<52.209.236.86> 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=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c215ba3b0 52.209.236.86 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1499872806.12-83391838048787/ /root/.ansible/tmp/ansible-tmp-1499872806.12-83391838048787/docker_network.py &amp;&amp; sleep 0'"'"''
<52.209.236.86> (0, '', 'OpenSSH_6.7p1 Debian-5+deb8u3, OpenSSL 1.0.1t  3 May 2016\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: 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, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 9723\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<52.209.236.86> ESTABLISH SSH CONNECTION FOR USER: root
<52.209.236.86> 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=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c215ba3b0 -tt 52.209.236.86 '/bin/sh -c '"'"'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1499872806.12-83391838048787/docker_network.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1499872806.12-83391838048787/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'"'"''
<52.209.236.86> (0, 'Traceback (most recent call last):\r\n  File "/tmp/ansible_RPGsM1/ansible_module_docker_network.py", line 393, in <module>\r\n    main()\r\n  File "/tmp/ansible_RPGsM1/ansible_module_docker_network.py", line 386, in main\r\n    cm = DockerNetworkManager(client)\r\n  File "/tmp/ansible_RPGsM1/ansible_module_docker_network.py", line 219, in __init__\r\n    self.present()\r\n  File "/tmp/ansible_RPGsM1/ansible_module_docker_network.py", line 350, in present\r\n    self.create_network()\r\n  File "/tmp/ansible_RPGsM1/ansible_module_docker_network.py", line 298, in create_network\r\n    ipam=ipam_config)\r\n  File "/usr/local/lib/python2.7/dist-packages/docker/utils/decorators.py", line 34, in wrapper\r\n    return f(self, *args, **kwargs)\r\n  File "/usr/local/lib/python2.7/dist-packages/docker/api/network.py", line 145, in create_network\r\n    return self._result(res, json=True)\r\n  File "/usr/local/lib/python2.7/dist-packages/docker/api/client.py", line 226, in _result\r\n    self._raise_for_status(response)\r\n  File "/usr/local/lib/python2.7/dist-packages/docker/api/client.py", line 222, in _raise_for_status\r\n    raise create_api_error_from_http_exception(e)\r\n  File "/usr/local/lib/python2.7/dist-packages/docker/errors.py", line 31, in create_api_error_from_http_exception\r\n    raise cls(e, response=response, explanation=explanation)\r\ndocker.errors.APIError: 500 Server Error: Internal Server Error ("json: cannot unmarshal bool into Go struct field NetworkCreateRequest.Options of type string")\r\n', 'OpenSSH_6.7p1 Debian-5+deb8u3, OpenSSL 1.0.1t  3 May 2016\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: 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, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 9723\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\nShared connection to 52.209.236.86 closed.\r\n')
fatal: [52.209.236.86]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "OpenSSH_6.7p1 Debian-5+deb8u3, OpenSSL 1.0.1t  3 May 2016\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: 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, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 9723\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\nShared connection to 52.209.236.86 closed.\r\n",
"module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_RPGsM1/ansible_module_docker_network.py\", line 393, in <module>\r\n    main()\r\n  File \"/tmp/ansible_RPGsM1/ansible_module_docker_network.py\", line 386, in main\r\n    cm = DockerNetworkManager(client)\r\n  File \"/tmp/ansible_RPGsM1/ansible_module_docker_network.py\", line 219, in __init__\r\n    self.present()\r\n  File \"/tmp/ansible_RPGsM1/ansible_module_docker_network.py\", line 350, in present\r\n    self.create_network()\r\n  File \"/tmp/ansible_RPGsM1/ansible_module_docker_network.py\", line 298, in create_network\r\n    ipam=ipam_config)\r\n  File \"/usr/local/lib/python2.7/dist-packages/docker/utils/decorators.py\", line 34, in wrapper\r\n    return f(self, *args, **kwargs)\r\n  File \"/usr/local/lib/python2.7/dist-packages/docker/api/network.py\", line 145, in create_network\r\n    return self._result(res, json=True)\r\n  File \"/usr/local/lib/python2.7/dist-packages/docker/api/client.py\", line 226, in _result\r\n    self._raise_for_status(response)\r\n  File \"/usr/local/lib/python2.7/dist-packages/docker/api/client.py\", line 222, in _raise_for_status\r\n    raise create_api_error_from_http_exception(e)\r\n  File \"/usr/local/lib/python2.7/dist-packages/docker/errors.py\", line 31, in create_api_error_from_http_exception\r\n    raise cls(e, response=response, explanation=explanation)\r\ndocker.errors.APIError: 500 Server Error: Internal Server Error (\"json: cannot unmarshal bool into Go struct field NetworkCreateRequest.Options of type string\")\r\n",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def __init__(self, client):
    self.client = client
    self.parameters = TaskParameters(client)
    self.check_mode = self.client.check_mode
    self.results = {"changed": False, "actions": []}
    self.diff = self.client.module._diff

    self.existing_network = self.get_existing_network()

    if not self.parameters.connected and self.existing_network:
        self.parameters.connected = container_names_in_network(self.existing_network)

    if self.parameters.driver_options:
        self.parameters.driver_options = get_driver_options(
            self.parameters.driver_options
        )

    state = self.parameters.state
    if state == "present":
        self.present()
    elif state == "absent":
        self.absent()