# Buggy code
def register_instances(
    name, instances, region=None, key=None, keyid=None, profile=None
):
    """
    Add instance/s to load balancer

    .. versionadded:: 2015.8.0

    .. code-block:: yaml

        add-instances:
          boto_elb.register_instances:
            - name: myloadbalancer
            - instances:
              - instance-id1
              - instance-id2
    """
    ret = {"name": name, "result": None, "comment": "", "changes": {}}
    lb = __salt__["boto_elb.exists"](name, region, key, keyid, profile)
    if lb:
        health = __salt__["boto_elb.get_instance_health"](
            name, region, key, keyid, profile
        )
        nodes = []
        new = []
        for value in health:
            nodes.append(value["instance_id"])
        for value in instances:
            if value not in nodes:
                new.append(value)
        if len(new) == 0:
            ret["comment"] = "Instance/s {0} already exist.".format(
                str(instances).strip("[]")
            )
            ret["result"] = True
        else:
            if __opts__["test"]:
                ret["comment"] = "ELB {0} is set to register : {1}.".format(name, new)
                ret["result"] = None
                return ret
            state = __salt__["boto_elb.register_instances"](
                name, instances, region, key, keyid, profile
            )
            if state:
                ret["comment"] = "Load Balancer {0} has been changed".format(name)
                ret["changes"]["old"] = "\n".join(nodes)
                new = set().union(nodes, instances)
                ret["changes"]["new"] = "\n".join(list(new))
                ret["result"] = True
            else:
                ret["comment"] = "Load balancer {0} failed to add instances".format(
                    name
                )
                ret["result"] = False
    else:
        ret["comment"] = "Could not find lb {0}".format(name)
    return ret


# Traceback (ParserError)
li1105-12 ~ master # salt jmoney-master state.show_top
jmoney-master:
The minion function caused an exception: Traceback (most recent call last):
File "/root/salt/salt/minion.py", line 1173, in _thread_return
return_data = func(*args, **kwargs)
File "/root/salt/salt/modules/state.py", line 1045, in show_top
top_ = st_.get_top()
File "/root/salt/salt/state.py", line 2436, in get_top
tops = self.get_tops()
File "/root/salt/salt/state.py", line 2313, in get_tops
saltenv=saltenv
File "/root/salt/salt/template.py", line 79, in compile_template
ret = render(input_data, saltenv, sls, **render_kwargs)
File "/root/salt/salt/renderers/yaml.py", line 50, in render
data = load(yaml_data, Loader=get_yaml_loader(argline))
File "/usr/lib/python2.7/dist-packages/yaml/__init__.py", line 71, in load
return loader.get_single_data()
File "/usr/lib/python2.7/dist-packages/yaml/constructor.py", line 37, in get_single_data
node = self.get_single_node()
File "/usr/lib/python2.7/dist-packages/yaml/composer.py", line 36, in get_single_node
document = self.compose_document()
File "/usr/lib/python2.7/dist-packages/yaml/composer.py", line 55, in compose_document
node = self.compose_node(None, None)
File "/usr/lib/python2.7/dist-packages/yaml/composer.py", line 84, in compose_node
node = self.compose_mapping_node(anchor)
File "/usr/lib/python2.7/dist-packages/yaml/composer.py", line 127, in compose_mapping_node
while not self.check_event(MappingEndEvent):
File "/usr/lib/python2.7/dist-packages/yaml/parser.py", line 98, in check_event
self.current_event = self.state()
File "/usr/lib/python2.7/dist-packages/yaml/parser.py", line 439, in parse_block_mapping_key
"expected <block end>, but found %r" % token.id, token.start_mark)
ParserError: while parsing a block mapping
in "<unicode string>", line 1, column 1:
base:
^
expected <block end>, but found '<block sequence start>'
in "<unicode string>", line 3, column 5:
- state1
^

# Fixed code
def register_instances(
    name, instances, region=None, key=None, keyid=None, profile=None
):
    """
    Add EC2 instance(s) to an Elastic Load Balancer. Removing an instance from
    the ``instances`` list does not remove it from the ELB.

    name
        The name of the Elastic Load Balancer to add EC2 instances to.

    instances
        A list of EC2 instance IDs that this Elastic Load Balancer should
        distribute traffic to. This state will only ever append new instances
        to the ELB. EC2 instances already associated with this ELB will not be
        removed if they are not in the ``instances`` list.

    .. versionadded:: 2015.8.0

    .. code-block:: yaml

        add-instances:
          boto_elb.register_instances:
            - name: myloadbalancer
            - instances:
              - instance-id1
              - instance-id2
    """
    ret = {"name": name, "result": None, "comment": "", "changes": {}}
    lb = __salt__["boto_elb.exists"](name, region, key, keyid, profile)
    if lb:
        health = __salt__["boto_elb.get_instance_health"](
            name, region, key, keyid, profile
        )
        nodes = []
        new = []
        for value in health:
            nodes.append(value["instance_id"])
        for value in instances:
            if value not in nodes:
                new.append(value)
        if len(new) == 0:
            ret["comment"] = "Instance/s {0} already exist.".format(
                str(instances).strip("[]")
            )
            ret["result"] = True
        else:
            if __opts__["test"]:
                ret["comment"] = "ELB {0} is set to register : {1}.".format(name, new)
                ret["result"] = None
                return ret
            state = __salt__["boto_elb.register_instances"](
                name, instances, region, key, keyid, profile
            )
            if state:
                ret["comment"] = "Load Balancer {0} has been changed".format(name)
                ret["changes"]["old"] = "\n".join(nodes)
                new = set().union(nodes, instances)
                ret["changes"]["new"] = "\n".join(list(new))
                ret["result"] = True
            else:
                ret["comment"] = "Load balancer {0} failed to add instances".format(
                    name
                )
                ret["result"] = False
    else:
        ret["comment"] = "Could not find lb {0}".format(name)
    return ret