# Buggy code
def peered(name):
    """
    Check if node is peered.

    name
        The remote host with which to peer.

    .. code-block:: yaml

        peer-cluster:
          glusterfs.peered:
            - name: two

        peer-clusters:
          glusterfs.peered:
            - names:
              - one
              - two
              - three
              - four
    """
    ret = {"name": name, "changes": {}, "comment": "", "result": False}

    peers = __salt__["glusterfs.list_peers"]()

    if peers:
        if name in peers:
            ret["result"] = True
            ret["comment"] = "Host {0} already peered".format(name)
            return ret
        elif __opts__["test"]:
            ret["comment"] = "Peer {0} will be added.".format(name)
            ret["result"] = None
            return ret

    if suc.check_name(name, "a-zA-Z0-9._-"):
        ret["comment"] = "Invalid characters in peer name."
        ret["result"] = False
        return ret

    if "output" in __salt__["glusterfs.peer"](name):
        ret["comment"] = __salt__["glusterfs.peer"](name)["output"]
    else:
        ret["comment"] = ""

    newpeers = __salt__["glusterfs.list_peers"]()
    # if newpeers was null, we know something didn't work.
    if newpeers and name in newpeers:
        ret["result"] = True
        ret["changes"] = {"new": newpeers, "old": peers}
    # In case the hostname doesn't have any periods in it
    elif name == socket.gethostname():
        ret["result"] = True
        return ret
    # In case they have a hostname like "example.com"
    elif name == socket.gethostname().split(".")[0]:
        ret["result"] = True
        return ret
    elif "on localhost not needed" in ret["comment"]:
        ret["result"] = True
        ret["comment"] = "Peering with localhost is not needed"
    else:
        ret["result"] = False
    return ret


# Traceback (TypeError)
2016-02-05 10:07:01,763 [salt.state       ][INFO    ][25335] Running state [10.129.2.33] at time 10:07:01.762913
2016-02-05 10:07:01,763 [salt.state       ][INFO    ][25335] Executing state glusterfs.peered for 10.129.2.33 <-- This is the primary glusterfs host
2016-02-05 10:07:01,764 [salt.loaded.int.module.cmdmod][INFO    ][25335] Executing command 'gluster --xml --mode=script' in directory '/root'
2016-02-05 10:07:01,871 [salt.loaded.int.module.cmdmod][INFO    ][25335] Executing command 'gluster --xml --mode=script' in directory '/root'
2016-02-05 10:07:01,964 [salt.loaded.int.module.cmdmod][INFO    ][25335] Executing command 'gluster --xml --mode=script' in directory '/root'
2016-02-05 10:07:02,057 [salt.state       ][ERROR   ][25335] An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1624, in call
**cdata['kwargs'])
File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1491, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/salt/states/glusterfs.py", line 83, in peered
elif 'on localhost not needed' in ret['comment']:
TypeError: argument of type 'bool' is not iterable

# Fixed code
def peered(name):
    """
    Check if node is peered.

    name
        The remote host with which to peer.

    .. code-block:: yaml

        peer-cluster:
          glusterfs.peered:
            - name: two

        peer-clusters:
          glusterfs.peered:
            - names:
              - one
              - two
              - three
              - four
    """
    ret = {"name": name, "changes": {}, "comment": "", "result": False}

    try:
        suc.check_name(name, "a-zA-Z0-9._-")
    except SaltCloudException as e:
        ret["comment"] = "Invalid characters in peer name."
        ret["result"] = False
        return ret

    peers = __salt__["glusterfs.list_peers"]()

    if peers:
        if name in peers or any([name in peers[x] for x in peers]):
            ret["result"] = True
            ret["comment"] = "Host {0} already peered".format(name)
            return ret

    result = __salt__["glusterfs.peer"](name)
    ret["comment"] = ""
    if "exitval" in result:
        if int(result["exitval"]) <= len(RESULT_CODES):
            ret["comment"] = RESULT_CODES[int(result["exitval"])].format(name)
        else:
            if "comment" in result:
                ret["comment"] = result["comment"]

    newpeers = __salt__["glusterfs.list_peers"]()
    # if newpeers was null, we know something didn't work.
    if newpeers and name in newpeers or any([name in newpeers[x] for x in newpeers]):
        ret["result"] = True
        ret["changes"] = {"new": newpeers, "old": peers}
    # In case the hostname doesn't have any periods in it
    elif name == socket.gethostname():
        ret["result"] = True
        return ret
    # In case they have a hostname like "example.com"
    elif name == socket.gethostname().split(".")[0]:
        ret["result"] = True
        return ret
    elif "on localhost not needed" in ret["comment"]:
        ret["result"] = True
        ret["comment"] = "Peering with localhost is not needed"
    else:
        ret["result"] = False
    return ret