Removes the previous configuration file, then creates a new one and writes
    the name line. This function is intended to be used from states.

    If :mod:`syslog_ng.set_config_file
    <salt.modules.syslog_ng.set_config_file>`, is called before, this function
    will use the set config file.

    CLI Example:

    .. code-block:: bash

        salt '*' syslog_ng.write_version name="3.6"

def write_version(name):
    '''
    Removes the previous configuration file, then creates a new one and writes
    the name line. This function is intended to be used from states.

    If :mod:`syslog_ng.set_config_file
    <salt.modules.syslog_ng.set_config_file>`, is called before, this function
    will use the set config file.

    CLI Example:

    .. code-block:: bash

        salt '*' syslog_ng.write_version name="3.6"

    '''
    line = '@version: {0}'.format(name)
    try:
        if os.path.exists(__SYSLOG_NG_CONFIG_FILE):
            log.debug(
                'Removing previous configuration file: %s',
                __SYSLOG_NG_CONFIG_FILE
            )
            os.remove(__SYSLOG_NG_CONFIG_FILE)
            log.debug('Configuration file successfully removed')

        header = _format_generated_config_header()
        _write_config(config=header, newlines=1)
        _write_config(config=line, newlines=2)

        return _format_state_result(name, result=True)
    except OSError as err:
        log.error(
            'Failed to remove previous configuration file \'%s\': %s',
            __SYSLOG_NG_CONFIG_FILE, err
        )
        return _format_state_result(name, result=False)