# Buggy code
def set_(name, value, **kwargs):
    """
    Set system rc configuration variables

    CLI Example:

     .. code-block:: bash

         salt '*' sysrc.set name=sshd_flags value="-p 2222"
    """

    cmd = "sysrc -v"

    if "file" in kwargs:
        cmd += " -f " + kwargs["file"]

    if "jail" in kwargs:
        cmd += " -j " + kwargs["jail"]

    # This is here because the YAML parser likes to convert the string literals
    # YES, NO, Yes, No, True, False, etc. to boolean types.  However, in this case,
    # we will check to see if that happened and replace it with "YES" or "NO" because
    # those items are accepted in sysrc.
    if type(value) == bool:
        if value:
            value = "YES"
        else:
            value = "NO"

    # This is here for the same reason, except for numbers
    if type(value) == int:
        value = str(value)

    cmd += " " + name + '="' + value + '"'

    sysrcs = __salt__["cmd.run"](cmd)

    ret = {}
    for sysrc in sysrcs.split("\n"):
        rcfile = sysrc.split(": ")[0]
        var = sysrc.split(": ")[1]
        oldval = sysrc.split(": ")[2].split(" -> ")[0]
        newval = sysrc.split(": ")[2].split(" -> ")[1]
        if rcfile not in ret:
            ret[rcfile] = {}
        ret[rcfile][var] = newval
    return ret


# Traceback (IndexError)
Traceback (most recent call last):
File "/usr/local/bin/salt-call", line 11, in <module>
load_entry_point('salt==2016.11.5', 'console_scripts', 'salt-call')()
File "/usr/local/lib/python2.7/site-packages/salt/scripts.py", line 379, in salt_call
client.run()
File "/usr/local/lib/python2.7/site-packages/salt/cli/call.py", line 58, in run
caller.run()
File "/usr/local/lib/python2.7/site-packages/salt/cli/caller.py", line 134, in run
ret = self.call()
File "/usr/local/lib/python2.7/site-packages/salt/cli/caller.py", line 197, in call
ret['return'] = func(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/salt/modules/sysrc.py", line 109, in set_
newval = sysrc.split(': ')[2].split(" -> ")[1]
IndexError: list index out of range

# Fixed code
def set_(name, value, **kwargs):
    """
    Set system rc configuration variables

    CLI Example:

     .. code-block:: bash

         salt '*' sysrc.set name=sshd_flags value="-p 2222"
    """

    cmd = "sysrc -v"

    if "file" in kwargs:
        cmd += " -f " + kwargs["file"]

    if "jail" in kwargs:
        cmd += " -j " + kwargs["jail"]

    # This is here because the YAML parser likes to convert the string literals
    # YES, NO, Yes, No, True, False, etc. to boolean types.  However, in this case,
    # we will check to see if that happened and replace it with "YES" or "NO" because
    # those items are accepted in sysrc.
    if type(value) == bool:
        if value:
            value = "YES"
        else:
            value = "NO"

    # This is here for the same reason, except for numbers
    if type(value) == int:
        value = str(value)

    cmd += " " + name + '="' + value + '"'

    sysrcs = __salt__["cmd.run"](cmd)

    ret = {}
    for sysrc in sysrcs.split("\n"):
        rcfile = sysrc.split(": ")[0]
        var = sysrc.split(": ")[1]
        oldval = sysrc.split(": ")[2].strip().split("->")[0]
        newval = sysrc.split(": ")[2].strip().split("->")[1]
        if rcfile not in ret:
            ret[rcfile] = {}
        ret[rcfile][var] = newval
    return ret