# Buggy code
def main():
    argument_spec = openstack_full_argument_spec(
        name=dict(required=True),
        shared=dict(default=False, type="bool"),
        admin_state_up=dict(default=True, type="bool"),
        external=dict(default=False, type="bool"),
        provider_physical_network=dict(required=False),
        provider_network_type=dict(required=False),
        provider_segmentation_id=dict(required=False, type="int"),
        state=dict(default="present", choices=["absent", "present"]),
        project=dict(default=None),
        port_security_enabled=dict(type="bool"),
        mtu=dict(required=False, type="int"),
        dns_domain=dict(required=False),
    )

    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec, **module_kwargs)

    state = module.params["state"]
    name = module.params["name"]
    shared = module.params["shared"]
    admin_state_up = module.params["admin_state_up"]
    external = module.params["external"]
    provider_physical_network = module.params["provider_physical_network"]
    provider_network_type = module.params["provider_network_type"]
    provider_segmentation_id = module.params["provider_segmentation_id"]
    project = module.params.get("project")
    port_security_enabled = module.params.get("port_security_enabled")
    mtu = module.params.get("mtu")
    dns_domain = module.params.get("dns_domain")

    sdk, cloud = openstack_cloud_from_module(module)
    try:
        if project is not None:
            proj = cloud.get_project(project)
            if proj is None:
                module.fail_json(msg="Project %s could not be found" % project)
            project_id = proj["id"]
            filters = {"tenant_id": project_id}
        else:
            project_id = None
            filters = None
        net = cloud.get_network(name, filters=filters)

        if state == "present":
            if not net:
                provider = {}
                if provider_physical_network:
                    provider["physical_network"] = provider_physical_network
                if provider_network_type:
                    provider["network_type"] = provider_network_type
                if provider_segmentation_id:
                    provider["segmentation_id"] = provider_segmentation_id

                if project_id is not None:
                    net = cloud.create_network(
                        name,
                        shared,
                        admin_state_up,
                        external,
                        provider,
                        project_id,
                        port_security_enabled=port_security_enabled,
                        mtu_size=mtu,
                        dns_domain=dns_domain,
                    )
                else:
                    net = cloud.create_network(
                        name,
                        shared,
                        admin_state_up,
                        external,
                        provider,
                        port_security_enabled=port_security_enabled,
                        mtu_size=mtu,
                        dns_domain=dns_domain,
                    )
                changed = True
            else:
                changed = False
            module.exit_json(changed=changed, network=net, id=net["id"])

        elif state == "absent":
            if not net:
                module.exit_json(changed=False)
            else:
                cloud.delete_network(name)
                module.exit_json(changed=True)

    except sdk.exceptions.OpenStackCloudException as e:
        module.fail_json(msg=str(e))


# Traceback (TypeError)
The full traceback is:
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/python2.7/runpy.py", line 192, in run_module
fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/tmp/ansible_os_network_payload_rQfk3D/ansible_os_network_payload.zip/ansible/modules/cloud/openstack/os_network.py", line 255, in <module>
File "/tmp/ansible_os_network_payload_rQfk3D/ansible_os_network_payload.zip/ansible/modules/cloud/openstack/os_network.py", line 237, in main
TypeError: create_network() got an unexpected keyword argument 'dns_domain'

fatal: [localhost]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (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/python2.7/runpy.py\", line 192, in run_module\n    fname, loader, pkg_name)\n  File \"/usr/lib/python2.7/runpy.py\", line 72, in _run_code\n    exec code in run_globals\n  File \"/tmp/ansible_os_network_payload_rQfk3D/ansible_os_network_payload.zip/ansible/modules/cloud/openstack/os_network.py\", line 255, in <module>\n  File \"/tmp/ansible_os_network_payload_rQfk3D/ansible_os_network_payload.zip/ansible/modules/cloud/openstack/os_network.py\", line 237, in main\nTypeError: create_network() got an unexpected keyword argument 'dns_domain'\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}

# Fixed code
def main():
    argument_spec = openstack_full_argument_spec(
        name=dict(required=True),
        shared=dict(default=False, type="bool"),
        admin_state_up=dict(default=True, type="bool"),
        external=dict(default=False, type="bool"),
        provider_physical_network=dict(required=False),
        provider_network_type=dict(required=False),
        provider_segmentation_id=dict(required=False, type="int"),
        state=dict(default="present", choices=["absent", "present"]),
        project=dict(default=None),
        port_security_enabled=dict(type="bool"),
        mtu=dict(required=False, type="int"),
        dns_domain=dict(required=False),
    )

    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec, **module_kwargs)

    state = module.params["state"]
    name = module.params["name"]
    shared = module.params["shared"]
    admin_state_up = module.params["admin_state_up"]
    external = module.params["external"]
    provider_physical_network = module.params["provider_physical_network"]
    provider_network_type = module.params["provider_network_type"]
    provider_segmentation_id = module.params["provider_segmentation_id"]
    project = module.params["project"]

    net_create_kwargs = {
        "port_security_enabled": module.params["port_security_enabled"],
        "mtu_size": module.params["mtu"],
    }

    if module.params["dns_domain"] is not None:
        sdk, cloud = openstack_cloud_from_module(module, min_version="0.29.0")
        net_create_kwargs["dns_domain"] = module.params["dns_domain"]
    else:
        sdk, cloud = openstack_cloud_from_module(module)
    try:
        if project is not None:
            proj = cloud.get_project(project)
            if proj is None:
                module.fail_json(msg="Project %s could not be found" % project)
            project_id = proj["id"]
            filters = {"tenant_id": project_id}
        else:
            project_id = None
            filters = None
        net = cloud.get_network(name, filters=filters)

        if state == "present":
            if not net:
                provider = {}
                if provider_physical_network:
                    provider["physical_network"] = provider_physical_network
                if provider_network_type:
                    provider["network_type"] = provider_network_type
                if provider_segmentation_id:
                    provider["segmentation_id"] = provider_segmentation_id

                if project_id is not None:
                    net = cloud.create_network(
                        name,
                        shared,
                        admin_state_up,
                        external,
                        provider,
                        project_id,
                        **net_create_kwargs,
                    )
                else:
                    net = cloud.create_network(
                        name,
                        shared,
                        admin_state_up,
                        external,
                        provider,
                        **net_create_kwargs,
                    )
                changed = True
            else:
                changed = False
            module.exit_json(changed=changed, network=net, id=net["id"])

        elif state == "absent":
            if not net:
                module.exit_json(changed=False)
            else:
                cloud.delete_network(name)
                module.exit_json(changed=True)

    except sdk.exceptions.OpenStackCloudException as e:
        module.fail_json(msg=str(e))