<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def generate_configfile(cfg_file,defaults=defaults):
 """ Write a new nago.ini config file from the defaults. Arguments: cfg_file -- File that is written to like /etc/nago/nago.ini defaults -- Dictionary with default values to use """

    # Create a directory if needed and write an empty file
    _mkdir_for_config(cfg_file=cfg_file)
    with open(cfg_file, 'w') as f:
        f.write('')
    for section in defaults.keys():
        set_option(section, cfg_file=cfg_file, **defaults[section])