.. versionadded:: 0.17.0

    Append a rule to a chain

    name
        A user-defined name to call this rule by in another part of a state or
        formula. This should not be an actual rule.

    family
        Network family, ipv4 or ipv6.

    All other arguments are passed in with the same name as the long option
    that would normally be used for nftables, with one exception: `--state` is
    specified as `connstate` instead of `state` (not to be confused with
    `ctstate`).

def append(name, family='ipv4', **kwargs):
    '''
    .. versionadded:: 0.17.0

    Append a rule to a chain

    name
        A user-defined name to call this rule by in another part of a state or
        formula. This should not be an actual rule.

    family
        Network family, ipv4 or ipv6.

    All other arguments are passed in with the same name as the long option
    that would normally be used for nftables, with one exception: `--state` is
    specified as `connstate` instead of `state` (not to be confused with
    `ctstate`).
    '''
    ret = {'name': name,
           'changes': {},
           'result': None,
           'comment': ''}

    for ignore in _STATE_INTERNAL_KEYWORDS:
        if ignore in kwargs:
            del kwargs[ignore]
    res = __salt__['nftables.build_rule'](family=family, **kwargs)
    if not res['result']:
        return res
    rule = res['rule']

    res = __salt__['nftables.build_rule'](full=True, family=family, command='add', **kwargs)
    if not res['result']:
        return res
    command = res['rule']

    res = __salt__['nftables.check'](kwargs['table'],
                                     kwargs['chain'],
                                     rule,
                                     family)
    if res['result']:
        ret['result'] = True
        ret['comment'] = 'nftables rule for {0} already set ({1}) for {2}'.format(
            name,
            command.strip(),
            family)
        return ret
    if 'test' in __opts__ and __opts__['test']:
        ret['comment'] = 'nftables rule for {0} needs to be set ({1}) for {2}'.format(
            name,
            command.strip(),
            family)
        return ret
    res = __salt__['nftables.append'](kwargs['table'],
                                      kwargs['chain'],
                                      rule,
                                      family)
    if res['result']:
        ret['changes'] = {'locale': name}
        ret['result'] = True
        ret['comment'] = 'Set nftables rule for {0} to: {1} for {2}'.format(
            name,
            command.strip(),
            family)
        if 'save' in kwargs:
            if kwargs['save']:
                __salt__['nftables.save'](filename=None, family=family)
                ret['comment'] = ('Set and Saved nftables rule for {0} to: '
                                  '{1} for {2}'.format(name, command.strip(), family))
        return ret
    else:
        ret['result'] = False
        ret['comment'] = ('Failed to set nftables rule for {0}.\n'
                          'Attempted rule was {1} for {2}.\n'
                          '{3}').format(
                                  name,
                                  command.strip(), family, res['comment'])
        return ret