# Buggy code
def _mod_config(self):
    """Modifies Apache config files to include challenge vhosts.

    Result: Apache config includes virtual servers for issued challs

    :returns: All TLS-SNI-01 addresses used
    :rtype: set

    """
    addrs = set()
    config_text = "<IfModule mod_ssl.c>\n"

    for achall in self.achalls:
        achall_addrs = self._get_addrs(achall)
        addrs.update(achall_addrs)

        config_text += self._get_config_text(achall, achall_addrs)

    config_text += "</IfModule>\n"

    self._conf_include_check(self.configurator.parser.loc["default"])
    self.configurator.reverter.register_file_creation(True, self.challenge_conf)

    logger.debug("writing a config file with text:\n %s", config_text)
    with open(self.challenge_conf, "w") as new_conf:
        new_conf.write(config_text)

    return addrs


# Traceback (PluginError)
Cannot find a cert or key directive in /files/etc/apache2/sites-available/default-ssl.conf/IfModule/VirtualHost. VirtualHost was not modified
Encountered exception:
Traceback (most recent call last):
File "/home/bmw/src/certbot/certbot/client.py", line 439, in deploy_certificate
fullchain_path=fullchain_path)
File "/home/bmw/src/certbot/certbot-apache/certbot_apache/configurator.py", line 269, in deploy_cert
"Unable to find cert and/or key directives")
PluginError: Unable to find cert and/or key directives

Calling registered functions
Reporting to user: Unable to install the certificate
Exiting abnormally:
Traceback (most recent call last):
File "/usr/local/bin/certbot", line 11, in <module>
load_entry_point('certbot', 'console_scripts', 'certbot')()
File "/home/bmw/src/certbot/certbot/main.py", line 743, in main
return config.func(config, plugins)
File "/home/bmw/src/certbot/certbot/main.py", line 604, in run
_install_cert(config, le_client, domains, new_lineage)
File "/home/bmw/src/certbot/certbot/main.py", line 469, in _install_cert
path_provider.cert_path, path_provider.chain_path, path_provider.fullchain_path)
File "/home/bmw/src/certbot/certbot/client.py", line 439, in deploy_certificate
fullchain_path=fullchain_path)
File "/home/bmw/src/certbot/certbot-apache/certbot_apache/configurator.py", line 269, in deploy_cert
"Unable to find cert and/or key directives")
PluginError: Unable to find cert and/or key directives

# Fixed code
def _mod_config(self):
    """Modifies Apache config files to include challenge vhosts.

    Result: Apache config includes virtual servers for issued challs

    :returns: All TLS-SNI-01 addresses used
    :rtype: set

    """
    addrs = set()
    config_text = "<IfModule mod_ssl.c>\n"

    for achall in self.achalls:
        achall_addrs = self._get_addrs(achall)
        addrs.update(achall_addrs)

        config_text += self._get_config_text(achall, achall_addrs)

    config_text += "</IfModule>\n"

    self.configurator.parser.add_include(
        self.configurator.parser.loc["default"], self.challenge_conf
    )
    self.configurator.reverter.register_file_creation(True, self.challenge_conf)

    logger.debug("writing a config file with text:\n %s", config_text)
    with open(self.challenge_conf, "w") as new_conf:
        new_conf.write(config_text)

    return addrs