# Buggy code
def create_connection(self):
    cmd = []
    if self.type == "team":
        if (self.dns4 is not None) or (self.dns6 is not None):
            cmd = self.create_connection_team()
            self.execute_command(cmd)
            cmd = self.modify_connection_team()
            self.execute_command(cmd)
            return self.up_connection()
        elif (self.dns4 is None) or (self.dns6 is None):
            cmd = self.create_connection_team()
    elif self.type == "team-slave":
        if self.mtu is not None:
            cmd = self.create_connection_team_slave()
            self.execute_command(cmd)
            cmd = self.modify_connection_team_slave()
            return self.execute_command(cmd)
        else:
            cmd = self.create_connection_team_slave()
    elif self.type == "bond":
        if (self.mtu is not None) or (self.dns4 is not None) or (self.dns6 is not None):
            cmd = self.create_connection_bond()
            self.execute_command(cmd)
            cmd = self.modify_connection_bond()
            self.execute_command(cmd)
            return self.up_connection()
        else:
            cmd = self.create_connection_bond()
    elif self.type == "bond-slave":
        cmd = self.create_connection_bond_slave()
    elif self.type == "ethernet":
        if (self.mtu is not None) or (self.dns4 is not None) or (self.dns6 is not None):
            cmd = self.create_connection_ethernet()
            self.execute_command(cmd)
            cmd = self.modify_connection_ethernet()
            self.execute_command(cmd)
            return self.up_connection()
        else:
            cmd = self.create_connection_ethernet()
    elif self.type == "bridge":
        cmd = self.create_connection_bridge()
    elif self.type == "vlan":
        cmd = self.create_connection_vlan()
    elif self.type == "generic":
        cmd = self.create_connection_ethernet(conn_type="generic")

    if cmd:
        return self.execute_command(cmd)
    else:
        self.module.fail_json(
            msg="Type of device or network connection is required "
            "while performing 'create' operation. Please specify 'type' as an argument."
        )


# Traceback (nTypeError)
failed: [sqlmaster1] (item={u'ip4': u'10.0.3.27/24', u'dev': u'ens224'}) => {"changed": false, "failed": true, "item": {"dev": "ens224", "ip4": "10.0.3.27/24"}, "module_stderr": "BECOME-SUCCESS-geacueqlzcdnmgrvmmrmkvmraxfijkly\r\n", "module_stdout": "/tmp/ansible_PpATO0/ansible_module_nmcli.py:493: PyGIWarning: NetworkManager was imported without specifying a version first. Use gi.require_version('NetworkManager', '1.0') before import to ensure that the right version gets loaded.\r\n  from gi.repository import NetworkManager, NMClient\r\n/tmp/ansible_PpATO0/ansible_module_nmcli.py:493: PyGIWarning: NMClient was imported without specifying a version first. Use gi.require_version('NMClient', '1.0') before import to ensure that the right version gets loaded.\r\n  from gi.repository import NetworkManager, NMClient\r\nTraceback (most recent call last):\r\n  File \"/tmp/ansible_PpATO0/ansible_module_nmcli.py\", line 1190, in <module>\r\n    main()\r\n  File \"/tmp/ansible_PpATO0/ansible_module_nmcli.py\", line 1134, in main\r\n    nmcli=Nmcli(module)\r\n  File \"/tmp/ansible_PpATO0/ansible_module_nmcli.py\", line 559, in __init__\r\n    self.dns4=' '.join(module.params['dns4'])\r\nTypeError\r\n", "msg": "MODULE FAILURE", "rc": 0}

# Fixed code
def create_connection(self):
    cmd = []
    if self.type == "team":
        if (self.dns4 is not None) or (self.dns6 is not None):
            cmd = self.create_connection_team()
            self.execute_command(cmd)
            cmd = self.modify_connection_team()
            self.execute_command(cmd)
            return self.up_connection()
        elif (self.dns4 is None) or (self.dns6 is None):
            cmd = self.create_connection_team()
    elif self.type == "team-slave":
        if self.mtu is not None:
            cmd = self.create_connection_team_slave()
            self.execute_command(cmd)
            cmd = self.modify_connection_team_slave()
            return self.execute_command(cmd)
        else:
            cmd = self.create_connection_team_slave()
    elif self.type == "bond":
        if (self.mtu is not None) or (self.dns4 is not None) or (self.dns6 is not None):
            cmd = self.create_connection_bond()
            self.execute_command(cmd)
            cmd = self.modify_connection_bond()
            self.execute_command(cmd)
            return self.up_connection()
        else:
            cmd = self.create_connection_bond()
    elif self.type == "bond-slave":
        cmd = self.create_connection_bond_slave()
    elif self.type == "ethernet":
        if (self.mtu is not None) or (self.dns4 is not None) or (self.dns6 is not None):
            cmd = self.create_connection_ethernet()
            self.execute_command(cmd)
            cmd = self.modify_connection_ethernet()
            self.execute_command(cmd)
            return self.up_connection()
        else:
            cmd = self.create_connection_ethernet()
    elif self.type == "bridge":
        cmd = self.create_connection_bridge()
    elif self.type == "bridge-slave":
        cmd = self.create_connection_bridge_slave()
    elif self.type == "vlan":
        cmd = self.create_connection_vlan()
    elif self.type == "generic":
        cmd = self.create_connection_ethernet(conn_type="generic")

    if cmd:
        return self.execute_command(cmd)
    else:
        self.module.fail_json(
            msg="Type of device or network connection is required "
            "while performing 'create' operation. Please specify 'type' as an argument."
        )