# Buggy code
def get_selinux_facts(self):
    if not HAVE_SELINUX:
        self.facts["selinux"] = False
        return
    self.facts["selinux"] = {}
    if not selinux.is_selinux_enabled():
        self.facts["selinux"]["status"] = "disabled"
    else:
        self.facts["selinux"]["status"] = "enabled"
        try:
            self.facts["selinux"]["policyvers"] = selinux.security_policyvers()
        except OSError:
            self.facts["selinux"]["policyvers"] = "unknown"
        try:
            (rc, configmode) = selinux.selinux_getenforcemode()
            if rc == 0:
                self.facts["selinux"]["config_mode"] = Facts.SELINUX_MODE_DICT.get(
                    configmode, "unknown"
                )
            else:
                self.facts["selinux"]["config_mode"] = "unknown"
        except OSError:
            self.facts["selinux"]["config_mode"] = "unknown"
        try:
            mode = selinux.security_getenforce()
            self.facts["selinux"]["mode"] = Facts.SELINUX_MODE_DICT.get(mode, "unknown")
        except OSError:
            self.facts["selinux"]["mode"] = "unknown"
        try:
            (rc, policytype) = selinux.selinux_getpolicytype()
            if rc == 0:
                self.facts["selinux"]["type"] = policytype
            else:
                self.facts["selinux"]["type"] = "unknown"
        except OSError:
            self.facts["selinux"]["type"] = "unknown"


# Traceback (nAttributeError)
$ ansible fc5 -m setup
fc51 | FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "",
"module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_PM_vSq/ansible_module_setup.py\", line 127, in ?\r\n    main()\r\n  File \"/tmp/ansible_PM_vSq/ansible_module_setup.py\", line 119, in main\r\n    data = get_all_facts(module)\r\n  File \"/tmp/ansible_PM_vSq/ansible_modlib.zip/ansible/module_utils/facts.py\", line 3179, in get_all_facts\r\n  File \"/tmp/ansible_PM_vSq/ansible_modlib.zip/ansible/module_utils/facts.py\", line 3123, in ansible_facts\r\n  File \"/tmp/ansible_PM_vSq/ansible_modlib.zip/ansible/module_utils/facts.py\", line 188, in __init__\r\n  File \"/tmp/ansible_PM_vSq/ansible_modlib.zip/ansible/module_utils/facts.py\", line 713, in get_selinux_facts\r\nAttributeError: 'module' object has no attribute 'selinux_getpolicytype'\r\n",
"msg": "MODULE FAILURE",
"parsed": false
}

# Fixed code
def get_selinux_facts(self):
    if not HAVE_SELINUX:
        self.facts["selinux"] = False
        return
    self.facts["selinux"] = {}
    if not selinux.is_selinux_enabled():
        self.facts["selinux"]["status"] = "disabled"
    else:
        self.facts["selinux"]["status"] = "enabled"
        try:
            self.facts["selinux"]["policyvers"] = selinux.security_policyvers()
        except (AttributeError, OSError):
            self.facts["selinux"]["policyvers"] = "unknown"
        try:
            (rc, configmode) = selinux.selinux_getenforcemode()
            if rc == 0:
                self.facts["selinux"]["config_mode"] = Facts.SELINUX_MODE_DICT.get(
                    configmode, "unknown"
                )
            else:
                self.facts["selinux"]["config_mode"] = "unknown"
        except (AttributeError, OSError):
            self.facts["selinux"]["config_mode"] = "unknown"
        try:
            mode = selinux.security_getenforce()
            self.facts["selinux"]["mode"] = Facts.SELINUX_MODE_DICT.get(mode, "unknown")
        except (AttributeError, OSError):
            self.facts["selinux"]["mode"] = "unknown"
        try:
            (rc, policytype) = selinux.selinux_getpolicytype()
            if rc == 0:
                self.facts["selinux"]["type"] = policytype
            else:
                self.facts["selinux"]["type"] = "unknown"
        except (AttributeError, OSError):
            self.facts["selinux"]["type"] = "unknown"