# Buggy code
def ip_fqdn():
    """
    Return ip address and FQDN grains
    """
    if salt.utils.is_proxy():
        return {}

    ret = {}
    ret["ipv4"] = salt.utils.network.ip_addrs(include_loopback=True)
    _fqdn = hostname()["fqdn"]
    sockets = [(socket.AF_INET, "4")]

    if __opts__.get("ipv6", True):
        ret["ipv6"] = salt.utils.network.ip_addrs6(include_loopback=True)
        sockets.append((socket.AF_INET6, "6"))

    for socket_type, ipv_num in sockets:
        key = "fqdn_ip" + ipv_num
        if not ret["ipv" + ipv_num]:
            ret[key] = []
        else:
            try:
                info = socket.getaddrinfo(_fqdn, None, socket_type)
                ret[key] = list(set(item[4][0] for item in info))
            except socket.error:
                if __opts__["__role"] == "master":
                    log.warning(
                        'Unable to find IPv{0} record for "{1}" causing a 10 second timeout when rendering grains. '
                        "Set the dns or /etc/hosts for IPv{0} to clear this.".format(
                            ipv_num, _fqdn
                        )
                    )
                ret[key] = []

    return ret


# Traceback (TypeError)
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
TypeError: can't serialize IPv6Address('fd00::ca0e:14ff:fea8:2344')
Traceback (most recent call last):
File "/usr/lib/python-exec/python2.7/salt-call", line 11, in <module>
salt_call()
File "/usr/lib64/python2.7/site-packages/salt/scripts.py", line 379, in salt_call
client.run()
File "/usr/lib64/python2.7/site-packages/salt/cli/call.py", line 48, in run
caller = salt.cli.caller.Caller.factory(self.config)
File "/usr/lib64/python2.7/site-packages/salt/cli/caller.py", line 79, in factory
return ZeroMQCaller(opts, **kwargs)
File "/usr/lib64/python2.7/site-packages/salt/cli/caller.py", line 274, in __init__
super(ZeroMQCaller, self).__init__(opts)
File "/usr/lib64/python2.7/site-packages/salt/cli/caller.py", line 102, in __init__
self.minion = salt.minion.SMinion(opts)
File "/usr/lib64/python2.7/site-packages/salt/minion.py", line 669, in __init__
self.gen_modules(initial_load=True)
File "/usr/lib64/python2.7/site-packages/salt/minion.py", line 717, in gen_modules
pillarenv=self.opts.get('pillarenv'),
File "/usr/lib64/python2.7/site-packages/salt/pillar/__init__.py", line 162, in compile_pillar
dictkey='pillar',
File "/usr/lib64/python2.7/site-packages/salt/utils/async.py", line 75, in wrap
ret = self._block_future(ret)
File "/usr/lib64/python2.7/site-packages/salt/utils/async.py", line 85, in _block_future
return future.result()
File "/usr/lib64/python2.7/site-packages/tornado/concurrent.py", line 237, in result
raise_exc_info(self._exc_info)
File "/usr/lib64/python2.7/site-packages/tornado/gen.py", line 285, in wrapper
yielded = next(result)
File "/usr/lib64/python2.7/site-packages/salt/transport/zeromq.py", line 190, in crypted_transfer_decode_dictentry
self._package_load(self.auth.crypticle.dumps(load)),
File "/usr/lib64/python2.7/site-packages/salt/crypt.py", line 1267, in dumps
return self.encrypt(self.PICKLE_PAD + self.serial.dumps(obj))
File "/usr/lib64/python2.7/site-packages/salt/payload.py", line 181, in dumps
return msgpack.dumps(msg, use_bin_type=use_bin_type)
File "/usr/lib64/python2.7/site-packages/msgpack/__init__.py", line 47, in packb
return Packer(**kwargs).pack(o)
File "msgpack/_packer.pyx", line 231, in msgpack._packer.Packer.pack (msgpack/_packer.cpp:3661)
File "msgpack/_packer.pyx", line 233, in msgpack._packer.Packer.pack (msgpack/_packer.cpp:3503)
File "msgpack/_packer.pyx", line 192, in msgpack._packer.Packer._pack (msgpack/_packer.cpp:2657)
File "msgpack/_packer.pyx", line 192, in msgpack._packer.Packer._pack (msgpack/_packer.cpp:2657)
File "msgpack/_packer.pyx", line 192, in msgpack._packer.Packer._pack (msgpack/_packer.cpp:2657)
File "msgpack/_packer.pyx", line 221, in msgpack._packer.Packer._pack (msgpack/_packer.cpp:3230)
File "msgpack/_packer.pyx", line 228, in msgpack._packer.Packer._pack (msgpack/_packer.cpp:3382)
TypeError: can't serialize IPv6Address('fd00::ca0e:14ff:fea8:2344')

# Fixed code
def ip_fqdn():
    """
    Return ip address and FQDN grains
    """
    if salt.utils.is_proxy():
        return {}

    ret = {}
    ret["ipv4"] = salt.utils.network.ip_addrs(include_loopback=True)
    ret["ipv6"] = salt.utils.network.ip_addrs6(include_loopback=True)

    _fqdn = hostname()["fqdn"]
    for socket_type, ipv_num in ((socket.AF_INET, "4"), (socket.AF_INET6, "6")):
        key = "fqdn_ip" + ipv_num
        if not ret["ipv" + ipv_num]:
            ret[key] = []
        else:
            try:
                info = socket.getaddrinfo(_fqdn, None, socket_type)
                ret[key] = list(set(item[4][0] for item in info))
            except socket.error:
                if __opts__["__role"] == "master":
                    log.warning(
                        'Unable to find IPv{0} record for "{1}" causing a 10 second timeout when rendering grains. '
                        "Set the dns or /etc/hosts for IPv{0} to clear this.".format(
                            ipv_num, _fqdn
                        )
                    )
                ret[key] = []

    return ret