# Buggy code
def read(self):
    """
    Read in the pg_hba from the system
    """
    self.rules = {}
    self.comment = []
    # read the pg_hbafile
    try:
        file = open(self.pg_hba_file, "r")
        for line in file:
            line = line.strip()
            # uncomment
            if "#" in line:
                line, comment = line.split("#", 1)
                self.comment.append("#" + comment)
            try:
                self.add_rule(PgHbaRule(line=line))
            except PgHbaRuleError:
                pass
        file.close()
        self.unchanged()
    except IOError:
        pass


# Traceback (nTypeError)
(venv3.6) ubuntu@ubuntu-GB-BXi3-5010:~/ansible$ ansible-playbook ~/ansible/renderworker/postgres/ansible/setup_postgres_pg_hba.yml

PLAY [192.168.1.110] ************************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************************
ok: [192.168.1.110]

TASK [Grant postgres access from home] ******************************************************************************************************************************************************************************
fatal: [192.168.1.110]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 192.168.1.110 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/home/ubuntu/.ansible/tmp/ansible-tmp-1557891828.8283231-200022434247587/AnsiballZ_postgresql_pg_hba.py\", line 125, in <module>\r\n    _ansiballz_main()\r\n  File \"/home/ubuntu/.ansible/tmp/ansible-tmp-1557891828.8283231-200022434247587/AnsiballZ_postgresql_pg_hba.py\", line 117, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/ubuntu/.ansible/tmp/ansible-tmp-1557891828.8283231-200022434247587/AnsiballZ_postgresql_pg_hba.py\", line 51, in invoke_module\r\n    spec.loader.exec_module(module)\r\n  File \"<frozen importlib._bootstrap_external>\", line 678, in exec_module\r\n  File \"<frozen importlib._bootstrap>\", line 219, in _call_with_frames_removed\r\n  File \"/tmp/ansible_postgresql_pg_hba_payload_y9useyqu/__main__.py\", line 709, in <module>\r\n  File \"/tmp/ansible_postgresql_pg_hba_payload_y9useyqu/__main__.py\", line 696, in main\r\n  File \"/tmp/ansible_postgresql_pg_hba_payload_y9useyqu/__main__.py\", line 319, in write\r\n  File \"/tmp/ansible_postgresql_pg_hba_payload_y9useyqu/__main__.py\", line 390, in render\r\n  File \"/tmp/ansible_postgresql_pg_hba_payload_y9useyqu/__main__.py\", line 390, in <listcomp>\r\n  File \"/tmp/ansible_postgresql_pg_hba_payload_y9useyqu/__main__.py\", line 371, in get_rules\r\n  File \"/usr/lib/python3.6/ipaddress.py\", line 652, in __lt__\r\n    self, other))\r\nTypeError: 127.0.0.1/32 and ::1/128 are not of the same version\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

PLAY RECAP **********************************************************************************************************************************************************************************************************
192.168.1.110              : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

# Fixed code
def read(self):
    """
    Read in the pg_hba from the system
    """
    self.rules = {}
    self.comment = []
    # read the pg_hbafile
    try:
        file = open(self.pg_hba_file, "r")
        for line in file:
            line = line.strip()
            # uncomment
            if "#" in line:
                line, comment = line.split("#", 1)
                self.comment.append("#" + comment)
            try:
                self.add_rule(PgHbaRule(line=line, order=self.order))
            except PgHbaRuleError:
                pass
        file.close()
        self.unchanged()
    except IOError:
        pass